mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 10:38:45 +02:00
N°8772 - dynamic form
This commit is contained in:
15
tests/php-unit-tests/unitary-tests/sources/Forms/Binding.php
Normal file
15
tests/php-unit-tests/unitary-tests/sources/Forms/Binding.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Forms;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
|
||||
class Binding extends ItopDataTestCase
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
92
tests/php-unit-tests/unitary-tests/sources/Forms/Block.php
Normal file
92
tests/php-unit-tests/unitary-tests/sources/Forms/Block.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Forms;
|
||||
|
||||
use Combodo\iTop\Forms\Block\AbstractFormBlock;
|
||||
use Combodo\iTop\Forms\Block\Base\CheckboxFormBlock;
|
||||
use Combodo\iTop\Forms\Block\Base\ChoiceFormBlock;
|
||||
use Combodo\iTop\Forms\Block\Base\FormBlock;
|
||||
use Combodo\iTop\Forms\Block\Base\TextFormBlock;
|
||||
use Combodo\iTop\Forms\Block\FormBlockException;
|
||||
use Combodo\iTop\Forms\Forms;
|
||||
use Combodo\iTop\Forms\IFormBlock;
|
||||
use Combodo\iTop\Service\InterfaceDiscovery\InterfaceDiscovery;
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use OutOfBoundsException;
|
||||
use ReflectionException;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
|
||||
class Block extends ItopDataTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testBlockFormType()
|
||||
{
|
||||
$oChoiceBlock = new ChoiceFormBlock('choiceBlock');
|
||||
$test = new \ReflectionClass($oChoiceBlock->GetFormType());
|
||||
$this->assertTrue($test->isSubclassOf(AbstractType::class));
|
||||
|
||||
$oFormBlock = new ChoiceFormBlock('formBlock');
|
||||
$test = new \ReflectionClass($oFormBlock->GetFormType());
|
||||
$this->assertTrue($test->isSubclassOf(AbstractType::class));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass a Symfony type instead of a FormBlock type will raise an exception
|
||||
*
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testAddBlockFromSymfonyType()
|
||||
{
|
||||
$oFormBlock = new FormBlock('formBlock');
|
||||
$this->expectException(FormBlockException::class);
|
||||
$oFormBlock->Add('wrong', TextType::class, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* All block may contain a reference to themselves in their options
|
||||
*/
|
||||
public function testBlockOptionsContainsBlockReference()
|
||||
{
|
||||
$aFormBlocks = InterfaceDiscovery::GetInstance()->FindItopClasses(iFormBlock::class);
|
||||
foreach ($aFormBlocks as $sFormBlock) {
|
||||
$oChoiceBlock = new($sFormBlock)($sFormBlock);
|
||||
$this->assertTrue($oChoiceBlock->GetOptions()['form_block'] === $oChoiceBlock);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Dependent fields are not added to the form directly.
|
||||
*
|
||||
* @return void
|
||||
* @throws FormBlockException
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testFormBlockNotContainsDependentFields()
|
||||
{
|
||||
// form with a dependent field
|
||||
$oFormBlock = new FormBlock('formBlock');
|
||||
$oFormBlock->Add('firstname', TextFormBlock::class, []);
|
||||
$oFormBlock->Add('lastname', TextFormBlock::class, []);
|
||||
$oFormBlock->Add('allow_age', CheckboxFormBlock::class, []);
|
||||
$oFormBlock->Add('birthdate', TextFormBlock::class, [])
|
||||
->DependsOn(AbstractFormBlock::INPUT_VISIBLE, 'allow_age', CheckboxFormBlock::OUTPUT_CHECKED);
|
||||
|
||||
// form builder
|
||||
$oFormFactoryBuilder = Forms::createFormFactoryBuilder();
|
||||
$oForm = $oFormFactoryBuilder->getFormFactory()->createNamedBuilder($oFormBlock->GetName(), $oFormBlock->GetFormType(), [], $oFormBlock->GetOptions())->getForm();
|
||||
|
||||
// try to get the dependent field
|
||||
$this->expectException(OutOfBoundsException::class);
|
||||
$oForm->get('birthdate');
|
||||
}
|
||||
}
|
||||
23
tests/php-unit-tests/unitary-tests/sources/Forms/BlockIO.php
Normal file
23
tests/php-unit-tests/unitary-tests/sources/Forms/BlockIO.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Forms;
|
||||
|
||||
use Combodo\iTop\Forms\Block\Base\CheckboxFormBlock;
|
||||
use Combodo\iTop\Forms\Block\Base\ChoiceFormBlock;
|
||||
use Combodo\iTop\Forms\Block\Base\FormBlock;
|
||||
use Combodo\iTop\Forms\Block\Base\TextFormBlock;
|
||||
use Combodo\iTop\Forms\Block\FormBlockException;
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use ReflectionException;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
|
||||
class BlockIO extends ItopDataTestCase
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
15
tests/php-unit-tests/unitary-tests/sources/Forms/Builder.php
Normal file
15
tests/php-unit-tests/unitary-tests/sources/Forms/Builder.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Forms;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
|
||||
class Builder extends ItopDataTestCase
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user