public function testMarshall()
 {
     $subs = new ExpressionCollection();
     $subs[] = new BaseValue(BaseType::INTEGER, 1);
     $subs[] = new BaseValue(BaseType::INTEGER, 2);
     $toleranceMode = ToleranceMode::EXACT;
     $includeLowerBound = false;
     $includeUpperBound = true;
     $component = new Equal($subs);
     $component->setToleranceMode($toleranceMode);
     $component->setIncludeLowerBound($includeLowerBound);
     $component->setIncludeUpperBound($includeUpperBound);
     $marshaller = $this->getMarshallerFactory()->createMarshaller($component);
     $element = $marshaller->marshall($component);
     $this->assertInstanceOf('\\DOMElement', $element);
     $this->assertEquals('equal', $element->nodeName);
     $this->assertEquals('exact', $element->getAttribute('toleranceMode'));
     $this->assertEquals('false', $element->getAttribute('includeLowerBound'));
     $this->assertEquals('', $element->getAttribute('includeUpperBound'));
     $this->assertEquals(2, $element->getElementsByTagName('baseValue')->length);
 }
Beispiel #2
0
 /**
  * @see \qtism\data\storage\xml\marshalling\OperatorMarshaller::unmarshallChildrenKnown()
  */
 protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children)
 {
     $object = new Equal($children);
     if (($toleranceMode = static::getDOMElementAttributeAs($element, 'toleranceMode')) !== null) {
         $toleranceMode = ToleranceMode::getConstantByName($toleranceMode);
         $object->setToleranceMode($toleranceMode);
     }
     if (($tolerance = static::getDOMElementAttributeAs($element, 'tolerance')) !== null) {
         $tolerance = explode(" ", $tolerance);
         if (count($tolerance) < 1) {
             $msg = "No 'tolerance' could be extracted from element '" . $element->localName . "'.";
             throw new UnmarshallingException($msg, $element);
         } elseif (count($tolerance) > 2) {
             $msg = "'tolerance' attribute not correctly formatted in element '" . $element->localName . "'.";
             throw new UnmarshallingException($msg, $element);
         } else {
             $finalTolerance = array();
             foreach ($tolerance as $t) {
                 $finalTolerance[] = Format::isFloat($t) ? floatval($t) : $t;
             }
             $object->setTolerance($finalTolerance);
         }
     }
     if (($includeLowerBound = static::getDOMElementAttributeAs($element, 'includeLowerBound', 'boolean')) !== null) {
         $object->setIncludeLowerBound($includeLowerBound);
     }
     if (($includeUpperBound = static::getDOMElementAttributeAs($element, 'includeUpperBound', 'boolean')) !== null) {
         $object->setIncludeUpperBound($includeUpperBound);
     }
     return $object;
 }