|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Cart module for Yii2 |
|
5
|
|
|
* |
|
6
|
|
|
* @link https://github.com/hiqdev/yii2-cart |
|
7
|
|
|
* @package yii2-cart |
|
8
|
|
|
* @license BSD-3-Clause |
|
9
|
|
|
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/) |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace hiqdev\yii2\cart\tests\unit; |
|
13
|
|
|
|
|
14
|
|
|
use hiqdev\yii2\cart\ShoppingCart; |
|
15
|
|
|
use Yii; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Generated by PHPUnit_SkeletonGenerator on 2015-11-26 at 08:00:52. |
|
19
|
|
|
*/ |
|
20
|
|
|
class ShoppingCartTest extends \PHPUnit\Framework\TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var ShoppingCart |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $object; |
|
26
|
|
|
|
|
27
|
|
|
protected $id = 'fake1'; |
|
28
|
|
|
protected $price = 9.99; |
|
29
|
|
|
protected $discount = 3.33; |
|
30
|
|
|
protected $quantity = 5; |
|
31
|
|
|
|
|
32
|
|
|
protected function setUp() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->object = new ShoppingCart(); |
|
35
|
|
|
$product = Yii::createObject([ |
|
36
|
|
|
'class' => FakeCartPosition::class, |
|
37
|
|
|
'id' => $this->id, |
|
38
|
|
|
'price' => $this->price, |
|
39
|
|
|
'discount' => $this->discount, |
|
40
|
|
|
]); |
|
41
|
|
|
$this->object->put($product, $this->quantity); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
protected function tearDown() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->object->removeAll(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testGetCount() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->assertSame(1, $this->object->getCount()); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testGetQuantity() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->assertSame($this->quantity, $this->object->getQuantity()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testGetSubtotal() |
|
60
|
|
|
{ |
|
61
|
|
|
$this->assertSame($this->quantity * $this->price, $this->object->getSubtotal()); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testGetTotal() |
|
65
|
|
|
{ |
|
66
|
|
|
$this->assertSame($this->quantity * ($this->price - $this->discount), $this->object->getTotal()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testGetDiscount() |
|
70
|
|
|
{ |
|
71
|
|
|
$this->assertSame($this->quantity * $this->discount, -$this->object->getDiscount()); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function testFormatCurrency() |
|
75
|
|
|
{ |
|
76
|
|
|
$this->assertSame('$9.99', $this->object->formatCurrency($this->price)); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|