1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Frontend\Basket\Decorator; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class BaseTest extends \PHPUnit_Framework_TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $stub; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
protected function setUp() |
19
|
|
|
{ |
20
|
|
|
$context = \TestHelperFrontend::getContext(); |
21
|
|
|
|
22
|
|
|
$this->stub = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Basket\Standard' ) |
23
|
|
|
->disableOriginalConstructor() |
24
|
|
|
->getMock(); |
25
|
|
|
|
26
|
|
|
$this->object = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Basket\Decorator\Base' ) |
27
|
|
|
->setConstructorArgs( [$this->stub, $context] ) |
28
|
|
|
->getMockForAbstractClass(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
protected function tearDown() |
33
|
|
|
{ |
34
|
|
|
unset( $this->object, $this->stub ); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
public function testClear() |
39
|
|
|
{ |
40
|
|
|
$this->stub->expects( $this->once() )->method( 'clear' ); |
41
|
|
|
|
42
|
|
|
$this->object->clear(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public function testGet() |
47
|
|
|
{ |
48
|
|
|
$context = \TestHelperFrontend::getContext(); |
49
|
|
|
$order = \Aimeos\MShop\Factory::createManager( $context, 'order/base' )->createItem(); |
50
|
|
|
|
51
|
|
|
$this->stub->expects( $this->once() )->method( 'get' ) |
52
|
|
|
->will( $this->returnValue( $order ) ); |
53
|
|
|
|
54
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Order\Item\Base\Iface', $this->object->get() ); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
public function testSave() |
59
|
|
|
{ |
60
|
|
|
$this->stub->expects( $this->once() )->method( 'save' ); |
61
|
|
|
|
62
|
|
|
$this->object->save(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
public function testAddProduct() |
67
|
|
|
{ |
68
|
|
|
$this->stub->expects( $this->once() )->method( 'addProduct' ); |
69
|
|
|
|
70
|
|
|
$this->object->addProduct( -1 ); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
public function testDeleteProduct() |
75
|
|
|
{ |
76
|
|
|
$this->stub->expects( $this->once() )->method( 'deleteProduct' ); |
77
|
|
|
|
78
|
|
|
$this->object->deleteProduct( 0 ); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
public function testEditProduct() |
83
|
|
|
{ |
84
|
|
|
$this->stub->expects( $this->once() )->method( 'editProduct' ); |
85
|
|
|
|
86
|
|
|
$this->object->editProduct( 0, 1 ); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
public function testAddCoupon() |
91
|
|
|
{ |
92
|
|
|
$this->stub->expects( $this->once() )->method( 'addCoupon' ); |
93
|
|
|
|
94
|
|
|
$this->object->addCoupon( 'test' ); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
public function testDeleteCoupon() |
99
|
|
|
{ |
100
|
|
|
$this->stub->expects( $this->once() )->method( 'deleteCoupon' ); |
101
|
|
|
|
102
|
|
|
$this->object->deleteCoupon( 'test' ); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
public function testSetAddress() |
107
|
|
|
{ |
108
|
|
|
$this->stub->expects( $this->once() )->method( 'setAddress' ); |
109
|
|
|
|
110
|
|
|
$this->object->setAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT, null ); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
public function testSetService() |
115
|
|
|
{ |
116
|
|
|
$this->stub->expects( $this->once() )->method( 'setService' ); |
117
|
|
|
|
118
|
|
|
$this->object->setService( \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT, -1 ); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
|
122
|
|
|
public function testGetController() |
123
|
|
|
{ |
124
|
|
|
$result = $this->access( 'getController' )->invokeArgs( $this->object, [] ); |
125
|
|
|
|
126
|
|
|
$this->assertSame( $this->stub, $result ); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
public function testGetContext() |
131
|
|
|
{ |
132
|
|
|
$result = $this->access( 'getContext' )->invokeArgs( $this->object, [] ); |
133
|
|
|
|
134
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Context\Item\Iface', $result ); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
|
138
|
|
|
protected function access( $name ) |
139
|
|
|
{ |
140
|
|
|
$class = new \ReflectionClass( '\Aimeos\Controller\Frontend\Basket\Decorator\Base' ); |
141
|
|
|
$method = $class->getMethod( $name ); |
142
|
|
|
$method->setAccessible( true ); |
143
|
|
|
|
144
|
|
|
return $method; |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|