public function testMarshall()
 {
     $sectionIdentifier = 'mySection1';
     $variableIdentifier = 'myVariable1';
     $includeCategory = 'cat1';
     $excludeCategory = 'cat2 cat3';
     $baseType = BaseType::INTEGER;
     $weightIdentifier = 'myWeight1';
     $component = new TestVariables($variableIdentifier, $baseType, $weightIdentifier);
     $component->setSectionIdentifier($sectionIdentifier);
     $component->setIncludeCategories(new IdentifierCollection(explode(" ", $includeCategory)));
     $component->setExcludeCategories(new IdentifierCollection(explode(" ", $excludeCategory)));
     $marshaller = $this->getMarshallerFactory('2.1.0')->createMarshaller($component);
     $element = $marshaller->marshall($component);
     $this->assertInstanceOf('\\DOMElement', $element);
     $this->assertEquals('testVariables', $element->nodeName);
     $this->assertEquals($sectionIdentifier, $element->getAttribute('sectionIdentifier'));
     $this->assertEquals($variableIdentifier, $element->getAttribute('variableIdentifier'));
     $this->assertEquals($weightIdentifier, $element->getAttribute('weightIdentifier'));
     $this->assertEquals($includeCategory, $element->getAttribute('includeCategory'));
     $this->assertEquals($excludeCategory, $element->getAttribute('excludeCategory'));
     $this->assertEquals('integer', $element->getAttribute('baseType'));
 }
 /**
  * Marshall a testVariable QTI element in its TestVariable object equivalent.
  *
  * @param \DOMElement A DOMElement object.
  * @return \qtism\data\QtiComponent The corresponding TestVariable object.
  */
 protected function unmarshall(DOMElement $element)
 {
     $baseComponent = parent::unmarshall($element);
     if (($variableIdentifier = static::getDOMElementAttributeAs($element, 'variableIdentifier')) !== null) {
         $object = new TestVariables($variableIdentifier);
         $object->setSectionIdentifier($baseComponent->getSectionIdentifier());
         $object->setIncludeCategories($baseComponent->getIncludeCategories());
         $object->setExcludeCategories($baseComponent->getExcludeCategories());
         if (($baseType = static::getDOMElementAttributeAs($element, 'baseType')) !== null) {
             $object->setBaseType(BaseType::getConstantByName($baseType));
         }
         if (($weightIdentifier = static::getDOMElementAttributeAs($element, 'weightIdentifier')) !== null) {
             $object->setWeightIdentifier($weightIdentifier);
         }
         return $object;
     } else {
         $msg = "The mandatory attribute 'variableIdentifier' is missing from element '" . $element->localName . "'.";
         throw new UnmarshallingException($msg, $element);
     }
 }
 protected static function getTestVariables($variableIdentifier, $baseType = -1, $weightIdentifier = '', $sectionIdentifier = '', IdentifierCollection $includeCategories = null, IdentifierCollection $excludeCategories = null)
 {
     $testVariables = new TestVariables($variableIdentifier, $baseType, $weightIdentifier);
     $testVariables->setSectionIdentifier($sectionIdentifier);
     if (empty($includeCategories) === false) {
         $testVariables->setIncludeCategories($includeCategories);
     }
     if (empty($excludeCategories) === false) {
         $testVariables->setExcludeCategories($excludeCategories);
     }
     return $testVariables;
 }
 /**
  * Append the outcome processing rules to populate an outcome variable with total score of items related to a given category.
  * 
  * This method will append a QTI outcome processing to a given QTI-SDK AssessmentTest $test, dedicated to store 
  * the total score of items related to a given QTI $category.
  * 
  * In case of the $weightIdentifier argument is given, the score will consider weights defined at the assessmentItemRef
  * level identified by $weightIdentifier. Otherwise, no weights are taken into account while computing total scores.
  * 
  * In case of an outcome processing rule targetting a variable name $varName already exists in the test, the outcome
  * processing rule is not appended to the test.
  * 
  * @param qtism\data\AssessmentTest $test A QTI-SDK AssessmentTest object.
  * @param string $category A QTI category identifier.
  * @param string $varName The QTI identifier of the variable to be populated by the outcome processing rule.
  * @param string $scoreIdentifier (optional) An optional QTI identifier to be used as items' score variable (defaults to "SCORE").
  * @param string $weightIdentifier (optional) An optional QTI identifier to be used as items' weight to be considered for total score. (defaults to empty string).
  */
 public static function appendTotalScoreOutcomeProcessing(AssessmentTest $test, $category, $varName, $scoreVariableIdentifier = 'SCORE', $weightIdentifier = '')
 {
     if (self::isVariableSetOutcomeValueTarget($test, $varName) === false) {
         $testVariablesExpression = new TestVariables($scoreVariableIdentifier, BaseType::FLOAT);
         $testVariablesExpression->setWeightIdentifier($weightIdentifier);
         $testVariablesExpression->setIncludeCategories(new IdentifierCollection(array($category)));
         $setOutcomeValue = new SetOutcomeValue($varName, new Sum(new ExpressionCollection(array($testVariablesExpression))));
         self::appendOutcomeRule($test, $setOutcomeValue);
     }
 }