|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package shop |
|
5
|
|
|
* @subpackage tests |
|
6
|
|
|
* |
|
7
|
|
|
*/ |
|
8
|
|
|
class FlatTaxModifierTest extends FunctionalTest |
|
9
|
|
|
{ |
|
10
|
|
|
protected static $fixture_file = 'silvershop/tests/fixtures/shop.yml'; |
|
11
|
|
|
protected static $disable_theme = true; |
|
12
|
|
|
|
|
13
|
|
|
public function setUpOnce() |
|
14
|
|
|
{ |
|
15
|
|
|
parent::setUpOnce(); |
|
16
|
|
|
// clear session |
|
17
|
|
|
ShoppingCart::singleton()->clear(); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function setUp() |
|
21
|
|
|
{ |
|
22
|
|
|
parent::setUp(); |
|
23
|
|
|
ShopTest::setConfiguration(); |
|
24
|
|
|
Order::config()->modifiers = array( |
|
25
|
|
|
"FlatTaxModifier", |
|
26
|
|
|
); |
|
27
|
|
|
FlatTaxModifier::config()->name = "GST"; |
|
28
|
|
|
FlatTaxModifier::config()->rate = 0.15; |
|
29
|
|
|
$this->cart = ShoppingCart::singleton(); |
|
|
|
|
|
|
30
|
|
|
$this->mp3player = $this->objFromFixture('Product', 'mp3player'); |
|
|
|
|
|
|
31
|
|
|
$this->mp3player->publish('Stage', 'Live'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testInclusiveTax() |
|
35
|
|
|
{ |
|
36
|
|
|
FlatTaxModifier::config()->exclusive = false; |
|
37
|
|
|
$this->cart->clear(); |
|
38
|
|
|
$this->cart->add($this->mp3player); |
|
39
|
|
|
$order = $this->cart->current(); |
|
40
|
|
|
$order->calculate(); |
|
41
|
|
|
$modifier = $order->Modifiers() |
|
42
|
|
|
->filter('ClassName', 'FlatTaxModifier') |
|
43
|
|
|
->first(); |
|
44
|
|
|
$this->assertEquals(26.09, $modifier->Amount); //remember that 15% tax inclusive is different to exclusive |
|
|
|
|
|
|
45
|
|
|
$this->assertEquals(200, $order->GrandTotal()); |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testExclusiveTax() |
|
49
|
|
|
{ |
|
50
|
|
|
FlatTaxModifier::config()->exclusive = true; |
|
51
|
|
|
$this->cart->clear(); |
|
52
|
|
|
$this->cart->add($this->mp3player); |
|
53
|
|
|
$order = $this->cart->current(); |
|
54
|
|
|
$order->calculate(); |
|
55
|
|
|
$modifier = $order->Modifiers() |
|
56
|
|
|
->filter('ClassName', 'FlatTaxModifier') |
|
57
|
|
|
->first(); |
|
58
|
|
|
$this->assertEquals(30, $modifier->Amount); |
|
|
|
|
|
|
59
|
|
|
$this->assertEquals(230, $order->GrandTotal()); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: