1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverCommerce\OrdersAdmin\Tests; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Dev\SapphireTest; |
6
|
|
|
use SilverCommerce\OrdersAdmin\Model\LineItem; |
7
|
|
|
use SilverCommerce\TaxAdmin\Tests\Model\TestProduct; |
8
|
|
|
|
9
|
|
|
class LineItemTest extends SapphireTest |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Add some scaffold order records |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected static $fixture_file = 'OrdersScaffold.yml'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Setup test only objects |
20
|
|
|
* |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
protected static $extra_dataobjects = [ |
24
|
|
|
TestProduct::class |
25
|
|
|
]; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Add some extra functionality on construction |
29
|
|
|
* |
30
|
|
|
* @return void |
31
|
|
|
*/ |
32
|
|
|
public function setUp() |
33
|
|
|
{ |
34
|
|
|
parent::setUp(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Clean up after tear down |
39
|
|
|
* |
40
|
|
|
* @return void |
41
|
|
|
*/ |
42
|
|
|
public function tearDown() |
43
|
|
|
{ |
44
|
|
|
parent::tearDown(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Test that a line item recieves the correct tax rate |
49
|
|
|
* |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
|
|
public function testGetTaxPercentage() |
53
|
|
|
{ |
54
|
|
|
$item_none = $this->objFromFixture(LineItem::class, 'notaxitem'); |
55
|
|
|
$item_reduced = $this->objFromFixture(LineItem::class, 'reducedtaxitem'); |
56
|
|
|
$item_vat = $this->objFromFixture(LineItem::class, 'taxitemone'); |
57
|
|
|
|
58
|
|
|
$this->assertEquals(0, $item_none->TaxPercentage); |
59
|
|
|
$this->assertEquals(5, $item_reduced->TaxPercentage); |
60
|
|
|
$this->assertEquals(20, $item_vat->TaxPercentage); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Test that a line item tracks a single unit price |
65
|
|
|
* |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
|
public function testGetUnitPrice() |
69
|
|
|
{ |
70
|
|
|
$item_none = $this->objFromFixture(LineItem::class, 'notaxitem'); |
71
|
|
|
$item_reduced = $this->objFromFixture(LineItem::class, 'reducedtaxitem'); |
72
|
|
|
$item_vat = $this->objFromFixture(LineItem::class, 'taxitemone'); |
73
|
|
|
|
74
|
|
|
$this->assertEquals(5.99, $item_none->UnitPrice); |
75
|
|
|
$this->assertEquals(5.99, $item_reduced->UnitPrice); |
76
|
|
|
$this->assertEquals(5.99, $item_vat->UnitPrice); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Test that a line item tracks tax for a single item |
81
|
|
|
* |
82
|
|
|
* @return void |
83
|
|
|
*/ |
84
|
|
|
public function testGetUnitTax() |
85
|
|
|
{ |
86
|
|
|
$item_none = $this->objFromFixture(LineItem::class, 'notaxitem'); |
87
|
|
|
$item_reduced = $this->objFromFixture(LineItem::class, 'reducedtaxitem'); |
88
|
|
|
$item_vat = $this->objFromFixture(LineItem::class, 'taxitemone'); |
89
|
|
|
|
90
|
|
|
$this->assertEquals(0, $item_none->UnitTax); |
91
|
|
|
$this->assertEquals(0.2995, $item_reduced->UnitTax); |
92
|
|
|
$this->assertEquals(1.198, $item_vat->UnitTax); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Test that a line item tracks the total amount for a single item |
97
|
|
|
* |
98
|
|
|
* @return void |
99
|
|
|
*/ |
100
|
|
|
public function testGetUnitTotal() |
101
|
|
|
{ |
102
|
|
|
$item_none = $this->objFromFixture(LineItem::class, 'notaxitem'); |
103
|
|
|
$item_reduced = $this->objFromFixture(LineItem::class, 'reducedtaxitem'); |
104
|
|
|
$item_vat = $this->objFromFixture(LineItem::class, 'taxitemone'); |
105
|
|
|
|
106
|
|
|
$this->assertEquals(5.99, $item_none->UnitTotal); |
107
|
|
|
$this->assertEquals(6.2895, $item_reduced->UnitTotal); |
108
|
|
|
$this->assertEquals(7.188, $item_vat->UnitTotal); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Test that a line item tracks the total amount (without tax) |
113
|
|
|
* |
114
|
|
|
* @return void |
115
|
|
|
*/ |
116
|
|
|
public function testGetSubTotal() |
117
|
|
|
{ |
118
|
|
|
$item_none = $this->objFromFixture(LineItem::class, 'notaxitem'); |
119
|
|
|
$item_reduced = $this->objFromFixture(LineItem::class, 'reducedtaxitem'); |
120
|
|
|
$item_vat = $this->objFromFixture(LineItem::class, 'taxitemone'); |
121
|
|
|
|
122
|
|
|
$this->assertEquals(11.98, $item_none->SubTotal); |
123
|
|
|
$this->assertEquals(11.98, $item_reduced->SubTotal); |
124
|
|
|
$this->assertEquals(11.98, $item_vat->SubTotal); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Test that a line item tracks the total amount of tax |
129
|
|
|
* |
130
|
|
|
* @return void |
131
|
|
|
*/ |
132
|
|
|
public function testGetTaxTotal() |
133
|
|
|
{ |
134
|
|
|
$item_none = $this->objFromFixture(LineItem::class, 'notaxitem'); |
135
|
|
|
$item_reduced = $this->objFromFixture(LineItem::class, 'reducedtaxitem'); |
136
|
|
|
$item_vat = $this->objFromFixture(LineItem::class, 'taxitemone'); |
137
|
|
|
|
138
|
|
|
$this->assertEquals(0, $item_none->TaxTotal); |
139
|
|
|
$this->assertEquals(0.599, $item_reduced->TaxTotal); |
140
|
|
|
$this->assertEquals(2.396, $item_vat->TaxTotal); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Test that a line item outputs the correct total |
145
|
|
|
* |
146
|
|
|
* @return void |
147
|
|
|
*/ |
148
|
|
|
public function testGetTotal() |
149
|
|
|
{ |
150
|
|
|
$item_none = $this->objFromFixture(LineItem::class, 'notaxitem'); |
151
|
|
|
$item_reduced = $this->objFromFixture(LineItem::class, 'reducedtaxitem'); |
152
|
|
|
$item_vat = $this->objFromFixture(LineItem::class, 'taxitemone'); |
153
|
|
|
|
154
|
|
|
$this->assertEquals(11.98, $item_none->Total); |
155
|
|
|
$this->assertEquals(12.579, $item_reduced->Total); |
156
|
|
|
$this->assertEquals(14.376, $item_vat->Total); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Test that a line item returns the correct customisation summary |
161
|
|
|
* |
162
|
|
|
* @return void |
163
|
|
|
*/ |
164
|
|
|
public function testCustomisationList() |
165
|
|
|
{ |
166
|
|
|
$line_item = $this->objFromFixture(LineItem::class, 'customitem'); |
167
|
|
|
$expected = "Customisation: Free, Customisation: Expensive"; |
168
|
|
|
|
169
|
|
|
$this->assertEquals($expected, $line_item->CustomisationList); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Test that a line item returns the correct customisation summary |
174
|
|
|
* |
175
|
|
|
* @return void |
176
|
|
|
*/ |
177
|
|
|
public function testCustomisationAndPriceList() |
178
|
|
|
{ |
179
|
|
|
$line_item = $this->objFromFixture(LineItem::class, 'customitem'); |
180
|
|
|
$expected = "Customisation: Free (£0.00), Customisation: Expensive (£100.00)"; |
181
|
|
|
|
182
|
|
|
$this->assertEquals($expected, $line_item->CustomisationAndPriceList); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Test that a line item matches a product correctly |
187
|
|
|
* |
188
|
|
|
* @return void |
189
|
|
|
*/ |
190
|
|
|
public function testMatch() |
191
|
|
|
{ |
192
|
|
|
$line_item = $this->objFromFixture(LineItem::class, 'sockitem'); |
193
|
|
|
$product = $line_item->Match(); |
194
|
|
|
|
195
|
|
|
$this->assertTrue(is_object($product)); |
196
|
|
|
$this->assertEquals("Socks", $product->Title); |
197
|
|
|
$this->assertEquals(5.99, $product->NoTaxPrice); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Test that a line item returns the correct amount of stock |
202
|
|
|
* |
203
|
|
|
* @return void |
204
|
|
|
*/ |
205
|
|
|
public function testCheckStockLevel() |
206
|
|
|
{ |
207
|
|
|
$line_item = $this->objFromFixture(LineItem::class, 'sockitem'); |
208
|
|
|
|
209
|
|
|
$this->assertEquals(8, $line_item->checkStockLevel(2)); |
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
|