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
|
|
|
Order::config()->log_status = array('Processing', 'Sent', 'AdminCancelled', 'MemberCancelled'); |
20
|
|
|
|
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testOrderStatusLogItemsWithMember() |
24
|
|
|
{ |
25
|
|
|
// start a new order |
26
|
|
|
$order = $this->objFromFixture("Order", "cart1"); |
27
|
|
|
$member = $this->objFromFixture('Member', 'jeremyperemy'); |
28
|
|
|
$order->MemberID = $member->ID; |
29
|
|
|
|
30
|
|
|
$no_log_generated_with_order_status_cart = OrderStatusLog::get()->sort('ID')->last(); |
31
|
|
|
$this->assertNull( |
|
|
|
|
32
|
|
|
$no_log_generated_with_order_status_cart, |
33
|
|
|
"no log generated with Status of 'Cart'" |
34
|
|
|
); |
35
|
|
|
|
36
|
|
|
$order->Status = "Unpaid"; |
37
|
|
|
$order->write(); |
38
|
|
|
|
39
|
|
|
$no_log_generated_with_order_status_unpaid = OrderStatusLog::get()->sort('ID')->last(); |
40
|
|
|
$this->assertNull( |
|
|
|
|
41
|
|
|
$no_log_generated_with_order_status_unpaid, |
42
|
|
|
"no log generated with Status of 'Unpaid'" |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
$processor = OrderProcessor::create($order); |
|
|
|
|
46
|
|
|
$response = $processor->makePayment("Manual", array()); |
|
|
|
|
47
|
|
|
$order->Status = "Paid"; |
48
|
|
|
$order->write(); |
49
|
|
|
|
50
|
|
|
$log_order_status_paid = OrderStatusLog::get()->sort('ID')->last(); |
51
|
|
|
$this->assertNull( |
|
|
|
|
52
|
|
|
$log_order_status_paid, |
53
|
|
|
"no log generated with Status of 'Unpaid'" |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
$order->Status = "Processing"; |
57
|
|
|
$order->write(); |
58
|
|
|
|
59
|
|
|
$log_order_status_processing = OrderStatusLog::get()->sort('ID')->last(); |
60
|
|
|
$this->assertEquals(OrderStatusLog::get()->count(), '1', "One items in the OrderStatusLog"); |
|
|
|
|
61
|
|
|
$this->assertNotNull( |
|
|
|
|
62
|
|
|
$log_order_status_processing, |
63
|
|
|
"a log when changing to 'Processing' status (and PaymentMethod is 'Manual')" |
64
|
|
|
); |
65
|
|
|
$this->assertSame( |
|
|
|
|
66
|
|
|
$log_order_status_processing->Order()->ID, |
67
|
|
|
$order->ID, |
68
|
|
|
"Log conatins an Order" |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
$this->assertContains( |
72
|
|
|
"Processing", |
73
|
|
|
$log_order_status_processing->Note, |
74
|
|
|
"Processing note is recorded" |
75
|
|
|
); |
76
|
|
|
$this->assertContains( |
77
|
|
|
'changed to "Processing"', |
78
|
|
|
$log_order_status_processing->Title, |
79
|
|
|
'Processing title is recorded' |
80
|
|
|
); |
81
|
|
|
$this->assertEmailSent( |
82
|
|
|
'[email protected]', |
83
|
|
|
'[email protected]', |
84
|
|
|
_t('ShopEmail.StatusChangeSubject') . $log_order_status_processing->Title |
85
|
|
|
); |
86
|
|
|
$order->Status = "Sent"; |
87
|
|
|
$order->write(); |
88
|
|
|
|
89
|
|
|
$log_order_status_sent = OrderStatusLog::get()->sort('ID')->last(); |
90
|
|
|
$this->assertEquals( |
|
|
|
|
91
|
|
|
OrderStatusLog::get()->count(), |
92
|
|
|
'2', |
93
|
|
|
"Three items in the OrderStatusLog" |
94
|
|
|
); |
95
|
|
|
$this->assertNotNull( |
|
|
|
|
96
|
|
|
$log_order_status_sent, |
97
|
|
|
"an log should be recorded when an order's status is changed to 'Sent' (and PaymentMethod is 'Manual')" |
98
|
|
|
); |
99
|
|
|
$this->assertSame( |
|
|
|
|
100
|
|
|
$log_order_status_sent->Order()->ID, |
101
|
|
|
$order->ID, |
102
|
|
|
"Log conatins an Order" |
103
|
|
|
); |
104
|
|
|
$this->assertContains( |
105
|
|
|
"sent", |
106
|
|
|
$log_order_status_sent->Note, |
107
|
|
|
"Sent note is recorded" |
108
|
|
|
); |
109
|
|
|
$this->assertContains( |
110
|
|
|
'changed to "Sent"', |
111
|
|
|
$log_order_status_sent->Title, |
112
|
|
|
"Sent title is recorded" |
113
|
|
|
); |
114
|
|
|
|
115
|
|
|
$this->assertEmailSent( |
116
|
|
|
"[email protected]", |
117
|
|
|
"[email protected]", |
118
|
|
|
_t('ShopEmail.StatusChangeSubject') . $log_order_status_sent->Title |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
$order->Status = "Complete"; |
122
|
|
|
$order->write(); |
123
|
|
|
$this->assertEquals( |
|
|
|
|
124
|
|
|
OrderStatusLog::get()->count(), |
125
|
|
|
'2', |
126
|
|
|
"Additional item in the OrderStatusLog has not been created" |
127
|
|
|
); |
128
|
|
|
|
129
|
|
|
$order->Status = "AdminCancelled"; |
130
|
|
|
$order->write(); |
131
|
|
|
|
132
|
|
|
$log_order_status_admin_cancelled = OrderStatusLog::get()->sort('ID')->last(); |
133
|
|
|
$this->assertEquals( |
|
|
|
|
134
|
|
|
OrderStatusLog::get()->count(), |
135
|
|
|
'3', |
136
|
|
|
"Three items in the OrderStatusLog" |
137
|
|
|
); |
138
|
|
|
$this->assertNotNull( |
|
|
|
|
139
|
|
|
$log_order_status_admin_cancelled, |
140
|
|
|
"a log should be recorded with change to 'Admin Cancelled' status (and PaymentMethod is 'Manual')" |
141
|
|
|
); |
142
|
|
|
$this->assertSame( |
|
|
|
|
143
|
|
|
$log_order_status_admin_cancelled->Order()->ID, |
144
|
|
|
$order->ID, |
145
|
|
|
"Log conatins an Order" |
146
|
|
|
); |
147
|
|
|
$this->assertContains( |
148
|
|
|
"cancelled", |
149
|
|
|
$log_order_status_admin_cancelled->Note, |
150
|
|
|
"Admin Cancelled note is recorded" |
151
|
|
|
); |
152
|
|
|
$this->assertContains( |
153
|
|
|
'changed to "Cancelled by admin"', |
154
|
|
|
$log_order_status_admin_cancelled->Title, |
155
|
|
|
"Admin Cancelled title is recorded" |
156
|
|
|
); |
157
|
|
|
$this->assertEmailSent( |
158
|
|
|
"[email protected]", |
159
|
|
|
"[email protected]", |
160
|
|
|
_t('ShopEmail.StatusChangeSubject') . $log_order_status_admin_cancelled->Title |
161
|
|
|
); |
162
|
|
|
|
163
|
|
|
$order->Status = "MemberCancelled"; |
164
|
|
|
$order->write(); |
165
|
|
|
$log_order_status_member_cancelled = OrderStatusLog::get()->sort('ID')->last(); |
166
|
|
|
$this->assertEquals( |
|
|
|
|
167
|
|
|
OrderStatusLog::get()->count(), |
168
|
|
|
'4', |
169
|
|
|
"Four items in the OrderStatusLog" |
170
|
|
|
); |
171
|
|
|
$this->assertNotNull( |
|
|
|
|
172
|
|
|
$log_order_status_member_cancelled, |
173
|
|
|
"a log should be recorded for change to 'Member Cancelled' status (and PaymentMethod is 'Manual')" |
174
|
|
|
); |
175
|
|
|
$this->assertSame( |
|
|
|
|
176
|
|
|
$log_order_status_member_cancelled->Order()->ID, |
177
|
|
|
$order->ID, |
178
|
|
|
"Log conatins an Order" |
179
|
|
|
); |
180
|
|
|
$this->assertSame( |
|
|
|
|
181
|
|
|
"Your cancellation of the order has been noted. Please contact us if you have any questions.", |
182
|
|
|
$log_order_status_member_cancelled->Note, |
183
|
|
|
"Member Cancelled note is recorded" |
184
|
|
|
); |
185
|
|
|
$this->assertContains( |
186
|
|
|
' changed to "Cancelled by member"', |
187
|
|
|
$log_order_status_member_cancelled->Title, |
188
|
|
|
"Member Cancelled title is recorded" |
189
|
|
|
); |
190
|
|
|
$this->assertEmailSent( |
191
|
|
|
'[email protected]', |
192
|
|
|
'[email protected]', |
193
|
|
|
_t('ShopEmail.StatusChangeSubject') . $log_order_status_member_cancelled->Title |
194
|
|
|
); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
public function testOrderPlacedByGuest() |
198
|
|
|
{ |
199
|
|
|
// start a new order |
200
|
|
|
$order = $this->objFromFixture("Order", "cart1"); |
201
|
|
|
$order->FirstName = "Edmund"; |
202
|
|
|
$order->Surname = "Hillary"; |
203
|
|
|
$order->Email = "[email protected]"; |
204
|
|
|
$order->Status = "Unpaid"; |
205
|
|
|
$order->write(); |
206
|
|
|
|
207
|
|
|
$no_log_generated_with_order_status_unpaid = OrderStatusLog::get()->sort('ID')->last(); |
208
|
|
|
$this->assertNull( |
|
|
|
|
209
|
|
|
$no_log_generated_with_order_status_unpaid, |
210
|
|
|
"no log generated with Status of 'Unpaid'" |
211
|
|
|
); |
212
|
|
|
|
213
|
|
|
$processor_guest = OrderProcessor::create($order); |
|
|
|
|
214
|
|
|
$response = $processor_guest->makePayment("Manual", array()); |
|
|
|
|
215
|
|
|
$order->Status = "Paid"; |
216
|
|
|
$order->write(); |
217
|
|
|
|
218
|
|
|
$log_order_status_paid = OrderStatusLog::get()->sort('ID')->last(); |
219
|
|
|
$this->assertNull( |
|
|
|
|
220
|
|
|
$log_order_status_paid, |
221
|
|
|
"no log generated with Status of 'Unpaid'" |
222
|
|
|
); |
223
|
|
|
|
224
|
|
|
$order->Status = "Processing"; |
225
|
|
|
$order->write(); |
226
|
|
|
|
227
|
|
|
$log_order_status_processing = OrderStatusLog::get()->sort('ID')->last(); |
228
|
|
|
$this->assertEquals(OrderStatusLog::get()->count(), '1', "One items in the OrderStatusLog"); |
|
|
|
|
229
|
|
|
$this->assertNotNull( |
|
|
|
|
230
|
|
|
$log_order_status_processing, |
231
|
|
|
"a log when changing to 'Processing' status (and PaymentMethod is 'Manual')" |
232
|
|
|
); |
233
|
|
|
$this->assertSame( |
|
|
|
|
234
|
|
|
$log_order_status_processing->Order()->ID, |
235
|
|
|
$order->ID, |
236
|
|
|
"Log conatins an Order" |
237
|
|
|
); |
238
|
|
|
|
239
|
|
|
$this->assertContains( |
240
|
|
|
"Processing", |
241
|
|
|
$log_order_status_processing->Note, |
242
|
|
|
"Processing note is recorded" |
243
|
|
|
); |
244
|
|
|
$this->assertContains( |
245
|
|
|
' changed to "Processing"', |
246
|
|
|
$log_order_status_processing->Title, |
247
|
|
|
"Processing title is recorded" |
248
|
|
|
); |
249
|
|
|
$this->assertEmailSent( |
250
|
|
|
"[email protected]", |
251
|
|
|
"[email protected]", |
252
|
|
|
_t('ShopEmail.StatusChangeSubject') . $log_order_status_processing->Title |
253
|
|
|
); |
254
|
|
|
} |
255
|
|
|
} |
256
|
|
|
|
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.