1 | <?php |
||||
2 | |||||
3 | namespace Dynamic\FoxyStripe\Test; |
||||
4 | |||||
5 | use Dynamic\FoxyStripe\Model\OptionItem; |
||||
6 | use Dynamic\FoxyStripe\Model\Order; |
||||
7 | use Dynamic\FoxyStripe\Model\OrderDetail; |
||||
8 | use Dynamic\FoxyStripe\Test\TestOnly\TestOption; |
||||
9 | use Dynamic\FoxyStripe\Test\TestOnly\TestProduct; |
||||
10 | use SilverStripe\Dev\SapphireTest; |
||||
11 | use SilverStripe\Forms\FieldList; |
||||
12 | |||||
13 | class FoxyStripeOptionInventoryManagerTest extends SapphireTest |
||||
14 | { |
||||
15 | /** |
||||
16 | * @var array |
||||
17 | */ |
||||
18 | protected static $fixture_file = array( |
||||
19 | '../fixtures.yml', |
||||
20 | ); |
||||
21 | |||||
22 | /** |
||||
23 | * @var array |
||||
24 | */ |
||||
25 | protected static $extra_dataobjects = [ |
||||
26 | TestProduct::class, |
||||
27 | TestOption::class, |
||||
28 | ]; |
||||
29 | |||||
30 | /** |
||||
31 | * |
||||
32 | */ |
||||
33 | public function testUpdateCMSFields() |
||||
34 | { |
||||
35 | $object = $this->objFromFixture(TestOption::class, 'one'); |
||||
36 | $fields = $object->getCMSFields(); |
||||
37 | $this->assertInstanceOf(FieldList::class, $fields); |
||||
38 | } |
||||
39 | |||||
40 | /** |
||||
41 | * |
||||
42 | */ |
||||
43 | public function testGetHasInventory() |
||||
44 | { |
||||
45 | /** @var TestOption $option */ |
||||
46 | $option = $this->objFromFixture(TestOption::class, 'one'); |
||||
47 | |||||
48 | $option->ControlInventory = false; |
||||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||
49 | $option->PurchaseLimit = 0; |
||||
0 ignored issues
–
show
The property
PurchaseLimit does not exist on Dynamic\FoxyStripe\Test\TestOnly\TestOption . Since you implemented __set , consider adding a @property annotation.
Loading history...
|
|||||
50 | $this->assertFalse($option->getHasInventory()); |
||||
0 ignored issues
–
show
The method
getHasInventory() does not exist on Dynamic\FoxyStripe\Test\TestOnly\TestOption . 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
Loading history...
|
|||||
51 | |||||
52 | $option->ControlInventory = true; |
||||
53 | $option->PurchaseLimit = 0; |
||||
54 | $this->assertFalse($option->getHasInventory()); |
||||
55 | |||||
56 | $option->ControlInventory = false; |
||||
57 | $option->PurchaseLimit = 10; |
||||
58 | $this->assertFalse($option->getHasInventory()); |
||||
59 | |||||
60 | $option->ControlInventory = true; |
||||
61 | $option->PurchaseLimit = 10; |
||||
62 | $this->assertTrue($option->getHasInventory()); |
||||
63 | } |
||||
64 | |||||
65 | /** |
||||
66 | * |
||||
67 | */ |
||||
68 | public function testGetIsOptionAvailable() |
||||
69 | { |
||||
70 | $this->markTestSkipped(); |
||||
71 | |||||
72 | /** @var TestOption $option */ |
||||
73 | $option = $this->objFromFixture(TestOption::class, 'one'); |
||||
74 | |||||
75 | // no inventory control |
||||
76 | $option->ControlInventory = false; |
||||
77 | $option->PurchaseLimit = 0; |
||||
78 | $this->assertTrue($option->getIsOptionAvailable()); |
||||
79 | |||||
80 | // inventory control, no limit |
||||
81 | $option->ControlInventory = true; |
||||
82 | $option->PurchaseLimit = 0; |
||||
83 | $this->assertTrue($option->getIsOptionAvailable()); |
||||
84 | |||||
85 | // inventory control, with limit |
||||
86 | $option->ControlInventory = true; |
||||
87 | $option->PurchaseLimit = 10; |
||||
88 | $this->assertTrue($option->getIsOptionAvailable()); |
||||
89 | |||||
90 | /** @var OrderDetail $detail */ |
||||
91 | $detail = OrderDetail::create(); |
||||
92 | $detail->Quantity = 10; |
||||
93 | $detail->write(); |
||||
94 | $detail->OptionItems()->add($option); |
||||
95 | |||||
96 | // inventory control, no inventory left |
||||
97 | $option->ControlInventory = true; |
||||
98 | $option->PurchaseLimit = 10; |
||||
99 | $this->assertFalse($option->getIsOptionAvailable()); |
||||
100 | |||||
101 | $detail->delete(); |
||||
102 | } |
||||
103 | |||||
104 | /** |
||||
105 | * |
||||
106 | */ |
||||
107 | public function testGetNumberPurchased() |
||||
108 | { |
||||
109 | $this->markTestSkipped(); |
||||
110 | |||||
111 | /** @var TestOption $option */ |
||||
112 | $option = $this->objFromFixture(TestOption::class, 'one'); |
||||
113 | |||||
114 | $this->assertEquals(0, $option->getNumberPurchased()); |
||||
115 | |||||
116 | /** @var OrderDetail $detail */ |
||||
117 | $detail = OrderDetail::create(); |
||||
118 | $detail->Quantity = 10; |
||||
119 | $detail->write(); |
||||
120 | $detail->OptionItems()->add($option); |
||||
121 | |||||
122 | $this->assertEquals(10, $option->getNumberPurchased()); |
||||
123 | |||||
124 | $detail->delete(); |
||||
125 | } |
||||
126 | |||||
127 | /** |
||||
128 | * |
||||
129 | */ |
||||
130 | public function testGetOrders() |
||||
131 | { |
||||
132 | $this->markTestSkipped(); |
||||
133 | |||||
134 | /** @var TestOption $option */ |
||||
135 | $option = $this->objFromFixture(TestOption::class, 'one'); |
||||
136 | |||||
137 | $this->assertEquals(0, $option->getOrders()->Count()); |
||||
138 | |||||
139 | /** @var OrderDetail $detail */ |
||||
140 | $detail = OrderDetail::create(); |
||||
141 | $detail->Quantity = 10; |
||||
142 | $detail->write(); |
||||
143 | $detail->OptionItems()->add($option); |
||||
144 | |||||
145 | $this->assertEquals(1, $option->getOrders()->count()); |
||||
146 | |||||
147 | $detail->delete(); |
||||
148 | } |
||||
149 | } |
||||
150 |