Passed
Pull Request — master (#14)
by Matthew
14:49
created

testGetHasInventory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 0
dl 0
loc 20
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
namespace Dynamic\FoxyStripe\Test;
4
5
use Dynamic\FoxyStripe\Model\Order;
6
use Dynamic\FoxyStripe\Model\OrderDetail;
7
use Dynamic\FoxyStripe\Test\TestOnly\TestOption;
8
use Dynamic\FoxyStripe\Test\TestOnly\TestProduct;
9
use SilverStripe\Dev\SapphireTest;
10
use SilverStripe\Forms\FieldList;
11
12
class FoxyStripeOptionInventoryManagerTest extends SapphireTest
13
{
14
    /**
15
     * @var array
16
     */
17
    protected static $fixture_file = array(
18
        '../fixtures.yml',
19
    );
20
21
    /**
22
     * @var array
23
     */
24
    protected static $extra_dataobjects = [
25
        TestProduct::class,
26
        TestOption::class,
27
    ];
28
29
    /**
30
     *
31
     */
32
    public function testUpdateCMSFields()
33
    {
34
        $object = $this->objFromFixture(TestOption::class, 'one');
35
        $fields = $object->getCMSFields();
36
        $this->assertInstanceOf(FieldList::class, $fields);
37
    }
38
39
    /**
40
     *
41
     */
42
    public function testGetHasInventory()
43
    {
44
        /** @var TestOption $option */
45
        $option = $this->objFromFixture(TestOption::class, 'one');
46
47
        $option->ControlInventory = false;
0 ignored issues
show
Bug Best Practice introduced by
The property ControlInventory does not exist on Dynamic\FoxyStripe\Test\TestOnly\TestOption. Since you implemented __set, consider adding a @property annotation.
Loading history...
48
        $option->PurchaseLimit = 0;
0 ignored issues
show
Bug Best Practice introduced by
The property PurchaseLimit does not exist on Dynamic\FoxyStripe\Test\TestOnly\TestOption. Since you implemented __set, consider adding a @property annotation.
Loading history...
49
        $this->assertFalse($option->getHasInventory());
0 ignored issues
show
Bug introduced by
The method getHasInventory() does not exist on Dynamic\FoxyStripe\Test\TestOnly\TestOption. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

49
        $this->assertFalse($option->/** @scrutinizer ignore-call */ getHasInventory());
Loading history...
50
51
        $option->ControlInventory = true;
52
        $option->PurchaseLimit = 0;
53
        $this->assertFalse($option->getHasInventory());
54
55
        $option->ControlInventory = false;
56
        $option->PurchaseLimit = 10;
57
        $this->assertFalse($option->getHasInventory());
58
59
        $option->ControlInventory = true;
60
        $option->PurchaseLimit = 10;
61
        $this->assertTrue($option->getHasInventory());
62
    }
63
64
    /**
65
     *
66
     */
67
    public function testGetIsOptionAvailable()
68
    {
69
        /** @var TestOption $option */
70
        $option = $this->objFromFixture(TestOption::class, 'one');
71
72
        // no inventory control
73
        $option->ControlInventory = false;
0 ignored issues
show
Bug Best Practice introduced by
The property ControlInventory does not exist on Dynamic\FoxyStripe\Test\TestOnly\TestOption. Since you implemented __set, consider adding a @property annotation.
Loading history...
74
        $option->PurchaseLimit = 0;
0 ignored issues
show
Bug Best Practice introduced by
The property PurchaseLimit does not exist on Dynamic\FoxyStripe\Test\TestOnly\TestOption. Since you implemented __set, consider adding a @property annotation.
Loading history...
75
        $this->assertTrue($option->getIsOptionAvailable());
0 ignored issues
show
Bug introduced by
The method getIsOptionAvailable() does not exist on Dynamic\FoxyStripe\Test\TestOnly\TestOption. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

75
        $this->assertTrue($option->/** @scrutinizer ignore-call */ getIsOptionAvailable());
Loading history...
76
77
        // inventory control, no inventory
78
        $option->ControlInventory = true;
79
        $option->PurchaseLimit = 0;
80
        $this->assertFalse($option->getIsOptionAvailable());
81
82
        // inventory control, with inventory
83
        $option->ControlInventory = true;
84
        $option->PurchaseLimit = 10;
85
        $this->assertTrue($option->getIsOptionAvailable());
86
87
        $detail = OrderDetail::create();
88
        $detail->Quantity = 10;
89
        $detail->write();
90
        $detail->OrderOptions()->add($option);
91
92
        // inventory control, no inventory left
93
        $option->ControlInventory = true;
94
        $option->PurchaseLimit = 10;
95
        $this->assertFalse($option->getIsOptionAvailable());
96
    }
97
98
    /**
99
     *
100
     */
101
    public function testGetNumberPurchased()
102
    {
103
        /** @var TestOption $option */
104
        $option = $this->objFromFixture(TestOption::class, 'one');
105
106
        $this->assertEquals(0, $option->getNumberPurchased());
0 ignored issues
show
Bug introduced by
The method getNumberPurchased() does not exist on Dynamic\FoxyStripe\Test\TestOnly\TestOption. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

106
        $this->assertEquals(0, $option->/** @scrutinizer ignore-call */ getNumberPurchased());
Loading history...
107
108
        $detail = OrderDetail::create();
109
        $detail->Quantity = 10;
110
        $detail->write();
111
        $detail->OrderOptions()->add($option);
112
113
        $this->assertEquals(10, $option->getNumberPurchased());
114
    }
115
116
    /**
117
     *
118
     */
119
    public function testGetOrders()
120
    {
121
        /** @var TestOption $option */
122
        $option = $this->objFromFixture(TestOption::class, 'one');
123
124
        $this->assertEquals(0, $option->getOrders()->Count());
0 ignored issues
show
Bug introduced by
The method getOrders() does not exist on Dynamic\FoxyStripe\Test\TestOnly\TestOption. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

124
        $this->assertEquals(0, $option->/** @scrutinizer ignore-call */ getOrders()->Count());
Loading history...
125
126
        $detail = OrderDetail::create();
127
        $detail->Quantity = 10;
128
        $detail->write();
129
        $detail->OrderOptions()->add($option);
130
131
        $this->assertEquals(1, $option->getOrders()->Count());
132
    }
133
}
134