diff --git a/sources/Forms/IO/AbstractFormIO.php b/sources/Forms/IO/AbstractFormIO.php index 93eb31dd8..3aa8541ef 100644 --- a/sources/Forms/IO/AbstractFormIO.php +++ b/sources/Forms/IO/AbstractFormIO.php @@ -43,9 +43,9 @@ class AbstractFormIO */ public function __construct(string $sName, string $sType, AbstractFormBlock $oOwnerBlock) { - $this->SetName($sName); $this->sType = $sType; $this->oOwnerBlock = $oOwnerBlock; + $this->SetName($sName); } /** @@ -84,12 +84,12 @@ class AbstractFormIO if ($sParsedName !== $sName) { $sName = json_encode($sName); $sParsedName = json_encode($sParsedName); - $sBlockName = json_encode($this->getName()); + $sBlockName = json_encode($this->GetOwnerBlock()->GetName()); throw new FormBlockIOException("Input $sName does not match $sParsedName for block $sBlockName."); } } else { $sName = json_encode($sName); - $sBlockName = json_encode($this->getName()); + $sBlockName = json_encode($this->GetOwnerBlock()->GetName()); throw new FormBlockIOException("Input $sName is not valid for block $sBlockName."); } diff --git a/tests/php-unit-tests/unitary-tests/sources/Forms/IO/AbstractFormIOTest.php b/tests/php-unit-tests/unitary-tests/sources/Forms/IO/AbstractFormIOTest.php index 65a488d73..9a62f2b5b 100644 --- a/tests/php-unit-tests/unitary-tests/sources/Forms/IO/AbstractFormIOTest.php +++ b/tests/php-unit-tests/unitary-tests/sources/Forms/IO/AbstractFormIOTest.php @@ -62,11 +62,37 @@ class AbstractFormIOTest extends AbstractFormsTest $this->assertEquals('The value posted', $oInput->GetValue()); } - public function testNameDoesNotAcceptBlank() + /** + * @dataProvider NameFormatSupportsOnlyLettersUnderscoreAndNumbersProvider + * @return void + * @throws \Combodo\iTop\Forms\IO\FormBlockIOException + */ + public function testNameFormatSupportsOnlyLettersUnderscoreAndNumbers(string $sName, bool $bGenerateException = true) { - $oInput = $this->GivenRawInput('test'); - $this->expectException(FormBlockIOException::class); - $oInput->SetName('The test name'); + if ($bGenerateException) { + $this->expectException(FormBlockIOException::class); + } + $oInput = $this->GivenRawInput($sName); + if (!$bGenerateException) { + $this->assertEquals($sName.'_input', $oInput->GetName()); + } } + + public function NameFormatSupportsOnlyLettersUnderscoreAndNumbersProvider() + { + return [ + 'Spaces not supported' => ['The test name'], + 'Minus not supported' => ['The-test-name'], + 'Percent not supported' => ['name%'], + 'Accent not supported' => ['namé'], + + // Corrects + 'Numbers OK' => ['name123', false], + 'Underscore OK' => ['The_test_name', false], + 'Camel OK' => ['TheTestName', false], + ]; + } + + }