|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class SteppedCheckoutTest extends FunctionalTest |
|
4
|
|
|
{ |
|
5
|
|
|
protected static $fixture_file = array( |
|
6
|
|
|
'silvershop/tests/fixtures/Pages.yml', |
|
7
|
|
|
'silvershop/tests/fixtures/shop.yml', |
|
8
|
|
|
); |
|
9
|
|
|
protected static $use_draft_site = true; //so we don't need to publish |
|
10
|
|
|
protected $autoFollowRedirection = false; |
|
11
|
|
|
/** @var CheckoutPage_Controller */ |
|
12
|
|
|
protected $checkout; |
|
13
|
|
|
/** @var Product */ |
|
14
|
|
|
protected $socks; |
|
15
|
|
|
|
|
16
|
|
|
public function setUpOnce() |
|
17
|
|
|
{ |
|
18
|
|
|
parent::setUpOnce(); |
|
19
|
|
|
// clear session |
|
20
|
|
|
ShoppingCart::singleton()->clear(); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function setUp() |
|
24
|
|
|
{ |
|
25
|
|
|
parent::setUp(); |
|
26
|
|
|
ShopTest::setConfiguration(); |
|
27
|
|
|
//set up steps |
|
28
|
|
|
SteppedCheckout::setupSteps(); //use default steps |
|
29
|
|
|
|
|
30
|
|
|
$this->socks = $this->objFromFixture("Product", "socks"); |
|
|
|
|
|
|
31
|
|
|
$this->socks->publish('Stage', 'Live'); |
|
32
|
|
|
|
|
33
|
|
|
$checkoutpage = $this->objFromFixture("CheckoutPage", "checkout"); |
|
34
|
|
|
$checkoutpage->publish('Stage', 'Live'); |
|
35
|
|
|
$this->checkout = new CheckoutPage_Controller(); |
|
36
|
|
|
$this->checkout->handleRequest(new SS_HTTPRequest("GET", "checkout"), DataModel::inst()); |
|
37
|
|
|
|
|
38
|
|
|
$this->cart = $this->objFromFixture("Order", "cart"); |
|
|
|
|
|
|
39
|
|
|
ShoppingCart::singleton()->setCurrent($this->cart); |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testTemplateFunctionsForFirstStep() |
|
43
|
|
|
{ |
|
44
|
|
|
//put us at the first step index == membership |
|
45
|
|
|
$indexRequest = new SS_HTTPRequest('GET', ""); |
|
46
|
|
|
$this->checkout = new CheckoutPage_Controller(); // from 3.3 on it's necessary to have a clean controller here |
|
47
|
|
|
$this->checkout->handleRequest($indexRequest, DataModel::inst()); |
|
48
|
|
|
$this->assertTrue($this->checkout->StepExists('membership')); |
|
|
|
|
|
|
49
|
|
|
$this->assertFalse($this->checkout->IsPastStep('membership')); |
|
|
|
|
|
|
50
|
|
|
$this->assertTrue($this->checkout->IsCurrentStep('membership')); |
|
|
|
|
|
|
51
|
|
|
$this->assertFalse($this->checkout->IsFutureStep('membership')); |
|
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
$this->checkout->NextStepLink(); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertTrue($this->checkout->StepExists('contactdetails')); |
|
|
|
|
|
|
56
|
|
|
$this->assertFalse($this->checkout->IsPastStep('contactdetails')); |
|
|
|
|
|
|
57
|
|
|
$this->assertFalse($this->checkout->IsCurrentStep('contactdetails')); |
|
|
|
|
|
|
58
|
|
|
$this->assertTrue($this->checkout->IsFutureStep('contactdetails')); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testTemplateFunctionsForOtherSteps() |
|
62
|
|
|
{ |
|
63
|
|
|
$summaryRequest = new SS_HTTPRequest('GET', "summary"); |
|
64
|
|
|
$this->checkout = new CheckoutPage_Controller(); |
|
65
|
|
|
$this->checkout->handleRequest($summaryRequest, DataModel::inst()); //change to summary step |
|
66
|
|
|
$this->assertTrue($this->checkout->StepExists('summary')); |
|
|
|
|
|
|
67
|
|
|
$this->assertFalse($this->checkout->IsPastStep('summary')); |
|
|
|
|
|
|
68
|
|
|
$this->assertTrue($this->checkout->IsCurrentStep('summary')); |
|
|
|
|
|
|
69
|
|
|
$this->assertFalse($this->checkout->IsFutureStep('summary')); |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
$this->assertFalse($this->checkout->StepExists('nosuchstep')); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function testMembershipStep() |
|
75
|
|
|
{ |
|
76
|
|
|
//this should still work if there is no cart |
|
77
|
|
|
ShoppingCart::singleton()->clear(); |
|
78
|
|
|
|
|
79
|
|
|
$this->checkout->index(); |
|
80
|
|
|
$this->checkout->membership(); |
|
81
|
|
|
$this->post('/checkout/guestcontinue', array()); //redirect to next step |
|
82
|
|
|
$this->checkout->createaccount(new SS_HTTPRequest('GET', "/checkout/createaccount")); |
|
83
|
|
|
|
|
84
|
|
|
$form = $this->checkout->MembershipForm(); |
|
85
|
|
|
$data = array(); |
|
86
|
|
|
$form->loadDataFrom($data); |
|
87
|
|
|
|
|
88
|
|
|
$data = array( |
|
89
|
|
|
'FirstName' => 'Michael', |
|
90
|
|
|
'Surname' => 'Black', |
|
91
|
|
|
'Email' => '[email protected]', |
|
92
|
|
|
'Password' => array( |
|
93
|
|
|
'_Password' => 'pass1234', |
|
94
|
|
|
'_ConfirmPassword' => 'pass1234', |
|
95
|
|
|
), |
|
96
|
|
|
'action_docreateaccount' => 'Create New Account', |
|
97
|
|
|
); |
|
98
|
|
|
$response = $this->post('/checkout/CreateAccountForm', $data); //redirect to next step |
|
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
$member = ShopMember::get_by_identifier("[email protected]"); |
|
101
|
|
|
$this->assertTrue((boolean)$member, "Check new account was created"); |
|
|
|
|
|
|
102
|
|
|
$this->assertEquals('Michael', $member->FirstName); |
|
|
|
|
|
|
103
|
|
|
$this->assertEquals('Black', $member->Surname); |
|
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function testContactDetails() |
|
107
|
|
|
{ |
|
108
|
|
|
$this->objFromFixture("Member", "joebloggs")->logIn(); |
|
109
|
|
|
$this->checkout->contactdetails(); |
|
110
|
|
|
$data = array( |
|
111
|
|
|
'FirstName' => 'Pauline', |
|
112
|
|
|
'Surname' => 'Richardson', |
|
113
|
|
|
'Email' => '[email protected]', |
|
114
|
|
|
'action_setcontactdetails' => 1, |
|
115
|
|
|
); |
|
116
|
|
|
$response = $this->post('/checkout/ContactDetailsForm', $data); |
|
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
$this->markTestIncomplete('check order has been updated'); |
|
|
|
|
|
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function testShippingAddress() |
|
122
|
|
|
{ |
|
123
|
|
|
$this->objFromFixture("Member", "joebloggs")->logIn(); |
|
124
|
|
|
$this->checkout->shippingaddress(); |
|
125
|
|
|
$data = array( |
|
126
|
|
|
'Address' => '2b Baba place', |
|
127
|
|
|
'AddressLine2' => 'Level 2', |
|
128
|
|
|
'City' => 'Newton', |
|
129
|
|
|
'State' => 'Wellington', |
|
130
|
|
|
'Country' => 'NZ', |
|
131
|
|
|
'action_setaddress' => 1, |
|
132
|
|
|
); |
|
133
|
|
|
$response = $this->post('/checkout/AddressForm', $data); |
|
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
$this->markTestIncomplete('assertions!'); |
|
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function testBillingAddress() |
|
139
|
|
|
{ |
|
140
|
|
|
$this->objFromFixture("Member", "joebloggs")->logIn(); |
|
141
|
|
|
$this->checkout->billingaddress(); |
|
142
|
|
|
$data = array( |
|
143
|
|
|
'Address' => '3 Art Cresent', |
|
144
|
|
|
'AddressLine2' => '', |
|
145
|
|
|
'City' => 'Walkworth', |
|
146
|
|
|
'State' => 'New Caliphoneya', |
|
147
|
|
|
'Country' => 'ZA', |
|
148
|
|
|
'action_setbillingaddress' => 1, |
|
149
|
|
|
); |
|
150
|
|
|
$response = $this->post('/checkout/AddressForm', $data); |
|
|
|
|
|
|
151
|
|
|
|
|
152
|
|
|
$this->markTestIncomplete('assertions!'); |
|
|
|
|
|
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
public function testPaymentMethod() |
|
156
|
|
|
{ |
|
157
|
|
|
$data = array( |
|
158
|
|
|
'PaymentMethod' => 'Dummy', |
|
159
|
|
|
'action_setpaymentmethod' => 1, |
|
160
|
|
|
); |
|
161
|
|
|
$response = $this->post('/checkout/PaymentMethodForm', $data); |
|
|
|
|
|
|
162
|
|
|
$this->assertEquals('Dummy', Checkout::get($this->cart)->getSelectedPaymentMethod()); |
|
|
|
|
|
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
public function testSummary() |
|
166
|
|
|
{ |
|
167
|
|
|
$this->checkout->summary(); |
|
168
|
|
|
$form = $this->checkout->ConfirmationForm(); |
|
169
|
|
|
$data = array( |
|
170
|
|
|
'Notes' => 'Leave it around the back', |
|
171
|
|
|
'ReadTermsAndConditions' => 1, |
|
172
|
|
|
); |
|
173
|
|
|
$member = $this->objFromFixture("Member", "joebloggs"); |
|
174
|
|
|
$member->logIn(); //log in member before processing |
|
175
|
|
|
|
|
176
|
|
|
Checkout::get($this->cart)->setPaymentMethod("Dummy"); //a selected payment method is required |
|
177
|
|
|
$form->loadDataFrom($data); |
|
178
|
|
|
$this->assertTrue($form->validate(), "Checkout data is valid"); |
|
|
|
|
|
|
179
|
|
|
$response = $this->post('/checkout/ConfirmationForm', $data); |
|
180
|
|
|
$this->assertEquals('Cart', $this->cart->Status, "Order is still in cart"); |
|
|
|
|
|
|
181
|
|
|
|
|
182
|
|
|
$order = Order::get()->byID($this->cart->ID); |
|
183
|
|
|
|
|
184
|
|
|
$this->assertEquals("Leave it around the back", $order->Notes); |
|
|
|
|
|
|
185
|
|
|
|
|
186
|
|
|
//redirect to make payment |
|
187
|
|
|
$this->assertEquals(302, $response->getStatusCode()); |
|
|
|
|
|
|
188
|
|
|
$this->assertEquals( |
|
|
|
|
|
|
189
|
|
|
Director::baseURL() . "checkout/payment", |
|
190
|
|
|
$response->getHeader('Location') |
|
191
|
|
|
); |
|
192
|
|
|
} |
|
193
|
|
|
} |
|
194
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.