Пример #1
0
 /**
  * Tests Line->toXML
  */
 public function testToXML()
 {
     $data = array('text' => 'just a random text', 'nbOfItems' => time());
     $expectedDocument = self::createDomDocument();
     $line = $expectedDocument->createElement('orderLine');
     foreach ($data as $key => $value) {
         $line->appendChild($expectedDocument->createElement($key, $value));
     }
     $expectedDocument->appendChild($line);
     $actualDocument = self::createDomDocument();
     $line = new Line($data['text'], $data['nbOfItems']);
     $actualDocument->appendChild($line->toXML($actualDocument, null));
     $this->assertEquals($expectedDocument, $actualDocument);
 }
Пример #2
0
 /**
  * @param  \SimpleXMLElement $xml
  * @return Order
  */
 public static function createFromXML(\SimpleXMLElement $xml)
 {
     // @todo work with classmaps ...
     if (!isset($xml->reference)) {
         throw new Exception('No reference found.');
     }
     $order = new Order((string) $xml->reference);
     if (isset($xml->costCenter) && $xml->costCenter != '') {
         $order->setCostCenter((string) $xml->costCenter);
     }
     if (isset($xml->orderLine)) {
         foreach ($xml->orderLine as $orderLine) {
             $order->addLine(Line::createFromXML($orderLine));
         }
     }
     if (isset($xml->box)) {
         foreach ($xml->box as $box) {
             $order->addBox(Box::createFromXML($box));
         }
     }
     return $order;
 }