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