test and corrections

This commit is contained in:
Benjamin Dalsass
2025-11-27 10:58:21 +01:00
parent d0a2af44ac
commit b8a093e625
22 changed files with 457 additions and 119 deletions

View File

@@ -94,7 +94,7 @@ abstract class AbstractFormBlock implements IFormBlock
*/
public function IsRootBlock(): bool
{
return $this->oParent !== null;
return $this->oParent === null;
}
/**

View File

@@ -93,7 +93,8 @@ abstract class AbstractTypeFormBlock extends AbstractFormBlock
parent::UpdateOptions($oOptionsRegister);
if ($this->GetInput(self::INPUT_ENABLE)->IsBound()) {
$oOptionsRegister->SetOption('disabled', !$this->GetInputValue(self::INPUT_ENABLE));
$test = $this->GetInputValue(self::INPUT_ENABLE)->IsTrue();
$oOptionsRegister->SetOption('disabled', !$this->GetInputValue(self::INPUT_ENABLE)->IsTrue());
}
}
}

View File

@@ -21,7 +21,7 @@ class ChoiceFormBlock extends AbstractTypeFormBlock
{
// Outputs
public const OUTPUT_LABEL = 'label';
public const OUTPUT_CODE = 'code';
public const OUTPUT_VALUE = 'value';
/** @inheritdoc */
public function GetFormType(): string
@@ -34,6 +34,6 @@ class ChoiceFormBlock extends AbstractTypeFormBlock
{
parent::RegisterIO($oIORegister);
$oIORegister->AddOutput(self::OUTPUT_LABEL, StringIOFormat::class, new ChoiceValueToLabelConverter($this));
$oIORegister->AddOutput(self::OUTPUT_CODE, StringIOFormat::class);
$oIORegister->AddOutput(self::OUTPUT_VALUE, StringIOFormat::class);
}
}

View File

@@ -27,9 +27,6 @@ class AttributeValueChoiceFormBlock extends ChoiceFormBlock
public const INPUT_CLASS_NAME = 'class_name';
public const INPUT_ATTRIBUTE = 'attribute';
// Outputs
public const OUTPUT_VALUE = 'value';
/** @inheritdoc */
protected function RegisterOptions(OptionsRegister $oOptionsRegister): void
{
@@ -45,7 +42,6 @@ class AttributeValueChoiceFormBlock extends ChoiceFormBlock
parent::RegisterIO($oIORegister);
$oIORegister->AddInput(self::INPUT_CLASS_NAME, ClassIOFormat::class);
$oIORegister->AddInput(self::INPUT_ATTRIBUTE, AttributeIOFormat::class);
$oIORegister->AddOutput(self::OUTPUT_VALUE, AttributeIOFormat::class);
}
/** @inheritdoc

View File

@@ -47,7 +47,7 @@ abstract class AbstractExpressionFormBlock extends AbstractFormBlock
$aParamsToResolve = $oExpression->GetParameters();
$aResolvedParams = [];
foreach ($aParamsToResolve as $sParamToResolve) {
$aResolvedParams[$sParamToResolve] = $this->GetInputValue($sParamToResolve);
$aResolvedParams[$sParamToResolve] = strval($this->GetInputValue($sParamToResolve));
}
return $oExpression->Evaluate($aResolvedParams);
} catch (\Exception $e) {

View File

@@ -0,0 +1,25 @@
<?php
/*
* @copyright Copyright (C) 2010-2025 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Forms\Block;
class FormBlockHelper
{
/**
* Returns a unique form ID for the given form block, based on its hierarchy.
*
* @param AbstractFormBlock $oForm
*
* @return string
*/
public static function GetFormId(AbstractFormBlock $oForm): string
{
if (is_null($oForm->getParent())) {
return $oForm->getName();
}
return self::GetFormId($oForm->getParent()).'_'.$oForm->getName();
}
}

View File

