|
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-2022 |
|
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
|
|
|
private $view; |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
protected function setUp() : void |
|
21
|
|
|
{ |
|
22
|
|
|
$this->view = \TestHelper::view(); |
|
23
|
|
|
$this->context = \TestHelper::context(); |
|
24
|
|
|
|
|
25
|
|
|
$this->object = new \Aimeos\Client\Html\Checkout\Standard\Process\Standard( $this->context ); |
|
26
|
|
|
$this->object->setView( $this->view ); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
protected function tearDown() : void |
|
31
|
|
|
{ |
|
32
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::create( $this->context )->clear(); |
|
33
|
|
|
unset( $this->object, $this->context, $this->view ); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
public function testBody() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->view->standardStepActive = 'process'; |
|
40
|
|
|
$this->object->setView( $this->object->data( $this->view ) ); |
|
41
|
|
|
|
|
42
|
|
|
$output = $this->object->body(); |
|
43
|
|
|
$this->assertStringStartsWith( '<div class="checkout-standard-process">', $output ); |
|
44
|
|
|
$this->assertEquals( 'http://baseurl/checkout/index/?c_step=payment', $this->view->standardUrlPayment ); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
public function testGetSubClientInvalid() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
|
51
|
|
|
$this->object->getSubClient( 'invalid', 'invalid' ); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
public function testGetSubClientInvalidName() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
|
58
|
|
|
$this->object->getSubClient( '$$$', '$$$' ); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
public function testInit() |
|
63
|
|
|
{ |
|
64
|
|
|
$param = array( 'c_step' => 'process', 'cs_order' => 1 ); |
|
65
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
|
66
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
67
|
|
|
|
|
68
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Checkout\Standard\Process\Standard::class ) |
|
69
|
|
|
->setConstructorArgs( [$this->context] ) |
|
70
|
|
|
->setMethods( ['processPayment'] ) |
|
71
|
|
|
->getMock(); |
|
72
|
|
|
$object->setView( $this->view ); |
|
73
|
|
|
|
|
74
|
|
|
$basketMock = $this->getMockBuilder( '\\Aimeos\\Controller\\Frontend\\Basket\Standard' ) |
|
75
|
|
|
->setConstructorArgs( [$this->context] ) |
|
76
|
|
|
->setMethods( ['store'] ) |
|
77
|
|
|
->getMock(); |
|
78
|
|
|
|
|
79
|
|
|
$orderMock = $this->getMockBuilder( '\\Aimeos\\Controller\\Frontend\\Order\Standard' ) |
|
80
|
|
|
->setConstructorArgs( [$this->context] ) |
|
81
|
|
|
->setMethods( ['store'] ) |
|
82
|
|
|
->getMock(); |
|
83
|
|
|
|
|
84
|
|
|
$form = new \Aimeos\MShop\Common\Helper\Form\Standard( 'url', 'POST', [], true ); |
|
85
|
|
|
$orderItem = \Aimeos\MShop::create( $this->context, 'order' )->create(); |
|
86
|
|
|
$product = \Aimeos\MShop::create( $this->context, 'product' )->find( 'CNE', ['price'] ); |
|
87
|
|
|
$service = \Aimeos\MShop::create( $this->context, 'service' )->find( 'paypalexpress' ); |
|
88
|
|
|
|
|
89
|
|
|
$basketMock->addProduct( $product ); |
|
90
|
|
|
$basketMock->addService( $service ); |
|
91
|
|
|
$object->expects( $this->once() )->method( 'processPayment' )->will( $this->returnValue( $form ) ); |
|
92
|
|
|
$basketMock->expects( $this->once() )->method( 'store' )->will( $this->returnValue( $basketMock->get()->setId( '123' ) ) ); |
|
93
|
|
|
$orderMock->expects( $this->once() )->method( 'store' )->will( $this->returnValue( $orderItem->setId( '123' ) ) ); |
|
94
|
|
|
|
|
95
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Basket\\Standard', $basketMock ); |
|
96
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Order\\Standard', $orderMock ); |
|
97
|
|
|
|
|
98
|
|
|
$object->init(); |
|
99
|
|
|
|
|
100
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Order\\Standard', null ); |
|
101
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Basket\\Standard', null ); |
|
102
|
|
|
|
|
103
|
|
|
$this->assertEquals( 0, count( $this->view->get( 'standardErrorList', [] ) ) ); |
|
104
|
|
|
$this->assertEquals( 'url', $this->view->standardUrlNext ); |
|
105
|
|
|
$this->assertEquals( 'POST', $this->view->standardMethod ); |
|
106
|
|
|
$this->assertEquals( [], $this->view->standardProcessParams ); |
|
107
|
|
|
$this->assertEquals( true, $this->view->standardUrlExternal ); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
public function testInitNoPayment() |
|
112
|
|
|
{ |
|
113
|
|
|
$param = array( 'c_step' => 'process', 'cs_order' => 1 ); |
|
114
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
|
115
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
116
|
|
|
|
|
117
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Checkout\Standard\Process\Standard::class ) |
|
118
|
|
|
->setConstructorArgs( [$this->context] ) |
|
119
|
|
|
->setMethods( ['processPayment'] ) |
|
120
|
|
|
->getMock(); |
|
121
|
|
|
$object->setView( $this->view ); |
|
122
|
|
|
|
|
123
|
|
|
$basketMock = $this->getMockBuilder( '\\Aimeos\\Controller\\Frontend\\Basket\Standard' ) |
|
124
|
|
|
->setConstructorArgs( [$this->context] ) |
|
125
|
|
|
->setMethods( ['store'] ) |
|
126
|
|
|
->getMock(); |
|
127
|
|
|
|
|
128
|
|
|
$orderMock = $this->getMockBuilder( '\\Aimeos\\Controller\\Frontend\\Order\Standard' ) |
|
129
|
|
|
->setConstructorArgs( [$this->context] ) |
|
130
|
|
|
->setMethods( ['store', 'save'] ) |
|
131
|
|
|
->getMock(); |
|
132
|
|
|
|
|
133
|
|
|
$orderItem = \Aimeos\MShop::create( $this->context, 'order' )->create(); |
|
134
|
|
|
|
|
135
|
|
|
$basketMock->expects( $this->once() )->method( 'store' )->will( $this->returnValue( $basketMock->get()->setId( '123' ) ) ); |
|
136
|
|
|
$orderMock->expects( $this->once() )->method( 'store' )->will( $this->returnValue( $orderItem->setId( '123' ) ) ); |
|
137
|
|
|
$orderMock->expects( $this->once() )->method( 'save' )->will( $this->returnValue( $orderItem ) ); |
|
138
|
|
|
|
|
139
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Basket\\Standard', $basketMock ); |
|
140
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Order\\Standard', $orderMock ); |
|
141
|
|
|
|
|
142
|
|
|
$object->init(); |
|
143
|
|
|
|
|
144
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Order\\Standard', null ); |
|
145
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Basket\\Standard', null ); |
|
146
|
|
|
|
|
147
|
|
|
$this->assertEquals( 0, count( $this->view->get( 'standardErrorList', [] ) ) ); |
|
148
|
|
|
$this->assertEquals( 'http://baseurl/checkout/confirm/', $this->view->standardUrlNext ); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
|
|
152
|
|
|
public function testInitNoService() |
|
153
|
|
|
{ |
|
154
|
|
|
$param = array( 'c_step' => 'process', 'cs_order' => 1 ); |
|
155
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
|
156
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
157
|
|
|
|
|
158
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Checkout\Standard\Process\Standard::class ) |
|
159
|
|
|
->setConstructorArgs( [$this->context] ) |
|
160
|
|
|
->setMethods( ['processPayment'] ) |
|
161
|
|
|
->getMock(); |
|
162
|
|
|
$object->setView( $this->view ); |
|
163
|
|
|
|
|
164
|
|
|
$basketMock = $this->getMockBuilder( '\\Aimeos\\Controller\\Frontend\\Basket\Standard' ) |
|
165
|
|
|
->setConstructorArgs( [$this->context] ) |
|
166
|
|
|
->setMethods( ['store'] ) |
|
167
|
|
|
->getMock(); |
|
168
|
|
|
|
|
169
|
|
|
$orderMock = $this->getMockBuilder( '\\Aimeos\\Controller\\Frontend\\Order\Standard' ) |
|
170
|
|
|
->setConstructorArgs( [$this->context] ) |
|
171
|
|
|
->setMethods( ['save', 'store'] ) |
|
172
|
|
|
->getMock(); |
|
173
|
|
|
|
|
174
|
|
|
$orderItem = \Aimeos\MShop::create( $this->context, 'order' )->create(); |
|
175
|
|
|
$product = \Aimeos\MShop::create( $this->context, 'product' )->find( 'CNE', ['price'] ); |
|
176
|
|
|
$service = \Aimeos\MShop::create( $this->context, 'service' )->find( 'paypalexpress' ); |
|
177
|
|
|
|
|
178
|
|
|
$basketMock->addProduct( $product ); |
|
179
|
|
|
$basketMock->addService( $service ); |
|
180
|
|
|
$object->expects( $this->once() )->method( 'processPayment' )->will( $this->returnValue( null ) ); |
|
181
|
|
|
$basketMock->expects( $this->once() )->method( 'store' )->will( $this->returnValue( $basketMock->get()->setId( '123' ) ) ); |
|
182
|
|
|
$orderMock->expects( $this->once() )->method( 'store' )->will( $this->returnValue( $orderItem->setId( '123' ) ) ); |
|
183
|
|
|
$orderMock->expects( $this->once() )->method( 'save' )->will( $this->returnValue( $orderItem ) ); |
|
184
|
|
|
|
|
185
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Basket\\Standard', $basketMock ); |
|
186
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Order\\Standard', $orderMock ); |
|
187
|
|
|
|
|
188
|
|
|
$object->init(); |
|
189
|
|
|
|
|
190
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Order\\Standard', null ); |
|
191
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::injectController( '\\Aimeos\\Controller\\Frontend\\Basket\\Standard', null ); |
|
192
|
|
|
|
|
193
|
|
|
$this->assertEquals( 0, count( $this->view->get( 'standardErrorList', [] ) ) ); |
|
194
|
|
|
$this->assertTrue( isset( $this->view->standardUrlNext ) ); |
|
195
|
|
|
$this->assertEquals( 'POST', $this->view->standardMethod ); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
|
|
199
|
|
|
public function testInitNoStep() |
|
200
|
|
|
{ |
|
201
|
|
|
$this->assertTrue( $this->object->init() ); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* @param string $date |
|
207
|
|
|
*/ |
|
208
|
|
|
protected function getOrder( $date ) |
|
209
|
|
|
{ |
|
210
|
|
|
$manager = \Aimeos\MShop\Order\Manager\Factory::create( $this->context ); |
|
211
|
|
|
|
|
212
|
|
|
$search = $manager->filter(); |
|
213
|
|
|
$search->setConditions( $search->compare( '==', 'order.datepayment', $date ) ); |
|
214
|
|
|
|
|
215
|
|
|
if( ( $item = $manager->search( $search )->first() ) === null ) { |
|
216
|
|
|
throw new \RuntimeException( 'No order found' ); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
return $item; |
|
220
|
|
|
} |
|
221
|
|
|
} |
|
222
|
|
|
|