|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverCommerce\OrdersAdmin\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
6
|
|
|
use SilverCommerce\OrdersAdmin\Model\Estimate; |
|
7
|
|
|
use SilverCommerce\OrdersAdmin\Tests\Model\TestProduct; |
|
8
|
|
|
use SilverCommerce\OrdersAdmin\Model\Invoice; |
|
9
|
|
|
|
|
10
|
|
|
class EstimateTest extends SapphireTest |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Add some scaffold order records |
|
14
|
|
|
* |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
protected static $fixture_file = 'OrdersScaffold.yml'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Setup test only objects |
|
21
|
|
|
* |
|
22
|
|
|
* @var array |
|
23
|
|
|
*/ |
|
24
|
|
|
protected static $extra_dataobjects = [ |
|
25
|
|
|
TestProduct::class |
|
26
|
|
|
]; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Add some extra functionality on construction |
|
30
|
|
|
* |
|
31
|
|
|
* @return void |
|
32
|
|
|
*/ |
|
33
|
|
|
public function setUp() |
|
34
|
|
|
{ |
|
35
|
|
|
parent::setUp(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Clean up after tear down |
|
40
|
|
|
* |
|
41
|
|
|
* @return void |
|
42
|
|
|
*/ |
|
43
|
|
|
public function tearDown() |
|
44
|
|
|
{ |
|
45
|
|
|
parent::tearDown(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Test that an estimate converts to invoice correctly |
|
50
|
|
|
*/ |
|
51
|
|
|
public function testConvertToInvoice() |
|
52
|
|
|
{ |
|
53
|
|
|
$estimate = $this->objFromFixture(Estimate::class, 'addressdetails'); |
|
54
|
|
|
$invoice = $estimate->convertToInvoice(); |
|
55
|
|
|
|
|
56
|
|
|
$this->assertTrue($invoice instanceof Invoice); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Test that an estimate returns the correct deliverable status |
|
61
|
|
|
* |
|
62
|
|
|
* @return void |
|
63
|
|
|
*/ |
|
64
|
|
|
public function testIsDeliverable() |
|
65
|
|
|
{ |
|
66
|
|
|
$deliverable = $this->objFromFixture(Estimate::class, 'deliverable'); |
|
67
|
|
|
$not_deliverable = $this->objFromFixture(Estimate::class, 'notdeliverable'); |
|
68
|
|
|
|
|
69
|
|
|
$this->assertTrue($deliverable->isDeliverable()); |
|
70
|
|
|
$this->assertFalse($not_deliverable->isDeliverable()); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Test that the country is retrieved correctly and |
|
75
|
|
|
* that billing and delivery addresses return as |
|
76
|
|
|
* expected |
|
77
|
|
|
* |
|
78
|
|
|
* @return void |
|
79
|
|
|
*/ |
|
80
|
|
|
public function testLocationDetails() |
|
81
|
|
|
{ |
|
82
|
|
|
$estimate = $this->objFromFixture(Estimate::class, 'addressdetails'); |
|
83
|
|
|
|
|
84
|
|
|
$bil_country = "United Kingdom"; |
|
85
|
|
|
$del_country = "United Kingdom"; |
|
86
|
|
|
$exp_billing = "123 Street Name,\nA Place,\nA City,\nAB12 3AB,\nGB"; |
|
87
|
|
|
$exp_delivery = "321 Street Name,\nDelivery City,\nZX98 9XZ,\nGB"; |
|
88
|
|
|
|
|
89
|
|
|
$this->assertEquals($bil_country, $estimate->getCountryFull()); |
|
90
|
|
|
$this->assertEquals($del_country, $estimate->getDeliveryCountryFull()); |
|
91
|
|
|
$this->assertEquals($exp_billing, $estimate->getBillingAddress()); |
|
92
|
|
|
$this->assertEquals($exp_delivery, $estimate->getDeliveryAddress()); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* test that generation of the summary and summary HTML |
|
97
|
|
|
* work as expected. |
|
98
|
|
|
* |
|
99
|
|
|
* @return void |
|
100
|
|
|
*/ |
|
101
|
|
|
public function testItemSummary() |
|
102
|
|
|
{ |
|
103
|
|
|
$estimate = $this->objFromFixture(Estimate::class, 'complextax'); |
|
104
|
|
|
|
|
105
|
|
|
$text = "2 x An item with reduced tax\n2 x Another tax item"; |
|
106
|
|
|
$html = "2 x An item with reduced tax<br />\n2 x Another tax item"; |
|
107
|
|
|
|
|
108
|
|
|
$this->assertEquals($text, $estimate->ItemSummary); |
|
109
|
|
|
$this->assertEquals($html, $estimate->ItemSummaryHTML); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* test that functions for calculating total amounts (such as) |
|
114
|
|
|
* total items, total weight, etc. |
|
115
|
|
|
* |
|
116
|
|
|
* @return void |
|
117
|
|
|
*/ |
|
118
|
|
|
public function testTotalCalculations() |
|
119
|
|
|
{ |
|
120
|
|
|
$no_tax_order = $this->objFromFixture(Estimate::class, 'standardnotax'); |
|
121
|
|
|
$tax_order = $this->objFromFixture(Estimate::class, 'standardtax'); |
|
122
|
|
|
|
|
123
|
|
|
$this->assertEquals(2, $no_tax_order->TotalItems); |
|
124
|
|
|
$this->assertEquals(1, $no_tax_order->TotalWeight); |
|
125
|
|
|
$this->assertEquals(2, $tax_order->TotalItems); |
|
126
|
|
|
$this->assertEquals(1.5, $tax_order->TotalWeight); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* test that functions for calculating tax monitary info on |
|
131
|
|
|
* an order are correct |
|
132
|
|
|
* |
|
133
|
|
|
* @return void |
|
134
|
|
|
*/ |
|
135
|
|
|
public function testTaxCalculations() |
|
136
|
|
|
{ |
|
137
|
|
|
$no_tax_order = $this->objFromFixture(Estimate::class, 'standardnotax'); |
|
138
|
|
|
$tax_order_one = $this->objFromFixture(Estimate::class, 'standardtax'); |
|
139
|
|
|
$tax_order_two = $this->objFromFixture(Estimate::class, 'complextax'); |
|
140
|
|
|
|
|
141
|
|
|
$this->assertEquals(0, $no_tax_order->TaxTotal); |
|
142
|
|
|
$this->assertEquals(2.3999999999999999, $tax_order_one->TaxTotal); |
|
143
|
|
|
$this->assertEquals(3.0, $tax_order_two->TaxTotal); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* test that functions for calculating monitary info on |
|
148
|
|
|
* an order are correct (such as tax, total, etc) |
|
149
|
|
|
* |
|
150
|
|
|
* @return void |
|
151
|
|
|
*/ |
|
152
|
|
|
public function testCurrencyCalculations() |
|
153
|
|
|
{ |
|
154
|
|
|
$no_tax_order = $this->objFromFixture(Estimate::class, 'standardnotax'); |
|
155
|
|
|
$tax_order_one = $this->objFromFixture(Estimate::class, 'standardtax'); |
|
156
|
|
|
$tax_order_two = $this->objFromFixture(Estimate::class, 'complextax'); |
|
157
|
|
|
|
|
158
|
|
|
$this->assertEquals(11.98, $no_tax_order->SubTotal); |
|
159
|
|
|
$this->assertEquals(11.98, $no_tax_order->Total); |
|
160
|
|
|
$this->assertEquals(11.98, $tax_order_one->SubTotal); |
|
161
|
|
|
$this->assertEquals(14.38, $tax_order_one->Total); |
|
162
|
|
|
$this->assertEquals(23.96, $tax_order_two->SubTotal); |
|
163
|
|
|
$this->assertEquals(26.96, $tax_order_two->Total); |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
|