1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class DMSDocumentCartCheckoutPageTest extends FunctionalTest |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
protected static $fixture_file = 'DMSDocumentCartTest.yml'; |
6
|
|
|
/** |
7
|
|
|
* @var DMSDocumentCartCheckoutPage_Controller |
8
|
|
|
*/ |
9
|
|
|
protected $controller; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @var DMSDocumentCart |
13
|
|
|
*/ |
14
|
|
|
protected $cart; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var DMSDocumentCartCheckoutPage |
18
|
|
|
*/ |
19
|
|
|
protected $page; |
20
|
|
|
|
21
|
|
|
public function setUp() |
22
|
|
|
{ |
23
|
|
|
parent::setUp(); |
24
|
|
|
$this->page = $this->objFromFixture('DMSDocumentCartCheckoutPage', 'page1'); |
|
|
|
|
25
|
|
|
DMSDocumentCartCheckoutPage_Controller::add_extension('StubDMSDocumentCheckoutPageExtension'); |
26
|
|
|
Injector::inst()->registerService(new StubEmail(), 'Email'); |
|
|
|
|
27
|
|
|
$this->controller = ModelAsController::controller_for($this->page); |
|
|
|
|
28
|
|
|
$this->cart = $this->controller->getCart(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Tests DMSDocumentRequest form has a FieldList |
33
|
|
|
*/ |
34
|
|
|
public function testDMSDocumentRequestForm() |
35
|
|
|
{ |
36
|
|
|
$form = $this->controller->DMSDocumentRequestForm(); |
37
|
|
|
$this->assertInstanceOf('FieldList', $form->Fields()); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Tests if the DMSDocumentRequestForm is extensible |
42
|
|
|
*/ |
43
|
|
|
public function testDMSDocumentRequestFormIsExtensible() |
44
|
|
|
{ |
45
|
|
|
$controller = $this->controller; |
46
|
|
|
$form = $controller->DMSDocumentRequestForm(); |
47
|
|
|
$this->assertNotNull( |
|
|
|
|
48
|
|
|
$form->Fields()->fieldByName('NewTextField'), |
49
|
|
|
'DMSDocumentRequestForm() is extensible as it included the field from the extension' |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Tests if a Cart is received |
55
|
|
|
*/ |
56
|
|
|
public function testGetCart() |
57
|
|
|
{ |
58
|
|
|
$this->assertInstanceOf('DMSDocumentCart', $this->controller->getCart()); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Tests whether the cart items are updated from the controller |
63
|
|
|
*/ |
64
|
|
|
public function testUpdateCartItems() |
65
|
|
|
{ |
66
|
|
|
$doc = $this->objFromFixture('DMSDocument', 'doc1'); |
67
|
|
|
/** @var DMSRequestItem $item */ |
68
|
|
|
$item = DMSRequestItem::create()->setDocument($doc)->setQuantity(2); |
|
|
|
|
69
|
|
|
$this->cart->addItem($item); |
70
|
|
|
$updatedQuantities = array( |
71
|
|
|
'ItemQuantity' => array($doc->ID => 5), |
72
|
|
|
); |
73
|
|
|
$this->controller->updateCartItems($updatedQuantities); |
74
|
|
|
$this->assertEquals(6, $this->cart->getItem($item->getItemId())->getQuantity()); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Tests whether the recipient details are updated from the controller |
79
|
|
|
*/ |
80
|
|
|
public function testUpdateCartReceiverInfo() |
81
|
|
|
{ |
82
|
|
|
$newInfo = array( |
83
|
|
|
'ReceiverName' => 'Joe Soap', |
84
|
|
|
'ReceiverPhone' => '111', |
85
|
|
|
'ReceiverEmail' => '[email protected]', |
86
|
|
|
'DeliveryAddressLine1' => 'A1', |
87
|
|
|
'DeliveryAddressLine2' => 'A2', |
88
|
|
|
'DeliveryAddressCountry' => 'NZ', |
89
|
|
|
'DeliveryAddressPostCode' => '6011', |
90
|
|
|
); |
91
|
|
|
$this->controller->updateCartReceiverInfo($newInfo); |
92
|
|
|
$this->assertEquals($newInfo, $this->cart->getReceiverInfo()); |
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Tests whether emails are sent. Emails are mocked so not actually sent. |
97
|
|
|
*/ |
98
|
|
|
public function testSend() |
99
|
|
|
{ |
100
|
|
|
// Set admin email |
101
|
|
|
Config::inst()->update('Email', 'admin_email', 'admin'); |
102
|
|
|
$data = array( |
103
|
|
|
'ReceiverName' => 'Joe Soap', |
104
|
|
|
'ReceiverPhone' => '111', |
105
|
|
|
'ReceiverEmail' => '[email protected]', |
106
|
|
|
'DeliveryAddressLine1' => 'A1', |
107
|
|
|
'DeliveryAddressLine2' => 'A2', |
108
|
|
|
'DeliveryAddressCountry' => 'NZ', |
109
|
|
|
'DeliveryAddressPostCode' => '6011' |
110
|
|
|
); |
111
|
|
|
$this->cart->setReceiverInfo($data); |
112
|
|
|
$result = $this->controller->send(); |
113
|
|
|
$this->assertTrue(is_array($result)); |
|
|
|
|
114
|
|
|
$this->assertEquals('[email protected]', $result['to']); |
|
|
|
|
115
|
|
|
$this->assertEquals('admin', $result['from']); |
|
|
|
|
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Tests whether email sending is extensible. |
120
|
|
|
*/ |
121
|
|
|
public function testSendIsExtensible() |
122
|
|
|
{ |
123
|
|
|
$result = $this->controller->send(); |
124
|
|
|
$this->assertEquals('Subject is changed', $result['subject']); |
|
|
|
|
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Test to see whether the cart is empty after a request is sent. |
129
|
|
|
*/ |
130
|
|
|
public function testDoRequestSend() |
131
|
|
|
{ |
132
|
|
|
// Form for use later |
133
|
|
|
$form = $this->controller->DMSDocumentRequestForm(); |
134
|
|
|
$doc = $this->objFromFixture('DMSDocument', 'doc1'); |
135
|
|
|
// Add some an item to the cart to assert later that its empty |
136
|
|
|
$item = DMSRequestItem::create()->setDocument($doc)->setQuantity(15); |
|
|
|
|
137
|
|
|
$this->controller->getCart()->addItem($item); |
138
|
|
|
$data = array( |
139
|
|
|
'ReceiverName' => 'Joe Soap', |
140
|
|
|
'ReceiverPhone' => '111', |
141
|
|
|
'ReceiverEmail' => '[email protected]', |
142
|
|
|
'DeliveryAddressLine1' => 'A1', |
143
|
|
|
'DeliveryAddressLine2' => 'A2', |
144
|
|
|
'DeliveryAddressCountry' => 'NZ', |
145
|
|
|
'DeliveryAddressPostCode' => '6011', |
146
|
|
|
'ItemQuantity' => array($doc->ID => 5), |
147
|
|
|
); |
148
|
|
|
$request = new SS_HTTPRequest('POST', 'mock/url'); |
149
|
|
|
// Assert cart is empty |
150
|
|
|
$this->assertFalse($this->controller->getCart()->isCartEmpty()); |
|
|
|
|
151
|
|
|
$result = $this->controller->doRequestSend($data, $form, $request); |
152
|
|
|
$this->assertInstanceOf('SS_HTTPResponse', $result); |
|
|
|
|
153
|
|
|
$this->assertTrue($this->controller->getCart()->isCartEmpty()); |
|
|
|
|
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.