|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class CheckoutFormTest extends SapphireTest |
|
4
|
|
|
{ |
|
5
|
|
|
public static $fixture_file = 'silvershop/tests/fixtures/shop.yml'; |
|
6
|
|
|
|
|
7
|
|
|
public function setUpOnce() |
|
8
|
|
|
{ |
|
9
|
|
|
parent::setUpOnce(); |
|
10
|
|
|
// clear session |
|
11
|
|
|
ShoppingCart::singleton()->clear(); |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
public function setUp() |
|
15
|
|
|
{ |
|
16
|
|
|
parent::setUp(); |
|
17
|
|
|
ShopTest::setConfiguration(); |
|
18
|
|
|
$this->mp3player = $this->objFromFixture('Product', 'mp3player'); |
|
|
|
|
|
|
19
|
|
|
$this->mp3player->publish('Stage', 'Live'); |
|
20
|
|
|
$this->socks = $this->objFromFixture('Product', 'socks'); |
|
|
|
|
|
|
21
|
|
|
$this->socks->publish('Stage', 'Live'); |
|
22
|
|
|
$this->beachball = $this->objFromFixture('Product', 'beachball'); |
|
|
|
|
|
|
23
|
|
|
$this->beachball->publish('Stage', 'Live'); |
|
24
|
|
|
|
|
25
|
|
|
$this->checkoutcontroller = new CheckoutPage_Controller(); |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
ShoppingCart::singleton()->add($this->socks); //start cart |
|
|
|
|
|
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testCheckoutForm() |
|
31
|
|
|
{ |
|
32
|
|
|
$order = ShoppingCart::curr(); |
|
33
|
|
|
$config = new SinglePageCheckoutComponentConfig($order); |
|
34
|
|
|
$form = new CheckoutForm($this->checkoutcontroller, "OrderForm", $config); |
|
35
|
|
|
$data = array( |
|
36
|
|
|
"CustomerDetailsCheckoutComponent_FirstName" => "Jane", |
|
37
|
|
|
"CustomerDetailsCheckoutComponent_Surname" => "Smith", |
|
38
|
|
|
"CustomerDetailsCheckoutComponent_Email" => "[email protected]", |
|
39
|
|
|
"ShippingAddressCheckoutComponent_Country" => "NZ", |
|
40
|
|
|
"ShippingAddressCheckoutComponent_Address" => "1234 Green Lane", |
|
41
|
|
|
"ShippingAddressCheckoutComponent_AddressLine2" => "Building 2", |
|
42
|
|
|
"ShippingAddressCheckoutComponent_City" => "Bleasdfweorville", |
|
43
|
|
|
"ShippingAddressCheckoutComponent_State" => "Trumpo", |
|
44
|
|
|
"ShippingAddressCheckoutComponent_PostalCode" => "4123", |
|
45
|
|
|
"ShippingAddressCheckoutComponent_Phone" => "032092277", |
|
46
|
|
|
"BillingAddressCheckoutComponent_Country" => "NZ", |
|
47
|
|
|
"BillingAddressCheckoutComponent_Address" => "1234 Green Lane", |
|
48
|
|
|
"BillingAddressCheckoutComponent_AddressLine2" => "Building 2", |
|
49
|
|
|
"BillingAddressCheckoutComponent_City" => "Bleasdfweorville", |
|
50
|
|
|
"BillingAddressCheckoutComponent_State" => "Trumpo", |
|
51
|
|
|
"BillingAddressCheckoutComponent_PostalCode" => "4123", |
|
52
|
|
|
"BillingAddressCheckoutComponent_Phone" => "032092277", |
|
53
|
|
|
"PaymentCheckoutComponent_PaymentMethod" => "Dummy", |
|
54
|
|
|
"NotesCheckoutComponent_Notes" => "Leave it around the back", |
|
55
|
|
|
"TermsCheckoutComponent_ReadTermsAndConditions" => "1", |
|
56
|
|
|
); |
|
57
|
|
|
$form->loadDataFrom($data, true); |
|
|
|
|
|
|
58
|
|
|
$valid = $form->validate(); |
|
59
|
|
|
$errors = $form->getValidator()->getErrors(); |
|
60
|
|
|
$this->assertTrue($valid, print_r($errors, true)); |
|
|
|
|
|
|
61
|
|
|
$form->checkoutSubmit($data, $form); |
|
62
|
|
|
$this->assertEquals("Jane", $order->FirstName); |
|
|
|
|
|
|
63
|
|
|
$shipping = $order->ShippingAddress(); |
|
|
|
|
|
|
64
|
|
|
$this->assertEquals("NZ", $shipping->Country); |
|
|
|
|
|
|
65
|
|
|
$this->assertEquals("Cart", $order->Status); |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
$this->markTestIncomplete('test invalid data'); |
|
|
|
|
|
|
68
|
|
|
$this->markTestIncomplete('test components individually'); |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testCheckoutFormForSingleCountrySiteWithReadonlyFieldsForCountry() |
|
72
|
|
|
{ |
|
73
|
|
|
|
|
74
|
|
|
// Set as a single country site |
|
75
|
|
|
$this->loadFixture("silvershop/tests/fixtures/singlecountry.yml"); |
|
76
|
|
|
$singlecountry = SiteConfig::current_site_config(); |
|
77
|
|
|
$this->assertEquals( |
|
|
|
|
|
|
78
|
|
|
"NZ", |
|
79
|
|
|
$singlecountry->getSingleCountry(), |
|
80
|
|
|
"Confirm that website is setup as a single country site" |
|
81
|
|
|
); |
|
82
|
|
|
|
|
83
|
|
|
$order = ShoppingCart::curr(); |
|
84
|
|
|
$config = new SinglePageCheckoutComponentConfig($order); |
|
85
|
|
|
$form = new CheckoutForm($this->checkoutcontroller, "OrderForm", $config); |
|
86
|
|
|
// no country fields due to readonly field |
|
87
|
|
|
$dataCountryAbsent = array( |
|
88
|
|
|
"CustomerDetailsCheckoutComponent_FirstName" => "Jane", |
|
89
|
|
|
"CustomerDetailsCheckoutComponent_Surname" => "Smith", |
|
90
|
|
|
"CustomerDetailsCheckoutComponent_Email" => "[email protected]", |
|
91
|
|
|
"ShippingAddressCheckoutComponent_Address" => "1234 Green Lane", |
|
92
|
|
|
"ShippingAddressCheckoutComponent_AddressLine2" => "Building 2", |
|
93
|
|
|
"ShippingAddressCheckoutComponent_City" => "Bleasdfweorville", |
|
94
|
|
|
"ShippingAddressCheckoutComponent_State" => "Trumpo", |
|
95
|
|
|
"ShippingAddressCheckoutComponent_PostalCode" => "4123", |
|
96
|
|
|
"ShippingAddressCheckoutComponent_Phone" => "032092277", |
|
97
|
|
|
"BillingAddressCheckoutComponent_Address" => "1234 Green Lane", |
|
98
|
|
|
"BillingAddressCheckoutComponent_AddressLine2" => "Building 2", |
|
99
|
|
|
"BillingAddressCheckoutComponent_City" => "Bleasdfweorville", |
|
100
|
|
|
"BillingAddressCheckoutComponent_State" => "Trumpo", |
|
101
|
|
|
"BillingAddressCheckoutComponent_PostalCode" => "4123", |
|
102
|
|
|
"BillingAddressCheckoutComponent_Phone" => "032092277", |
|
103
|
|
|
"PaymentCheckoutComponent_PaymentMethod" => "Dummy", |
|
104
|
|
|
"NotesCheckoutComponent_Notes" => "Leave it around the back", |
|
105
|
|
|
"TermsCheckoutComponent_ReadTermsAndConditions" => "1", |
|
106
|
|
|
); |
|
107
|
|
|
$form->loadDataFrom($dataCountryAbsent, true); |
|
|
|
|
|
|
108
|
|
|
$valid = $form->validate(); |
|
109
|
|
|
$errors = $form->getValidator()->getErrors(); |
|
110
|
|
|
$this->assertTrue($valid, print_r($errors, true)); |
|
|
|
|
|
|
111
|
|
|
$this->assertTrue( |
|
|
|
|
|
|
112
|
|
|
$form->Fields()->fieldByName("ShippingAddressCheckoutComponent_Country_readonly")->isReadonly(), |
|
113
|
|
|
"Shipping Address Country field is readonly" |
|
114
|
|
|
); |
|
115
|
|
|
$this->assertTrue( |
|
|
|
|
|
|
116
|
|
|
$form->Fields()->fieldByName("BillingAddressCheckoutComponent_Country_readonly")->isReadonly(), |
|
117
|
|
|
"Billing Address Country field is readonly" |
|
118
|
|
|
); |
|
119
|
|
|
$form->checkoutSubmit($dataCountryAbsent, $form); |
|
120
|
|
|
|
|
121
|
|
|
$shipping = $order->ShippingAddress(); |
|
|
|
|
|
|
122
|
|
|
$this->assertEquals("NZ", $shipping->Country); |
|
|
|
|
|
|
123
|
|
|
|
|
124
|
|
|
$billing = $order->BillingAddress(); |
|
|
|
|
|
|
125
|
|
|
$this->assertEquals("NZ", $billing->Country); |
|
|
|
|
|
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
|
|
130
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: