Example #1
0
 /**
  * Test validation in the setters
  */
 public function testFaultyProperties()
 {
     $receiver = new Receiver();
     try {
         $receiver->setEmailAddress(str_repeat('a', 51));
     } catch (\Exception $e) {
         $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e);
         $this->assertEquals('Invalid length, maximum is 50.', $e->getMessage());
     }
     try {
         $receiver->setPhoneNumber(str_repeat('a', 21));
     } catch (\Exception $e) {
         $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e);
         $this->assertEquals('Invalid length, maximum is 20.', $e->getMessage());
     }
 }
Example #2
0
 /**
  * Tests Box->toXML
  */
 public function testInternationalToXML()
 {
     $data = array('sender' => 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'), 'internationalBox' => array('international' => array('product' => 'bpack World Express Pro', 'receiver' => array('name' => 'Tijs Verkoyen', 'company' => 'Sumo Coders', 'address' => array('streetName' => 'Kerkstraat', 'number' => '108', 'postalCode' => '9050', 'locality' => 'Gentbrugge', 'countryCode' => 'BE'), 'emailAddress' => '*****@*****.**', 'phoneNumber' => '+32 9 395 02 51'))), 'remark' => 'remark');
     $expectedDocument = self::createDomDocument();
     $box = $expectedDocument->createElement('box');
     $expectedDocument->appendChild($box);
     $sender = $expectedDocument->createElement('sender');
     foreach ($data['sender'] 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));
             }
             $sender->appendChild($address);
         } else {
             $sender->appendChild($expectedDocument->createElement($key, $value));
         }
     }
     $nationalBox = $expectedDocument->createElement('internationalBox');
     $atHome = $expectedDocument->createElement('international:international');
     $nationalBox->appendChild($atHome);
     $atHome->appendChild($expectedDocument->createElement('international:product', $data['internationalBox']['international']['product']));
     $receiver = $expectedDocument->createElement('international:receiver');
     $atHome->appendChild($receiver);
     foreach ($data['internationalBox']['international']['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));
         }
     }
     $box->appendChild($sender);
     $box->appendChild($nationalBox);
     $box->appendChild($expectedDocument->createElement('remark', $data['remark']));
     $actualDocument = self::createDomDocument();
     $address = new Address($data['sender']['address']['streetName'], $data['sender']['address']['number'], $data['sender']['address']['box'], $data['sender']['address']['postalCode'], $data['sender']['address']['locality'], $data['sender']['address']['countryCode']);
     $sender = new Sender();
     $sender->setName($data['sender']['name']);
     $sender->setCompany($data['sender']['company']);
     $sender->setAddress($address);
     $sender->setEmailAddress($data['sender']['emailAddress']);
     $sender->setPhoneNumber($data['sender']['phoneNumber']);
     $address = new Address($data['internationalBox']['international']['receiver']['address']['streetName'], $data['internationalBox']['international']['receiver']['address']['number'], null, $data['internationalBox']['international']['receiver']['address']['postalCode'], $data['internationalBox']['international']['receiver']['address']['locality'], $data['internationalBox']['international']['receiver']['address']['countryCode']);
     $receiver = new Receiver();
     $receiver->setAddress($address);
     $receiver->setName($data['internationalBox']['international']['receiver']['name']);
     $receiver->setCompany($data['internationalBox']['international']['receiver']['company']);
     $receiver->setPhoneNumber($data['internationalBox']['international']['receiver']['phoneNumber']);
     $receiver->setEmailAddress($data['internationalBox']['international']['receiver']['emailAddress']);
     $international = new International();
     $international->setProduct($data['internationalBox']['international']['product']);
     $international->setReceiver($receiver);
     $box = new Box();
     $box->setSender($sender);
     $box->setInternationalBox($international);
     $box->setRemark($data['remark']);
     $actualDocument->appendChild($box->toXML($actualDocument, null));
     $this->assertEquals($expectedDocument, $actualDocument);
 }
Example #3
0
 /**
  * Tests International->toXML
  */
 public function testToXML()
 {
     $data = array('international' => array('product' => 'bpack World Express Pro', 'options' => array(array('common:infoNextDay' => array('@attributes' => array('language' => 'NL'), 'common:emailAddress' => '*****@*****.**'))), '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'), 'parcelWeight' => 2000, 'customsInfo' => array('parcelValue' => 700, 'contentDescription' => 'BOOK', 'shipmentType' => 'DOCUMENTS', 'parcelReturnInstructions' => 'RTS', 'privateAddress' => false)));
     $expectedDocument = self::createDomDocument();
     $nationalBox = $expectedDocument->createElement('internationalBox');
     $expectedDocument->appendChild($nationalBox);
     $international = $expectedDocument->createElement('international:international');
     $nationalBox->appendChild($international);
     $international->appendChild($expectedDocument->createElement('international:product', $data['international']['product']));
     $options = $expectedDocument->createElement('international:options');
     foreach ($data['international']['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);
         }
     }
     $international->appendChild($options);
     $receiver = $expectedDocument->createElement('international:receiver');
     $international->appendChild($receiver);
     foreach ($data['international']['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));
         }
     }
     $international->appendChild($expectedDocument->createElement('international:parcelWeight', $data['international']['parcelWeight']));
     $customsInfo = $expectedDocument->createElement('international:customsInfo');
     foreach ($data['international']['customsInfo'] as $key => $value) {
         if ($key == 'privateAddress') {
             $value = $value ? 'true' : 'false';
         }
         $customsInfo->appendChild($expectedDocument->createElement('international:' . $key, $value));
     }
     $international->appendChild($customsInfo);
     $actualDocument = self::createDomDocument();
     $address = new Address($data['international']['receiver']['address']['streetName'], $data['international']['receiver']['address']['number'], $data['international']['receiver']['address']['box'], $data['international']['receiver']['address']['postalCode'], $data['international']['receiver']['address']['locality'], $data['international']['receiver']['address']['countryCode']);
     $receiver = new Receiver();
     $receiver->setName($data['international']['receiver']['name']);
     $receiver->setCompany($data['international']['receiver']['company']);
     $receiver->setAddress($address);
     $receiver->setEmailAddress($data['international']['receiver']['emailAddress']);
     $receiver->setPhoneNumber($data['international']['receiver']['phoneNumber']);
     $customsInfo = new CustomsInfo();
     $customsInfo->setParcelValue($data['international']['customsInfo']['parcelValue']);
     $customsInfo->setContentDescription($data['international']['customsInfo']['contentDescription']);
     $customsInfo->setShipmentType($data['international']['customsInfo']['shipmentType']);
     $customsInfo->setParcelReturnInstructions($data['international']['customsInfo']['parcelReturnInstructions']);
     $customsInfo->setPrivateAddress($data['international']['customsInfo']['privateAddress']);
     $messaging = new Messaging('infoNextDay', $data['international']['options'][0]['common:infoNextDay']['@attributes']['language'], $data['international']['options'][0]['common:infoNextDay']['common:emailAddress']);
     $international = new International();
     $international->setProduct($data['international']['product']);
     $international->setReceiver($receiver);
     $international->setParcelWeight($data['international']['parcelWeight']);
     $international->setCustomsInfo($customsInfo);
     $international->addOption($messaging);
     // I know, the line below is kinda bogus, but it will make sure all code is tested
     $international->setOptions(array($messaging));
     $actualDocument->appendChild($international->toXML($actualDocument));
     $this->assertEquals($expectedDocument, $actualDocument);
 }
Example #4
0
 /**
  * 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);
 }
Example #5
0
$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', '*****@*****.**');
//$option = new Messaging('infoNextDay', 'NL', '*****@*****.**');
//$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
Example #6
0
 /**
  * @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;
 }