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