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; |
|
|
|
|
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(); |
|
|
|
|
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
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths