1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2024 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Frontend\Basket\Decorator; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class Example extends Base |
13
|
|
|
{ |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
class BaseTest extends \PHPUnit\Framework\TestCase |
18
|
|
|
{ |
19
|
|
|
private $context; |
20
|
|
|
private $object; |
21
|
|
|
private $stub; |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
protected function setUp() : void |
25
|
|
|
{ |
26
|
|
|
$this->context = \TestHelper::context(); |
27
|
|
|
|
28
|
|
|
$this->stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Basket\Standard::class ) |
29
|
|
|
->disableOriginalConstructor() |
30
|
|
|
->getMock(); |
31
|
|
|
|
32
|
|
|
$this->object = new \Aimeos\Controller\Frontend\Basket\Decorator\Example( $this->stub, $this->context ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
protected function tearDown() : void |
37
|
|
|
{ |
38
|
|
|
unset( $this->context, $this->object, $this->stub ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
public function testCall() |
43
|
|
|
{ |
44
|
|
|
$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Basket\Standard::class ) |
45
|
|
|
->disableOriginalConstructor() |
46
|
|
|
->onlyMethods( ['__call'] ) |
47
|
|
|
->getMock(); |
48
|
|
|
|
49
|
|
|
$object = new \Aimeos\Controller\Frontend\Basket\Decorator\Example( $stub, $this->context ); |
50
|
|
|
|
51
|
|
|
$stub->expects( $this->once() )->method( '__call' )->willReturn( true ); |
52
|
|
|
|
53
|
|
|
$this->assertTrue( $object->invalid() ); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
public function testAdd() |
58
|
|
|
{ |
59
|
|
|
$this->stub->expects( $this->once() )->method( 'add' ); |
60
|
|
|
$this->assertSame( $this->object, $this->object->add( [] ) ); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
public function testClear() |
65
|
|
|
{ |
66
|
|
|
$this->stub->expects( $this->once() )->method( 'clear' ); |
67
|
|
|
$this->assertSame( $this->object, $this->object->clear() ); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
public function testGet() |
72
|
|
|
{ |
73
|
|
|
$context = \TestHelper::context(); |
74
|
|
|
$order = \Aimeos\MShop::create( $context, 'order' )->create(); |
75
|
|
|
|
76
|
|
|
$this->stub->expects( $this->once() )->method( 'get' )->willReturn( $order ); |
77
|
|
|
|
78
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $this->object->get() ); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
public function testSave() |
83
|
|
|
{ |
84
|
|
|
$this->stub->expects( $this->once() )->method( 'save' ); |
85
|
|
|
$this->assertSame( $this->object, $this->object->save() ); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
public function testSetType() |
90
|
|
|
{ |
91
|
|
|
$this->stub->expects( $this->once() )->method( 'setType' ); |
92
|
|
|
$this->assertSame( $this->object, $this->object->setType( 'test' ) ); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
public function testStore() |
97
|
|
|
{ |
98
|
|
|
$basket = \Aimeos\MShop::create( $this->context, 'order' )->create(); |
99
|
|
|
|
100
|
|
|
$this->stub->expects( $this->once() )->method( 'store' )->willReturn( $basket ); |
101
|
|
|
|
102
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $this->object->store() ); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
public function testLoad() |
107
|
|
|
{ |
108
|
|
|
$basket = \Aimeos\MShop::create( $this->context, 'order' )->create(); |
109
|
|
|
|
110
|
|
|
$this->stub->expects( $this->once() )->method( 'load' )->willReturn( $basket ); |
111
|
|
|
|
112
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $this->object->load( -1 ) ); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
public function testAddProduct() |
117
|
|
|
{ |
118
|
|
|
$product = \Aimeos\MShop::create( $this->context, 'product' )->create(); |
119
|
|
|
|
120
|
|
|
$this->stub->expects( $this->once() )->method( 'addProduct' ); |
121
|
|
|
|
122
|
|
|
$this->assertSame( $this->object, $this->object->addProduct( $product ) ); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
public function testDeleteProduct() |
127
|
|
|
{ |
128
|
|
|
$this->stub->expects( $this->once() )->method( 'deleteProduct' ); |
129
|
|
|
|
130
|
|
|
$this->assertSame( $this->object, $this->object->deleteProduct( 0 ) ); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
|
134
|
|
|
public function testUpdateProduct() |
135
|
|
|
{ |
136
|
|
|
$this->stub->expects( $this->once() )->method( 'updateProduct' ); |
137
|
|
|
|
138
|
|
|
$this->assertSame( $this->object, $this->object->updateProduct( 0, 1 ) ); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
|
142
|
|
|
public function testAddCoupon() |
143
|
|
|
{ |
144
|
|
|
$this->stub->expects( $this->once() )->method( 'addCoupon' ); |
145
|
|
|
|
146
|
|
|
$this->assertSame( $this->object, $this->object->addCoupon( 'test' ) ); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
public function testDeleteCoupon() |
151
|
|
|
{ |
152
|
|
|
$this->stub->expects( $this->once() )->method( 'deleteCoupon' ); |
153
|
|
|
|
154
|
|
|
$this->assertSame( $this->object, $this->object->deleteCoupon( 'test' ) ); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
|
158
|
|
|
public function testAddAddress() |
159
|
|
|
{ |
160
|
|
|
$this->stub->expects( $this->once() )->method( 'addAddress' ); |
161
|
|
|
|
162
|
|
|
$this->assertSame( $this->object, $this->object->addAddress( 'payment', [] ) ); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
|
166
|
|
|
public function testDeleteAddress() |
167
|
|
|
{ |
168
|
|
|
$this->stub->expects( $this->once() )->method( 'deleteAddress' ); |
169
|
|
|
|
170
|
|
|
$this->assertSame( $this->object, $this->object->deleteAddress( 'payment' ) ); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
|
174
|
|
|
public function testAddService() |
175
|
|
|
{ |
176
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'service' )->create()->setType( 'payment' ); |
177
|
|
|
|
178
|
|
|
$this->stub->expects( $this->once() )->method( 'addService' ); |
179
|
|
|
|
180
|
|
|
$this->assertSame( $this->object, $this->object->addService( $item ) ); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
|
184
|
|
|
public function testDeleteService() |
185
|
|
|
{ |
186
|
|
|
$this->stub->expects( $this->once() )->method( 'deleteService' ); |
187
|
|
|
|
188
|
|
|
$this->assertSame( $this->object, $this->object->deleteService( 'payment' ) ); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
|
192
|
|
|
public function testGetController() |
193
|
|
|
{ |
194
|
|
|
$result = $this->access( 'getController' )->invokeArgs( $this->object, [] ); |
195
|
|
|
|
196
|
|
|
$this->assertSame( $this->stub, $result ); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
|
200
|
|
|
protected function access( $name ) |
201
|
|
|
{ |
202
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Basket\Decorator\Base::class ); |
203
|
|
|
$method = $class->getMethod( $name ); |
204
|
|
|
$method->setAccessible( true ); |
205
|
|
|
|
206
|
|
|
return $method; |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
|