]> git.agnieray.net Git - galette.git/commitdiff
Typehint DynamicFields, add tests
authorJohan Cwiklinski <johan@x-tnd.be>
Thu, 11 Nov 2021 21:53:05 +0000 (22:53 +0100)
committerJohan Cwiklinski <johan@x-tnd.be>
Fri, 12 Nov 2021 02:05:00 +0000 (03:05 +0100)
18 files changed:
galette/includes/routes/management.routes.php
galette/lib/Galette/Controllers/Crud/DynamicFieldsController.php
galette/lib/Galette/DynamicFields/Boolean.php
galette/lib/Galette/DynamicFields/Choice.php
galette/lib/Galette/DynamicFields/Date.php
galette/lib/Galette/DynamicFields/DynamicField.php
galette/lib/Galette/DynamicFields/File.php
galette/lib/Galette/DynamicFields/Line.php
galette/lib/Galette/DynamicFields/Separator.php
galette/lib/Galette/DynamicFields/Text.php
tests/Galette/DynamicFields/tests/units/Boolean.php
tests/Galette/DynamicFields/tests/units/Choice.php [new file with mode: 0644]
tests/Galette/DynamicFields/tests/units/Date.php [new file with mode: 0644]
tests/Galette/DynamicFields/tests/units/DynamicField.php [new file with mode: 0644]
tests/Galette/DynamicFields/tests/units/File.php [new file with mode: 0644]
tests/Galette/DynamicFields/tests/units/Line.php [new file with mode: 0644]
tests/Galette/DynamicFields/tests/units/Separator.php
tests/Galette/DynamicFields/tests/units/Text.php [new file with mode: 0644]

index 74161d603a74ea61c668dc32a26da195c61f3e0c..24120be465fab846478627121b94d3dbe298e1e2 100644 (file)
@@ -43,6 +43,7 @@ use Galette\Controllers\PdfController;
 use Galette\Controllers\CsvController;
 use Galette\Controllers\AdminToolsController;
 use Galette\Controllers\TextController;
