testGetNumberPurchased()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 13
rs 9.9666
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\TestVariation;
10
use Dynamic\Foxy\Inventory\Test\TestOnly\Page\TestProduct;
11
use SilverStripe\Core\Config\Config;
12
use SilverStripe\Core\Injector\Injector;
13
use SilverStripe\Dev\SapphireTest;
14
use SilverStripe\Forms\FieldList;
15
16
class ProductVariationInventoryManagerTest extends SapphireTest
17
{
18
    /**
19
     * @var array
20
     */
21
    protected static $fixture_file = '../fixtures.yml';
22
23
    /**
24
     * @var array
25
     */
26
    protected static $extra_dataobjects = [
27
        TestProduct::class,
28
        TestVariation::class,
29
    ];
30
31
    /**
32
     * @var array
33
     */
34
    protected static $required_extensions = [
35
        TestProduct::class => [
36
            Purchasable::class,
37
            ProductInventoryManager::class,
38
            ProductExpirationManager::class,
39
        ],
40
        TestVariation::class => [
41
            ProductVariationInventoryManager::class,
42
        ],
43
    ];
44
45
    /**
46
     *
47
     */
48
    protected function setUp()
49
    {
50
        parent::setUp();
51
52
        Config::modify()->set('Dynamic\\Foxy\\SingleSignOn\\Client\\CustomerClient', 'foxy_sso_enabled', false);
53
    }
54
55
    /**
56
     *
57
     */
58
    public function testUpdateCMSFields()
59
    {
60
        $object = Injector::inst()->create(TestProduct::class);
61
        $fields = $object->getCMSFields();
62
        $this->assertInstanceOf(FieldList::class, $fields);
63
    }
64
65
    /**
66
     *
67
     */
68
    public function testGetHasInventory()
69
    {
70
        /** @var TestVariation $option */
71
        $option = Injector::inst()->create(TestVariation::class);
72
        $option->ControlInventory = false;
0 ignored issues
show
Bug Best Practice introduced by
The property ControlInventory does not exist on Dynamic\Foxy\Inventory\T...nly\Model\TestVariation. Since you implemented __set, consider adding a @property annotation.
Loading history...
73
        $option->PurchaseLimit = 0;
0 ignored issues
show
Bug Best Practice introduced by
The property PurchaseLimit does not exist on Dynamic\Foxy\Inventory\T...nly\Model\TestVariation. Since you implemented __set, consider adding a @property annotation.
Loading history...
74
        $this->assertFalse($option->getHasInventory());
0 ignored issues
show
Bug introduced by
The method getHasInventory() does not exist on Dynamic\Foxy\Inventory\T...nly\Model\TestVariation. 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

74
        $this->assertFalse($option->/** @scrutinizer ignore-call */ getHasInventory());
Loading history...
75
        $option->ControlInventory = true;
76
        $option->PurchaseLimit = 0;
77
        $this->assertFalse($option->getHasInventory());
78
        $option->ControlInventory = false;
79
        $option->PurchaseLimit = 10;
80
        $this->assertFalse($option->getHasInventory());
81
        $option->ControlInventory = true;
82
        $option->PurchaseLimit = 10;
83
        $this->assertTrue($option->getHasInventory());
84
    }
85
86
    /**
87
     *
88
     */
89
    public function testGetIsOptionAvailable()
90
    {
91
        $this->markTestSkipped();
92
        /** @var TestProductOption $option */
93
        $option = $this->objFromFixture(TestProductOption::class, 'one');
0 ignored issues
show
Bug introduced by
The type Dynamic\Foxy\Inventory\T...nsion\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...
94
        // no inventory control
95
        $option->ControlInventory = false;
96
        $option->PurchaseLimit = 0;
97
        $this->assertTrue($option->getIsOptionAvailable());
98
        // inventory control, no limit
99
        $option->ControlInventory = true;
100
        $option->PurchaseLimit = 0;
101
        $this->assertTrue($option->getIsOptionAvailable());
102
        // inventory control, with limit
103
        $option->ControlInventory = true;
104
        $option->PurchaseLimit = 10;
105
        $this->assertTrue($option->getIsOptionAvailable());
106
        /** @var OrderDetail $detail */
107
        $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...
108
        $detail->Quantity = 10;
109
        $detail->write();
110
        $detail->OptionItems()->add($option);
111
        // inventory control, no inventory left
112
        $option->ControlInventory = true;
113
        $option->PurchaseLimit = 10;
114
        $this->assertFalse($option->getIsOptionAvailable());
115
        $detail->delete();
116
    }
117
118
    /**
119
     *
120
     */
121
    public function testGetNumberPurchased()
122
    {
123
        $this->markTestSkipped();
124
        /** @var TestProductOption $option */
125
        $option = $this->objFromFixture(TestProductOption::class, 'one');
126
        $this->assertEquals(0, $option->getNumberPurchased());
127
        /** @var OrderDetail $detail */
128
        $detail = OrderDetail::create();
129
        $detail->Quantity = 10;
130
        $detail->write();
131
        $detail->OptionItems()->add($option);
132
        $this->assertEquals(10, $option->getNumberPurchased());
133
        $detail->delete();
134
    }
135
136
    /**
137
     *
138
     */
139
    public function testGetOrders()
140
    {
141
        $this->markTestSkipped();
142
        /** @var TestProductOption $option */
143
        $option = $this->objFromFixture(TestProductOption::class, 'one');
144
        $this->assertEquals(0, $option->getOrders()->Count());
145
        /** @var OrderDetail $detail */
146
        $detail = OrderDetail::create();
147
        $detail->Quantity = 10;
148
        $detail->write();
149
        $detail->OptionItems()->add($option);
150
        $this->assertEquals(1, $option->getOrders()->count());
151
        $detail->delete();
152
    }
153
}
154