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