@@ -45,7 +45,7 @@ class FormOutput extends AbstractFormIO
{
if (is_null($this->oConverter)) {
$sType = $this->GetDataType();
return new $sType($oData);
return $oData !== null ? new $sType($oData) : null;
}
return $this->oConverter->Convert($oData);

View File

@@ -8,8 +8,12 @@
namespace Combodo\iTop\Forms\Register;
use Combodo\iTop\Forms\Block\AbstractFormBlock;
use Combodo\iTop\Forms\Block\Base\FormBlock;
use Combodo\iTop\Forms\Block\FormBlockException;
use Combodo\iTop\Forms\Block\FormBlockHelper;
use Combodo\iTop\Forms\FormType\FormTypeHelper;
use Combodo\iTop\Forms\IO\Converter\AbstractConverter;
use Combodo\iTop\Forms\IO\FormBlockIOException;
use Combodo\iTop\Forms\IO\FormInput;
use Combodo\iTop\Forms\IO\FormOutput;
@@ -25,7 +29,7 @@ class IORegister
private array $aOutputs = [];
/**
* @param \Combodo\iTop\Forms\Block\AbstractFormBlock $oFormBlock
* @param AbstractFormBlock $oFormBlock
*/
public function __construct(private readonly AbstractFormBlock $oFormBlock)
{
@@ -35,16 +39,18 @@ class IORegister
* @param string $sName
* @param string $sType
*
* @return void
* @throws \Combodo\iTop\Forms\IO\FormBlockIOException
* @return $this
* @throws FormBlockIOException
*/
public function AddInput(string $sName, string $sType): void
public function AddInput(string $sName, string $sType): self
{
$oFormInput = new FormInput($sName, $sType, $this->oFormBlock);
if (array_key_exists($oFormInput->GetName(), $this->aInputs)) {
throw new RegisterException('Input already exists '.json_encode($oFormInput->GetName()).' for '.json_encode($this->oFormBlock->GetName()));
}
$this->aInputs[$oFormInput->GetName()] = $oFormInput;
return $this;
}
/**
@@ -55,9 +61,9 @@ class IORegister
* @param string $sOutputName
*
* @return $this
* @throws \Combodo\iTop\Forms\Block\FormBlockException
* @throws \Combodo\iTop\Forms\IO\FormBlockIOException
* @throws \Combodo\iTop\Forms\Register\RegisterException
* @throws FormBlockException
* @throws FormBlockIOException
* @throws RegisterException
*/
public function AddInputDependsOn(string $sName, string $sOutputBlockName, string $sOutputName): self
{
@@ -78,9 +84,9 @@ class IORegister
* @param string $sOutputName the dependency output name
*
* @return $this
* @throws \Combodo\iTop\Forms\Block\FormBlockException
* @throws \Combodo\iTop\Forms\IO\FormBlockIOException
* @throws \Combodo\iTop\Forms\Register\RegisterException
* @throws FormBlockException
* @throws FormBlockIOException
* @throws RegisterException
*/
public function DependsOn(string $sInputName, string $sOutputBlockName, string $sOutputName): self
{
@@ -102,9 +108,9 @@ class IORegister
* @param string $sParentOutputName parent output name
*
* @return $this
* @throws \Combodo\iTop\Forms\Block\FormBlockException
* @throws \Combodo\iTop\Forms\IO\FormBlockIOException
* @throws \Combodo\iTop\Forms\Register\RegisterException
* @throws FormBlockException
* @throws FormBlockIOException
* @throws RegisterException
*/
public function ImpactParent(string $sOutputName, string $sParentOutputName): self
{
@@ -119,7 +125,7 @@ class IORegister
{
$oFormOutput = new FormOutput($sName, $sType, $this->oFormBlock, $oConverter);
if (array_key_exists($oFormOutput->GetName(), $this->aOutputs)) {
throw new RegisterException('Output already exists '.json_encode($oFormOutput->GetName()).' for '.json_encode($this->oFormBlock->GetName()));
throw new RegisterException('Output already exists '.json_encode($oFormOutput->GetName()).' for '.json_encode($this->oFormBlock->GetName()) . ' in block ' . FormBlockHelper::GetFormId($this->oFormBlock) . ' of class ' . get_class($this->oFormBlock));
}
$this->aOutputs[$oFormOutput->GetName()] = $oFormOutput;
}
@@ -130,17 +136,29 @@ class IORegister
* @param string $sName
*
* @return FormInput
* @throws \Combodo\iTop\Forms\Register\RegisterException
* @throws RegisterException
*/
public function GetInput(string $sName): FormInput
{
if (!array_key_exists($sName, $this->aInputs)) {
if (!$this->HasInput($sName)) {
throw new RegisterException('Missing input '.json_encode($sName).' for '.json_encode($this->oFormBlock->GetName()));
}
return $this->aInputs[$sName];
}
/**
* Test input existence.
*
* @param string $sName
*
* @return bool
*/
public function HasInput(string $sName): bool
{
return array_key_exists($sName, $this->aInputs);
}
/**
* @return array
*/
@@ -189,7 +207,7 @@ class IORegister
* @param string $sName output name
*
* @return FormOutput
* @throws \Combodo\iTop\Forms\Register\RegisterException
* @throws RegisterException
*/
public function GetOutput(string $sName): FormOutput
{
@@ -326,9 +344,9 @@ class IORegister
* @param string $sParentInputName parent input name
*
* @return $this
* @throws \Combodo\iTop\Forms\Block\FormBlockException
* @throws \Combodo\iTop\Forms\IO\FormBlockIOException
* @throws \Combodo\iTop\Forms\Register\RegisterException
* @throws FormBlockException
* @throws FormBlockIOException
* @throws RegisterException
*/
public function DependsOnParent(string $sInputName, string $sParentInputName): self
{