1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverCommerce\Postage\Tests; |
4
|
|
|
|
5
|
|
|
use SilverStripe\i18n\i18n; |
6
|
|
|
use SilverStripe\Dev\SapphireTest; |
7
|
|
|
use SilverStripe\Security\Security; |
8
|
|
|
use SilverCommerce\TaxAdmin\Model\TaxRate; |
9
|
|
|
use SilverCommerce\Postage\Helpers\PostageOption; |
10
|
|
|
use SilverCommerce\Postage\Tests\Model\ExtendableObject; |
11
|
|
|
use SilverStripe\ORM\FieldType\DBCurrency; |
12
|
|
|
use SilverStripe\Core\Config\Config; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Test functionality of postage extension |
16
|
|
|
* |
17
|
|
|
*/ |
18
|
|
|
class PostageExtensionTest extends SapphireTest |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
protected static $fixture_file = 'PostageExtensionTest.yml'; |
22
|
|
|
|
23
|
|
|
protected static $extra_dataobjects = [ |
24
|
|
|
ExtendableObject::class |
25
|
|
|
]; |
26
|
|
|
|
27
|
|
|
public function setUp() |
28
|
|
|
{ |
29
|
|
|
parent::setUp(); |
30
|
|
|
|
31
|
|
|
// Setup default locale |
32
|
|
|
i18n::set_locale("en_GB"); |
33
|
|
|
$member = Security::getCurrentUser(); |
34
|
|
|
$member->Locale = "en_GB"; |
35
|
|
|
|
36
|
|
|
// Set default currency |
37
|
|
|
Config::inst()->set(DBCurrency::class, "currency_symbol", "£"); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
protected function createPostageOption() |
41
|
|
|
{ |
42
|
|
|
$tax = $this->objFromFixture(TaxRate::class, "vat"); |
43
|
|
|
|
44
|
|
|
return PostageOption::create( |
45
|
|
|
"Postage", |
46
|
|
|
10, |
47
|
|
|
$tax |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Test possible postage results for flat rate shipping |
53
|
|
|
*/ |
54
|
|
|
public function testSetGetPostage() |
55
|
|
|
{ |
56
|
|
|
$postage = $this->createPostageOption(); |
57
|
|
|
$obj = $this->objFromFixture(ExtendableObject::class, "test"); |
58
|
|
|
$obj->setPostage($postage); |
59
|
|
|
|
60
|
|
|
$this->assertInstanceOf(PostageOption::class, $obj->getPostage()); |
61
|
|
|
$this->assertEquals($postage, $obj->getPostage()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Test that clearing postage emptys relevent data |
66
|
|
|
*/ |
67
|
|
|
public function testClearPostage() |
68
|
|
|
{ |
69
|
|
|
$obj = $this->objFromFixture(ExtendableObject::class, "test"); |
70
|
|
|
$obj->clearPostage(); |
71
|
|
|
|
72
|
|
|
$this->assertEquals("", $obj->PostageTitle); |
73
|
|
|
$this->assertEquals(0, $obj->PostagePrice); |
74
|
|
|
$this->assertEquals(null, $obj->PostageTaxID); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Test the postage details are correctly rendered |
79
|
|
|
*/ |
80
|
|
|
public function testPostageDetails() |
81
|
|
|
{ |
82
|
|
|
$postage = $this->createPostageOption(); |
83
|
|
|
$obj = $this->objFromFixture(ExtendableObject::class, "test"); |
84
|
|
|
$obj->setPostage($postage); |
85
|
|
|
|
86
|
|
|
$this->assertEquals("Postage (£12.00)", $obj->PostageDetails); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Test the postage total is correct |
91
|
|
|
*/ |
92
|
|
|
public function testPostageTotal() |
93
|
|
|
{ |
94
|
|
|
$postage = $this->createPostageOption(); |
95
|
|
|
$obj = $this->objFromFixture(ExtendableObject::class, "test"); |
96
|
|
|
$obj->setPostage($postage); |
97
|
|
|
|
98
|
|
|
$this->assertEquals(12.0, $obj->PostageTotal); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Test the postage tax price is correct |
103
|
|
|
*/ |
104
|
|
|
public function testPostageTaxPrice() |
105
|
|
|
{ |
106
|
|
|
$postage = $this->createPostageOption(); |
107
|
|
|
$obj = $this->objFromFixture(ExtendableObject::class, "test"); |
108
|
|
|
$obj->setPostage($postage); |
109
|
|
|
|
110
|
|
|
$this->assertEquals(2.0, $obj->PostageTaxPrice); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|