+use Galette\DynamicFields\DynamicField;
 
 //galette's dashboard
 $app->get(
@@ -338,7 +339,7 @@ $app->get(
 
 $app->get(
     '/fields/dynamic/move/{form_name:adh|contrib|trans}' .
-        '/{direction:up|down}/{id:\d+}',
+        '/{direction:' . DynamicField::MOVE_UP . '|' . DynamicField::MOVE_DOWN . '}/{id:\d+}',
     [Crud\DynamicFieldsController::class, 'move']
 )->setName('moveDynamicField')->add($authenticate);
 
index 73734c29f61d00e6b384f91fde99e774466299a8..1f60a34b5911b88758cebadbabd6064e71202271 100644 (file)
@@ -491,14 +491,14 @@ class DynamicFieldsController extends CrudController
      * @param Response $response  PSR Response
      * @param integer  $id        Field id
      * @param string   $form_name Form name
-     * @param string   $direction Either 'up' or 'down'
+     * @param string   $direction One of DynamicField::MOVE_*
      *
      * @return Response
      */
     public function move(
         Request $request,
         Response $response,
-        int $id = null,
+        int $id,
         string $form_name,
         string $direction
     ): Response {
index b61541511e5074ad62a351bcd03a13eca8b5b73d..9ca9a10d10b6d4a325c3b045c3767ac98e08ec77 100644 (file)
@@ -58,7 +58,7 @@ class Boolean extends DynamicField
      * Default constructor
      *
      * @param Db  $zdb Database instance
-     * @param int $id  Optionnal field id to load data
+     * @param int $id  Optional field id to load data
      */
     public function __construct(Db $zdb, $id = null)
     {
@@ -71,7 +71,7 @@ class Boolean extends DynamicField
      *
      * @return integer
      */
-    public function getType()
+    public function getType(): int
     {
         return self::BOOLEAN;
     }
index ec360be1e0fcb23b479d1e2e9f180f28d148d533..933cff2456072ca1a752eb1f71970ebd30194862 100644 (file)
@@ -58,7 +58,7 @@ class Choice extends DynamicField
      * Default constructor
      *
      * @param Db  $zdb Database instance
-     * @param int $id  Optionnal field id to load data
+     * @param int $id  Optional field id to load data
      */
     public function __construct(Db $zdb, $id = null)
     {
@@ -72,7 +72,7 @@ class Choice extends DynamicField
      *
      * @return integer
      */
-    public function getType()
+    public function getType(): int
     {
         return self::CHOICE;
     }
index d2c078ef142b77044d71e1c2d19bd4354d5e6d4b..12ffedfe9246fe10afac50638d196b2d98636393 100644 (file)
@@ -58,7 +58,7 @@ class Date extends DynamicField
      * Default constructor
      *
      * @param Db  $zdb Database instance
-     * @param int $id  Optionnal field id to load data
+     * @param int $id  Optional field id to load data
      */
     public function __construct(Db $zdb, $id = null)
     {
@@ -71,7 +71,7 @@ class Date extends DynamicField
      *
      * @return integer
      */
-    public function getType()
+    public function getType(): int
     {
         return self::DATE;
     }
index d87aba0ce2e2e689583067b112df28a4d8f78ef1..67e24a1e0c500b37b26440813a27203149e05896 100644 (file)
@@ -81,6 +81,9 @@ abstract class DynamicField
     /** File field (upload) */
     public const FILE = 6;
 
+    public const MOVE_UP = 'up';
+    public const MOVE_DOWN = 'down';
+
     public const PERM_USER_WRITE = 0;
     public const PERM_ADMIN = 1;
     public const PERM_STAFF = 2;
@@ -110,7 +113,7 @@ abstract class DynamicField
     protected $values;
     protected $form;
 
-    protected $errors;
+    protected $errors = [];
 
     protected $zdb;
 
@@ -126,7 +129,7 @@ abstract class DynamicField
 
         if (is_int($args)) {
             $this->load($args);
-        } elseif ($args !== null && is_object($args)) {
+        } elseif (is_object($args)) {
             $this->loadFromRs($args);
         }
     }
@@ -139,7 +142,7 @@ abstract class DynamicField
      *
      * @return DynamicField|false
      */
-    public static function loadFieldType(Db $zdb, $id)
+    public static function loadFieldType(Db $zdb, int $id)
     {
         try {
             $select = $zdb->select(self::TABLE);
@@ -167,13 +170,13 @@ abstract class DynamicField
     /**
      * Get correct field type instance
      *
-     * @param Db  $zdb Database instance
-     * @param int $t   Field type
-     * @param int $id  Optional dynamic field id (to load data)
+     * @param Db       $zdb Database instance
+     * @param int      $t   Field type
+     * @param int|null $id  Optional dynamic field id (to load data)
      *
      * @return DynamicField
      */
-    public static function getFieldType(Db $zdb, $t, $id = null)
+    public static function getFieldType(Db $zdb, int $t, int $id = null)
     {
         $df = null;
         switch ($t) {
@@ -200,7 +203,6 @@ abstract class DynamicField
                 break;
             default:
                 throw new \Exception('Unknown field type ' . $t . '!');
-                break;
         }
         return $df;
     }
@@ -212,7 +214,7 @@ abstract class DynamicField
      *
      * @return void
      */
-    public function load($id)
+    public function load(int $id): void
     {
         try {
             $select = $this->zdb->select(self::TABLE);
@@ -241,16 +243,16 @@ abstract class DynamicField
      *
      * @return void
      */
-    public function loadFromRs($rs, $values = true)
+    public function loadFromRs($rs, bool $values = true): void
     {
         $this->id = (int)$rs->field_id;
         $this->name = $rs->field_name;
         $this->index = (int)$rs->field_index;
         $this->perm = (int)$rs->field_perm;
-        $this->required = ($rs->field_required == 1 ? true : false);
+        $this->required = $rs->field_required == 1;
         $this->width = $rs->field_width;
         $this->height = $rs->field_height;
-        $this->repeat = $rs->field_repeat;
+        $this->repeat = (int)$rs->field_repeat;
         $this->size = $rs->field_size;
         $this->form = $rs->field_form;
         if ($values && $this->hasFixedValues()) {
@@ -266,7 +268,7 @@ abstract class DynamicField
      *
      * @return string
      */
-    public static function getFixedValuesTableName($id, $prefixed = false)
+    public static function getFixedValuesTableName(int $id, bool $prefixed = false): string
     {
         $name = 'field_contents_' . $id;
         if ($prefixed === true) {
@@ -313,21 +315,21 @@ abstract class DynamicField
      *
      * @return integer
      */
-    abstract public function getType();
+    abstract public function getType(): int;
 
     /**
      * Get field type name
      *
      * @return String
      */
-    public function getTypeName()
+    public function getTypeName(): string
     {
         $types = $this->getFieldsTypesNames();
         if (isset($types[$this->getType()])) {
             return $types[$this->getType()];
         } else {
             throw new \RuntimeException(
-                'Unknow type ' . $this->getType()
+                'Unknown type ' . $this->getType()
             );
         }
     }
@@ -337,9 +339,9 @@ abstract class DynamicField
      *
      * @return boolean
      */
-    public function hasData()
+    public function hasData(): bool
     {
-        return $this->has_data;
+        return (bool)$this->has_data;
     }
 
     /**
@@ -347,9 +349,9 @@ abstract class DynamicField
      *
      * @return boolean
      */
-    public function hasWidth()
+    public function hasWidth(): bool
     {
-        return $this->has_width;
+        return (bool)$this->has_width;
     }
 
     /**
@@ -357,9 +359,9 @@ abstract class DynamicField
      *
      * @return boolean
      */
-    public function hasHeight()
+    public function hasHeight(): bool
     {
-        return $this->has_height;
+        return (bool)$this->has_height;
     }
 
     /**
@@ -367,19 +369,19 @@ abstract class DynamicField
      *
      * @return boolean
      */
-    public function hasSize()
+    public function hasSize(): bool
     {
-        return $this->has_size;
+        return (bool)$this->has_size;
     }
 
     /**
-     * Is the field multi valued?
+     * Is the field multivalued?
      *
      * @return boolean
      */
-    public function isMultiValued()
+    public function isMultiValued(): bool
     {
-        return $this->multi_valued;
+        return (bool)$this->multi_valued;
     }
 
     /**
@@ -387,9 +389,9 @@ abstract class DynamicField
      *
      * @return boolean
      */
-    public function hasFixedValues()
+    public function hasFixedValues(): bool
     {
-        return $this->fixed_values;
+        return (bool)$this->fixed_values;
     }
 
     /**
@@ -397,18 +399,18 @@ abstract class DynamicField
      *
      * @return boolean
      */
-    public function hasPermissions()
+    public function hasPermissions(): bool
     {
-        return $this->has_permissions;
+        return (bool)$this->has_permissions;
     }
 
 
     /**
      * Get field id
      *
-     * @return integer
+     * @return integer|null
      */
-    public function getId()
+    public function getId(): ?int
     {
         return $this->id;
     }
@@ -416,9 +418,9 @@ abstract class DynamicField
     /**
      * Get field Permissions
      *
-     * @return integer
+     * @return integer|null
      */
-    public function getPerm()
+    public function getPerm(): ?int
     {
         return $this->perm;
     }
@@ -429,17 +431,17 @@ abstract class DynamicField
      *
      * @return boolean
      */
-    public function isRequired()
+    public function isRequired(): bool
     {
-        return $this->required;
+        return (bool)$this->required;
     }
 
     /**
      * Get field width
      *
-     * @return integer
+     * @return integer|null
      */
-    public function getWidth()
+    public function getWidth(): ?int
     {
         return $this->width;
     }
@@ -447,9 +449,9 @@ abstract class DynamicField
     /**
      * Get field height
      *
-     * @return integer
+     * @return integer|null
      */
-    public function getHeight()
+    public function getHeight(): ?int
     {
         return $this->height;
     }
@@ -459,7 +461,7 @@ abstract class DynamicField
      *
      * @return boolean
      */
-    public function isRepeatable()
+    public function isRepeatable(): bool
     {
         return $this->repeat != null && trim($this->repeat) != '' && (int)$this->repeat >= 0;
     }
@@ -467,9 +469,9 @@ abstract class DynamicField
     /**
      * Get fields repetitions
      *
-     * @return integer|boolean
+     * @return integer|null
      */
-    public function getRepeat()
+    public function getRepeat(): ?int
     {
         return $this->repeat;
     }
@@ -477,9 +479,9 @@ abstract class DynamicField
     /**
      * Get field size
      *
-     * @return integer
+     * @return integer|null
      */
-    public function getSize()
+    public function getSize(): ?int
     {
         return $this->size;
     }
@@ -487,9 +489,9 @@ abstract class DynamicField
     /**
      * Get field index
      *
-     * @return integer
+     * @return integer|null
      */
-    public function getIndex()
+    public function getIndex(): ?int
     {
         return $this->index;
     }
@@ -499,7 +501,7 @@ abstract class DynamicField
      *
      * @return array
      */
-    public static function getPermsNames()
+    public static function getPermsNames(): array
     {
         return [
             self::PERM_USER_WRITE => _T("User, read/write"),
@@ -515,7 +517,7 @@ abstract class DynamicField
      *
      * @return array
      */
-    public static function getFormsNames()
+    public static function getFormsNames(): array
     {
         return [
             'adh'       => _T("Members"),
@@ -531,7 +533,7 @@ abstract class DynamicField
      *
      * @return string
      */
-    public static function getFormTitle($form_name)
+    public static function getFormTitle(string $form_name): string
     {
         $names = self::getFormsNames();
         return $names[$form_name];
@@ -542,7 +544,7 @@ abstract class DynamicField
      *
      * @return string
      */
-    public function getPermName()
+    public function getPermName(): string
     {
         $perms = self::getPermsNames();
         return $perms[$this->getPerm()];
@@ -553,7 +555,7 @@ abstract class DynamicField
      *
      * @return string
      */
-    public function getForm()
+    public function getForm(): string
     {
         return $this->form;
     }
@@ -563,9 +565,9 @@ abstract class DynamicField
      *
      * @param boolean $imploded Whether to implode values
      *
-     * @return array
+     * @return array|string|false
      */
-    public function getValues($imploded = false)
+    public function getValues(bool $imploded = false)
     {
         if (!is_array($this->values)) {
             return false;
@@ -585,7 +587,7 @@ abstract class DynamicField
      *
      * @return true|array
      */
-    public function check($values)
+    public function check(array $values)
     {
         $this->errors = [];
         $this->warnings = [];
@@ -684,7 +686,7 @@ abstract class DynamicField
      *
      * @return boolean
      */
-    public function store($values)
+    public function store(array $values): bool
     {
         if (!$this->check($values)) {
             return false;
@@ -807,7 +809,7 @@ abstract class DynamicField
      *
      * @return integer
      */
-    protected function getNewIndex()
+    protected function getNewIndex(): int
     {
         $select = $this->zdb->select(self::TABLE);
         $select->columns(
@@ -819,7 +821,7 @@ abstract class DynamicField
         $results = $this->zdb->execute($select);
         $result = $results->current();
         $idx = $result->idx;
-        return $idx;
+        return (int)$idx;
     }
 
     /**
@@ -827,7 +829,7 @@ abstract class DynamicField
      *
      * @return boolean
      */
-    public function isDuplicate()
+    public function isDuplicate(): bool
     {
         //let's consider field is duplicated, in case of future errors
         $duplicated = true;
@@ -867,21 +869,26 @@ abstract class DynamicField
         }
         return $duplicated;
     }
+
     /**
      * Move a dynamic field
      *
-     * @param string $action What to do (either 'up' or 'down')
+     * @param string $action What to do (one of self::MOVE_*)
      *
      * @return boolean
      */
-    public function move($action)
+    public function move(string $action): bool
     {
+        if ($action !== self::MOVE_UP && $action !== self::MOVE_DOWN) {
+            throw new \RuntimeException(('Unknown action ' . $action));
+        }
+
         try {
             $this->zdb->connection->beginTransaction();
 
             $old_rank = $this->index;
 
-            $direction = $action == 'up' ? -1 : 1;
+            $direction = $action == self::MOVE_UP ? -1 : 1;
             $new_rank = $old_rank + $direction;
             $update = $this->zdb->update(self::TABLE);
             $update->set([
@@ -922,7 +929,7 @@ abstract class DynamicField
      *
      * @return boolean
      */
-    public function remove()
+    public function remove(): bool
     {
         try {
             if ($this->hasFixedValues()) {
@@ -992,7 +999,7 @@ abstract class DynamicField
      *
      * @return array
      */
-    public static function getFieldsTypesNames()
+    public static function getFieldsTypesNames(): array
     {
         $names = [
             self::SEPARATOR => _T("separator"),
@@ -1011,7 +1018,7 @@ abstract class DynamicField
      *
      * @return array
      */
-    public function getErrors()
+    public function getErrors(): array
     {
         return $this->errors;
     }
@@ -1021,7 +1028,7 @@ abstract class DynamicField
      *
      * @return array
      */
-    public function getWarnings()
+    public function getWarnings(): array
     {
         return $this->warnings;
     }
index d0e20f4cd632fb9c626d99b112701dfc7c8fa1b3..2bddce820a7319b7037b9193ca7e5dfddd36516b 100644 (file)
@@ -58,7 +58,7 @@ class File extends DynamicField
      * Default constructor
      *
      * @param Db  $zdb Database instance
-     * @param int $id  Optionnal field id to load data
+     * @param int $id  Optional field id to load data
      */
     public function __construct(Db $zdb, $id = null)
     {
@@ -72,7 +72,7 @@ class File extends DynamicField
      *
      * @return integer
      */
-    public function getType()
+    public function getType(): int
     {
         return self::FILE;
     }
index ca24a25198d0261d52c9dd5828a569f2769eed8d..002adb64d2de977075195b3c8507c06f9cf5e61d 100644 (file)
@@ -58,7 +58,7 @@ class Line extends DynamicField
      * Default constructor
      *
      * @param Db  $zdb Database instance
-     * @param int $id  Optionnal field id to load data
+     * @param int $id  Optional field id to load data
      */
     public function __construct(Db $zdb, $id = null)
     {
@@ -74,7 +74,7 @@ class Line extends DynamicField
      *
      * @return integer
      */
-    public function getType()
+    public function getType(): int
     {
         return self::LINE;
     }
index ab16a7791b9d3b032f918a9f9f7e17fd74598f31..bbdf4fb7e1ed92c9ed994ed7c96fe35fb4a0cb8c 100644 (file)
@@ -58,7 +58,7 @@ class Separator extends DynamicField
      * Default constructor
      *
      * @param Db  $zdb Database instance
-     * @param int $id  Optionnal field id to load data
+     * @param int $id  Optional field id to load data
      */
     public function __construct(Db $zdb, $id = null)
     {
@@ -71,7 +71,7 @@ class Separator extends DynamicField
      *
      * @return integer
      */
-    public function getType()
+    public function getType(): int
     {
         return self::SEPARATOR;
     }
index 21b1e190f3c26028a623ce1073cd21f731d0f26b..19adb89ac96ab3ce37fbe1e6da8119343736774d 100644 (file)
@@ -58,7 +58,7 @@ class Text extends DynamicField
      * Default constructor
      *
      * @param Db  $zdb Database instance
-     * @param int $id  Optionnal field id to load data
+     * @param int $id  Optional field id to load data
      */
     public function __construct(Db $zdb, $id = null)
     {
@@ -74,7 +74,7 @@ class Text extends DynamicField
      *
      * @return integer
      */
-    public function getType()
+    public function getType(): int
     {
         return self::TEXT;
     }
index efe5301d3f5ed53344f9c9fff203f1fcb993de45..0cb5c486e567279aaebaaa067ea0a46faa10a2fb 100644 (file)
@@ -43,7 +43,7 @@ use atoum;
  * Dynamic booleans test
  *
  * @category  DynamicFields
- * @name      Separator
+ * @name      Boolean
  * @package   GaletteTests
  * @author    Johan Cwiklinski <johan@x-tnd.be>
  * @copyright 2013-2014 The Galette Team
@@ -103,8 +103,7 @@ class Boolean extends atoum
         $this->boolean($muliple)->isFalse();
 
         $required = $this->bool->isRequired();
-        //should'nt that one be false?
-        $this->variable($required)->isNull();
+        $this->boolean($required)->isFalse();
 
         $name = $this->bool->getName();
         $this->variable($name)->isIdenticalTo('');
@@ -136,10 +135,15 @@ class Boolean extends atoum
         $repeat = $this->bool->getRepeat();
         $this->variable($repeat)->isNull();
 
+        $repeat = $this->bool->isRepeatable();
+        $this->boolean($repeat)->isFalse();
+
         $size = $this->bool->getSize();
         $this->variable($size)->isNull();
 
         $values = $this->bool->getValues();
         $this->boolean($values)->isFalse();
+
+        $this->boolean($this->bool->hasPermissions())->isTrue();
     }
 }
diff --git a/tests/Galette/DynamicFields/tests/units/Choice.php b/tests/Galette/DynamicFields/tests/units/Choice.php
new file mode 100644 (file)
index 0000000..9e6feca
--- /dev/null
@@ -0,0 +1,149 @@
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Dynamic choice tests
+ *
+ * PHP version 5
+ *
+ * Copyright © 2021 The Galette Team
+ *
+ * This file is part of Galette (http://galette.tuxfamily.org).
+ *
+ * Galette is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Galette is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Galette. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category  DynamicFields
+ * @package   GaletteTests
+ *
+ * @author    Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2021 The Galette Team
+ * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
+ * @version   SVN: $Id$
+ * @link      http://galette.tuxfamily.org
+ * @since     2021-11-11
+ */
+
+namespace Galette\DynamicFields\test\units;
+
+use atoum;
+
+/**
+ * Dynamic choice test
+ *
+ * @category  DynamicFields
+ * @name      Choice
+ * @package   GaletteTests
+ * @author    Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2021 The Galette Team
+ * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
+ * @link      http://galette.tuxfamily.org
+ * @since     2021-11-11
+ */
+class Choice extends atoum
+{
+    private $zdb;
+    private $choice;
+
+    /**
+     * Set up tests
+     *
+     * @param string $method Current test method
+     *
+     * @return void
+     */
+    public function beforeTestMethod($method)
+    {
+        $this->zdb = new \Galette\Core\Db();
+        $this->choice = new \Galette\DynamicFields\Choice($this->zdb);
+    }
+
+    /**
+     * Test constructor
+     *
+     * @return void
+     */
+    public function testConstructor()
+    {
+        $o = new \Galette\DynamicFields\Choice($this->zdb, 10);
+        $this->variable($o->getId())
+            ->isNull();
+    }
+
+    /**
+     * Test get type name
+     *
+     * @return void
+     */
+    public function testGetTypeName()
+    {
+        $this->variable($this->choice->getTypeName())
+            ->isIdenticalTo(_T('choice'));
+    }
+
+    /**
+     * Test if basic properties are ok
+     *
+     * @return void
+     */
+    public function testBaseProperties()
+    {
+        $muliple = $this->choice->isMultiValued();
+        $this->boolean($muliple)->isFalse();
+
+        $required = $this->choice->isRequired();
+        $this->boolean($required)->isFalse();
+
+        $name = $this->choice->getName();
+        $this->variable($name)->isIdenticalTo('');
+
+        $has_fixed_values = $this->choice->hasFixedValues();
+        $this->boolean($has_fixed_values)->isTrue();
+
+        $has_data = $this->choice->hasData();
+        $this->boolean($has_data)->isTrue();
+
+        $has_w = $this->choice->hasWidth();
+        $this->boolean($has_w)->isFalse();
+
+        $has_h = $this->choice->hasHeight();
+        $this->boolean($has_h)->isFalse();
+
+        $has_s = $this->choice->hasSize();
+        $this->boolean($has_s)->isFalse();
+
+        $perms = $this->choice->getPerm();
+        $this->variable($perms)->isNull();
+
+        $width = $this->choice->getWidth();
+        $this->variable($width)->isNull();
+
+        $height = $this->choice->getHeight();
+        $this->variable($height)->isNull();
+
+        $repeat = $this->choice->getRepeat();
+        $this->variable($repeat)->isNull();
+
+        $repeat = $this->choice->isRepeatable();
+        $this->boolean($repeat)->isFalse();
+
+        $size = $this->choice->getSize();
+        $this->variable($size)->isNull();
+
+        $values = $this->choice->getValues();
+        $this->boolean($values)->isFalse();
+
+        $this->boolean($this->choice->hasPermissions())->isTrue();
+    }
+}
diff --git a/tests/Galette/DynamicFields/tests/units/Date.php b/tests/Galette/DynamicFields/tests/units/Date.php
new file mode 100644 (file)
index 0000000..d624b1b
--- /dev/null
@@ -0,0 +1,149 @@
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Dynamic date tests
+ *
+ * PHP version 5
+ *
+ * Copyright © 2021 The Galette Team
+ *
+ * This file is part of Galette (http://galette.tuxfamily.org).
+ *
+ * Galette is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Galette is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Galette. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category  DynamicFields
+ * @package   GaletteTests
+ *
+ * @author    Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2021 The Galette Team
+ * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
+ * @version   SVN: $Id$
+ * @link      http://galette.tuxfamily.org
+ * @since     2021-11-11
+ */
+
+namespace Galette\DynamicFields\test\units;
+
+use atoum;
+
+/**
+ * Dynamic date test
+ *
+ * @category  DynamicFields
+ * @name      Date
+ * @package   GaletteTests
+ * @author    Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2021 The Galette Team
+ * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
+ * @link      http://galette.tuxfamily.org
+ * @since     2021-11-11
+ */
+class Date extends atoum
+{
+    private $zdb;
+    private $date;
+
+    /**
+     * Set up tests
+     *
+     * @param string $method Current test method
+     *
+     * @return void
+     */
+    public function beforeTestMethod($method)
+    {
+        $this->zdb = new \Galette\Core\Db();
+        $this->date = new \Galette\DynamicFields\Date($this->zdb);
+    }
+
+    /**
+     * Test constructor
+     *
+     * @return void
+     */
+    public function testConstructor()
+    {
+        $o = new \Galette\DynamicFields\Date($this->zdb, 10);
+        $this->variable($o->getId())
+            ->isNull();
+    }
+
+    /**
+     * Test get type name
+     *
+     * @return void
+     */
+    public function testGetTypeName()
+    {
+        $this->variable($this->date->getTypeName())
+            ->isIdenticalTo(_T('date'));
+    }
+
+    /**
+     * Test if basic properties are ok
+     *
+     * @return void
+     */
+    public function testBaseProperties()
+    {
+        $muliple = $this->date->isMultiValued();
+        $this->boolean($muliple)->isFalse();
+
+        $required = $this->date->isRequired();
+        $this->boolean($required)->isFalse();
+
+        $name = $this->date->getName();
+        $this->variable($name)->isIdenticalTo('');
+
+        $has_fixed_values = $this->date->hasFixedValues();
+        $this->boolean($has_fixed_values)->isFalse();
+
+        $has_data = $this->date->hasData();
+        $this->boolean($has_data)->isTrue();
+
+        $has_w = $this->date->hasWidth();
+        $this->boolean($has_w)->isFalse();
+
+        $has_h = $this->date->hasHeight();
+        $this->boolean($has_h)->isFalse();
+
+        $has_s = $this->date->hasSize();
+        $this->boolean($has_s)->isFalse();
+
+        $perms = $this->date->getPerm();
+        $this->variable($perms)->isNull();
+
+        $width = $this->date->getWidth();
+        $this->variable($width)->isNull();
+
+        $height = $this->date->getHeight();
+        $this->variable($height)->isNull();
+
+        $repeat = $this->date->getRepeat();
+        $this->variable($repeat)->isNull();
+
+        $repeat = $this->date->isRepeatable();
+        $this->boolean($repeat)->isFalse();
+
+        $size = $this->date->getSize();
+        $this->variable($size)->isNull();
+
+        $values = $this->date->getValues();
+        $this->boolean($values)->isFalse();
+
+        $this->boolean($this->date->hasPermissions())->isTrue();
+    }
+}
diff --git a/tests/Galette/DynamicFields/tests/units/DynamicField.php b/tests/Galette/DynamicFields/tests/units/DynamicField.php
new file mode 100644 (file)
index 0000000..0dc2a55
--- /dev/null
@@ -0,0 +1,519 @@
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Dynamic fields tests
+ *
+ * PHP version 5
+ *
+ * Copyright © 2021 The Galette Team
+ *
+ * This file is part of Galette (http://galette.tuxfamily.org).
+ *
+ * Galette is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Galette is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Galette. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category  DynamicFields
+ * @package   GaletteTests
+ *
+ * @author    Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2021 The Galette Team
+ * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
+ * @version   SVN: $Id$
+ * @link      http://galette.tuxfamily.org
+ * @since     2021-11-11
+ */
+
+namespace Galette\DynamicFields\test\units;
+
+use atoum;
+
+/**
+ * Dynamic fields test
+ *
+ * @category  DynamicFields
+ * @name      DynamicField
+ * @package   GaletteTests
+ * @author    Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2021 The Galette Team
+ * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
+ * @link      http://galette.tuxfamily.org
+ * @since     2021-11-11
+ */
+class DynamicField extends atoum
+{
+    private $zdb;
+
+    /**
+     * Set up tests
+     *
+     * @param string $method Current test method
+     *
+     * @return void
+     */
+    public function beforeTestMethod($method)
+    {
+        $this->zdb = new \Galette\Core\Db();
+    }
+
+    /**
+     * Tear down tests
+     *
+     * @param string $method Calling method
+     *
+     * @return void
+     */
+    public function afterTestMethod($method)
+    {
+        $delete = $this->zdb->delete(\Galette\DynamicFields\DynamicField::TABLE);
+        $this->zdb->execute($delete);
+        //cleanup dynamic translations
+        $delete = $this->zdb->delete(\Galette\Core\L10n::TABLE);
+        $this->zdb->execute($delete);
+
+        $tables = $this->zdb->getTables();
+        foreach ($tables as $table) {
+            if (str_starts_with($table, 'galette_field_contents_')) {
+                $this->zdb->db->query(
+                    'DROP TABLE ' . $table,
+                    \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE
+                );
+            }
+        }
+    }
+
+    /**
+     * Test loadFieldType
+     *
+     * @return void
+     */
+    public function testLoadFieldType()
+    {
+        $this->boolean(\Galette\DynamicFields\DynamicField::loadFieldType($this->zdb, 10))->isFalse();
+
+        $field_data = [
+            'form_name'         => 'adh',
+            'field_name'        => 'Dynamic text field',
+            'field_perm'        => \Galette\DynamicFields\DynamicField::PERM_USER_WRITE,
+            'field_type'        => \Galette\DynamicFields\DynamicField::TEXT,
+            'field_required'    => true,
+            'field_repeat'      => 1
+        ];
+
+        $df = \Galette\DynamicFields\DynamicField::getFieldType($this->zdb, $field_data['field_type']);
+        $stored = $df->store($field_data);
+        $this->boolean($stored)->isTrue(
+            implode(
+                ' ',
+                $df->getErrors() + $df->getWarnings()
+            )
+        );
+        $this->boolean($stored)->isTrue();
+        $this->object(\Galette\DynamicFields\DynamicField::loadFieldType($this->zdb, $df->getId()))->isEqualTo($df);
+        $this->string($df->getForm())->isIdenticalTo('adh');
+        $this->integer($df->getIndex())->isIdenticalTo(1);
+
+        $df = \Galette\DynamicFields\DynamicField::getFieldType($this->zdb, $field_data['field_type']);
+        $field_data['field_name'] = 'Another one';
+        $stored = $df->store($field_data);
+        $this->boolean($stored)->isTrue(
+            implode(
+                ' ',
+                $df->getErrors() + $df->getWarnings()
+            )
+        );
+        $this->boolean($stored)->isTrue();
+        $this->object(\Galette\DynamicFields\DynamicField::loadFieldType($this->zdb, $df->getId()))->isEqualTo($df);
+        $this->integer($df->getIndex())->isIdenticalTo(2);
+
+        $field_data['field_name'] = 'Another one - modified';
+        $stored = $df->store($field_data);
+        $this->boolean($stored)->isTrue(
+            implode(
+                ' ',
+                $df->getErrors() + $df->getWarnings()
+            )
+        );
+        $this->boolean($stored)->isTrue();
+        $this->string($df->getName())->isIdenticalTo($field_data['field_name']);
+    }
+
+    /**
+     * Permissions names provider
+     *
+     * @return array
+     */
+    protected function permsProvider(): array
+    {
+        return [
+            [
+                'perm' => \Galette\DynamicFields\DynamicField::PERM_USER_WRITE,
+                'name' => "User, read/write"
+            ],
+            [
+                'perm' => \Galette\DynamicFields\DynamicField::PERM_STAFF,
+                'name' => "Staff member"
+            ],
+            [
+                'perm' => \Galette\DynamicFields\DynamicField::PERM_ADMIN,
+                'name' => "Administrator"
+            ],
+            [
+                'perm' => \Galette\DynamicFields\DynamicField::PERM_MANAGER,
+                'name' => "Group manager"
+            ],
+            [
+                'perm' => \Galette\DynamicFields\DynamicField::PERM_USER_READ,
+                'name' => "User, read only"
+            ]
+        ];
+    }
+
+    /**
+     * Test getPermsNames
+     *
+     * @return void
+     */
+    public function testGetPermsNames()
+    {
+        $expected = [];
+        foreach ($this->permsProvider() as $perm) {
+            $expected[$perm['perm']] = $perm['name'];
+        }
+
+        $this->array(\Galette\DynamicFields\DynamicField::getPermsNames())->isIdenticalTo($expected);
+    }
+
+    /**
+     * Tets getPermName
+     *
+     * @param integer $perm Permission
+     * @param string  $name Name
+     *
+     * @dataProvider permsProvider
+     *
+     * @return void
+     */
+    public function testGetPermName(int $perm, string $name)
+    {
+        $field_data = [
+            'form_name'         => 'adh',
+            'field_name'        => 'Dynamic separator ' . $name,
+            'field_perm'        => $perm,
+            'field_type'        => \Galette\DynamicFields\DynamicField::SEPARATOR,
+            'field_required'    => false,
+            'field_repeat'      => null
+        ];
+
+        $df = \Galette\DynamicFields\DynamicField::getFieldType($this->zdb, $field_data['field_type']);
+        $stored = $df->store($field_data);
+        $this->boolean($stored)->isTrue(
+            implode(
+                ' ',
+                $df->getErrors() + $df->getWarnings()
+            )
+        );
+        $this->boolean($stored)->isTrue();
+        $this->string($df->getPermName())->isIdenticalTo($name);
+    }
+
+    /**
+     * Test getFormsNames
+     *
+     * @return void
+     */
+    public function testGetFormsNames()
+    {
+        $expected = [];
+        foreach ($this->formNamesProvider() as $form) {
+            $expected[$form['form']] = $form['expected'];
+        }
+        $this->array(\Galette\DynamicFields\DynamicField::getFormsNames())->isIdenticalTo($expected);
+    }
+
+    /**
+     * Form names provider
+     *
+     * @return \string[][]
+     */
+    protected function formNamesProvider(): array
+    {
+        return [
+            [
+                'form' => 'adh',
+                'expected' => "Members"
+            ],
+            [
+                'form' => 'contrib',
+                'expected' => "Contributions"
+            ],
+            [
+                'form' => 'trans',
+                'expected' => "Transactions"
+            ]
+        ];
+    }
+
+    /**
+     * Test getFormTitle
+     *
+     * @param string $form     Form name
+     * @param string $expected Expected name
+     *
+     * @dataProvider formNamesProvider
+     *
+     * @return void
+     */
+    public function testGetFormTitle(string $form, string $expected)
+    {
+        $this->string(\Galette\DynamicFields\DynamicField::getFormTitle($form))->isIdenticalTo($expected);
+    }
+
+    /**
+     * Test getFixedValuesTableName
+     *
+     * @return void
+     */
+    public function testGetFixedValuesTableName()
+    {
+        $this->string(\Galette\DynamicFields\DynamicField::getFixedValuesTableName(10))->isIdenticalTo('field_contents_10');
+        $this->string(\Galette\DynamicFields\DynamicField::getFixedValuesTableName(10, false))->isIdenticalTo('field_contents_10');
+        $this->string(\Galette\DynamicFields\DynamicField::getFixedValuesTableName(10, true))->isIdenticalTo('galette_field_contents_10');
+    }
+
+    /**
+     * Test getValues
+     *
+     * @return void
+     */
+    public function testGetValues()
+    {
+        $field_data = [
+            'form_name'         => 'adh',
+            'field_name'        => 'Dynamic choice',
+            'field_perm'        => \Galette\DynamicFields\DynamicField::PERM_USER_WRITE,
+            'field_type'        => \Galette\DynamicFields\DynamicField::CHOICE,
+            'field_required'    => false,
+            'field_repeat'      => null,
+            'fixed_values'      => implode("\n", [
+                'One',
+                'Two',
+                'Three'
+            ])
+        ];
+
+        $df = \Galette\DynamicFields\DynamicField::getFieldType($this->zdb, $field_data['field_type']);
+        $stored = $df->store($field_data);
+        $this->boolean($stored)->isTrue(
+            implode(
+                ' ',
+                $df->getErrors() + $df->getWarnings()
+            )
+        );
+        $this->boolean($stored)->isTrue();
+
+        $stored = $df->load($df->getId());
+        $this->array($df->getValues())->isIdenticalTo(['One', 'Two', 'Three']);
+        $this->string($df->getValues(true))->isIdenticalTo("One\nTwo\nThree");
+        $this->integer($df->getIndex())->isIdenticalTo(1);
+    }
+
+    /**
+     * Test check
+     *
+     * @return void
+     */
+    public function testCheck()
+    {
+        $values = [
+            'form_name'         => 'adh',
+            'field_name'        => 'Dynamic choice',
+            'field_perm'        => \Galette\DynamicFields\DynamicField::PERM_USER_WRITE,
+            'field_type'        => \Galette\DynamicFields\DynamicField::CHOICE,
+            'field_required'    => false,
+            'field_repeat'      => null,
+            'fixed_values'      => implode("\n", [
+                'One',
+                'Two',
+                'Three'
+            ])
+        ];
+        $orig_values = $values;
+        $df = \Galette\DynamicFields\DynamicField::getFieldType($this->zdb, $values['field_type']);
+
+        $this->boolean($df->check($values))->isTrue();
+        $this->array($df->getErrors())->isIdenticalTo([]);
+
+        $values['form_name'] = 'unk';
+        $this->boolean($df->check($values))->isFalse();
+        $this->array($df->getErrors())->isIdenticalTo(['Unknown form!']);
+
+        $values['field_perm'] = 42;
+        $this->boolean($df->check($values))->isFalse();
+        $this->array($df->getErrors())->isIdenticalTo(['Unknown permission!', 'Unknown form!']);
+
+        $values = $orig_values;
+        $values['field_perm'] = '';
+        $this->boolean($df->check($values))->isFalse();
+        $this->array($df->getErrors())->isIdenticalTo(['Missing required field permissions!']);
+
+        unset($values['field_perm']);
+        $this->boolean($df->check($values))->isFalse();
+        $this->array($df->getErrors())->isIdenticalTo(['Missing required field permissions!']);
+
+        $values = $orig_values;
+        $values['form_name'] = '';
+        $this->boolean($df->check($values))->isFalse();
+        $this->array($df->getErrors())->isIdenticalTo(['Missing required form!']);
+        $values = $orig_values;
+        unset($values['form_name']);
+        $this->boolean($df->check($values))->isFalse();
+        $this->array($df->getErrors())->isIdenticalTo(['Missing required form!']);
+
+        $values = $orig_values;
+        $values['field_name'] = '';
+        $this->boolean($df->check($values))->isFalse();
+        $this->array($df->getErrors())->isIdenticalTo(['Missing required field name!']);
+        $values = $orig_values;
+        unset($values['field_name']);
+        $this->boolean($df->check($values))->isFalse();
+        $this->array($df->getErrors())->isIdenticalTo(['Missing required field name!']);
+        $this->boolean($df->store($values))->isFalse();
+    }
+
+    /**
+     * Test move
+     *
+     * @return void
+     */
+    public function testMove()
+    {
+        $field_data = [
+            'form_name'         => 'adh',
+            'field_name'        => 'A first text field',
+            'field_perm'        => \Galette\DynamicFields\DynamicField::PERM_USER_WRITE,
+            'field_type'        => \Galette\DynamicFields\DynamicField::TEXT,
+            'field_required'    => true,
+            'field_repeat'      => 1
+        ];
+
+        $df = \Galette\DynamicFields\DynamicField::getFieldType($this->zdb, $field_data['field_type']);
+        $stored = $df->store($field_data);
+        $this->boolean($stored)->isTrue(
+            implode(
+                ' ',
+                $df->getErrors() + $df->getWarnings()
+            )
+        );
+        $this->boolean($stored)->isTrue();
+        $this->object(\Galette\DynamicFields\DynamicField::loadFieldType($this->zdb, $df->getId()))->isEqualTo($df);
+        $this->integer($df->getIndex())->isIdenticalTo(1);
+        $df_id_1 = $df->getId();
+
+        $df = \Galette\DynamicFields\DynamicField::getFieldType($this->zdb, $field_data['field_type']);
+        $field_data['field_name'] = 'A second text field';
+        $stored = $df->store($field_data);
+        $this->boolean($stored)->isTrue(
+            implode(
+                ' ',
+                $df->getErrors() + $df->getWarnings()
+            )
+        );
+        $this->boolean($stored)->isTrue();
+        $this->object(\Galette\DynamicFields\DynamicField::loadFieldType($this->zdb, $df->getId()))->isEqualTo($df);
+        $this->integer($df->getIndex())->isIdenticalTo(2);
+        $df_id_2 = $df->getId();
+
+        $df = \Galette\DynamicFields\DynamicField::getFieldType($this->zdb, $field_data['field_type']);
+        $field_data['field_name'] = 'A third text field';
+        $stored = $df->store($field_data);
+        $this->boolean($stored)->isTrue(
+            implode(
+                ' ',
+                $df->getErrors() + $df->getWarnings()
+            )
+        );
+        $this->boolean($stored)->isTrue();
+        $this->object(\Galette\DynamicFields\DynamicField::loadFieldType($this->zdb, $df->getId()))->isEqualTo($df);
+        $this->integer($df->getIndex())->isIdenticalTo(3);
+        $df_id_3 = $df->getId();
+
+        $this->boolean($df->move(\Galette\DynamicFields\DynamicField::MOVE_UP))->isTrue();
+        $df->load($df_id_1);
+        $this->integer($df->getIndex())->isIdenticalTo(1);
+
+        $df->load($df_id_2);
+        $this->integer($df->getIndex())->isIdenticalTo(3);
+
+        $df->load($df_id_3);
+        $this->integer($df->getIndex())->isIdenticalTo(2);
+
+        $df->load($df_id_1);
+        $this->boolean($df->move(\Galette\DynamicFields\DynamicField::MOVE_DOWN))->isTrue();
+        $df->load($df_id_1);
+        $this->integer($df->getIndex())->isIdenticalTo(2);
+
+        $df->load($df_id_2);
+        $this->integer($df->getIndex())->isIdenticalTo(3);
+
+        $df->load($df_id_3);
+        $this->integer($df->getIndex())->isIdenticalTo(1);
+    }
+
+    /**
+     * Test remove
+     *
+     * @return void
+     */
+    public function testRemove()
+    {
+        $field_data = [
+            'form_name'         => 'adh',
+            'field_name'        => 'Dynamic choice',
+            'field_perm'        => \Galette\DynamicFields\DynamicField::PERM_USER_WRITE,
+            'field_type'        => \Galette\DynamicFields\DynamicField::CHOICE,
+            'field_required'    => false,
+            'field_repeat'      => null,
+            'fixed_values'      => implode("\n", [
+                'One',
+                'Two',
+                'Three'
+            ])
+        ];
+        $df = \Galette\DynamicFields\DynamicField::getFieldType($this->zdb, $field_data['field_type']);
+        $stored = $df->store($field_data);
+        $this->boolean($stored)->isTrue(
+            implode(
+                ' ',
+                $df->getErrors() + $df->getWarnings()
+            )
+        );
+        $this->boolean($stored)->isTrue();
+        $df_id = $df->getId();
+
+        //check if table has been created
+        $select = $this->zdb->select($df::getFixedValuesTableName($df->getId()));
+        $results = $this->zdb->execute($select);
+        $this->integer($results->count())->isIdenticalTo(3);
+
+        $this->boolean($df->remove())->isTrue();
+
+        $this->exception(
+            function () use ($select) {
+                $results = $this->zdb->execute($select);
+            }
+        )->isInstanceOf('\PDOException');
+        $this->boolean(\Galette\DynamicFields\DynamicField::loadFieldType($this->zdb, $df_id))->isFalse();
+    }
+}
diff --git a/tests/Galette/DynamicFields/tests/units/File.php b/tests/Galette/DynamicFields/tests/units/File.php
new file mode 100644 (file)
index 0000000..4df1814
--- /dev/null
@@ -0,0 +1,149 @@
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Dynamic file tests
+ *
+ * PHP version 5
+ *
+ * Copyright © 2021 The Galette Team
+ *
+ * This file is part of Galette (http://galette.tuxfamily.org).
+ *
+ * Galette is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Galette is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Galette. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category  DynamicFields
+ * @package   GaletteTests
+ *
+ * @author    Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2021 The Galette Team
+ * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
+ * @version   SVN: $Id$
+ * @link      http://galette.tuxfamily.org
+ * @since     2021-11-11
+ */
+
+namespace Galette\DynamicFields\test\units;
+
+use atoum;
+
+/**
+ * Dynamic file test
+ *
+ * @category  DynamicFields
+ * @name      File
+ * @package   GaletteTests
+ * @author    Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2021 The Galette Team
+ * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
+ * @link      http://galette.tuxfamily.org
+ * @since     2021-11-11
+ */
+class File extends atoum
+{
+    private $zdb;
+    private $file;
+
+    /**
+     * Set up tests
+     *
+     * @param string $method Current test method
+     *
+     * @return void
+     */
+    public function beforeTestMethod($method)
+    {
+        $this->zdb = new \Galette\Core\Db();
+        $this->file = new \Galette\DynamicFields\File($this->zdb);
+    }
+
+    /**
+     * Test constructor
+     *
+     * @return void
+     */
+    public function testConstructor()
+    {
+        $o = new \Galette\DynamicFields\File($this->zdb, 10);
+        $this->variable($o->getId())
+            ->isNull();
+    }
+
+    /**
+     * Test get type name
+     *
+     * @return void
+     */
+    public function testGetTypeName()
+    {
+        $this->variable($this->file->getTypeName())
+            ->isIdenticalTo(_T('file'));
+    }
+
+    /**
+     * Test if basic properties are ok
+     *
+     * @return void
+     */
+    public function testBaseProperties()
+    {
+        $muliple = $this->file->isMultiValued();
+        $this->boolean($muliple)->isFalse();
+
+        $required = $this->file->isRequired();
+        $this->boolean($required)->isFalse();
+
+        $name = $this->file->getName();
+        $this->variable($name)->isIdenticalTo('');
+
+        $has_fixed_values = $this->file->hasFixedValues();
+        $this->boolean($has_fixed_values)->isFalse();
+
+        $has_data = $this->file->hasData();
+        $this->boolean($has_data)->isTrue();
+
+        $has_w = $this->file->hasWidth();
+        $this->boolean($has_w)->isFalse();
+
+        $has_h = $this->file->hasHeight();
+        $this->boolean($has_h)->isFalse();
+
+        $has_s = $this->file->hasSize();
+        $this->boolean($has_s)->isTrue();
+
+        $perms = $this->file->getPerm();
+        $this->variable($perms)->isNull();
+
+        $width = $this->file->getWidth();
+        $this->variable($width)->isNull();
+
+        $height = $this->file->getHeight();
+        $this->variable($height)->isNull();
+
+        $repeat = $this->file->getRepeat();
+        $this->variable($repeat)->isNull();
+
+        $repeat = $this->file->isRepeatable();
+        $this->boolean($repeat)->isFalse();
+
+        $size = $this->file->getSize();
+        $this->variable($size)->isNull();
+
+        $values = $this->file->getValues();
+        $this->boolean($values)->isFalse();
+
+        $this->boolean($this->file->hasPermissions())->isTrue();
+    }
+}
diff --git a/tests/Galette/DynamicFields/tests/units/Line.php b/tests/Galette/DynamicFields/tests/units/Line.php
new file mode 100644 (file)
index 0000000..1a05431
--- /dev/null
@@ -0,0 +1,149 @@
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Dynamic single line tests
+ *
+ * PHP version 5
+ *
+ * Copyright © 2021 The Galette Team
+ *
+ * This file is part of Galette (http://galette.tuxfamily.org).
+ *
+ * Galette is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Galette is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Galette. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category  DynamicFields
+ * @package   GaletteTests
+ *
+ * @author    Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2021 The Galette Team
+ * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
+ * @version   SVN: $Id$
+ * @link      http://galette.tuxfamily.org
+ * @since     2021-11-11
+ */
+
+namespace Galette\DynamicFields\test\units;
+
+use atoum;
+
+/**
+ * Dynamic single line test
+ *
+ * @category  DynamicFields
+ * @name      Line
+ * @package   GaletteTests
+ * @author    Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2021 The Galette Team
+ * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
+ * @link      http://galette.tuxfamily.org
+ * @since     2021-11-11
+ */
+class Line extends atoum
+{
+    private $zdb;
+    private $line;
+
+    /**
+     * Set up tests
+     *
+     * @param string $method Current test method
+     *
+     * @return void
+     */
+    public function beforeTestMethod($method)
+    {
+        $this->zdb = new \Galette\Core\Db();
+        $this->line = new \Galette\DynamicFields\Line($this->zdb);
+    }
+
+    /**
+     * Test constructor
+     *
+     * @return void
+     */
+    public function testConstructor()
+    {
+        $o = new \Galette\DynamicFields\Line($this->zdb, 10);
+        $this->variable($o->getId())
+            ->isNull();
+    }
+
+    /**
+     * Test get type name
+     *
+     * @return void
+     */
+    public function testGetTypeName()
+    {
+        $this->variable($this->line->getTypeName())
+            ->isIdenticalTo(_T('single line'));
+    }
+
+    /**
+     * Test if basic properties are ok
+     *
+     * @return void
+     */
+    public function testBaseProperties()
+    {
+        $muliple = $this->line->isMultiValued();
+        $this->boolean($muliple)->isTrue();
+
+        $required = $this->line->isRequired();
+        $this->boolean($required)->isFalse();
+
+        $name = $this->line->getName();
+        $this->variable($name)->isIdenticalTo('');
+
+        $has_fixed_values = $this->line->hasFixedValues();
+        $this->boolean($has_fixed_values)->isFalse();
+
+        $has_data = $this->line->hasData();
+        $this->boolean($has_data)->isTrue();
+
+        $has_w = $this->line->hasWidth();
+        $this->boolean($has_w)->isTrue();
+
+        $has_h = $this->line->hasHeight();
+        $this->boolean($has_h)->isFalse();
+
+        $has_s = $this->line->hasSize();
+        $this->boolean($has_s)->isTrue();
+
+        $perms = $this->line->getPerm();
+        $this->variable($perms)->isNull();
+
+        $width = $this->line->getWidth();
+        $this->variable($width)->isNull();
+
+        $height = $this->line->getHeight();
+        $this->variable($height)->isNull();
+
+        $repeat = $this->line->getRepeat();
+        $this->variable($repeat)->isNull();
+
+        $repeat = $this->line->isRepeatable();
+        $this->boolean($repeat)->isFalse();
+
+        $size = $this->line->getSize();
+        $this->variable($size)->isNull();
+
+        $values = $this->line->getValues();
+        $this->boolean($values)->isFalse();
+
+        $this->boolean($this->line->hasPermissions())->isTrue();
+    }
+}
index 7efb432a0cd6c87d820a2efaad2c796277ec1423..eab7b96864ec98ad9aa12d2fdf4fc73417258726 100644 (file)
@@ -103,8 +103,7 @@ class Separator extends atoum
         $this->boolean($muliple)->isFalse();
 
         $required = $this->separator->isRequired();
-        //should'nt that one be false?
-        $this->variable($required)->isNull();
+        $this->boolean($required)->isFalse();
 
         $name = $this->separator->getName();
         $this->variable($name)->isIdenticalTo('');
@@ -136,10 +135,15 @@ class Separator extends atoum
         $repeat = $this->separator->getRepeat();
         $this->variable($repeat)->isNull();
 
+        $repeat = $this->separator->isRepeatable();
+        $this->boolean($repeat)->isFalse();
+
         $size = $this->separator->getSize();
         $this->variable($size)->isNull();
 
         $values = $this->separator->getValues();
         $this->boolean($values)->isFalse();
+
+        $this->boolean($this->separator->hasPermissions())->isFalse();
     }
 }
diff --git a/tests/Galette/DynamicFields/tests/units/Text.php b/tests/Galette/DynamicFields/tests/units/Text.php
new file mode 100644 (file)
index 0000000..2b90ba5
--- /dev/null
@@ -0,0 +1,149 @@
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Dynamic texts tests
+ *
+ * PHP version 5
+ *
+ * Copyright © 2021 The Galette Team
+ *
+ * This file is part of Galette (http://galette.tuxfamily.org).
+ *
+ * Galette is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Galette is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Galette. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category  DynamicFields
+ * @package   GaletteTests
+ *
+ * @author    Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2021 The Galette Team
+ * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
+ * @version   SVN: $Id$
+ * @link      http://galette.tuxfamily.org
+ * @since     2021-11-11
+ */
+
+namespace Galette\DynamicFields\test\units;
+
+use atoum;
+
+/**
+ * Dynamic texts test
+ *
+ * @category  DynamicFields
+ * @name      Text
+ * @package   GaletteTests
+ * @author    Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2021 The Galette Team
+ * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
+ * @link      http://galette.tuxfamily.org
+ * @since     2021-11-11
+ */
+class Text extends atoum
+{
+    private $zdb;
+    private $text;
+
+    /**
+     * Set up tests
+     *
+     * @param string $method Current test method
+     *
+     * @return void
+     */
+    public function beforeTestMethod($method)
+    {
+        $this->zdb = new \Galette\Core\Db();
+        $this->text = new \Galette\DynamicFields\Text($this->zdb);
+    }
+
+    /**
+     * Test constructor
+     *
+     * @return void
+     */
+    public function testConstructor()
+    {
+        $o = new \Galette\DynamicFields\Text($this->zdb, 10);
+        $this->variable($o->getId())
+            ->isNull();
+    }
+
+    /**
+     * Test get type name
+     *
+     * @return void
+     */
+    public function testGetTypeName()
+    {
+        $this->variable($this->text->getTypeName())
+            ->isIdenticalTo(_T('free text'));
+    }
+
+    /**
+     * Test if basic properties are ok
+     *
+     * @return void
+     */
+    public function testBaseProperties()
+    {
+        $muliple = $this->text->isMultiValued();
+        $this->boolean($muliple)->isFalse();
+
+        $required = $this->text->isRequired();
+        $this->boolean($required)->isFalse();
+
+        $name = $this->text->getName();
+        $this->variable($name)->isIdenticalTo('');
+
+        $has_fixed_values = $this->text->hasFixedValues();
+        $this->boolean($has_fixed_values)->isFalse();
+
+        $has_data = $this->text->hasData();
+        $this->boolean($has_data)->isTrue();
+
+        $has_w = $this->text->hasWidth();
+        $this->boolean($has_w)->isTrue();
+
+        $has_h = $this->text->hasHeight();
+        $this->boolean($has_h)->isTrue();
+
+        $has_s = $this->text->hasSize();
+        $this->boolean($has_s)->isFalse();
+
+        $perms = $this->text->getPerm();
+        $this->variable($perms)->isNull();
+
+        $width = $this->text->getWidth();
+        $this->variable($width)->isNull();
+
+        $height = $this->text->getHeight();
+        $this->variable($height)->isNull();
+
+        $repeat = $this->text->getRepeat();
+        $this->integer($repeat)->isIdenticalTo(1);
+
+        $repeat = $this->text->isRepeatable();
+        $this->boolean($repeat)->isTrue();
+
+        $size = $this->text->getSize();
+        $this->variable($size)->isNull();
+
+        $values = $this->text->getValues();
+        $this->boolean($values)->isFalse();
+
+        $this->boolean($this->text->hasPermissions())->isTrue();
+    }
+}