1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverCommerce\OrdersAdmin\Tests; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Dev\SapphireTest; |
6
|
|
|
use SilverCommerce\OrdersAdmin\Model\Invoice; |
7
|
|
|
use SilverCommerce\OrdersAdmin\Model\Estimate; |
8
|
|
|
use SilverCommerce\TaxAdmin\Tests\Model\TestProduct; |
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
|
|
|
* Test that an estimate converts to invoice correctly |
30
|
|
|
*/ |
31
|
|
|
public function testConvertToInvoice() |
32
|
|
|
{ |
33
|
|
|
$estimate = $this->objFromFixture(Estimate::class, 'addressdetails'); |
34
|
|
|
$invoice = $estimate->convertToInvoice(); |
35
|
|
|
|
36
|
|
|
$this->assertTrue($invoice instanceof Invoice); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Test that an estimate returns the correct deliverable status |
41
|
|
|
* |
42
|
|
|
* @return void |
43
|
|
|
*/ |
44
|
|
|
public function testIsDeliverable() |
45
|
|
|
{ |
46
|
|
|
$deliverable = $this->objFromFixture(Estimate::class, 'deliverable'); |
47
|
|
|
$not_deliverable = $this->objFromFixture(Estimate::class, 'notdeliverable'); |
48
|
|
|
|
49
|
|
|
$this->assertTrue($deliverable->isDeliverable()); |
50
|
|
|
$this->assertFalse($not_deliverable->isDeliverable()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Test that the country is retrieved correctly and |
55
|
|
|
* that billing and delivery addresses return as |
56
|
|
|
* expected |
57
|
|
|
* |
58
|
|
|
* @return void |
59
|
|
|
*/ |
60
|
|
|
public function testLocationDetails() |
61
|
|
|
{ |
62
|
|
|
$estimate = $this->objFromFixture(Estimate::class, 'addressdetails'); |
63
|
|
|
|
64
|
|
|
$bil_country = "United Kingdom"; |
65
|
|
|
$del_country = "United Kingdom"; |
66
|
|
|
$exp_billing = "123 Street Name,\nA Place,\nA City,\nAB12 3AB,\nGB"; |
67
|
|
|
$exp_delivery = "321 Street Name,\nDelivery City,\nZX98 9XZ,\nGB"; |
68
|
|
|
|
69
|
|
|
$this->assertEquals($bil_country, $estimate->getCountryFull()); |
70
|
|
|
$this->assertEquals($del_country, $estimate->getDeliveryCountryFull()); |
71
|
|
|
$this->assertEquals($exp_billing, $estimate->getBillingAddress()); |
72
|
|
|
$this->assertEquals($exp_delivery, $estimate->getDeliveryAddress()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* test that generation of the summary and summary HTML |
77
|
|
|
* work as expected. |
78
|
|
|
* |
79
|
|
|
* @return void |
80
|
|
|
*/ |
81
|
|
|
public function testItemSummary() |
82
|
|
|
{ |
83
|
|
|
$estimate = $this->objFromFixture(Estimate::class, 'complextax'); |
84
|
|
|
|
85
|
|
|
$text = "2 x An item with reduced tax\n2 x Another tax item"; |
86
|
|
|
$html = "2 x An item with reduced tax<br />\n2 x Another tax item"; |
87
|
|
|
|
88
|
|
|
$this->assertEquals($text, $estimate->ItemSummary); |
89
|
|
|
$this->assertEquals($html, $estimate->ItemSummaryHTML); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* test that functions for calculating total amounts (such as) |
94
|
|
|
* total items, total weight, etc. |
95
|
|
|
* |
96
|
|
|
* @return void |
97
|
|
|
*/ |
98
|
|
|
public function testTotalCalculations() |
99
|
|
|
{ |
100
|
|
|
$no_tax_order = $this->objFromFixture(Estimate::class, 'standardnotax'); |
101
|
|
|
$tax_order = $this->objFromFixture(Estimate::class, 'standardtax'); |
102
|
|
|
|
103
|
|
|
$this->assertEquals(2, $no_tax_order->TotalItems); |
104
|
|
|
$this->assertEquals(1, $no_tax_order->TotalWeight); |
105
|
|
|
$this->assertEquals(2, $tax_order->TotalItems); |
106
|
|
|
$this->assertEquals(1.5, $tax_order->TotalWeight); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* test that functions for calculating tax monitary info on |
111
|
|
|
* an order are correct |
112
|
|
|
* |
113
|
|
|
* @return void |
114
|
|
|
*/ |
115
|
|
|
public function testTaxCalculations() |
116
|
|
|
{ |
117
|
|
|
$no_tax_order = $this->objFromFixture(Estimate::class, 'standardnotax'); |
118
|
|
|
$tax_order_one = $this->objFromFixture(Estimate::class, 'standardtax'); |
119
|
|
|
$tax_order_two = $this->objFromFixture(Estimate::class, 'complextax'); |
120
|
|
|
|
121
|
|
|
$this->assertEquals(0, $no_tax_order->TaxTotal); |
122
|
|
|
$this->assertEquals(2.396, $tax_order_one->TaxTotal); |
123
|
|
|
$this->assertEquals(2.995, $tax_order_two->TaxTotal); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* test that functions for calculating monitary info on |
128
|
|
|
* an order are correct (such as tax, total, etc) |
129
|
|
|
* |
130
|
|
|
* @return void |
131
|
|
|
*/ |
132
|
|
|
public function testCurrencyCalculations() |
133
|
|
|
{ |
134
|
|
|
$no_tax_order = $this->objFromFixture(Estimate::class, 'standardnotax'); |
135
|
|
|
$tax_order_one = $this->objFromFixture(Estimate::class, 'standardtax'); |
136
|
|
|
$tax_order_two = $this->objFromFixture(Estimate::class, 'complextax'); |
137
|
|
|
|
138
|
|
|
$this->assertEquals(11.98, $no_tax_order->SubTotal); |
139
|
|
|
$this->assertEquals(11.98, $no_tax_order->Total); |
140
|
|
|
$this->assertEquals(11.98, $tax_order_one->SubTotal); |
141
|
|
|
$this->assertEquals(14.376, $tax_order_one->Total); |
142
|
|
|
$this->assertEquals(23.96, $tax_order_two->SubTotal); |
143
|
|
|
$this->assertEquals(26.955, $tax_order_two->Total); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|