use Galette\Controllers\CsvController;
use Galette\Controllers\AdminToolsController;
use Galette\Controllers\TextController;
+use Galette\DynamicFields\DynamicField;
//galette's dashboard
$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);
* @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 {
* 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)
{
*
* @return integer
*/
- public function getType()
+ public function getType(): int
{
return self::BOOLEAN;
}
* 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)
{
*
* @return integer
*/
- public function getType()
+ public function getType(): int
{
return self::CHOICE;
}
* 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)
{
*
* @return integer
*/
- public function getType()
+ public function getType(): int
{
return self::DATE;
}
/** 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;
protected $values;
protected $form;
- protected $errors;
+ protected $errors = [];
protected $zdb;
if (is_int($args)) {
$this->load($args);
- } elseif ($args !== null && is_object($args)) {
+ } elseif (is_object($args)) {
$this->loadFromRs($args);
}
}
*
* @return DynamicField|false
*/
- public static function loadFieldType(Db $zdb, $id)
+ public static function loadFieldType(Db $zdb, int $id)
{
try {
$select = $zdb->select(self::TABLE);
/**
* 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) {
break;
default:
throw new \Exception('Unknown field type ' . $t . '!');
- break;
}
return $df;
}
*
* @return void
*/
- public function load($id)
+ public function load(int $id): void
{
try {
$select = $this->zdb->select(self::TABLE);
*
* @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()) {
*
* @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) {
*
* @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()
);
}
}
*
* @return boolean
*/
- public function hasData()
+ public function hasData(): bool
{
- return $this->has_data;
+ return (bool)$this->has_data;
}
/**
*
* @return boolean
*/
- public function hasWidth()
+ public function hasWidth(): bool
{
- return $this->has_width;
+ return (bool)$this->has_width;
}
/**
*
* @return boolean
*/
- public function hasHeight()
+ public function hasHeight(): bool
{
- return $this->has_height;
+ return (bool)$this->has_height;
}
/**
*
* @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;
}
/**
*
* @return boolean
*/
- public function hasFixedValues()
+ public function hasFixedValues(): bool
{
- return $this->fixed_values;
+ return (bool)$this->fixed_values;
}
/**
*
* @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;
}
/**
* Get field Permissions
*
- * @return integer
+ * @return integer|null
*/
- public function getPerm()
+ public function getPerm(): ?int
{
return $this->perm;
}
*
* @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;
}
/**
* Get field height
*
- * @return integer
+ * @return integer|null
*/
- public function getHeight()
+ public function getHeight(): ?int
{
return $this->height;
}
*
* @return boolean
*/
- public function isRepeatable()
+ public function isRepeatable(): bool
{
return $this->repeat != null && trim($this->repeat) != '' && (int)$this->repeat >= 0;
}
/**
* Get fields repetitions
*
- * @return integer|boolean
+ * @return integer|null
*/
- public function getRepeat()
+ public function getRepeat(): ?int
{
return $this->repeat;
}
/**
* Get field size
*
- * @return integer
+ * @return integer|null
*/
- public function getSize()
+ public function getSize(): ?int
{
return $this->size;
}
/**
* Get field index
*
- * @return integer
+ * @return integer|null
*/
- public function getIndex()
+ public function getIndex(): ?int
{
return $this->index;
}
*
* @return array
*/
- public static function getPermsNames()
+ public static function getPermsNames(): array
{
return [
self::PERM_USER_WRITE => _T("User, read/write"),
*
* @return array
*/
- public static function getFormsNames()
+ public static function getFormsNames(): array
{
return [
'adh' => _T("Members"),
*
* @return string
*/
- public static function getFormTitle($form_name)
+ public static function getFormTitle(string $form_name): string
{
$names = self::getFormsNames();
return $names[$form_name];
*
* @return string
*/
- public function getPermName()
+ public function getPermName(): string
{
$perms = self::getPermsNames();
return $perms[$this->getPerm()];
*
* @return string
*/
- public function getForm()
+ public function getForm(): string
{
return $this->form;
}
*
* @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;
*
* @return true|array
*/
- public function check($values)
+ public function check(array $values)
{
$this->errors = [];
$this->warnings = [];
*
* @return boolean
*/
- public function store($values)
+ public function store(array $values): bool
{
if (!$this->check($values)) {
return false;
*
* @return integer
*/
- protected function getNewIndex()
+ protected function getNewIndex(): int
{
$select = $this->zdb->select(self::TABLE);
$select->columns(
$results = $this->zdb->execute($select);
$result = $results->current();
$idx = $result->idx;
- return $idx;
+ return (int)$idx;
}
/**
*
* @return boolean
*/
- public function isDuplicate()
+ public function isDuplicate(): bool
{
//let's consider field is duplicated, in case of future errors
$duplicated = true;
}
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([
*
* @return boolean
*/
- public function remove()
+ public function remove(): bool
{
try {
if ($this->hasFixedValues()) {
*
* @return array
*/
- public static function getFieldsTypesNames()
+ public static function getFieldsTypesNames(): array
{
$names = [
self::SEPARATOR => _T("separator"),
*
* @return array
*/
- public function getErrors()
+ public function getErrors(): array
{
return $this->errors;
}
*
* @return array
*/
- public function getWarnings()
+ public function getWarnings(): array
{
return $this->warnings;
}
* 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)
{
*
* @return integer
*/
- public function getType()
+ public function getType(): int
{
return self::FILE;
}
* 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)
{
*
* @return integer
*/
- public function getType()
+ public function getType(): int
{
return self::LINE;
}
* 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)
{
*
* @return integer
*/
- public function getType()
+ public function getType(): int
{
return self::SEPARATOR;
}
* 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)
{
*
* @return integer
*/
- public function getType()
+ public function getType(): int
{
return self::TEXT;
}
* Dynamic booleans test
*
* @category DynamicFields
- * @name Separator
+ * @name Boolean
* @package GaletteTests
* @author Johan Cwiklinski <johan@x-tnd.be>
* @copyright 2013-2014 The Galette Team
$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('');
$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();
}
}
--- /dev/null
+<?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();
+ }
+}
--- /dev/null
+<?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();
+ }
+}
--- /dev/null
+<?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();
+ }
+}
--- /dev/null
+<?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();
+ }
+}
--- /dev/null
+<?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();
+ }
+}
$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('');
$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();
}
}
--- /dev/null
+<?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();
+ }
+}