/** * Tests CustomsInfo->createFromXML */ public function testCreateFromXML() { $data = array('parcelValue' => '700', 'contentDescription' => 'BOOK', 'shipmentType' => 'DOCUMENTS', 'parcelReturnInstructions' => 'RTS', 'privateAddress' => false); $document = self::createDomDocument(); $customsInfo = $document->createElement('CustomsInfo'); foreach ($data as $key => $value) { $customsInfo->appendChild($document->createElement($key, $value)); } $document->appendChild($customsInfo); $customsInfo = CustomsInfo::createFromXML(simplexml_load_string($document->saveXML())); $this->assertEquals($data['parcelValue'], $customsInfo->getParcelValue()); $this->assertEquals($data['parcelReturnInstructions'], $customsInfo->getParcelReturnInstructions()); $this->assertEquals($data['contentDescription'], $customsInfo->getContentDescription()); $this->assertEquals($data['shipmentType'], $customsInfo->getShipmentType()); $this->assertEquals($data['privateAddress'], $customsInfo->getPrivateAddress()); $data = array('parcelValue' => '700', 'contentDescription' => 'BOOK', 'shipmentType' => 'DOCUMENTS', 'parcelReturnInstructions' => 'RTS', 'privateAddress' => 'true'); $document = self::createDomDocument(); $customsInfo = $document->createElement('CustomsInfo'); foreach ($data as $key => $value) { $customsInfo->appendChild($document->createElement($key, $value)); } $document->appendChild($customsInfo); $customsInfo = CustomsInfo::createFromXML(simplexml_load_string($document->saveXML())); $this->assertEquals($data['parcelValue'], $customsInfo->getParcelValue()); $this->assertEquals($data['parcelReturnInstructions'], $customsInfo->getParcelReturnInstructions()); $this->assertEquals($data['contentDescription'], $customsInfo->getContentDescription()); $this->assertEquals($data['shipmentType'], $customsInfo->getShipmentType()); $this->assertEquals($data['privateAddress'] == 'true', $customsInfo->getPrivateAddress()); }
/** * @param \SimpleXMLElement $xml * @return International */ public static function createFromXML(\SimpleXMLElement $xml) { $international = new International(); if (isset($xml->international->product) && $xml->international->product != '') { $international->setProduct((string) $xml->international->product); } if (isset($xml->international->options)) { foreach ($xml->international->options as $optionData) { $optionData = $optionData->children('http://schema.post.be/shm/deepintegration/v3/common'); if (in_array($optionData->getName(), array('infoDistributed'))) { $option = Messaging::createFromXML($optionData); } else { $className = '\\TijsVerkoyen\\Bpost\\Bpost\\Order\\Box\\Option\\' . ucfirst($optionData->getName()); if (!method_exists($className, 'createFromXML')) { throw new Exception('Not Implemented'); } $option = call_user_func(array($className, 'createFromXML'), $optionData); } $international->addOption($option); } } if (isset($xml->international->parcelWeight) && $xml->international->parcelWeight != '') { $international->setParcelWeight((int) $xml->international->parcelWeight); } if (isset($xml->international->receiver)) { $receiverData = $xml->international->receiver->children('http://schema.post.be/shm/deepintegration/v3/common'); $international->setReceiver(Receiver::createFromXML($receiverData)); } if (isset($xml->international->customsInfo)) { $international->setCustomsInfo(CustomsInfo::createFromXML($xml->international->customsInfo)); } return $international; }