/** * Tests Address->toXML */ public function testToXML() { $data = array('atBpost' => array('product' => 'bpack@bpost', 'weight' => 2000, 'pugoId' => '207500', 'pugoName' => 'WIJNEGEM', 'pugoAddress' => array('streetName' => 'Turnhoutsebaan', 'number' => '468', 'postalCode' => '2110', 'locality' => 'WIJNEGEM', 'countryCode' => 'BE'), 'receiverName' => 'Tijs Verkoyen', 'receiverCompany' => 'Sumo Coders')); $expectedDocument = self::createDomDocument(); $nationalBox = $expectedDocument->createElement('nationalBox'); $atBpost = $expectedDocument->createElement('atBpost'); $nationalBox->appendChild($atBpost); $expectedDocument->appendChild($nationalBox); foreach ($data['atBpost'] as $key => $value) { if ($key == 'pugoAddress') { $address = $expectedDocument->createElement($key); foreach ($value as $key2 => $value2) { $key2 = 'common:' . $key2; $address->appendChild($expectedDocument->createElement($key2, $value2)); } $atBpost->appendChild($address); } else { $atBpost->appendChild($expectedDocument->createElement($key, $value)); } } $actualDocument = self::createDomDocument(); $pugoAddress = new PugoAddress($data['atBpost']['pugoAddress']['streetName'], $data['atBpost']['pugoAddress']['number'], null, $data['atBpost']['pugoAddress']['postalCode'], $data['atBpost']['pugoAddress']['locality'], $data['atBpost']['pugoAddress']['countryCode']); $atBpost = new AtBpost(); $atBpost->setProduct($data['atBpost']['product']); $atBpost->setWeight($data['atBpost']['weight']); $atBpost->setPugoId($data['atBpost']['pugoId']); $atBpost->setPugoName($data['atBpost']['pugoName']); $atBpost->setPugoAddress($pugoAddress); $atBpost->setReceiverName($data['atBpost']['receiverName']); $atBpost->setReceiverCompany($data['atBpost']['receiverCompany']); $actualDocument->appendChild($atBpost->toXML($actualDocument)); $this->assertEquals($expectedDocument, $actualDocument); }
/** * @param \SimpleXMLElement $xml * @return AtBpost */ public static function createFromXML(\SimpleXMLElement $xml) { $atBpost = new AtBpost(); if (isset($xml->atBpost->product) && $xml->atBpost->product != '') { $atBpost->setProduct((string) $xml->atBpost->product); } if (isset($xml->atBpost->options)) { foreach ($xml->atBpost->options as $optionData) { $optionData = $optionData->children('http://schema.post.be/shm/deepintegration/v3/common'); if (in_array($optionData->getName(), array('infoDistributed', 'infoNextDay', 'infoReminder', 'keepMeInformed'))) { $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); } $atBpost->addOption($option); } } if (isset($xml->atBpost->weight) && $xml->atBpost->weight != '') { $atBpost->setWeight((int) $xml->atBpost->weight); } if (isset($xml->atBpost->receiverName) && $xml->atBpost->receiverName != '') { $atBpost->setReceiverName((string) $xml->atBpost->receiverName); } if (isset($xml->atBpost->receiverCompany) && $xml->atBpost->receiverCompany != '') { $atBpost->setReceiverCompany((string) $xml->atBpost->receiverCompany); } if (isset($xml->atBpost->pugoId) && $xml->atBpost->pugoId != '') { $atBpost->setPugoId((string) $xml->atBpost->pugoId); } if (isset($xml->atBpost->pugoName) && $xml->atBpost->pugoName != '') { $atBpost->setPugoName((string) $xml->atBpost->pugoName); } if (isset($xml->atBpost->pugoAddress)) { $pugoAddressData = $xml->atBpost->pugoAddress->children('http://schema.post.be/shm/deepintegration/v3/common'); $atBpost->setPugoAddress(PugoAddress::createFromXML($pugoAddressData)); } return $atBpost; }
// 'GEBABEBB' //); //$option = new Signature(); //$option = new Insurance('additionalInsurance', 3); //$option = new AutomaticSecondPresentation(); // @Home $atHome = new AtHome(); $atHome->setProduct('bpack 24h Pro'); $atHome->setWeight(2000); $atHome->setReceiver($receiver); $atHome->addOption($option); $box->setNationalBox($atHome); // @Bpost $pugoAddress = new PugoAddress('Turnhoutsebaan', '468', null, '2110', 'Wijnegem', 'BE'); $atBpost = new AtBpost(); $atBpost->setWeight(2000); $atBpost->setPugoId('207500'); $atBpost->setPugoName('WIJNEGEM'); $atBpost->setPugoAddress($pugoAddress); $atBpost->setReceiverName('Tijs Verkoyen'); $atBpost->setReceiverCompany('Sumo Coders'); //$box->setNationalBox($atBpost); // @24/7 $parcelsDepotAddress = new ParcelsDepotAddress('Turnhoutsebaan', '468', null, '2110', 'Wijnegem', 'BE'); $parcelsDepotAddress->setBox('A'); $at247 = new At247(); $at247->setParcelsDepotId('014472'); $at247->setParcelsDepotName('WIJNEGEM'); $at247->setParcelsDepotAddress($parcelsDepotAddress); $at247->setMemberId('188565346'); $at247->setReceiverName('Tijs Verkoyen');