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\Test\TestOnly\Page\TestProduct; |
9
|
|
|
use Dynamic\Foxy\Inventory\Test\TestOnly\Page\TestProductController; |
10
|
|
|
use Dynamic\Foxy\Model\Variation; |
|
|
|
|
11
|
|
|
use Dynamic\Foxy\Orders\Model\Order; |
12
|
|
|
use Dynamic\Foxy\Orders\Model\OrderDetail; |
13
|
|
|
use SilverStripe\Core\Config\Config; |
14
|
|
|
use SilverStripe\Dev\SapphireTest; |
15
|
|
|
use SilverStripe\Forms\FieldList; |
16
|
|
|
use SilverStripe\Forms\Form; |
17
|
|
|
|
18
|
|
|
class ProductInventoryManagerTest extends SapphireTest |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
protected static $fixture_file = [ |
24
|
|
|
'../fixtures.yml', |
25
|
|
|
]; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
protected static $extra_dataobjects = [ |
31
|
|
|
TestProduct::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
|
|
|
]; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var array |
47
|
|
|
*/ |
48
|
|
|
protected static $extra_controllers = [ |
49
|
|
|
TestProductController::class, |
50
|
|
|
]; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* |
54
|
|
|
*/ |
55
|
|
|
protected function setUp() |
56
|
|
|
{ |
57
|
|
|
parent::setUp(); |
58
|
|
|
|
59
|
|
|
Config::modify()->set('Dynamic\\Foxy\\SingleSignOn\\Client\\CustomerClient', 'foxy_sso_enabled', false); |
60
|
|
|
Config::modify()->set(Variation::class, 'has_one', ['TestProduct' => TestProduct::class]); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* |
65
|
|
|
*/ |
66
|
|
|
public function testUpdateCMSFields() |
67
|
|
|
{ |
68
|
|
|
$object = $this->objFromFixture(TestProduct::class, 'one'); |
69
|
|
|
$fields = $object->getCMSFields(); |
70
|
|
|
$this->assertInstanceOf(FieldList::class, $fields); |
71
|
|
|
$this->assertNotNull($fields->dataFieldByName('ControlInventory')); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* |
76
|
|
|
*/ |
77
|
|
|
public function testFoxyStripePurchaseForm() |
78
|
|
|
{ |
79
|
|
|
/** @var TestProduct $object */ |
80
|
|
|
$object = $this->objFromFixture(TestProduct::class, 'one'); |
81
|
|
|
/** @var TestProductController $controller */ |
82
|
|
|
$controller = TestProductController::create($object); |
83
|
|
|
$form = $controller->AddToCartForm(); |
|
|
|
|
84
|
|
|
$this->assertInstanceOf(Form::class, $form); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* |
89
|
|
|
*/ |
90
|
|
|
public function testGetHasInventory() |
91
|
|
|
{ |
92
|
|
|
/** @var TestProduct $product */ |
93
|
|
|
$product = $this->objFromFixture(TestProduct::class, 'one'); |
94
|
|
|
$product->ControlInventory = false; |
|
|
|
|
95
|
|
|
$product->PurchaseLimit = 0; |
|
|
|
|
96
|
|
|
$this->assertFalse($product->getHasInventory()); |
|
|
|
|
97
|
|
|
$product->ControlInventory = true; |
98
|
|
|
$product->PurchaseLimit = 0; |
99
|
|
|
$this->assertFalse($product->getHasInventory()); |
100
|
|
|
$product->ControlInventory = false; |
101
|
|
|
$product->PurchaseLimit = 10; |
102
|
|
|
$this->assertFalse($product->getHasInventory()); |
103
|
|
|
$product->ControlInventory = true; |
104
|
|
|
$product->PurchaseLimit = 10; |
105
|
|
|
$this->assertTrue($product->getHasInventory()); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* |
110
|
|
|
*/ |
111
|
|
|
public function testGetIsProductAvailable() |
112
|
|
|
{ |
113
|
|
|
/** @var TestProduct $product */ |
114
|
|
|
$product = $this->objFromFixture(TestProduct::class, 'one'); |
115
|
|
|
// no inventory control |
116
|
|
|
$product->ControlInventory = false; |
|
|
|
|
117
|
|
|
$product->PurchaseLimit = 0; |
|
|
|
|
118
|
|
|
$product->write(); |
119
|
|
|
|
120
|
|
|
$product = TestProduct::get()->byID($product->ID); |
121
|
|
|
|
122
|
|
|
$this->assertTrue($product->getIsProductAvailable()); |
123
|
|
|
|
124
|
|
|
// inventory control, with limit |
125
|
|
|
$product->ControlInventory = true; |
126
|
|
|
$product->PurchaseLimit = 10; |
127
|
|
|
$product->write(); |
128
|
|
|
$product = TestProduct::get()->byID($product->ID); |
129
|
|
|
|
130
|
|
|
$this->assertTrue($product->getIsProductAvailable()); |
131
|
|
|
|
132
|
|
|
/** @var OrderDetail $detail */ |
133
|
|
|
$detail = OrderDetail::create(); |
134
|
|
|
$detail->OrderID = $this->objFromFixture(Order::class, 'one')->ID; |
135
|
|
|
$detail->Quantity = 10; |
136
|
|
|
$detail->ProductID = $product->ID; |
137
|
|
|
$detail->write(); |
138
|
|
|
|
139
|
|
|
$product = TestProduct::get()->byID($product->ID); |
140
|
|
|
|
141
|
|
|
// inventory control, no inventory left |
142
|
|
|
$this->assertFalse($product->getIsProductAvailable()); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* |
147
|
|
|
*/ |
148
|
|
|
public function testGetNumberPurchased() |
149
|
|
|
{ |
150
|
|
|
/** @var TestProduct $product */ |
151
|
|
|
$product = $this->objFromFixture(TestProduct::class, 'one'); |
152
|
|
|
$this->assertEquals(0, $product->getNumberPurchased()); |
|
|
|
|
153
|
|
|
|
154
|
|
|
/** @var Order $order */ |
155
|
|
|
$order = $this->objFromFixture(Order::class, 'one'); |
156
|
|
|
|
157
|
|
|
/** @var OrderDetail $detail */ |
158
|
|
|
$detail = OrderDetail::create(); |
159
|
|
|
$detail->OrderID = $order->ID; |
160
|
|
|
$detail->Quantity = 10; |
161
|
|
|
$detail->ProductID = $product->ID; |
162
|
|
|
$detail->write(); |
163
|
|
|
|
164
|
|
|
$this->assertEquals(10, $product->getNumberPurchased()); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* |
169
|
|
|
*/ |
170
|
|
|
public function testGetOrders() |
171
|
|
|
{ |
172
|
|
|
/** @var TestProduct $product */ |
173
|
|
|
$product = $this->objFromFixture(TestProduct::class, 'one'); |
174
|
|
|
$this->assertEquals(0, $product->getOrders()->Count()); |
|
|
|
|
175
|
|
|
/** @var OrderDetail $detail */ |
176
|
|
|
$detail = OrderDetail::create(); |
177
|
|
|
$detail->OrderID = $this->objFromFixture(Order::class, 'one')->ID; |
178
|
|
|
$detail->Quantity = 10; |
179
|
|
|
$detail->ProductID = $product->ID; |
180
|
|
|
$detail->write(); |
181
|
|
|
$this->assertEquals(1, $product->getOrders()->count()); |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|
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