Esempio n. 1
0
 /**
  * Tests Customer->toXML
  */
 public function testToXML()
 {
     $data = array('FirstName' => 'Tijs', 'LastName' => 'Verkoyen', 'Email' => '*****@*****.**', 'Street' => 'Afrikalaan', 'Number' => '289', 'MobilePrefix' => '0032', 'MobileNumber' => '486123456', 'PostalCode' => '9000', 'PreferredLanguage' => 'nl-BE', 'Title' => 'Mr.');
     $expectedDocument = self::createDomDocument();
     $customer = $expectedDocument->createElement('Customer');
     $customer->setAttribute('xmlns', 'http://schema.post.be/ServiceController/customer');
     $customer->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
     $customer->setAttribute('xsi:schemaLocation', 'http://schema.post.be/ServiceController/customer');
     $customer->appendChild($expectedDocument->createElement('FirstName', $data['FirstName']));
     $customer->appendChild($expectedDocument->createElement('LastName', $data['LastName']));
     $customer->appendChild($expectedDocument->createElement('Street', $data['Street']));
     $customer->appendChild($expectedDocument->createElement('Number', $data['Number']));
     $customer->appendChild($expectedDocument->createElement('Email', $data['Email']));
     $customer->appendChild($expectedDocument->createElement('MobilePrefix', $data['MobilePrefix']));
     $customer->appendChild($expectedDocument->createElement('MobileNumber', $data['MobileNumber']));
     $customer->appendChild($expectedDocument->createElement('PostalCode', $data['PostalCode']));
     $customer->appendChild($expectedDocument->createElement('PreferredLanguage', $data['PreferredLanguage']));
     $customer->appendChild($expectedDocument->createElement('Title', $data['Title']));
     $expectedDocument->appendChild($customer);
     $customer = new Customer();
     $customer->setFirstName($data['FirstName']);
     $customer->setLastName($data['LastName']);
     $customer->setEmail($data['Email']);
     $customer->setStreet($data['Street']);
     $customer->setNumber($data['Number']);
     $customer->setMobileNumber($data['MobileNumber']);
     $customer->setPostalCode($data['PostalCode']);
     $customer->setPreferredLanguage($data['PreferredLanguage']);
     $customer->setTitle($data['Title']);
     $actualDocument = self::createDomDocument();
     $actualDocument->appendChild($customer->toXML($actualDocument));
     $this->assertEquals($expectedDocument->saveXML(), $actualDocument->saveXML());
 }
Esempio n. 2
0
 /**
  * @param  \SimpleXMLElement $xml
  * @return Customer
  */
 public static function createFromXML(\SimpleXMLElement $xml)
 {
     // @todo work with classmaps ...
     if (!isset($xml->UserID)) {
         throw new Exception('No UserId found.');
     }
     $customer = new Customer();
     if (isset($xml->UserID) && $xml->UserID != '') {
         $customer->setUserID((string) $xml->UserID);
     }
     if (isset($xml->FirstName) && $xml->FirstName != '') {
         $customer->setFirstName((string) $xml->FirstName);
     }
     if (isset($xml->LastName) && $xml->LastName != '') {
         $customer->setLastName((string) $xml->LastName);
     }
     if (isset($xml->Street) && $xml->Street != '') {
         $customer->setStreet((string) $xml->Street);
     }
     if (isset($xml->Number) && $xml->Number != '') {
         $customer->setNumber((string) $xml->Number);
     }
     if (isset($xml->CompanyName) && $xml->CompanyName != '') {
         $customer->setCompanyName((string) $xml->CompanyName);
     }
     if (isset($xml->DateOfBirth) && $xml->DateOfBirth != '') {
         $dateTime = new \DateTime((string) $xml->DateOfBirth);
         $customer->setDateOfBirth($dateTime);
     }
     if (isset($xml->DeliveryCode) && $xml->DeliveryCode != '') {
         $customer->setDeliveryCode((string) $xml->DeliveryCode);
     }
     if (isset($xml->Email) && $xml->Email != '') {
         $customer->setEmail((string) $xml->Email);
     }
     if (isset($xml->MobilePrefix) && $xml->MobilePrefix != '') {
         $customer->setMobilePrefix(trim((string) $xml->MobilePrefix));
     }
     if (isset($xml->MobileNumber) && $xml->MobileNumber != '') {
         $customer->setMobileNumber((string) $xml->MobileNumber);
     }
     if (isset($xml->Postalcode) && $xml->Postalcode != '') {
         $customer->setPostalCode((string) $xml->Postalcode);
     }
     if (isset($xml->PreferredLanguage) && $xml->PreferredLanguage != '') {
         $customer->setPreferredLanguage((string) $xml->PreferredLanguage);
     }
     if (isset($xml->ReceivePromotions) && $xml->ReceivePromotions != '') {
         $receivePromotions = in_array((string) $xml->ReceivePromotions, array('true', '1'));
         $customer->setReceivePromotions($receivePromotions);
     }
     if (isset($xml->actived) && $xml->actived != '') {
         $activated = in_array((string) $xml->actived, array('true', '1'));
         $customer->setActivated($activated);
     }
     if (isset($xml->Title) && $xml->Title != '') {
         $title = (string) $xml->Title;
         $title = ucfirst(strtolower($title));
         if (substr($title, -1) != '.') {
             $title .= '.';
         }
         $customer->setTitle($title);
     }
     if (isset($xml->Town) && $xml->Town != '') {
         $customer->setTown((string) $xml->Town);
     }
     if (isset($xml->PackStations->CustomerPackStation)) {
         foreach ($xml->PackStations->CustomerPackStation as $packStation) {
             $customer->addPackStation(CustomerPackStation::createFromXML($packStation));
         }
     }
     return $customer;
 }