/** * Tests Address->toXML */ public function testToXML() { $data = array('atHome' => array('product' => 'bpack 24h Pro', 'options' => array(array('common:infoNextDay' => array('@attributes' => array('language' => 'NL'), 'common:emailAddress' => '*****@*****.**'))), 'weight' => 2000, 'openingHours' => array('Monday' => '10:00-17:00'), 'desiredDeliveryPlace' => 1234, 'receiver' => array('name' => 'Tijs Verkoyen', 'company' => 'Sumo Coders', 'address' => array('streetName' => 'Afrikalaan', 'number' => '289', 'box' => '3', 'postalCode' => '9000', 'locality' => 'Gent', 'countryCode' => 'BE'), 'emailAddress' => '*****@*****.**', 'phoneNumber' => '+32 9 395 02 51'))); $expectedDocument = self::createDomDocument(); $nationalBox = $expectedDocument->createElement('nationalBox'); $expectedDocument->appendChild($nationalBox); $atHome = $expectedDocument->createElement('atHome'); $nationalBox->appendChild($atHome); $atHome->appendChild($expectedDocument->createElement('product', $data['atHome']['product'])); $options = $expectedDocument->createElement('options'); foreach ($data['atHome']['options'] as $value) { foreach ($value as $key2 => $value2) { $element = $expectedDocument->createElement($key2); foreach ($value2 as $key3 => $value3) { if ($key3 == '@attributes') { foreach ($value3 as $key4 => $value4) { $element->setAttribute($key4, $value4); } } else { $element->appendChild($expectedDocument->createElement($key3, $value3)); } } $options->appendChild($element); } } $atHome->appendChild($options); $atHome->appendChild($expectedDocument->createElement('weight', $data['atHome']['weight'])); $openingHours = $expectedDocument->createElement('openingHours'); foreach ($data['atHome']['openingHours'] as $key => $value) { $openingHours->appendChild($expectedDocument->createElement($key, $value)); } $atHome->appendChild($openingHours); $atHome->appendChild($expectedDocument->createElement('desiredDeliveryPlace', $data['atHome']['desiredDeliveryPlace'])); $receiver = $expectedDocument->createElement('receiver'); $atHome->appendChild($receiver); foreach ($data['atHome']['receiver'] as $key => $value) { $key = 'common:' . $key; if ($key == 'common:address') { $address = $expectedDocument->createElement($key); foreach ($value as $key2 => $value2) { $key2 = 'common:' . $key2; $address->appendChild($expectedDocument->createElement($key2, $value2)); } $receiver->appendChild($address); } else { $receiver->appendChild($expectedDocument->createElement($key, $value)); } } $actualDocument = self::createDomDocument(); $address = new Address($data['atHome']['receiver']['address']['streetName'], $data['atHome']['receiver']['address']['number'], $data['atHome']['receiver']['address']['box'], $data['atHome']['receiver']['address']['postalCode'], $data['atHome']['receiver']['address']['locality'], $data['atHome']['receiver']['address']['countryCode']); $receiver = new Receiver(); $receiver->setName($data['atHome']['receiver']['name']); $receiver->setCompany($data['atHome']['receiver']['company']); $receiver->setAddress($address); $receiver->setEmailAddress($data['atHome']['receiver']['emailAddress']); $receiver->setPhoneNumber($data['atHome']['receiver']['phoneNumber']); $openingHourDay = new OpeninghourDay('Monday', $data['atHome']['openingHours']['Monday']); $messaging = new Messaging('infoNextDay', $data['atHome']['options'][0]['common:infoNextDay']['@attributes']['language'], $data['atHome']['options'][0]['common:infoNextDay']['common:emailAddress']); $atHome = new AtHome(); $atHome->setProduct($data['atHome']['product']); $atHome->setWeight($data['atHome']['weight']); $atHome->setReceiver($receiver); $atHome->setDesiredDeliveryPlace($data['atHome']['desiredDeliveryPlace']); $atHome->addOpeningHour($openingHourDay); // I know, the line below is kinda bogus, but it will make sure all code is tested $atHome->setOpeningHours(array($openingHourDay)); $atHome->addOption($messaging); // I know, the line below is kinda bogus, but it will make sure all code is tested $atHome->setOptions(array($messaging)); $actualDocument->appendChild($atHome->toXML($actualDocument)); $this->assertEquals($expectedDocument, $actualDocument); }
//$option = new Messaging('infoReminder', 'NL', '*****@*****.**'); //$option = new Messaging('keepMeInformed', 'NL', '*****@*****.**'); //$option = new CashOnDelivery( // 1251, // 'BE19210023508812', // '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();
/** * @param \SimpleXMLElement $xml * @return AtHome */ public static function createFromXML(\SimpleXMLElement $xml) { $atHome = new AtHome(); if (isset($xml->atHome->product) && $xml->atHome->product != '') { $atHome->setProduct((string) $xml->atHome->product); } if (isset($xml->atHome->options) and !empty($xml->atHome->options)) { foreach ($xml->atHome->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); } $atHome->addOption($option); } } if (isset($xml->atHome->weight) && $xml->atHome->weight != '') { $atHome->setWeight((int) $xml->atHome->weight); } if (isset($xml->atHome->openingHours) && $xml->atHome->openingHours != '') { throw new Exception('Not Implemented'); $atHome->setProduct((string) $xml->atHome->openingHours); } if (isset($xml->atHome->desiredDeliveryPlace) && $xml->atHome->desiredDeliveryPlace != '') { $atHome->setDesiredDeliveryPlace((string) $xml->atHome->desiredDeliveryPlace); } if (isset($xml->atHome->receiver)) { $atHome->setReceiver(Receiver::createFromXML($xml->atHome->receiver->children('http://schema.post.be/shm/deepintegration/v3/common'))); } return $atHome; }
/** * @return Order */ protected function createAtHomeOrderObject() { // create order $orderId = time(); $order = new Order($orderId); $order->setCostCenter('Cost Center'); // add lines $line1 = new OrderLine('Beer', 1); $order->addLine($line1); $line2 = new OrderLine('Whisky', 100); $order->addLine($line2); // add box $address = new Address(); $address->setStreetName('Afrikalaan'); $address->setNumber('289'); $address->setPostalCode('9000'); $address->setLocality('Gent'); $address->setCountryCode('BE'); $sender = new Sender(); $sender->setAddress($address); $sender->setName('Tijs Verkoyen'); $sender->setCompany('Sumo Coders'); $sender->setPhoneNumber('+32 9 395 02 51'); $sender->setEmailAddress('*****@*****.**'); $box = new Box(); $box->setSender($sender); $box->setRemark('Remark'); // add label $address = new Address(); $address->setStreetName('Kerkstraat'); $address->setNumber('108'); $address->setPostalCode('9050'); $address->setLocality('Gentbrugge'); $address->setCountryCode('BE'); $receiver = new Receiver(); $receiver->setAddress($address); $receiver->setName('Tijs Verkoyen'); $receiver->setCompany('Sumo Coders'); $receiver->setPhoneNumber('+32 9 395 02 51'); $receiver->setEmailAddress('*****@*****.**'); // options $option = new Messaging('infoDistributed', 'NL', '*****@*****.**'); // @Home $atHome = new AtHome(); $atHome->setProduct('bpack 24h Pro'); $atHome->setWeight(2000); $atHome->setReceiver($receiver); $atHome->addOption($option); $box->setNationalBox($atHome); $order->addBox($box); return $order; }