/**
  * 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);
     }
 }
 /**
  * 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);
     }
 }