1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2013 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2021 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\Client\Html\Checkout\Standard\Process; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $object; |
16
|
|
|
private $context; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() : void |
20
|
|
|
{ |
21
|
|
|
$this->context = \TestHelperHtml::getContext(); |
22
|
|
|
|
23
|
|
|
$this->object = new \Aimeos\Client\Html\Checkout\Standard\Process\Standard( $this->context ); |
24
|
|
|
$this->object->setView( \TestHelperHtml::getView() ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
protected function tearDown() : void |
29
|
|
|
{ |
30
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::create( $this->context )->clear(); |
31
|
|
|
unset( $this->object, $this->context ); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
public function testHeader() |
36
|
|
|
{ |
37
|
|
|
$view = $this->object->getView(); |
38
|
|
|
$view->standardStepActive = 'process'; |
39
|
|
|
$this->object->setView( $this->object->data( $view ) ); |
40
|
|
|
|
41
|
|
|
$output = $this->object->header(); |
42
|
|
|
$this->assertNotNull( $output ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public function testHeaderSkip() |
47
|
|
|
{ |
48
|
|
|
$output = $this->object->header(); |
49
|
|
|
$this->assertNotNull( $output ); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
public function testBody() |
54
|
|
|
{ |
55
|
|
|
$view = $this->object->getView(); |
56
|
|
|
$view->standardStepActive = 'process'; |
57
|
|
|
$this->object->setView( $this->object->data( $view ) ); |
58
|
|
|
|
59
|
|
|
$output = $this->object->body(); |
60
|
|
|
$this->assertStringStartsWith( '<div class="checkout-standard-process">', $output ); |
61
|
|
|
$this->assertEquals( 'http://baseurl/checkout/index/?c_step=payment', $view->standardUrlPayment ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
public function testGetSubClientInvalid() |
66
|
|
|
{ |
67
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
68
|
|
|
$this->object->getSubClient( 'invalid', 'invalid' ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
public function testGetSubClientInvalidName() |
73
|
|
|
{ |
74
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
75
|
|
|
$this->object->getSubClient( '$$$', '$$$' ); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
public function testInit() |
80
|
|
|
{ |
81
|
|
|
$view = $this->object->getView(); |
82
|
|
|
$param = array( 'c_step' => 'process', 'cs_order' => 1 ); |
83
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param ); |
84
|
|
|
$view->addHelper( 'param', $helper ); |
85
|
|
|
|
86
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Checkout\Standard\Process\Standard::class ) |
87
|
|
|
->setConstructorArgs( [$this->context] ) |
88
|
|
|
->setMethods( ['processPayment'] ) |
89
|
|
|
->getMock(); |
90
|
|
|
$object->setView( $view ); |
91
|
|
|
|
92
|
|
|
$basketMock = $this->getMockBuilder( '\\Aimeos\\Controller\\Frontend\\Basket\Standard' ) |
93
|
|
|
->setConstructorArgs( [$this->context] ) |
94
|
|
|
->setMethods( ['store'] ) |
95
|
|
|
->getMock(); |
96
|
|
|
|
97
|
|
|
$orderMock = $this->getMockBuilder( '\\Aimeos\\Controller\\Frontend\\Order\Standard' ) |
98
|
|
|
->setConstructorArgs( [$this->context] ) |
99
|
|
|
->setMethods( ['store'] ) |
100
|
|
|
->getMock(); |
101
|
|
|
|
102
|
|
|
$form = new \Aimeos\MShop\Common\Helper\Form\Standard( 'url', 'POST', [], true ); |
103
|
|
|
$orderItem = \Aimeos\MShop::create( $this->context, 'order' )->create(); |
104
|
|
|
$product = \Aimeos\MShop::create( $this->context, 'product' )->find( 'CNE', ['price'] ); |
105
|
|
|
$service = \Aimeos\MShop::create( $this->context, 'service' )->find( 'paypalexpress' ); |
106
|
|
|
|
107
|
|
|
$basketMock->addProduct( $product ); |
108
|
|
|
$basketMock->addService( $service ); |
109
|
|
|
$object->expects( $this->once() )->method( 'processPayment' )->will( $this->returnValue( $form ) ); |
110
|
|
|
$basketMock->expects( $this->once() )->method( 'store' )->will( $this->returnValue( $basketMock->get()->setId( '123' ) ) ); |
111
|
|
|
$orderMock->expects( $this->once() )->method( 'store' )->will( $this->returnValue( $orderItem->setId( '123' ) ) ); |
112
|
|
|
|
113
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Basket\\Standard', $basketMock ); |
114
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Order\\Standard', $orderMock ); |
115
|
|
|
|
116
|
|
|
$object->init(); |
117
|
|
|
|
118
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Order\\Standard', null ); |
119
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Basket\\Standard', null ); |
120
|
|
|
|
121
|
|
|
$this->assertEquals( 0, count( $view->get( 'standardErrorList', [] ) ) ); |
122
|
|
|
$this->assertEquals( 'url', $view->standardUrlNext ); |
123
|
|
|
$this->assertEquals( 'POST', $view->standardMethod ); |
124
|
|
|
$this->assertEquals( [], $view->standardProcessParams ); |
125
|
|
|
$this->assertEquals( true, $view->standardUrlExternal ); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
public function testInitNoPayment() |
130
|
|
|
{ |
131
|
|
|
$view = $this->object->getView(); |
132
|
|
|
$param = array( 'c_step' => 'process', 'cs_order' => 1 ); |
133
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param ); |
134
|
|
|
$view->addHelper( 'param', $helper ); |
135
|
|
|
|
136
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Checkout\Standard\Process\Standard::class ) |
137
|
|
|
->setConstructorArgs( [$this->context] ) |
138
|
|
|
->setMethods( ['processPayment'] ) |
139
|
|
|
->getMock(); |
140
|
|
|
$object->setView( $view ); |
141
|
|
|
|
142
|
|
|
$basketMock = $this->getMockBuilder( '\\Aimeos\\Controller\\Frontend\\Basket\Standard' ) |
143
|
|
|
->setConstructorArgs( [$this->context] ) |
144
|
|
|
->setMethods( ['store'] ) |
145
|
|
|
->getMock(); |
146
|
|
|
|
147
|
|
|
$orderMock = $this->getMockBuilder( '\\Aimeos\\Controller\\Frontend\\Order\Standard' ) |
148
|
|
|
->setConstructorArgs( [$this->context] ) |
149
|
|
|
->setMethods( ['store', 'save'] ) |
150
|
|
|
->getMock(); |
151
|
|
|
|
152
|
|
|
$orderItem = \Aimeos\MShop::create( $this->context, 'order' )->create(); |
153
|
|
|
|
154
|
|
|
$basketMock->expects( $this->once() )->method( 'store' )->will( $this->returnValue( $basketMock->get()->setId( '123' ) ) ); |
155
|
|
|
$orderMock->expects( $this->once() )->method( 'store' )->will( $this->returnValue( $orderItem->setId( '123' ) ) ); |
156
|
|
|
$orderMock->expects( $this->once() )->method( 'save' )->will( $this->returnValue( $orderItem ) ); |
157
|
|
|
|
158
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Basket\\Standard', $basketMock ); |
159
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Order\\Standard', $orderMock ); |
160
|
|
|
|
161
|
|
|
$object->init(); |
162
|
|
|
|
163
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Order\\Standard', null ); |
164
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Basket\\Standard', null ); |
165
|
|
|
|
166
|
|
|
$this->assertEquals( 0, count( $view->get( 'standardErrorList', [] ) ) ); |
167
|
|
|
$this->assertEquals( 'http://baseurl/checkout/confirm/', $view->standardUrlNext ); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
|
171
|
|
|
public function testInitNoService() |
172
|
|
|
{ |
173
|
|
|
$view = $this->object->getView(); |
174
|
|
|
$param = array( 'c_step' => 'process', 'cs_order' => 1 ); |
175
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param ); |
176
|
|
|
$view->addHelper( 'param', $helper ); |
177
|
|
|
|
178
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Checkout\Standard\Process\Standard::class ) |
179
|
|
|
->setConstructorArgs( [$this->context] ) |
180
|
|
|
->setMethods( ['processPayment'] ) |
181
|
|
|
->getMock(); |
182
|
|
|
$object->setView( $view ); |
183
|
|
|
|
184
|
|
|
$basketMock = $this->getMockBuilder( '\\Aimeos\\Controller\\Frontend\\Basket\Standard' ) |
185
|
|
|
->setConstructorArgs( [$this->context] ) |
186
|
|
|
->setMethods( ['store'] ) |
187
|
|
|
->getMock(); |
188
|
|
|
|
189
|
|
|
$orderMock = $this->getMockBuilder( '\\Aimeos\\Controller\\Frontend\\Order\Standard' ) |
190
|
|
|
->setConstructorArgs( [$this->context] ) |
191
|
|
|
->setMethods( ['save', 'store'] ) |
192
|
|
|
->getMock(); |
193
|
|
|
|
194
|
|
|
$orderItem = \Aimeos\MShop::create( $this->context, 'order' )->create(); |
195
|
|
|
$product = \Aimeos\MShop::create( $this->context, 'product' )->find( 'CNE', ['price'] ); |
196
|
|
|
$service = \Aimeos\MShop::create( $this->context, 'service' )->find( 'paypalexpress' ); |
197
|
|
|
|
198
|
|
|
$basketMock->addProduct( $product ); |
199
|
|
|
$basketMock->addService( $service ); |
200
|
|
|
$object->expects( $this->once() )->method( 'processPayment' )->will( $this->returnValue( null ) ); |
201
|
|
|
$basketMock->expects( $this->once() )->method( 'store' )->will( $this->returnValue( $basketMock->get()->setId( '123' ) ) ); |
202
|
|
|
$orderMock->expects( $this->once() )->method( 'store' )->will( $this->returnValue( $orderItem->setId( '123' ) ) ); |
203
|
|
|
$orderMock->expects( $this->once() )->method( 'save' )->will( $this->returnValue( $orderItem ) ); |
204
|
|
|
|
205
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Basket\\Standard', $basketMock ); |
206
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Order\\Standard', $orderMock ); |
207
|
|
|
|
208
|
|
|
$object->init(); |
209
|
|
|
|
210
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Order\\Standard', null ); |
211
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Basket\\Standard', null ); |
212
|
|
|
|
213
|
|
|
$this->assertEquals( 0, count( $view->get( 'standardErrorList', [] ) ) ); |
214
|
|
|
$this->assertTrue( isset( $view->standardUrlNext ) ); |
215
|
|
|
$this->assertEquals( 'POST', $view->standardMethod ); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
|
219
|
|
|
public function testInitNoStep() |
220
|
|
|
{ |
221
|
|
|
$this->assertTrue( $this->object->init() ); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
|
225
|
|
|
public function testInitHtmlException() |
226
|
|
|
{ |
227
|
|
|
$view = $this->object->getView(); |
228
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, ['c_step' => 'process', 'cs_order' => 1] ); |
229
|
|
|
$view->addHelper( 'param', $helper ); |
230
|
|
|
|
231
|
|
|
$mock = $this->getMockBuilder( '\\Aimeos\\Controller\\Frontend\\Basket\Standard' ) |
232
|
|
|
->setConstructorArgs( [$this->context] ) |
233
|
|
|
->setMethods( ['store'] ) |
234
|
|
|
->getMock(); |
235
|
|
|
|
236
|
|
|
$mock->expects( $this->once() )->method( 'store' ) |
237
|
|
|
->will( $this->throwException( new \Aimeos\Client\Html\Exception() ) ); |
238
|
|
|
|
239
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Basket\\Standard', $mock ); |
240
|
|
|
$this->object->init(); |
241
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Basket\\Standard', null ); |
242
|
|
|
|
243
|
|
|
$this->assertIsArray( $view->standardErrorList ); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
|
247
|
|
|
public function testInitFrontendException() |
248
|
|
|
{ |
249
|
|
|
$view = $this->object->getView(); |
250
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, ['c_step' => 'process', 'cs_order' => 1] ); |
251
|
|
|
$view->addHelper( 'param', $helper ); |
252
|
|
|
|
253
|
|
|
$mock = $this->getMockBuilder( '\\Aimeos\\Controller\\Frontend\\Basket\Standard' ) |
254
|
|
|
->setConstructorArgs( [$this->context] ) |
255
|
|
|
->setMethods( ['store'] ) |
256
|
|
|
->getMock(); |
257
|
|
|
|
258
|
|
|
$mock->expects( $this->once() )->method( 'store' ) |
259
|
|
|
->will( $this->throwException( new \Aimeos\Controller\Frontend\Exception() ) ); |
260
|
|
|
|
261
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Basket\\Standard', $mock ); |
262
|
|
|
$this->object->init(); |
263
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Basket\\Standard', null ); |
264
|
|
|
|
265
|
|
|
$this->assertIsArray( $view->standardErrorList ); |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
|
269
|
|
|
public function testInitMShopException() |
270
|
|
|
{ |
271
|
|
|
$view = $this->object->getView(); |
272
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, ['c_step' => 'process', 'cs_order' => 1] ); |
273
|
|
|
$view->addHelper( 'param', $helper ); |
274
|
|
|
|
275
|
|
|
$mock = $this->getMockBuilder( '\\Aimeos\\Controller\\Frontend\\Basket\Standard' ) |
276
|
|
|
->setConstructorArgs( [$this->context] ) |
277
|
|
|
->setMethods( ['store'] ) |
278
|
|
|
->getMock(); |
279
|
|
|
|
280
|
|
|
$mock->expects( $this->once() )->method( 'store' ) |
281
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
282
|
|
|
|
283
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Basket\\Standard', $mock ); |
284
|
|
|
$this->object->init(); |
285
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Basket\\Standard', null ); |
286
|
|
|
|
287
|
|
|
$this->assertIsArray( $view->standardErrorList ); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
|
291
|
|
|
public function testInitException() |
292
|
|
|
{ |
293
|
|
|
$view = $this->object->getView(); |
294
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, ['c_step' => 'process', 'cs_order' => 1] ); |
295
|
|
|
$view->addHelper( 'param', $helper ); |
296
|
|
|
|
297
|
|
|
$mock = $this->getMockBuilder( '\\Aimeos\\Controller\\Frontend\\Basket\Standard' ) |
298
|
|
|
->setConstructorArgs( [$this->context] ) |
299
|
|
|
->setMethods( ['store'] ) |
300
|
|
|
->getMock(); |
301
|
|
|
|
302
|
|
|
$mock->expects( $this->once() )->method( 'store' ) |
303
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
304
|
|
|
|
305
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Basket\\Standard', $mock ); |
306
|
|
|
$this->object->init(); |
307
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Basket\\Standard', null ); |
308
|
|
|
|
309
|
|
|
$this->assertIsArray( $view->standardErrorList ); |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* @param string $date |
315
|
|
|
*/ |
316
|
|
|
protected function getOrder( $date ) |
317
|
|
|
{ |
318
|
|
|
$manager = \Aimeos\MShop\Order\Manager\Factory::create( $this->context ); |
319
|
|
|
|
320
|
|
|
$search = $manager->filter(); |
321
|
|
|
$search->setConditions( $search->compare( '==', 'order.datepayment', $date ) ); |
322
|
|
|
|
323
|
|
|
if( ( $item = $manager->search( $search )->first() ) === null ) { |
324
|
|
|
throw new \RuntimeException( 'No order found' ); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
return $item; |
328
|
|
|
} |
329
|
|
|
} |
330
|
|
|
|