Passed
Push — 1.0 ( c8a1ca...1955ea )
by Morven
02:40
created

TaxCategoryTest::testValidTax()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
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);
0 ignored issues
show
Bug introduced by
The method set() does not exist on SilverStripe\Config\Coll...nfigCollectionInterface. It seems like you code against a sub-type of SilverStripe\Config\Coll...nfigCollectionInterface such as SilverStripe\Config\Coll...nfigCollectionInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        Config::inst()->/** @scrutinizer ignore-call */ set(Region::class, "create_on_build", false);
Loading history...
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", "ABE"));
57
58
        // Test unavailable location
59
        $this->assertNull($obj->ValidTax("ES"));
60
    }
61
}
62