diff --git a/src/qtism/runtime/expressions/operators/FieldValueProcessor.php b/src/qtism/runtime/expressions/operators/FieldValueProcessor.php index 8e61cd913..3e689d596 100644 --- a/src/qtism/runtime/expressions/operators/FieldValueProcessor.php +++ b/src/qtism/runtime/expressions/operators/FieldValueProcessor.php @@ -24,6 +24,7 @@ namespace qtism\runtime\expressions\operators; use qtism\data\expressions\operators\FieldValue; +use qtism\runtime\common\RecordContainer; /** * The FieldValueProcessor class aims at processing FieldValue expressions. @@ -45,16 +46,20 @@ class FieldValueProcessor extends OperatorProcessor #[\ReturnTypeWillChange] public function process() { - $operands = $this->getOperands(); + $operand = $this->getOperands()[0]; - if ($operands->exclusivelyRecord() === false) { + if ($operand === null) { + return null; + } + + if (!$operand instanceof RecordContainer) { $msg = 'The FieldValue operator only accepts operands with a cardinality of record.'; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } $fieldIdentifier = $this->getExpression()->getFieldIdentifier(); - return $operands[0][$fieldIdentifier]; + return $operand[$fieldIdentifier]; } /** diff --git a/test/qtismtest/runtime/expressions/operators/FieldValueProcessorTest.php b/test/qtismtest/runtime/expressions/operators/FieldValueProcessorTest.php index dc72bbb19..edbc6730e 100644 --- a/test/qtismtest/runtime/expressions/operators/FieldValueProcessorTest.php +++ b/test/qtismtest/runtime/expressions/operators/FieldValueProcessorTest.php @@ -5,6 +5,7 @@ use qtism\common\datatypes\QtiInteger; use qtism\common\datatypes\QtiPoint; use qtism\common\enums\BaseType; +use qtism\data\expressions\Expression; use qtism\data\QtiComponent; use qtism\data\storage\xml\marshalling\MarshallerNotFoundException; use qtism\runtime\common\MultipleContainer; @@ -24,7 +25,7 @@ public function testNotEnoughOperands(): void $expression = $this->createFakeExpression(); $operands = new OperandsCollection(); $this->expectException(ExpressionProcessingException::class); - $processor = new FieldValueProcessor($expression, $operands); + new FieldValueProcessor($expression, $operands); } public function testTooMuchOperands(): void @@ -34,7 +35,7 @@ public function testTooMuchOperands(): void $operands[] = new RecordContainer(); $operands[] = new RecordContainer(); $this->expectException(ExpressionProcessingException::class); - $processor = new FieldValueProcessor($expression, $operands); + new FieldValueProcessor($expression, $operands); } public function testNullOne(): void @@ -55,9 +56,9 @@ public function testNullTwo(): void $operands = new OperandsCollection(); // null value as operand. $operands[] = null; - $this->expectException(ExpressionProcessingException::class); $processor = new FieldValueProcessor($expression, $operands); $result = $processor->process(); + $this::assertNull($result); } public function testWrongCardinalityOne(): void @@ -68,7 +69,7 @@ public function testWrongCardinalityOne(): void $operands[] = new QtiInteger(10); $processor = new FieldValueProcessor($expression, $operands); $this->expectException(ExpressionProcessingException::class); - $result = $processor->process(); + $processor->process(); } public function testWrongCardinalityTwo(): void @@ -79,7 +80,7 @@ public function testWrongCardinalityTwo(): void $operands[] = new QtiPoint(1, 2); $processor = new FieldValueProcessor($expression, $operands); $this->expectException(ExpressionProcessingException::class); - $result = $processor->process(); + $processor->process(); } public function testWrongCardinalityThree(): void @@ -91,7 +92,7 @@ public function testWrongCardinalityThree(): void // Wrong container (Multiple, Ordered) $processor = new FieldValueProcessor($expression, $operands); $this->expectException(ExpressionProcessingException::class); - $result = $processor->process(); + $processor->process(); } public function testFieldValue(): void @@ -116,7 +117,7 @@ public function testFieldValue(): void * @return QtiComponent * @throws MarshallerNotFoundException */ - public function createFakeExpression($identifier = ''): QtiComponent + public function createFakeExpression($identifier = ''): Expression { // The following XML Component creation // underlines the need of a operator... :) diff --git a/test/qtismtest/runtime/processing/ResponseProcessingEngineTest.php b/test/qtismtest/runtime/processing/ResponseProcessingEngineTest.php index a258bea63..ae6ca3d9a 100644 --- a/test/qtismtest/runtime/processing/ResponseProcessingEngineTest.php +++ b/test/qtismtest/runtime/processing/ResponseProcessingEngineTest.php @@ -221,7 +221,7 @@ public function testResponseProcessingErrorCollection(): void self::assertNotNull($exceptions); self::assertEquals( - 'The FieldValue operator only accepts operands with a cardinality of record.', + 'No variable with identifier \'SCORE\' to be set in the current state.', $exceptions->getProcessingExceptions()[0]->getMessage() ); }