public function testMarshalling() { $expectedXml = <<<XML <?xml version="1.0"?> <purchase-order xmlns="http://openuri.org/easypo"> <customer> <name>Gladys Kravitz</name> <address>Anytown, PA</address> </customer> <date>2003-01-07T14:16:00-05:00</date> <line-item> <description>Burnham's Celestial Handbook, Vol 1</description> <per-unit-ounces>5</per-unit-ounces> <price>21.79</price> <quantity>2</quantity> </line-item> <line-item> <description>Burnham's Celestial Handbook, Vol 2</description> <per-unit-ounces>5</per-unit-ounces> <price>19.89</price> <quantity>2</quantity> </line-item> <shipper> <name>ZipShip</name> <per-ounce-rate>0.74</per-ounce-rate> </shipper> </purchase-order> XML; $filepath = dirname(__FILE__) . '/../../_files/EasyPO/'; $binding = new PiBX_Runtime_Binding($filepath . '/binding.xml'); $marshaller = new PiBX_Runtime_Marshaller($binding); $po = new PurchaseOrder(); $po->setDate('2003-01-07T14:16:00-05:00'); $customer = new Customer(); $customer->setName('Gladys Kravitz'); $customer->setAddress('Anytown, PA'); $lineItem1 = new LineItem(); $lineItem1->setDescription('Burnham\'s Celestial Handbook, Vol 1'); $lineItem1->setPerUnitOunces('5'); $lineItem1->setPrice(21.79); $lineItem1->setQuantity(2); $lineItem2 = new LineItem(); $lineItem2->setDescription('Burnham\'s Celestial Handbook, Vol 2'); $lineItem2->setPerUnitOunces('5'); $lineItem2->setPrice(19.89); $lineItem2->setQuantity(2); $shipper = new Shipper(); $shipper->setName('ZipShip'); $shipper->setPerOunceRate(0.74); $po->setCustomer($customer); $po->setLineItems(array($lineItem1, $lineItem2)); $po->setShipper($shipper); $xml = $marshaller->marshal($po); $this->assertEquals($expectedXml, $xml); $dom = new DOMDocument(); $dom->loadXML($xml); $this->assertTrue($dom->schemaValidate($filepath . '/easypo.xsd')); }
public function testTwoBooks() { $expectedXml = <<<XML <?xml version="1.0"?> <Collection> <books> <book itemId="0001"> <name>Book #1 Name</name> <ISBN>123456789</ISBN> <price>\$ 1.23</price> <authors> <authorName>Adam</authorName> <authorName>Bob</authorName> <authorName>Eve</authorName> </authors> <description>Book #1 Description</description> <promotion> <Discount>7%</Discount> </promotion> <publicationDate>2010-12-29</publicationDate> <bookCategory>fiction</bookCategory> </book> <book itemId="0002"> <name>Book #2 Name</name> <ISBN>987654321</ISBN> <price>\$ 4.56</price> <authors> <authorName>Mark</authorName> <authorName>Kate</authorName> </authors> <description>Book #2 Description</description> <promotion> <None>Regular price</None> </promotion> <publicationDate>2010-06-01</publicationDate> <bookCategory>novel</bookCategory> </book> </books> </Collection> XML; $filepath = dirname(__FILE__) . '/../_files/Books/'; $binding = new PiBX_Runtime_Binding($filepath . '/binding.xml'); $marshaller = new PiBX_Runtime_Marshaller($binding); $c = new Collection(); $book1 = new BookType(); $book1->setName('Book #1 Name'); $book1->setIsbn(123456789); $book1->setPrice('$ 1.23'); $book1->setAuthorNames(array('Adam', 'Bob', 'Eve')); $book1->setDescription('Book #1 Description'); $book1->setPromotionDiscount('7%'); $book1->setPublicationdate('2010-12-29'); $book1->setBookcategory('fiction'); $book1->setItemId('0001'); $book2 = new BookType(); $book2->setName('Book #2 Name'); $book2->setIsbn(987654321); $book2->setPrice('$ 4.56'); $book2->setAuthorNames(array('Mark', 'Kate')); $book2->setDescription('Book #2 Description'); $book2->setPromotionNone('Regular price'); $book2->setPublicationdate('2010-06-01'); $book2->setBookcategory('novel'); $book2->setItemId('0002'); $list = array($book1, $book2); $c->setBooks($list); $xml = $marshaller->marshal($c); $this->assertEquals($expectedXml, $xml); $dom = new DOMDocument(); $dom->loadXML($xml); $this->assertTrue($dom->schemaValidate($filepath . '/books.xsd')); }