@@ -208,131 +208,42 @@ public function testBasketWithNoDiscount()
208208 $ this ->assertNotContains ('<discount> ' , $ data ['BasketXML ' ]);
209209 }
210210
211- public function testBasketWithOneDiscount ()
211+ public function testMixedBasketWithSpecialChars ()
212212 {
213213 $ items = new \Omnipay \Common \ItemBag (array (
214214 new \Omnipay \Common \Item (array (
215- 'name ' => 'Name ' ,
216- 'description ' => 'Description ' ,
217- 'quantity ' => 1 ,
218- 'price ' => 10.0 ,
219- )),
220- array (
221- 'name ' => 'One Discount ' ,
222- 'description ' => 'My Offer ' ,
223- 'quantity ' => 1 ,
224- 'price ' => -4 ,
225- )
226- ));
227-
228- $ this ->request ->setItems ($ items );
229- $ data = $ this ->request ->getData ();
230- // The element does exist, and must contain the basket XML, with optional XML header and
231- // trailing newlines.
232- $ this ->assertArrayHasKey ('BasketXML ' , $ data );
233- $ this ->assertContains ('<discounts> ' , $ data ['BasketXML ' ]);
234- }
235-
236- public function testBasketWithTwoDiscount ()
237- {
238- $ items = new \Omnipay \Common \ItemBag (array (
239- new \Omnipay \Common \Item (array (
240- 'name ' => 'Name ' ,
215+ 'name ' => "Denisé's Odd & Wierd £name? # " ,
241216 'description ' => 'Description ' ,
242- 'quantity ' => 1 ,
243- 'price ' => 1 .23 ,
217+ 'quantity ' => 2 ,
218+ 'price ' => 4 .23 ,
244219 )),
245220 array (
246- 'name ' => ' One Discount ' ,
221+ 'name ' => " Denisé's \" Odd \" & Wierd £discount? # " ,
247222 'description ' => 'My Offer ' ,
248- 'quantity ' => 1 ,
249- 'price ' => -4 ,
223+ 'quantity ' => 2 ,
224+ 'price ' => -0.10 ,
250225 ),
251226 array (
252227 'name ' => 'Second Discount ' ,
253228 'description ' => 'My 2nd Offer ' ,
254229 'quantity ' => 1 ,
255- 'price ' => -5 ,
230+ 'price ' => -1.60 ,
256231 )
257232 ));
258233
259234 $ expected = '<basket><item> '
260- . '<description>Name</description><quantity>1</quantity> '
261- . '<unitNetAmount>1.23</unitNetAmount><unitTaxAmount>0.00</unitTaxAmount> '
262- . '<unitGrossAmount>1.23</unitGrossAmount><totalGrossAmount>1.23</totalGrossAmount> '
263- . '</item><discounts><discount><fixed>4</fixed><description>One Discount</description></discount><discount><fixed>5</fixed><description>Second Discount</description></discount></discounts></basket> ' ;
264-
265- $ this ->request ->setItems ($ items );
266- $ data = $ this ->request ->getData ();
267- // The element does exist, and must contain the basket XML, with optional XML header and
268- // trailing newlines.
269- $ this ->assertArrayHasKey ('BasketXML ' , $ data );
270- $ this ->assertContains ($ expected , $ data ['BasketXML ' ]);
271- }
272-
273- public function testBasketWithNotEscapedName ()
274- {
275- $ items = new \Omnipay \Common \ItemBag (array (
276- new \Omnipay \Common \Item (array (
277- 'name ' => "Denise's Very Odd & Wierd name? " ,
278- 'description ' => 'Description ' ,
279- 'quantity ' => 1 ,
280- 'price ' => 1.23 ,
281- )),
282- array (
283- 'name ' => 'One Discount ' ,
284- 'description ' => 'My Offer ' ,
285- 'quantity ' => 1 ,
286- 'price ' => 4 ,
287- ),
288- array (
289- 'name ' => 'Second Discount ' ,
290- 'description ' => 'My 2nd Offer ' ,
291- 'quantity ' => 1 ,
292- 'price ' => 5 ,
293- )
294- ));
295-
296- $ expected = "<basket><item><description>Denise's Very Odd & Wierd name?</description><quantity>1</quantity><unitNetAmount>1.23</unitNetAmount><unitTaxAmount>0.00</unitTaxAmount><unitGrossAmount>1.23</unitGrossAmount><totalGrossAmount>1.23</totalGrossAmount></item><item>
297- <description>One Discount</description><quantity>1</quantity><unitNetAmount>4</unitNetAmount><unitTaxAmount>0.00</unitTaxAmount><unitGrossAmount>4</unitGrossAmount><totalGrossAmount>4</totalGrossAmount></item><item><description>Second Discount</description><quantity>1</quantity><unitNetAmoubnt>5</unitNetAmoubnt>
298- <totalGrossAmount>5</totalGrossAmount> " ;
299-
300- $ this ->request ->setItems ($ items );
301- $ data = $ this ->request ->getData ();
302-
303-
304- $ this ->assertNotContains ($ expected , $ data ['BasketXML ' ], "Should fail as name was not escaped " );
305-
306- }
307-
308- public function testBasketWithEscapedName ()
309- {
310- $ items = new \Omnipay \Common \ItemBag (array (
311- new \Omnipay \Common \Item (array (
312- 'name ' => "<Denise's Very Odd & Wierd 'name'?> " ,
313- 'description ' => 'Description ' ,
314- 'quantity ' => 1 ,
315- 'price ' => 1.23 ,
316- )),
317- array (
318- 'name ' => 'One Discount ' ,
319- 'description ' => 'My Offer ' ,
320- 'quantity ' => 1 ,
321- 'price ' => 4 ,
322- ),
323- array (
324- 'name ' => 'Second Discount ' ,
325- 'description ' => 'My 2nd Offer ' ,
326- 'quantity ' => 1 ,
327- 'price ' => 5 ,
328- )
329- ));
330-
235+ . '<description>Denis \'s Odd & Wierd name</description><quantity>2</quantity> '
236+ . '<unitNetAmount>4.23</unitNetAmount><unitTaxAmount>0.00</unitTaxAmount> '
237+ . '<unitGrossAmount>4.23</unitGrossAmount><totalGrossAmount>8.46</totalGrossAmount> '
238+ . '</item><discounts> '
239+ . '<discount><fixed>0.2</fixed><description>Denis \'s "Odd" Wierd discount? #</description></discount> '
240+ . '<discount><fixed>1.6</fixed><description>Second Discount</description></discount> '
241+ . '</discounts></basket> ' ;
331242
332243 $ this ->request ->setItems ($ items );
333244 $ data = $ this ->request ->getData ();
334245
335- $ this ->assertArrayHasKey ('BasketXML ' , $ data, " Should create XML " );
336- $ this ->assertContains ($ data ['BasketXML ' ], $ data , " Should not fail as name was escaped " );
246+ $ this ->assertArrayHasKey ('BasketXML ' , $ data );
247+ $ this ->assertContains ($ expected , $ data ['BasketXML ' ], ' Basket XML does not match the expected output ' );
337248 }
338249}
0 commit comments