Passed
Push — 1.0 ( e7375e...fc03f3 )
by Morven
01:58
created

PostageExtensionTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
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",
0 ignored issues
show
Bug introduced by
'Postage' of type string is incompatible with the type array expected by parameter $args of SilverCommerce\Postage\H...PostageOption::create(). ( Ignorable by Annotation )

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

40
            /** @scrutinizer ignore-type */ "Postage",
Loading history...
41
            10,
0 ignored issues
show
Bug introduced by
10 of type integer is incompatible with the type array expected by parameter $args of SilverCommerce\Postage\H...PostageOption::create(). ( Ignorable by Annotation )

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

41
            /** @scrutinizer ignore-type */ 10,
Loading history...
42
            $tax
0 ignored issues
show
Bug introduced by
$tax of type SilverStripe\ORM\DataObject is incompatible with the type array expected by parameter $args of SilverCommerce\Postage\H...PostageOption::create(). ( Ignorable by Annotation )

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

42
            /** @scrutinizer ignore-type */ $tax
Loading history...
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