1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link OrderStatusLog |
4
|
|
|
* @package shop_statuschangeemail |
5
|
|
|
* @subpackage tests |
6
|
|
|
*/ |
7
|
|
|
class OrderStatusLogTest extends SapphireTest |
8
|
|
|
{ |
9
|
|
|
protected static $fixture_file = array( |
10
|
|
|
'silvershop/tests/fixtures/Orders.yml', |
11
|
|
|
'silvershop/tests/fixtures/ShopMembers.yml', |
12
|
|
|
'silvershop/tests/fixtures/Pages.yml' |
13
|
|
|
); |
14
|
|
|
|
15
|
|
|
public function setUp() |
16
|
|
|
{ |
17
|
|
|
parent::setUp(); |
18
|
|
|
ShopTest::setConfiguration(); |
19
|
|
|
Config::inst()->update('Order', 'log_status', array('Processing', 'Sent', 'AdminCancelled', 'MemberCancelled')); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testOrderStatusLogItemsWithMember() |
23
|
|
|
{ |
24
|
|
|
// start a new order |
25
|
|
|
$order = $this->objFromFixture("Order", "cart1"); |
26
|
|
|
$member = $this->objFromFixture('Member', 'jeremyperemy'); |
27
|
|
|
$order->MemberID = $member->ID; |
28
|
|
|
|
29
|
|
|
$no_log_generated_with_order_status_cart = OrderStatusLog::get()->sort('ID')->last(); |
30
|
|
|
$this->assertNull( |
|
|
|
|
31
|
|
|
$no_log_generated_with_order_status_cart, |
32
|
|
|
"no log generated with Status of 'Cart'" |
33
|
|
|
); |
34
|
|
|
|
35
|
|
|
$order->Status = "Unpaid"; |
36
|
|
|
$order->write(); |
37
|
|
|
|
38
|
|
|
$no_log_generated_with_order_status_unpaid = OrderStatusLog::get()->sort('ID')->last(); |
39
|
|
|
$this->assertNull( |
|
|
|
|
40
|
|
|
$no_log_generated_with_order_status_unpaid, |
41
|
|
|
"no log generated with Status of 'Unpaid'" |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
$processor = OrderProcessor::create($order); |
|
|
|
|
45
|
|
|
$response = $processor->makePayment("Manual", array()); |
|
|
|
|
46
|
|
|
$order->Status = "Paid"; |
47
|
|
|
$order->write(); |
48
|
|
|
|
49
|
|
|
$log_order_status_paid = OrderStatusLog::get()->sort('ID')->last(); |
50
|
|
|
$this->assertNull( |
|
|
|
|
51
|
|
|
$log_order_status_paid, |
52
|
|
|
"no log generated with Status of 'Unpaid'" |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
$order->Status = "Processing"; |
56
|
|
|
$order->write(); |
57
|
|
|
|
58
|
|
|
$log_order_status_processing = OrderStatusLog::get()->sort('ID')->last(); |
59
|
|
|
$this->assertEquals(OrderStatusLog::get()->count(), '1', "One items in the OrderStatusLog"); |
|
|
|
|
60
|
|
|
$this->assertNotNull( |
|
|
|
|
61
|
|
|
$log_order_status_processing, |
62
|
|
|
"a log when changing to 'Processing' status (and PaymentMethod is 'Manual')" |
63
|
|
|
); |
64
|
|
|
$this->assertSame( |
|
|
|
|
65
|
|
|
$log_order_status_processing->Order()->ID, |
66
|
|
|
$order->ID, |
67
|
|
|
"Log conatins an Order" |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
$this->assertContains( |
71
|
|
|
"Processing", |
72
|
|
|
$log_order_status_processing->Note, |
73
|
|
|
"Processing note is recorded" |
74
|
|
|
); |
75
|
|
|
$this->assertContains( |
76
|
|
|
'changed to "Processing"', |
77
|
|
|
$log_order_status_processing->Title, |
78
|
|
|
'Processing title is recorded' |
79
|
|
|
); |
80
|
|
|
$this->assertEmailSent( |
81
|
|
|
'[email protected]', |
82
|
|
|
'[email protected]', |
83
|
|
|
_t('ShopEmail.StatusChangeSubject') . $log_order_status_processing->Title |
84
|
|
|
); |
85
|
|
|
$order->Status = "Sent"; |
86
|
|
|
$order->write(); |
87
|
|
|
|
88
|
|
|
$log_order_status_sent = OrderStatusLog::get()->sort('ID')->last(); |
89
|
|
|
$this->assertEquals( |
|
|
|
|
90
|
|
|
OrderStatusLog::get()->count(), |
91
|
|
|
'2', |
92
|
|
|
"Three items in the OrderStatusLog" |
93
|
|
|
); |
94
|
|
|
$this->assertNotNull( |
|
|
|
|
95
|
|
|
$log_order_status_sent, |
96
|
|
|
"an log should be recorded when an order's status is changed to 'Sent' (and PaymentMethod is 'Manual')" |
97
|
|
|
); |
98
|
|
|
$this->assertSame( |
|
|
|
|
99
|
|
|
$log_order_status_sent->Order()->ID, |
100
|
|
|
$order->ID, |
101
|
|
|
"Log conatins an Order" |
102
|
|
|
); |
103
|
|
|
$this->assertContains( |
104
|
|
|
"sent", |
105
|
|
|
$log_order_status_sent->Note, |
106
|
|
|
"Sent note is recorded" |
107
|
|
|
); |
108
|
|
|
$this->assertContains( |
109
|
|
|
'changed to "Sent"', |
110
|
|
|
$log_order_status_sent->Title, |
111
|
|
|
"Sent title is recorded" |
112
|
|
|
); |
113
|
|
|
|
114
|
|
|
$this->assertEmailSent( |
115
|
|
|
"[email protected]", |
116
|
|
|
"[email protected]", |
117
|
|
|
_t('ShopEmail.StatusChangeSubject') . $log_order_status_sent->Title |
118
|
|
|
); |
119
|
|
|
|
120
|
|
|
$order->Status = "Complete"; |
121
|
|
|
$order->write(); |
122
|
|
|
$this->assertEquals( |
|
|
|
|
123
|
|
|
OrderStatusLog::get()->count(), |
124
|
|
|
'2', |
125
|
|
|
"Additional item in the OrderStatusLog has not been created" |
126
|
|
|
); |
127
|
|
|
|
128
|
|
|
$order->Status = "AdminCancelled"; |
129
|
|
|
$order->write(); |
130
|
|
|
|
131
|
|
|
$log_order_status_admin_cancelled = OrderStatusLog::get()->sort('ID')->last(); |
132
|
|
|
$this->assertEquals( |
|
|
|
|
133
|
|
|
OrderStatusLog::get()->count(), |
134
|
|
|
'3', |
135
|
|
|
"Three items in the OrderStatusLog" |
136
|
|
|
); |
137
|
|
|
$this->assertNotNull( |
|
|
|
|
138
|
|
|
$log_order_status_admin_cancelled, |
139
|
|
|
"a log should be recorded with change to 'Admin Cancelled' status (and PaymentMethod is 'Manual')" |
140
|
|
|
); |
141
|
|
|
$this->assertSame( |
|
|
|
|
142
|
|
|
$log_order_status_admin_cancelled->Order()->ID, |
143
|
|
|
$order->ID, |
144
|
|
|
"Log conatins an Order" |
145
|
|
|
); |
146
|
|
|
$this->assertContains( |
147
|
|
|
"cancelled", |
148
|
|
|
$log_order_status_admin_cancelled->Note, |
149
|
|
|
"Admin Cancelled note is recorded" |
150
|
|
|
); |
151
|
|
|
$this->assertContains( |
152
|
|
|
'changed to "Cancelled by admin"', |
153
|
|
|
$log_order_status_admin_cancelled->Title, |
154
|
|
|
"Admin Cancelled title is recorded" |
155
|
|
|
); |
156
|
|
|
$this->assertEmailSent( |
157
|
|
|
"[email protected]", |
158
|
|
|
"[email protected]", |
159
|
|
|
_t('ShopEmail.StatusChangeSubject') . $log_order_status_admin_cancelled->Title |
160
|
|
|
); |
161
|
|
|
|
162
|
|
|
$order->Status = "MemberCancelled"; |
163
|
|
|
$order->write(); |
164
|
|
|
$log_order_status_member_cancelled = OrderStatusLog::get()->sort('ID')->last(); |
165
|
|
|
$this->assertEquals( |
|
|
|
|
166
|
|
|
OrderStatusLog::get()->count(), |
167
|
|
|
'4', |
168
|
|
|
"Four items in the OrderStatusLog" |
169
|
|
|
); |
170
|
|
|
$this->assertNotNull( |
|
|
|
|
171
|
|
|
$log_order_status_member_cancelled, |
172
|
|
|
"a log should be recorded for change to 'Member Cancelled' status (and PaymentMethod is 'Manual')" |
173
|
|
|
); |
174
|
|
|
$this->assertSame( |
|
|
|
|
175
|
|
|
$log_order_status_member_cancelled->Order()->ID, |
176
|
|
|
$order->ID, |
177
|
|
|
"Log conatins an Order" |
178
|
|
|
); |
179
|
|
|
$this->assertSame( |
|
|
|
|
180
|
|
|
"Your cancellation of the order has been noted. Please contact us if you have any questions.", |
181
|
|
|
$log_order_status_member_cancelled->Note, |
182
|
|
|
"Member Cancelled note is recorded" |
183
|
|
|
); |
184
|
|
|
$this->assertContains( |
185
|
|
|
' changed to "Cancelled by member"', |
186
|
|
|
$log_order_status_member_cancelled->Title, |
187
|
|
|
"Member Cancelled title is recorded" |
188
|
|
|
); |
189
|
|
|
$this->assertEmailSent( |
190
|
|
|
'[email protected]', |
191
|
|
|
'[email protected]', |
192
|
|
|
_t('ShopEmail.StatusChangeSubject') . $log_order_status_member_cancelled->Title |
193
|
|
|
); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public function testEmailSentOnce() |
197
|
|
|
{ |
198
|
|
|
$order = $this->objFromFixture("Order", "cart1"); |
199
|
|
|
$member = $this->objFromFixture('Member', 'jeremyperemy'); |
200
|
|
|
$order->MemberID = $member->ID; |
201
|
|
|
|
202
|
|
|
$order->Status = 'Processing'; |
203
|
|
|
$order->write(); |
204
|
|
|
|
205
|
|
|
$logEntry = OrderStatusLog::get()->sort('ID')->last(); |
206
|
|
|
|
207
|
|
|
$this->assertEquals( |
|
|
|
|
208
|
|
|
OrderStatusLog::get()->count(), |
209
|
|
|
1, |
210
|
|
|
"An item has been added to the status-log" |
211
|
|
|
); |
212
|
|
|
|
213
|
|
|
$this->assertEmailSent( |
214
|
|
|
'[email protected]', |
215
|
|
|
'[email protected]', |
216
|
|
|
_t('ShopEmail.StatusChangeSubject') . $logEntry->Title |
217
|
|
|
); |
218
|
|
|
|
219
|
|
|
// clear sent emails |
220
|
|
|
$this->mailer->clearEmails(); |
221
|
|
|
|
222
|
|
|
// force another write on the order |
223
|
|
|
$order->Notes = 'Random Test Notes'; |
224
|
|
|
$order->write(); |
225
|
|
|
|
226
|
|
|
// Status hasn't changed, so there should be just one log entry still |
227
|
|
|
$this->assertEquals( |
|
|
|
|
228
|
|
|
OrderStatusLog::get()->count(), |
229
|
|
|
1, |
230
|
|
|
"An item has been added to the status-log" |
231
|
|
|
); |
232
|
|
|
|
233
|
|
|
$this->assertFalse( |
|
|
|
|
234
|
|
|
(bool)$this->findEmail('[email protected]', '[email protected]'), |
235
|
|
|
'No additional email should be sent' |
236
|
|
|
); |
237
|
|
|
|
238
|
|
|
// Try re-writing the Log entry |
239
|
|
|
$logEntry->Note = 'Some random notes'; |
240
|
|
|
$logEntry->write(); |
241
|
|
|
|
242
|
|
|
$this->assertFalse( |
|
|
|
|
243
|
|
|
(bool)$this->findEmail('[email protected]', '[email protected]'), |
244
|
|
|
'No additional email should be sent' |
245
|
|
|
); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
public function testOrderPlacedByGuest() |
249
|
|
|
{ |
250
|
|
|
// start a new order |
251
|
|
|
$order = $this->objFromFixture("Order", "cart1"); |
252
|
|
|
$order->FirstName = "Edmund"; |
253
|
|
|
$order->Surname = "Hillary"; |
254
|
|
|
$order->Email = "[email protected]"; |
255
|
|
|
$order->Status = "Unpaid"; |
256
|
|
|
$order->write(); |
257
|
|
|
|
258
|
|
|
$no_log_generated_with_order_status_unpaid = OrderStatusLog::get()->sort('ID')->last(); |
259
|
|
|
$this->assertNull( |
|
|
|
|
260
|
|
|
$no_log_generated_with_order_status_unpaid, |
261
|
|
|
"no log generated with Status of 'Unpaid'" |
262
|
|
|
); |
263
|
|
|
|
264
|
|
|
$processor_guest = OrderProcessor::create($order); |
|
|
|
|
265
|
|
|
$response = $processor_guest->makePayment("Manual", array()); |
|
|
|
|
266
|
|
|
$order->Status = "Paid"; |
267
|
|
|
$order->write(); |
268
|
|
|
|
269
|
|
|
$log_order_status_paid = OrderStatusLog::get()->sort('ID')->last(); |
270
|
|
|
$this->assertNull( |
|
|
|
|
271
|
|
|
$log_order_status_paid, |
272
|
|
|
"no log generated with Status of 'Unpaid'" |
273
|
|
|
); |
274
|
|
|
|
275
|
|
|
$order->Status = "Processing"; |
276
|
|
|
$order->write(); |
277
|
|
|
|
278
|
|
|
$log_order_status_processing = OrderStatusLog::get()->sort('ID')->last(); |
279
|
|
|
$this->assertEquals(OrderStatusLog::get()->count(), '1', "One items in the OrderStatusLog"); |
|
|
|
|
280
|
|
|
$this->assertNotNull( |
|
|
|
|
281
|
|
|
$log_order_status_processing, |
282
|
|
|
"a log when changing to 'Processing' status (and PaymentMethod is 'Manual')" |
283
|
|
|
); |
284
|
|
|
$this->assertSame( |
|
|
|
|
285
|
|
|
$log_order_status_processing->Order()->ID, |
286
|
|
|
$order->ID, |
287
|
|
|
"Log conatins an Order" |
288
|
|
|
); |
289
|
|
|
|
290
|
|
|
$this->assertContains( |
291
|
|
|
"Processing", |
292
|
|
|
$log_order_status_processing->Note, |
293
|
|
|
"Processing note is recorded" |
294
|
|
|
); |
295
|
|
|
$this->assertContains( |
296
|
|
|
' changed to "Processing"', |
297
|
|
|
$log_order_status_processing->Title, |
298
|
|
|
"Processing title is recorded" |
299
|
|
|
); |
300
|
|
|
$this->assertEmailSent( |
301
|
|
|
"[email protected]", |
302
|
|
|
"[email protected]", |
303
|
|
|
_t('ShopEmail.StatusChangeSubject') . $log_order_status_processing->Title |
304
|
|
|
); |
305
|
|
|
} |
306
|
|
|
} |
307
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.