N°6414 Separate SubFormField and Scalar fields

This will help to set methods as final, as SubFormField is often the sole one to have a real custom impl
This commit is contained in:
Pierre Goiffon
2023-06-22 14:53:07 +02:00
parent 6606af71ff
commit d085f15b6d
15 changed files with 126 additions and 67 deletions

View File

@@ -7,6 +7,7 @@
namespace Combodo\iTop\Test\UnitTest\Sources\Form\Field;
use Combodo\iTop\Form\Field\StringField;
use Combodo\iTop\Form\Field\SubFormField;
use Combodo\iTop\Form\Validator\CustomRegexpValidator;
use Combodo\iTop\Form\Validator\IntegerValidator;
use Combodo\iTop\Form\Validator\MandatoryValidator;
@@ -80,4 +81,23 @@ class FieldTest extends ItopTestCase
$this->assertCount(1, $oField->GetErrorMessages());
$this->assertSame($sFirstValidatorInvalidResultErrorMsg, $oField->GetErrorMessages()[0]);
}
public function testSubFormFieldValidation(): void
{
$oSubFormField = new SubFormField('test_subformfield');
$oField = new StringField('test_field');
$oField->SetMandatory(true);
$oSubFormField->GetForm()->AddField($oField);
$bIsSubFormFieldValid = $oSubFormField->Validate();
$this->assertFalse($bIsSubFormFieldValid);
$this->assertCount(1, $oSubFormField->GetErrorMessages());
$oField->SetCurrentValue('test string');
$bIsSubFormFieldValidAfterFieldUpdate = $oSubFormField->Validate();
$this->assertTrue($bIsSubFormFieldValidAfterFieldUpdate);
$this->assertCount(0, $oSubFormField->GetErrorMessages());
}
}