1
|
|
|
<?php |
2
|
|
|
namespace PHPSC\PagSeguro\Requests\Checkout; |
3
|
|
|
|
4
|
|
|
use SimpleXMLElement; |
5
|
|
|
use PHPSC\PagSeguro\Items\Items; |
6
|
|
|
use PHPSC\PagSeguro\Items\Item; |
7
|
|
|
use PHPSC\PagSeguro\Shipping\Shipping; |
8
|
|
|
use PHPSC\PagSeguro\Customer\Customer; |
9
|
|
|
use PHPSC\PagSeguro\Customer\Phone; |
10
|
|
|
use PHPSC\PagSeguro\Customer\Address; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @author Renato Moura <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class CheckoutSerializerTest extends \PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
|
public function testSerializeShouldXMLEmpty() |
18
|
|
|
{ |
19
|
|
|
$serializer = new CheckoutSerializer; |
20
|
|
|
$xml = $serializer->serialize(new Checkout); |
21
|
|
|
|
22
|
|
|
$this->assertInstanceOf(SimpleXMLElement::class, $xml); |
23
|
|
|
|
24
|
|
|
$expected = simplexml_load_file(__DIR__.'/xml/checkoutEmpty.xml'); |
25
|
|
|
$this->assertEquals($expected, $xml); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @test |
30
|
|
|
*/ |
31
|
|
|
public function testSerializeShouldReturnXMLCustomer() |
32
|
|
|
{ |
33
|
|
|
$customer = new Customer('[email protected]'); |
34
|
|
|
|
35
|
|
|
$checkout = new Checkout; |
36
|
|
|
$checkout->setCustomer($customer); |
37
|
|
|
|
38
|
|
|
$serializer = new CheckoutSerializer; |
39
|
|
|
$xml = $serializer->serialize($checkout); |
40
|
|
|
|
41
|
|
|
$this->assertInstanceOf(SimpleXMLElement::class, $xml); |
42
|
|
|
$expected = simplexml_load_file(__DIR__.'/xml/checkoutCustomer.xml'); |
43
|
|
|
$this->assertEquals($expected, $xml); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @test |
48
|
|
|
*/ |
49
|
|
|
public function testSerializeShouldReturnXMLFull() |
50
|
|
|
{ |
51
|
|
|
$items = new Items; |
52
|
|
|
$items->add(new Item(77, 'Produto 01', 2.5, 4, 20, 300)); |
53
|
|
|
$items->add(new Item(88, 'Produto 02', 342.51, 3, 134.98, 1000)); |
54
|
|
|
|
55
|
|
|
$shippingAddress = new Address('CE', 'Ortega do Norte', '40610-912', 'Ipe', 'R. Regina Salas', '3601', 'Bl.A'); |
56
|
|
|
$shipping = new Shipping(1, $shippingAddress, 23.45); |
57
|
|
|
|
58
|
|
|
$order = new Order($items); |
59
|
|
|
$order->setReference('REF1234'); |
60
|
|
|
$order->setExtraAmount(1.01); |
61
|
|
|
$order->setShipping($shipping); |
62
|
|
|
|
63
|
|
|
$customerAddress = new Address('AC', 'Sao Maite', '99500-079', 'Centro', 'Rua David Delgado', '55', 'Fundos'); |
64
|
|
|
$customerPhone = new Phone('11', '99999999'); |
65
|
|
|
$customer = new Customer('[email protected]', 'FooBar', $customerPhone, $customerAddress); |
66
|
|
|
|
67
|
|
|
$checkout = new Checkout($order); |
68
|
|
|
$checkout->setCustomer($customer); |
69
|
|
|
$checkout->setRedirectTo('http://localhost/return.php'); |
70
|
|
|
$checkout->setMaxUses(5); |
71
|
|
|
$checkout->setMaxAge(60); |
72
|
|
|
|
73
|
|
|
$serializer = new CheckoutSerializer; |
74
|
|
|
$xml = $serializer->serialize($checkout); |
75
|
|
|
|
76
|
|
|
$this->assertInstanceOf(SimpleXMLElement::class, $xml); |
77
|
|
|
$expected = simplexml_load_file(__DIR__.'/xml/checkoutFull.xml'); |
78
|
|
|
$this->assertEquals($expected, $xml); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|