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; |
|
|
|
|
73
|
|
|
$option->PurchaseLimit = 0; |
|
|
|
|
74
|
|
|
$this->assertFalse($option->getHasInventory()); |
|
|
|
|
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'); |
|
|
|
|
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(); |
|
|
|
|
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
|
|
|
|