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