diff --git a/composer.json b/composer.json index d7b4502ed..2cf7360bd 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "qtism/qtism", "description": "OAT QTI Software Module Library", "type": "library", - "version": "0.9.32", + "version": "0.9.33", "authors": [ { "name": "Open Assessment Technologies S.A.", diff --git a/qtism/data/rules/ResponseElseIf.php b/qtism/data/rules/ResponseElseIf.php index bc768d722..eb5308238 100644 --- a/qtism/data/rules/ResponseElseIf.php +++ b/qtism/data/rules/ResponseElseIf.php @@ -14,7 +14,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Copyright (c) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); + * Copyright (c) 2013-2016 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); * * @author Jérôme Bogaerts, * @license GPLv2 @@ -61,7 +61,6 @@ class ResponseElseIf extends QtiComponent { * * @param Expression $expression An expression to be evaluated with the Else If statement. * @param ResponseRuleCollection $responseRules A collection of ResponseRule objects. - * @throws InvalidArgumentException If $responseRules is an empty collection. */ public function __construct(Expression $expression, ResponseRuleCollection $responseRules) { $this->setExpression($expression); @@ -101,16 +100,9 @@ public function getResponseRules() { * to the Else If statement returns true. * * @param ResponseRuleCollection $responseRules A collection of ResponseRule objects. - * @throws InvalidArgumentException If $responseRules is an empty collection. */ public function setResponseRules(ResponseRuleCollection $responseRules) { - if (count($responseRules) > 0) { - $this->responseRules = $responseRules; - } - else { - $msg = "A ResponseElseIf object must be bound to at lease one ResponseRule object."; - throw new InvalidArgumentException($msg); - } + $this->responseRules = $responseRules; } public function getQtiClassName() { diff --git a/qtism/data/rules/ResponseIf.php b/qtism/data/rules/ResponseIf.php index c2518f5e9..c373522ca 100644 --- a/qtism/data/rules/ResponseIf.php +++ b/qtism/data/rules/ResponseIf.php @@ -14,7 +14,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Copyright (c) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); + * Copyright (c) 2013-2016 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); * * @author Jérôme Bogaerts, * @license GPLv2 @@ -25,7 +25,6 @@ namespace qtism\data\rules; use qtism\data\QtiComponentCollection; - use qtism\data\QtiComponent; use qtism\data\expressions\Expression; use \InvalidArgumentException; @@ -67,7 +66,6 @@ class ResponseIf extends QtiComponent { * * @param Expression $expression The expression to be evaluated with the If statement. * @param ResponseRuleCollection $responseRules A collection of sub expressions to be evaluated if the Expression returns true. - * @throws InvalidArgumentException If $responseRules does not contain any ResponseRule object. */ public function __construct(Expression $expression, ResponseRuleCollection $responseRules) { $this->setExpression($expression); @@ -97,16 +95,9 @@ public function setExpression(Expression $expression) { * evaluated with the If statement returns true. * * @param ResponseRuleCollection $responseRules A collection of ResponseRule objects. - * @throws InvalidArgumentException If $responseRules is an empty collection. */ public function setResponseRules(ResponseRuleCollection $responseRules) { - if (count($responseRules) > 0) { - $this->responseRules = $responseRules; - } - else { - $msg = "A ResponseIf object must be bound to at least one ResponseRule."; - throw new InvalidArgumentException($msg); - } + $this->responseRules = $responseRules; } /** @@ -124,8 +115,10 @@ public function getQtiClassName() { } public function getComponents() { - $comp = array_merge(array($this->getExpression()), - $this->getResponseRules()->getArrayCopy()); + $comp = array_merge( + array($this->getExpression()), + $this->getResponseRules()->getArrayCopy() + ); return new QtiComponentCollection($comp); } diff --git a/test/qtism/runtime/processing/ResponseProcessingEngineTest.php b/test/qtism/runtime/processing/ResponseProcessingEngineTest.php index 038fb26f8..a787453f9 100644 --- a/test/qtism/runtime/processing/ResponseProcessingEngineTest.php +++ b/test/qtism/runtime/processing/ResponseProcessingEngineTest.php @@ -44,6 +44,61 @@ public function testResponseProcessingMatchCorrect() { $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $context['SCORE']); $this->assertEquals(1.0, $context['SCORE']->getValue()); } + + public function testResponseProcessingNoResponseRule() { + $responseProcessing = $this->createComponentFromXml(' + + + + + + ChoiceA + + + + + + + ChoiceB + + + + + + 1.0 + + + + + '); + + $responseDeclaration = $this->createComponentFromXml(' + + '); + + $outcomeDeclaration = $this->createComponentFromXml(' + + '); + + $respVar = ResponseVariable::createFromDataModel($responseDeclaration); + $outVar = OutcomeVariable::createFromDataModel($outcomeDeclaration); + $context = new State(array($respVar, $outVar)); + + $engine = new ResponseProcessingEngine($responseProcessing, $context); + + $context['RESPONSE'] = new Identifier('ChoiceA'); + $engine->process(); + $this->assertNull($context['SCORE']); + + $context['RESPONSE'] = new Identifier('ChoiceB'); + $engine->process(); + $this->assertNull($context['SCORE']); + + $context['RESPONSE'] = new Identifier('ChoiceC'); + $engine->process(); + $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $context['SCORE']); + $this->assertEquals(1.0, $context['SCORE']->getValue()); + } public function testResponseProcessingExitResponse() { $responseProcessing = $this->createComponentFromXml(' @@ -64,4 +119,4 @@ public function testResponseProcessingExitResponse() { $this->assertEquals(RuleProcessingException::EXIT_RESPONSE, $e->getCode()); } } -} \ No newline at end of file +}