N°8772 - XML description traduction to PHP wip

This commit is contained in:
Eric Espie
2025-12-01 16:34:10 +01:00
parent 54aaf55a92
commit 3d8e429c2b
5 changed files with 23 additions and 9 deletions

View File

@@ -11,6 +11,7 @@ use Combodo\iTop\Forms\Block\AbstractFormBlock;
use Combodo\iTop\Forms\Block\FormBlockException;
use Combodo\iTop\Forms\IO\Format\BooleanIOFormat;
use Combodo\iTop\Forms\Register\IORegister;
use Exception;
use Expression;
use Symfony\Component\Form\FormEvents;
@@ -52,9 +53,13 @@ abstract class AbstractExpressionFormBlock extends AbstractFormBlock
foreach ($aParamsToResolve as $sParamToResolve) {
$aResolvedParams[$sParamToResolve] = strval($this->GetInputValue($sParamToResolve));
}
$aFieldsToResolve = $oExpression->ListRequiredFields();
foreach ($aFieldsToResolve as $sFieldToResolve) {
$aResolvedParams[$sFieldToResolve] = strval($this->GetInputValue($sFieldToResolve));
}
return $oExpression->Evaluate($aResolvedParams);
} catch (\Exception $e) {
throw new FormBlockException('Compute expression '.json_encode($sExpression).' block issue', 0, $e);
} catch (Exception $e) {
throw new FormBlockException('Compute expression '.json_encode($sExpression).' block issue: '.$e->getMessage(), 0, $e);
}
}

View File

@@ -19,4 +19,10 @@ use Throwable;
*/
class FormsException extends Exception
{
public function __construct(string $sMessage = '', int $iCode = 0, ?Throwable $oPrevious = null, array $aContext = [])
{
parent::__construct($sMessage, $iCode, $oPrevious);
IssueLog::Exception(get_class($this).' occurs: '.$sMessage, $this, null, $aContext);
}
}

View File

@@ -86,7 +86,7 @@ class AbstractFormIO
public function SetName(string $sName): self
{
// Check name validity
if (preg_match('/(?<name>\w+)/', $sName, $aMatches)) {
if (preg_match('/^(?<name>((\w+\.\w+)|\w+))$/', $sName, $aMatches)) {
$sParsedName = $aMatches['name'];
if ($sParsedName !== $sName) {
$sName = json_encode($sName);

View File

@@ -25,16 +25,16 @@ abstract class AbstractFormsTest extends ItopDataTestCase
{
public function GivenInput(string $sName, string $sType = StringIOFormat::class): FormInput
{
$oBlock = $this->GivenFormBlock($sName.'_block');
$oBlock = $this->GivenFormBlock($sName);
return new FormInput($sName.'_input', $sType, $oBlock);
return new FormInput($sName, $sType, $oBlock);
}
public function GivenOutput(string $sName, string $sType = StringIOFormat::class): FormOutput
{
$oBlock = $this->GivenFormBlock($sName.'_block');
$oBlock = $this->GivenFormBlock($sName);
return new FormOutput($sName.'_output', $sType, $oBlock);
return new FormOutput($sName, $sType, $oBlock);
}
public function GivenFormBlock(string $sName): FormBlock

View File

@@ -67,7 +67,7 @@ class AbstractFormIOTest extends AbstractFormsTest
* @return void
* @throws \Combodo\iTop\Forms\IO\FormBlockIOException
*/
public function testNameFormatSupportsOnlyLettersUnderscoreAndNumbers(string $sName, bool $bGenerateException = true)
public function testNameFormatSupportsOnlyLettersUnderscoreAndNumbersAndDot(string $sName, bool $bGenerateException = true)
{
if ($bGenerateException) {
@@ -75,7 +75,7 @@ class AbstractFormIOTest extends AbstractFormsTest
}
$oInput = $this->GivenInput($sName);
if (!$bGenerateException) {
$this->assertEquals($sName.'_input', $oInput->GetName());
$this->assertEquals($sName, $oInput->GetName());
}
}
@@ -88,12 +88,15 @@ class AbstractFormIOTest extends AbstractFormsTest
'Percent not supported' => ['name%'],
'Accent not supported' => ['namé'],
'emoji not supported' => ['🎄🎄🎄🎄🎄'],
'.name not supported' => ['.name'],
'name. not supported' => ['name.'],
// Corrects
'Numbers OK' => ['name123', false],
'Starting with number OK' => ['123name123', false],
'Underscore OK' => ['The_test_name', false],
'Camel OK' => ['TheTestName', false],
'name.subname OK' => ['name.subname', false],
];
}