1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverCommerce\TaxAdmin\Tests; |
4
|
|
|
|
5
|
|
|
use SilverStripe\i18n\i18n; |
6
|
|
|
use SilverStripe\Dev\SapphireTest; |
7
|
|
|
use SilverStripe\Security\Security; |
8
|
|
|
use SilverStripe\Core\Config\Config; |
9
|
|
|
use SilverCommerce\GeoZones\Model\Region; |
10
|
|
|
use SilverCommerce\TaxAdmin\Model\TaxCategory; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Test functionality of postage extension |
14
|
|
|
* |
15
|
|
|
*/ |
16
|
|
|
class TaxCategoryTest extends SapphireTest |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
protected static $fixture_file = 'TaxData.yml'; |
20
|
|
|
|
21
|
|
|
public function setUp() |
22
|
|
|
{ |
23
|
|
|
parent::setUp(); |
24
|
|
|
Config::inst()->set(Region::class, "create_on_build", false); |
|
|
|
|
25
|
|
|
|
26
|
|
|
// Setup default locale |
27
|
|
|
i18n::set_locale("en_GB"); |
28
|
|
|
$member = Security::getCurrentUser(); |
29
|
|
|
$member->Locale = "en_GB"; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Test category valid tax retursn the correct value |
34
|
|
|
*/ |
35
|
|
|
public function testValidTax() |
36
|
|
|
{ |
37
|
|
|
$obj = $this->objFromFixture(TaxCategory::class, "uk"); |
38
|
|
|
|
39
|
|
|
// Test default location (when logged in) |
40
|
|
|
$this->assertEquals("VAT", $obj->ValidTax()->Title); |
41
|
|
|
|
42
|
|
|
// Test default location (when not logged in) |
43
|
|
|
Security::setCurrentUser(null); |
44
|
|
|
$this->assertEquals("VAT", $obj->ValidTax()->Title); |
45
|
|
|
|
46
|
|
|
// Test VAT location |
47
|
|
|
$this->assertEquals("VAT", $obj->ValidTax("GB")->Title); |
48
|
|
|
|
49
|
|
|
// Test VAT location for country and region |
50
|
|
|
$this->assertEquals("VAT", $obj->ValidTax("GB", "GLS")->Title); |
51
|
|
|
|
52
|
|
|
// Test reduced location |
53
|
|
|
$this->assertEquals("reduced", $obj->ValidTax("US")->Title); |
54
|
|
|
|
55
|
|
|
// Test location for valid country and invalid region |
56
|
|
|
$this->assertNull($obj->ValidTax("GB", "HDF")); |
57
|
|
|
|
58
|
|
|
// Test unavailable location |
59
|
|
|
$this->assertNull($obj->ValidTax("ES")); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Test category valid tax returns the correct value when using |
66
|
|
|
* the global flag. |
67
|
|
|
*/ |
68
|
|
|
public function testGlobalValidTax() |
69
|
|
|
{ |
70
|
|
|
$obj = $this->objFromFixture(TaxCategory::class, "uk_global"); |
71
|
|
|
|
72
|
|
|
// Test default location (when logged in) |
73
|
|
|
$this->assertEquals("VAT Global", $obj->ValidTax()->Title); |
74
|
|
|
|
75
|
|
|
// Test default location (when not logged in) |
76
|
|
|
Security::setCurrentUser(null); |
77
|
|
|
$this->assertEquals("VAT Global", $obj->ValidTax()->Title); |
78
|
|
|
|
79
|
|
|
// Test VAT location |
80
|
|
|
$this->assertEquals("VAT Global", $obj->ValidTax("GB")->Title); |
81
|
|
|
|
82
|
|
|
// Test VAT location for country and region |
83
|
|
|
$this->assertEquals("VAT Global", $obj->ValidTax("GB", "GLS")->Title); |
84
|
|
|
|
85
|
|
|
// Test reduced location |
86
|
|
|
$this->assertEquals("VAT Global", $obj->ValidTax("US")->Title); |
87
|
|
|
|
88
|
|
|
// Test invalid location |
89
|
|
|
$this->assertEquals("VAT Global", $obj->ValidTax("ES")->Title); |
90
|
|
|
|
91
|
|
|
// Test location for valid country and invalid region |
92
|
|
|
$this->assertNull($obj->ValidTax("GB", "HDF")); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|