Passed
Branch 1.0 (badbbc)
by Morven
01:40
created

PostageExtensionTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 80
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A createPostageOption() 0 8 1
A testSetGetPostage() 0 8 1
A testPostageTaxPrice() 0 7 1
A testPostageTotal() 0 7 1
A testClearPostage() 0 8 1
A testPostageDetails() 0 7 1
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",
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

28
            /** @scrutinizer ignore-type */ "Postage",
Loading history...
29
            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

29
            /** @scrutinizer ignore-type */ 10,
Loading history...
30
            $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

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