Passed
Push — master ( c5f1b0...81641b )
by Jason
03:09
created

testUpdateCMSFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Dynamic\Foxy\Inventory\Test\Extension;
4
5
use Dynamic\Foxy\Extension\Purchasable;
6
use Dynamic\Foxy\Inventory\Extension\ProductExpirationManager;
7
use Dynamic\Foxy\Inventory\Extension\ProductInventoryManager;
8
use Dynamic\Foxy\Inventory\Extension\ProductVariationInventoryManager;
9
use Dynamic\Foxy\Inventory\Test\TestOnly\Model\TestProductOption;
0 ignored issues
show
Bug introduced by
The type Dynamic\Foxy\Inventory\T...Model\TestProductOption was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Dynamic\Foxy\Inventory\Test\TestOnly\Model\TestVariation;
11
use Dynamic\Foxy\Inventory\Test\TestOnly\Page\TestProduct;
12
use SilverStripe\Core\Config\Config;
13
use SilverStripe\Core\Injector\Injector;
14
use SilverStripe\Dev\SapphireTest;
15
use SilverStripe\Forms\FieldList;
16
17
18
19
class ProductVariationInventoryManagerTest extends SapphireTest
20
{
21
    /**
22
     * @var array
23
     */
24
    protected static $fixture_file = '../fixtures.yml';
25
26
    /**
27
     * @var array
28
     */
29
    protected static $extra_dataobjects = [
30
        TestProduct::class,
31
        TestVariation::class,
32
    ];
33
34
    /**
35
     * @var array
36
     */
37
    protected static $required_extensions = [
38
        TestProduct::class => [
39
            Purchasable::class,
40
            ProductInventoryManager::class,
41
            ProductExpirationManager::class,
42
        ],
43
        TestVariation::class => [
44
            ProductVariationInventoryManager::class,
45
        ],
46
    ];
47
48
    /**
49
     *
50
     */
51
    protected function setUp()
52
    {
53
        parent::setUp();
54
55
        Config::modify()->set('Dynamic\\Foxy\\SingleSignOn\\Client\\CustomerClient', 'foxy_sso_enabled', false);
56
    }
57
58
    /**
59
     *
60
     */
61
    public function testUpdateCMSFields()
62
    {
63
        $object = Injector::inst()->create(TestProduct::class);
64
        $fields = $object->getCMSFields();
65
        $this->assertInstanceOf(FieldList::class, $fields);
66
    }
67
68
    /**
69
     *
70
     */
71
    public function testGetHasInventory()
72
    {
73
        /** @var TestProductOption $option */
74
        $option = Injector::inst()->create(TestVariation::class);
75
        $option->ControlInventory = false;
76
        $option->PurchaseLimit = 0;
77
        $this->assertFalse($option->getHasInventory());
78
        $option->ControlInventory = true;
79
        $option->PurchaseLimit = 0;
80
        $this->assertFalse($option->getHasInventory());
81
        $option->ControlInventory = false;
82
        $option->PurchaseLimit = 10;
83
        $this->assertFalse($option->getHasInventory());
84
        $option->ControlInventory = true;
85
        $option->PurchaseLimit = 10;
86
        $this->assertTrue($option->getHasInventory());
87
    }
88
89
    /**
90
     *
91
     */
92
    public function testGetIsOptionAvailable()
93
    {
94
        $this->markTestSkipped();
95
        /** @var TestProductOption $option */
96
        $option = $this->objFromFixture(TestProductOption::class, 'one');
97
        // no inventory control
98
        $option->ControlInventory = false;
99
        $option->PurchaseLimit = 0;
100
        $this->assertTrue($option->getIsOptionAvailable());
101
        // inventory control, no limit
102
        $option->ControlInventory = true;
103
        $option->PurchaseLimit = 0;
104
        $this->assertTrue($option->getIsOptionAvailable());
105
        // inventory control, with limit
106
        $option->ControlInventory = true;
107
        $option->PurchaseLimit = 10;
108
        $this->assertTrue($option->getIsOptionAvailable());
109
        /** @var OrderDetail $detail */
110
        $detail = OrderDetail::create();
0 ignored issues
show
Bug introduced by
The type Dynamic\Foxy\Inventory\Test\Extension\OrderDetail was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
111
        $detail->Quantity = 10;
112
        $detail->write();
113
        $detail->OptionItems()->add($option);
114
        // inventory control, no inventory left
115
        $option->ControlInventory = true;
116
        $option->PurchaseLimit = 10;
117
        $this->assertFalse($option->getIsOptionAvailable());
118
        $detail->delete();
119
    }
120
121
    /**
122
     *
123
     */
124
    public function testGetNumberPurchased()
125
    {
126
        $this->markTestSkipped();
127
        /** @var TestProductOption $option */
128
        $option = $this->objFromFixture(TestProductOption::class, 'one');
129
        $this->assertEquals(0, $option->getNumberPurchased());
130
        /** @var OrderDetail $detail */
131
        $detail = OrderDetail::create();
132
        $detail->Quantity = 10;
133
        $detail->write();
134
        $detail->OptionItems()->add($option);
135
        $this->assertEquals(10, $option->getNumberPurchased());
136
        $detail->delete();
137
    }
138
139
    /**
140
     *
141
     */
142
    public function testGetOrders()
143
    {
144
        $this->markTestSkipped();
145
        /** @var TestProductOption $option */
146
        $option = $this->objFromFixture(TestProductOption::class, 'one');
147
        $this->assertEquals(0, $option->getOrders()->Count());
148
        /** @var OrderDetail $detail */
149
        $detail = OrderDetail::create();
150
        $detail->Quantity = 10;
151
        $detail->write();
152
        $detail->OptionItems()->add($option);
153
        $this->assertEquals(1, $option->getOrders()->count());
154
        $detail->delete();
155
    }
156
}
157