1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class ShippingEstimateFormTest extends FunctionalTest{ |
4
|
|
|
|
5
|
|
|
static $fixture_file = array( |
6
|
|
|
"silvershop-shipping/tests/fixtures/TableShippingMethod.yml", |
7
|
|
|
"silvershop/tests/fixtures/shop.yml", |
8
|
|
|
"silvershop/tests/fixtures/Pages.yml" |
9
|
|
|
); |
10
|
|
|
protected static $use_draft_site = true; |
11
|
|
|
|
12
|
|
|
function setUp() { |
|
|
|
|
13
|
|
|
if(method_exists('SapphireTest', 'useTestTheme')){ |
14
|
|
|
$this->useTestTheme($themeBaseDir = dirname(__FILE__), 'testtheme', function(){}); |
15
|
|
|
} else { |
16
|
|
|
$this->useTheme('testtheme'); |
17
|
|
|
} |
18
|
|
|
parent::setUp(); |
19
|
|
|
ShopTest::setConfiguration(); |
20
|
|
|
// add product to the cart |
21
|
|
|
$this->socks = $this->objFromFixture('Product', 'socks'); |
|
|
|
|
22
|
|
|
$this->socks->publish('Stage','Live'); |
23
|
|
|
|
24
|
|
|
$this->cartpage = $this->objFromFixture("CartPage", "cart"); |
|
|
|
|
25
|
|
|
$this->cartpage->publish('Stage','Live'); |
26
|
|
|
ShoppingCart::singleton()->setCurrent($this->objFromFixture("Order", "cart")); //set the current cart |
|
|
|
|
27
|
|
|
|
28
|
|
|
// Open cart page |
29
|
|
|
$page = $this->get('/cart'); |
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
function testGetEstimates() { |
|
|
|
|
33
|
|
|
|
34
|
|
|
//good data for Shipping Estimate Form |
35
|
|
|
$data = array( |
36
|
|
|
'Country' => 'NZ', |
37
|
|
|
'State' => 'Auckland', |
38
|
|
|
'City' => 'Auckland', |
39
|
|
|
'PostalCode' => 1010 |
40
|
|
|
); |
41
|
|
|
$page1 = $this->post('/cart/ShippingEstimateForm', $data); |
42
|
|
|
$this->assertEquals(200, $page1->getStatusCode(), "a page should load"); |
|
|
|
|
43
|
|
|
$this->assertContains("Quantity-based shipping", $page1->getBody(), "ShippingEstimates presented in a table"); |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
//un-escaped data for Shipping Estimate Form |
47
|
|
|
$data = array( |
48
|
|
|
'Country' => 'NZ', |
49
|
|
|
'State' => 'Hawke\'s Bay', |
50
|
|
|
'City' => 'SELECT * FROM \" \' WHERE AND EVIL', |
51
|
|
|
'PostalCode' => 1234 |
52
|
|
|
); |
53
|
|
|
$page2 = $this->post('/cart/ShippingEstimateForm', $data); |
54
|
|
|
$this->assertEquals(200, $page2->getStatusCode(), "a page should load"); |
|
|
|
|
55
|
|
|
$this->assertContains("Quantity-based shipping", $page2->getBody(), "ShippingEstimates can be successfully presented with un-escaped data in the form"); |
56
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
function testShippingEstimateWithReadonlyFieldForCountry() { |
|
|
|
|
60
|
|
|
// setup a single-country site |
61
|
|
|
$siteconfig = DataObject::get_one('SiteConfig'); |
62
|
|
|
$siteconfig->AllowedCountries = "NZ"; |
63
|
|
|
$siteconfig->write(); |
64
|
|
|
|
65
|
|
|
// Open cart page where Country field is readonly |
66
|
|
|
$page = $this->get('/cart'); |
67
|
|
|
$this->assertContains("Country_readonly", $page->getBody(), "The Country field is readonly"); |
68
|
|
|
$this->assertNotContains("<option value=\"NZ\">New Zealand</option>", $page->getBody(), "Dropdown field is not shown"); |
69
|
|
|
|
70
|
|
|
// The Shipping Estimate Form can post with a Country readonly field |
71
|
|
|
$data = array( |
72
|
|
|
'State' => 'Waikato', |
73
|
|
|
'City' => 'Hamilton', |
74
|
|
|
'PostalCode' => 3210 |
75
|
|
|
); |
76
|
|
|
$page3 = $this->post('/cart/ShippingEstimateForm', $data); |
77
|
|
|
$this->assertEquals(200, $page3->getStatusCode(), "a page should load"); |
|
|
|
|
78
|
|
|
$this->assertContains("Quantity-based shipping", $page3->getBody(), "ShippingEstimates can be successfully presented with a Country readonly field"); |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Test against a SS Shop Shipping theme |
86
|
|
|
* |
87
|
|
|
* Template CartPage.ss contains <% include ShippingEstimator %> |
88
|
|
|
* Function adapted from SSViewerTest.php in SSv3.1 |
89
|
|
|
* @param $theme string - theme name |
90
|
|
|
*/ |
91
|
|
|
protected function useTheme($theme) { |
92
|
|
|
global $project; |
93
|
|
|
|
94
|
|
|
$themeBaseDir = dirname(__FILE__); |
95
|
|
|
$manifest = new SS_TemplateManifest($themeBaseDir, $project, true, true); |
96
|
|
|
|
97
|
|
|
SS_TemplateLoader::instance()->pushManifest($manifest); |
98
|
|
|
|
99
|
|
|
$origTheme = Config::inst()->get('SSViewer', 'theme'); |
100
|
|
|
Config::inst()->update('SSViewer', 'theme', $theme); |
101
|
|
|
|
102
|
|
|
// Remove all the test themes we created |
103
|
|
|
SS_TemplateLoader::instance()->popManifest(); |
104
|
|
|
Config::inst()->update('SSViewer', 'theme', $origTheme); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.