N°8772 -

This commit is contained in:
Eric Espie
2025-11-18 18:08:36 +01:00
parent f93926528f
commit 546912ad77
10 changed files with 227 additions and 201 deletions

View File

@@ -21,18 +21,18 @@ use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
abstract class AbstractFormsTest extends ItopDataTestCase
{
public function GivenRawInput(string $sName): FormInput
public function GivenInput(string $sName, string $sType = RawFormat::class): FormInput
{
$oBlock = $this->GivenFormBlock($sName.'_block');
return new FormInput($sName.'_input', RawFormat::class, $oBlock);
return new FormInput($sName.'_input', $sType, $oBlock);
}
public function GivenRawOutput(string $sName): FormOutput
public function GivenOutput(string $sName, string $sType = RawFormat::class): FormOutput
{
$oBlock = $this->GivenFormBlock($sName.'_block');
return new FormOutput($sName.'_output', RawFormat::class, $oBlock);
return new FormOutput($sName.'_output', $sType, $oBlock);
}
public function GivenFormBlock(string $sName, array $aOptions = [], array $aIOs = []): AbstractFormBlock

View File

@@ -16,13 +16,13 @@ class AbstractFormIOTest extends AbstractFormsTest
public function testFormIoHasNoDataAtCreation()
{
$oInput = $this->GivenRawInput('test');
$oInput = $this->GivenInput('test');
$this->assertFalse($oInput->IsDataReady(), 'Created Input must no have data ready at creation');
$this->assertFalse($oInput->HasValue(), 'Created Input must no have value at creation');
$this->assertFalse($oInput->HasBindingOut());
$oOutput = $this->GivenRawOutput('test');
$oOutput = $this->GivenOutput('test');
$this->assertFalse($oOutput->IsDataReady(), 'Created output must no have data ready at creation');
$this->assertFalse($oOutput->HasValue(), 'Created output must no have value at creation');
@@ -32,13 +32,13 @@ class AbstractFormIOTest extends AbstractFormsTest
public function testFormIoHasDataAfterSetValue()
{
$oInput = $this->GivenRawInput('test');
$oInput = $this->GivenInput('test');
$oInput->SetValue(FormEvents::POST_SET_DATA, 'test');
$this->assertTrue($oInput->IsDataReady(), 'Input must have data ready when set');
$this->assertTrue($oInput->HasValue(), 'Input must have value when set');
$oOutput = $this->GivenRawOutput('test');
$oOutput = $this->GivenOutput('test');
$oOutput->SetValue(FormEvents::POST_SET_DATA, 'test');
$this->assertTrue($oOutput->IsDataReady(), 'Output must have data ready when set');
@@ -47,7 +47,7 @@ class AbstractFormIOTest extends AbstractFormsTest
public function testIOValueReflectsTheValuePostedOrTheValueSet()
{
$oInput = $this->GivenRawInput('test');
$oInput = $this->GivenInput('test');
// When
$oInput->SetValue(FormEvents::POST_SET_DATA, 'The value set');
@@ -73,7 +73,7 @@ class AbstractFormIOTest extends AbstractFormsTest
if ($bGenerateException) {
$this->expectException(FormBlockIOException::class);
}
$oInput = $this->GivenRawInput($sName);
$oInput = $this->GivenInput($sName);
if (!$bGenerateException) {
$this->assertEquals($sName.'_input', $oInput->GetName());
}

View File

@@ -21,8 +21,8 @@ class FormBindingTest extends AbstractFormsTest
{
public function testCreatingABinding()
{
$oInputIO = $this->GivenRawInput('test');
$oOutputIO = $this->GivenRawOutput('test');
$oInputIO = $this->GivenInput('test');
$oOutputIO = $this->GivenOutput('test');
// When Linking output to input
new FormBinding($oOutputIO, $oInputIO);
@@ -33,9 +33,9 @@ class FormBindingTest extends AbstractFormsTest
public function testBindingTwiceToTheSameInputIsNotPossible()
{
$oInputIO = $this->GivenRawInput('test');
$oOutputIO1 = $this->GivenRawOutput('test1');
$oOutputIO2 = $this->GivenRawOutput('test2');
$oInputIO = $this->GivenInput('test');
$oOutputIO1 = $this->GivenOutput('test1');
$oOutputIO2 = $this->GivenOutput('test2');
// When
new FormBinding($oOutputIO1, $oInputIO);
@@ -47,9 +47,9 @@ class FormBindingTest extends AbstractFormsTest
public function testBindingTwiceToTheSameOutputIsNotPossible()
{
$oOutputIO1 = $this->GivenRawOutput('test1');
$oOutputIO2 = $this->GivenRawOutput('test2');
$oOutputIO3 = $this->GivenRawOutput('test3');
$oOutputIO1 = $this->GivenOutput('test1');
$oOutputIO2 = $this->GivenOutput('test2');
$oOutputIO3 = $this->GivenOutput('test3');
// When
new FormBinding($oOutputIO1, $oOutputIO3);
@@ -62,8 +62,8 @@ class FormBindingTest extends AbstractFormsTest
public function testOutputCanBeBoundToInputAndInputIsBoundAfterThat()
{
$oInputIO = $this->GivenRawInput('test');
$oOutputIO = $this->GivenRawOutput('test1');
$oInputIO = $this->GivenInput('test');
$oOutputIO = $this->GivenOutput('test1');
// When
$oOutputIO->BindToInput($oInputIO);
@@ -74,8 +74,8 @@ class FormBindingTest extends AbstractFormsTest
public function testInputCanBeBoundToAnotherInputAndItIsBoundAfterThat()
{
$oInputIO1 = $this->GivenRawInput('test1');
$oInputIO2 = $this->GivenRawInput('test2');
$oInputIO1 = $this->GivenInput('test1');
$oInputIO2 = $this->GivenInput('test2');
// When
$oInputIO1->BindToInput($oInputIO2);
@@ -86,8 +86,8 @@ class FormBindingTest extends AbstractFormsTest
public function testOutputCanBeBoundToAnotherOutputAndItIsBoundAfterThat()
{
$oOutputIO1 = $this->GivenRawOutput('test1');
$oOutputIO2 = $this->GivenRawOutput('test2');
$oOutputIO1 = $this->GivenOutput('test1');
$oOutputIO2 = $this->GivenOutput('test2');
// When
$oOutputIO1->BindToOutput($oOutputIO2);
@@ -98,9 +98,9 @@ class FormBindingTest extends AbstractFormsTest
public function testOutBindingsAreStoredWhenBindToInput()
{
$oInputIO1 = $this->GivenRawInput('test1');
$oInputIO2 = $this->GivenRawInput('test2');
$oOutputIO1 = $this->GivenRawOutput('test1');
$oInputIO1 = $this->GivenInput('test1');
$oInputIO2 = $this->GivenInput('test2');
$oOutputIO1 = $this->GivenOutput('test1');
// When
$oBindingO2ToI1 = $oOutputIO1->BindToInput($oInputIO1);
@@ -118,9 +118,9 @@ class FormBindingTest extends AbstractFormsTest
public function testOutBindingsAreStoredWhenBindToOutput()
{
$oOutputIO1 = $this->GivenRawOutput('test1');
$oOutputIO2 = $this->GivenRawOutput('test2');
$oOutputIO3 = $this->GivenRawOutput('test3');
$oOutputIO1 = $this->GivenOutput('test1');
$oOutputIO2 = $this->GivenOutput('test2');
$oOutputIO3 = $this->GivenOutput('test3');
// When
$oBindingO1ToO2 = $oOutputIO1->BindToOutput($oOutputIO2);
@@ -138,8 +138,8 @@ class FormBindingTest extends AbstractFormsTest
public function testSourceValueIsPropagatedToDestIO()
{
$oOutputIO1 = $this->GivenRawOutput('test1');
$oInputIO1 = $this->GivenRawInput('test1');
$oOutputIO1 = $this->GivenOutput('test1');
$oInputIO1 = $this->GivenInput('test1');
$oBinding = $oOutputIO1->BindToInput($oInputIO1);
$oOutputIO1->SetValue(FormEvents::PRE_SET_DATA, 'The Value');

View File

@@ -0,0 +1,21 @@
<?php
/*
* @copyright Copyright (C) 2010-2025 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Test\UnitTest\sources\Forms\IO\Format;
use Combodo\iTop\Forms\IO\Format\AttributeIOFormat;
use Combodo\iTop\Test\UnitTest\sources\Forms\AbstractFormsTest;
use Symfony\Component\Form\FormEvents;
class TestAttributeIOFormat extends AbstractFormsTest
{
public function testAttributeIOIsAString()
{
$oInputIO = $this->GivenInput('test', AttributeIOFormat::class);
$oInputIO->SetValue(FormEvents::POST_SUBMIT, 'name');
$this->assertEquals('name', $oInputIO->GetValue());
}
}

View File

@@ -0,0 +1,22 @@
<?php
/*
* @copyright Copyright (C) 2010-2025 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Test\UnitTest\sources\Forms\IO\Format;
use Combodo\iTop\Forms\IO\Format\BooleanIOFormat;
use Combodo\iTop\Test\UnitTest\sources\Forms\AbstractFormsTest;
use Symfony\Component\Form\FormEvents;
class TestBooleanIOFormat extends AbstractFormsTest
{
public function testBooleanIOFormatIsABoolean()
{
$oInputIO = $this->GivenInput('test', BooleanIOFormat::class);
$oInputIO->SetValue(FormEvents::POST_SUBMIT, 'true');
$this->assertEquals(true, $oInputIO->GetValue());
}
}

View File

@@ -0,0 +1,13 @@
<?php
/*
* @copyright Copyright (C) 2010-2025 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Test\UnitTest\sources\Forms\IO\Format;
use Combodo\iTop\Test\UnitTest\sources\Forms\AbstractFormsTest;
class TestClassIOFormat extends AbstractFormsTest
{
}

View File

@@ -0,0 +1,13 @@
<?php
/*
* @copyright Copyright (C) 2010-2025 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Test\UnitTest\sources\Forms\IO\Format;
use Combodo\iTop\Test\UnitTest\sources\Forms\AbstractFormsTest;
class TestNumberIOFormat extends AbstractFormsTest
{
}