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 print requests are incremented |
55
|
|
|
*/ |
56
|
|
View Code Duplication |
public function testTrackTimestampedPrintRequest() |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
$doc = $this->objFromFixture('DMSDocument', 'doc1'); |
59
|
|
|
/** @var DMSRequestItem $item */ |
60
|
|
|
$item = DMSRequestItem::create()->setDocument($doc)->setQuantity(2); |
|
|
|
|
61
|
|
|
$this->cart->addItem($item); |
62
|
|
|
|
63
|
|
|
$this->controller->trackTimestampedPrintRequest(); |
64
|
|
|
$this->assertEquals(1, $item->getDocument()->PrintRequestCount); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Tests if a Cart is received |
69
|
|
|
*/ |
70
|
|
|
public function testGetCart() |
71
|
|
|
{ |
72
|
|
|
$this->assertInstanceOf('DMSDocumentCart', $this->controller->getCart()); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Tests whether the cart items are updated from the controller |
77
|
|
|
*/ |
78
|
|
|
public function testUpdateCartItems() |
79
|
|
|
{ |
80
|
|
|
$doc = $this->objFromFixture('DMSDocument', 'doc1'); |
81
|
|
|
/** @var DMSRequestItem $item */ |
82
|
|
|
$item = DMSRequestItem::create()->setDocument($doc)->setQuantity(2); |
|
|
|
|
83
|
|
|
$this->cart->addItem($item); |
84
|
|
|
$updatedQuantities = array( |
85
|
|
|
'ItemQuantity' => array($doc->ID => 5), |
86
|
|
|
); |
87
|
|
|
$this->controller->updateCartItems($updatedQuantities); |
88
|
|
|
$this->assertEquals(6, $this->cart->getItem($item->getItemId())->getQuantity()); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Tests whether the recipient details are updated from the controller |
93
|
|
|
*/ |
94
|
|
|
public function testUpdateCartReceiverInfo() |
95
|
|
|
{ |
96
|
|
|
$newInfo = array( |
97
|
|
|
'ReceiverName' => 'Joe Soap', |
98
|
|
|
'ReceiverPhone' => '111', |
99
|
|
|
'ReceiverEmail' => '[email protected]', |
100
|
|
|
'DeliveryAddressLine1' => 'A1', |
101
|
|
|
'DeliveryAddressLine2' => 'A2', |
102
|
|
|
'DeliveryAddressCountry' => 'NZ', |
103
|
|
|
'DeliveryAddressPostCode' => '6011', |
104
|
|
|
); |
105
|
|
|
$this->controller->updateCartReceiverInfo($newInfo); |
106
|
|
|
$this->assertEquals($newInfo, $this->cart->getReceiverInfo()); |
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Tests whether emails are sent. Emails are mocked so not actually sent. |
111
|
|
|
*/ |
112
|
|
|
public function testSend() |
113
|
|
|
{ |
114
|
|
|
// Set admin email |
115
|
|
|
Config::inst()->update('Email', 'admin_email', 'admin'); |
116
|
|
|
$data = array( |
117
|
|
|
'ReceiverName' => 'Joe Soap', |
118
|
|
|
'ReceiverPhone' => '111', |
119
|
|
|
'ReceiverEmail' => '[email protected]', |
120
|
|
|
'DeliveryAddressLine1' => 'A1', |
121
|
|
|
'DeliveryAddressLine2' => 'A2', |
122
|
|
|
'DeliveryAddressCountry' => 'NZ', |
123
|
|
|
'DeliveryAddressPostCode' => '6011' |
124
|
|
|
); |
125
|
|
|
$this->cart->setReceiverInfo($data); |
126
|
|
|
$result = $this->controller->send(); |
127
|
|
|
$this->assertTrue(is_array($result)); |
|
|
|
|
128
|
|
|
$this->assertEquals('[email protected]', $result['to']); |
|
|
|
|
129
|
|
|
$this->assertEquals('admin', $result['from']); |
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Tests whether email sending is extensible. |
134
|
|
|
*/ |
135
|
|
|
public function testSendIsExtensible() |
136
|
|
|
{ |
137
|
|
|
$result = $this->controller->send(); |
138
|
|
|
$this->assertEquals('Subject is changed', $result['subject']); |
|
|
|
|
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Test to see whether the cart is empty after a request is sent. |
143
|
|
|
*/ |
144
|
|
|
public function testDoRequestSend() |
145
|
|
|
{ |
146
|
|
|
// Form for use later |
147
|
|
|
$form = $this->controller->DMSDocumentRequestForm(); |
148
|
|
|
$doc = $this->objFromFixture('DMSDocument', 'doc1'); |
149
|
|
|
// Add some an item to the cart to assert later that its empty |
150
|
|
|
$item = DMSRequestItem::create()->setDocument($doc)->setQuantity(15); |
|
|
|
|
151
|
|
|
$this->controller->getCart()->addItem($item); |
152
|
|
|
$data = array( |
153
|
|
|
'ReceiverName' => 'Joe Soap', |
154
|
|
|
'ReceiverPhone' => '111', |
155
|
|
|
'ReceiverEmail' => '[email protected]', |
156
|
|
|
'DeliveryAddressLine1' => 'A1', |
157
|
|
|
'DeliveryAddressLine2' => 'A2', |
158
|
|
|
'DeliveryAddressCountry' => 'NZ', |
159
|
|
|
'DeliveryAddressPostCode' => '6011', |
160
|
|
|
'ItemQuantity' => array($doc->ID => 5), |
161
|
|
|
); |
162
|
|
|
$request = new SS_HTTPRequest('POST', 'mock/url'); |
163
|
|
|
// Assert cart is empty |
164
|
|
|
$this->assertFalse($this->controller->getCart()->isCartEmpty()); |
|
|
|
|
165
|
|
|
$result = $this->controller->doRequestSend($data, $form, $request); |
166
|
|
|
$this->assertInstanceOf('SS_HTTPResponse', $result); |
|
|
|
|
167
|
|
|
$this->assertTrue($this->controller->getCart()->isCartEmpty()); |
|
|
|
|
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|
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.