Passed
Push — 1.0 ( 07b100...83f8df )
by Morven
05:31
created

OrderTest::testItemSummary()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 9
rs 9.6666
c 1
b 0
f 0
1
<?php
2
/**
3
 * Test functionality of an order
4
 *
5
 * @package orders
6
 * @subpackage tests
7
 */
8
class OrderTest extends SapphireTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
Bug introduced by
The type SapphireTest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
{
10
	/**
11
	 * Add some scaffold order records
12
	 *
13
	 * @var string
14
	 * @config
15
	 */
16
	protected static $fixture_file = 'OrderTest.yml';
17
18
	/**
19
	 * Add some extra functionality on construction
20
	 *
21
	 * @return void
22
	 */	
23
	public function setUp()
24
    {
25
		parent::setUp();
26
	}
27
28
	/**
29
	 * Clean up after tear down
30
	 *
31
	 * @return void
32
	 */	
33
	public function tearDown()
34
    {
35
		parent::tearDown();
36
	}
37
38
	/**
39
	 * Test that the country is retrieved correctly and
40
	 * that billing and delivery addresses return as
41
	 * expected
42
	 *
43
	 * @return void
44
	 */
45
	public function testLocationDetails()
46
    {
47
		$order = $this->objFromFixture('Order', 'addressdetails');
48
49
		$bil_country = "United Kingdom";
50
		$del_country = "United Kingdom";
51
		$exp_billing = "123 Street Name,\nA Place,\nA City,\nAB12 3AB,\nGB";
52
		$exp_delivery = "321 Street Name,\nDelivery City,\nZX98 9XZ,\nGB";
53
54
		$this->assertEquals($bil_country, $order->getCountryFull());
55
		$this->assertEquals($del_country, $order->getDeliveryCountryFull());
56
		$this->assertEquals($exp_billing, $order->getBillingAddress());
57
		$this->assertEquals($exp_delivery, $order->getDeliveryAddress());
58
	}
59
60
	/**
61
	 * test that functions for changing statuses of an order
62
	 * behave correctly
63
	 *
64
	 * @return void
65
	 */
66
	public function testStatusDetails()
67
    {
68
		$order = $this->objFromFixture('Order', 'addressdetails');
69
		$order->markComplete();
70
71
		$this->assertTrue($order->isPaid());
72
	}
73
74
	/**
75
	 * test that generation of the summary and summary HTML
76
	 * work as expected.
77
	 *
78
	 * @return void
79
	 */
80
	public function testItemSummary()
81
	{
82
		$order = $this->objFromFixture('Order', 'discount');
83
84
		$text = "2 x An item to discount;\n1 x Another item to discount;\n";
85
		$html = "2 x An item to discount;<br />\n1 x Another item to discount;<br />\n";
86
87
		$this->assertEquals($text, $order->ItemSummary);
88
		$this->assertEquals($html, $order->ItemSummaryHTML->RAW());
89
	}
90
91
	/**
92
	 * test that functions for setting and getting discounts
93
	 * work as expected
94
	 *
95
	 * @return void
96
	 */
97
	public function testDiscount()
98
    {
99
		$order = $this->objFromFixture('Order', 'standardnotax');
100
101
		$this->assertFalse($order->hasDiscount());
102
		$order->setDiscount("A Discount", 5.00);
103
		$this->assertTrue($order->hasDiscount());
104
105
		$this->assertEquals("A Discount", $order->Discount);
106
		$this->assertEquals(5.00, $order->DiscountAmount);
107
	}
108
109
110
	/**
111
	 * test that functions for setting and getting postage
112
	 * work as expected
113
	 *
114
	 * @return void
115
	 */
116
	public function testPostage()
117
    {
118
		$no_tax_order = $this->objFromFixture('Order', 'standardnotax');
119
		$tax_order = $this->objFromFixture('Order', 'standardtax');
120
121
		$no_tax_order->setPostage("Different Postage", 0.50);
122
		$tax_order->setPostage("Different Tax Postage", 1.00, 0.20);
123
		
124
		$this->assertEquals("Different Postage", $no_tax_order->PostageType);
125
		$this->assertEquals(0.50, $no_tax_order->PostageCost);
126
		$this->assertEquals(0, $no_tax_order->PostageTax);
127
		$this->assertEquals(0.50, $no_tax_order->Postage);
128
129
		$this->assertEquals("Different Tax Postage", $tax_order->PostageType);
130
		$this->assertEquals(1.00, $tax_order->PostageCost);
131
		$this->assertEquals(0.20, $tax_order->PostageTax);
132
		$this->assertEquals(1.00, $tax_order->Postage);
133
	}
134
135
	/**
136
	 * test that functions for calculating total amounts (such as)
137
	 * total items, total weight, etc.
138
	 *
139
	 * @return void
140
	 */
141
	public function testTotalCalculations()
142
    {
143
		$no_tax_order = $this->objFromFixture('Order', 'standardnotax');
144
		$tax_order = $this->objFromFixture('Order', 'standardtax');
145
		$discount_order = $this->objFromFixture('Order', 'discount');
146
147
		$this->assertEquals(2, $no_tax_order->TotalItems);
148
		$this->assertEquals(1, $no_tax_order->TotalWeight);
149
		$this->assertEquals(1, $tax_order->TotalItems);
150
		$this->assertEquals(0.75, $tax_order->TotalWeight);
151
		$this->assertEquals(3, $discount_order->TotalItems);
152
		$this->assertEquals(1.75, $discount_order->TotalWeight);
153
	}
154
155
	/**
156
	 * test that functions for calculating tax monitary info on
157
	 * an order are correct
158
	 *
159
	 * @return void
160
	 */
161
	public function testTaxCalculations()
162
    {
163
		$no_tax_order = $this->objFromFixture('Order', 'standardnotax');
164
		$tax_order_one = $this->objFromFixture('Order', 'standardtax');
165
		$tax_order_two = $this->objFromFixture('Order', 'complextax');
166
		$discount_order = $this->objFromFixture('Order', 'discount');
167
168
		$this->assertEquals(0, $no_tax_order->TaxTotal);
169
		$this->assertEquals(1.60, $tax_order_one->TaxTotal);
170
		$this->assertEquals(3.20, $tax_order_two->TaxTotal);
171
		$this->assertEquals(3.0, $discount_order->TaxTotal);
172
	}
173
174
	/**
175
	 * test that functions for calculating monitary info on
176
	 * an order are correct (such as tax, total, etc)
177
	 *
178
	 * @return void
179
	 */
180
	public function testCurrencyCalculations()
181
    {
182
		$no_tax_order = $this->objFromFixture('Order', 'standardnotax');
183
		$tax_order_one = $this->objFromFixture('Order', 'standardtax');
184
		$tax_order_two = $this->objFromFixture('Order', 'complextax');
185
		$discount_order = $this->objFromFixture('Order', 'discount');
186
187
		$this->assertEquals(11.98, $no_tax_order->SubTotal);
188
		$this->assertEquals(13.98, $no_tax_order->Total);
189
		$this->assertEquals(5.99, $tax_order_one->SubTotal);
190
		$this->assertEquals(9.59, $tax_order_one->Total);
191
		$this->assertEquals(13.97, $tax_order_two->SubTotal);
192
		$this->assertEquals(19.17, $tax_order_two->Total);
193
		$this->assertEquals(15.97, $discount_order->SubTotal);
194
		$this->assertEquals(17.97, $discount_order->Total);
195
	}
196
}