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
|
|
|
namespace Aimeos\Client\Html\Checkout\Standard\Address\Delivery; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $context; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
protected function setUp() : void |
19
|
|
|
{ |
20
|
|
|
\Aimeos\Controller\Frontend::cache( true ); |
21
|
|
|
|
22
|
|
|
$this->context = \TestHelperHtml::getContext(); |
23
|
|
|
$this->context->setUserId( \Aimeos\MShop::create( $this->context, 'customer' )->find( '[email protected]' )->getId() ); |
24
|
|
|
|
25
|
|
|
$this->object = new \Aimeos\Client\Html\Checkout\Standard\Address\Delivery\Standard( $this->context ); |
26
|
|
|
$this->object->setView( \TestHelperHtml::getView() ); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
protected function tearDown() : void |
31
|
|
|
{ |
32
|
|
|
\Aimeos\Controller\Frontend\Customer\Factory::injectController( '\Aimeos\Controller\Frontend\Customer\Standard', null ); |
33
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::create( $this->context )->clear(); |
34
|
|
|
\Aimeos\Controller\Frontend::cache( false ); |
35
|
|
|
|
36
|
|
|
unset( $this->object, $this->context ); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
public function testBody() |
41
|
|
|
{ |
42
|
|
|
$view = $this->object->getView(); |
43
|
|
|
$view->standardBasket = \Aimeos\MShop::create( $this->context, 'order/base' )->create(); |
44
|
|
|
$this->object->setView( $this->object->data( $view ) ); |
45
|
|
|
|
46
|
|
|
$output = $this->object->body(); |
47
|
|
|
$this->assertStringStartsWith( '<div class="checkout-standard-address-delivery', $output ); |
48
|
|
|
|
49
|
|
|
$this->assertGreaterThan( 0, count( $view->addressDeliveryMandatory ) ); |
50
|
|
|
$this->assertGreaterThan( 0, count( $view->addressDeliveryOptional ) ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
public function testGetSubClientInvalid() |
55
|
|
|
{ |
56
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
57
|
|
|
$this->object->getSubClient( 'invalid', 'invalid' ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
public function testGetSubClientInvalidName() |
62
|
|
|
{ |
63
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
64
|
|
|
$this->object->getSubClient( '$$$', '$$$' ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
public function testInit() |
69
|
|
|
{ |
70
|
|
|
$this->object->init(); |
71
|
|
|
|
72
|
|
|
$this->assertEmpty( $this->object->getView()->get( 'addressDeliveryError' ) ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
public function testInitNewAddress() |
77
|
|
|
{ |
78
|
|
|
$view = \TestHelperHtml::getView(); |
79
|
|
|
|
80
|
|
|
$param = array( |
81
|
|
|
'ca_deliveryoption' => 'null', |
82
|
|
|
'ca_delivery' => array( |
83
|
|
|
'order.base.address.salutation' => 'mr', |
84
|
|
|
'order.base.address.firstname' => 'test', |
85
|
|
|
'order.base.address.lastname' => 'user', |
86
|
|
|
'order.base.address.address1' => 'mystreet 1', |
87
|
|
|
'order.base.address.postal' => '20000', |
88
|
|
|
'order.base.address.city' => 'hamburg', |
89
|
|
|
'order.base.address.languageid' => 'en', |
90
|
|
|
), |
91
|
|
|
); |
92
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param ); |
93
|
|
|
$view->addHelper( 'param', $helper ); |
94
|
|
|
|
95
|
|
|
$this->object->setView( $view ); |
96
|
|
|
|
97
|
|
|
$this->object->init(); |
98
|
|
|
|
99
|
|
|
$basket = \Aimeos\Controller\Frontend\Basket\Factory::create( $this->context )->get(); |
100
|
|
|
$this->assertEquals( 'hamburg', $basket->getAddress( 'delivery', 0 )->getCity() ); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
public function testInitNewAddressMissing() |
105
|
|
|
{ |
106
|
|
|
$view = \TestHelperHtml::getView(); |
107
|
|
|
|
108
|
|
|
$param = array( |
109
|
|
|
'ca_deliveryoption' => 'null', |
110
|
|
|
'ca_delivery' => array( |
111
|
|
|
'order.base.address.firstname' => 'test', |
112
|
|
|
'order.base.address.lastname' => 'user', |
113
|
|
|
'order.base.address.address1' => 'mystreet 1', |
114
|
|
|
'order.base.address.postal' => '20000', |
115
|
|
|
'order.base.address.city' => 'hamburg', |
116
|
|
|
), |
117
|
|
|
); |
118
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param ); |
119
|
|
|
$view->addHelper( 'param', $helper ); |
120
|
|
|
|
121
|
|
|
$this->object->setView( $view ); |
122
|
|
|
|
123
|
|
|
try |
124
|
|
|
{ |
125
|
|
|
$this->object->init(); |
126
|
|
|
} |
127
|
|
|
catch( \Aimeos\Client\Html\Exception $e ) |
128
|
|
|
{ |
129
|
|
|
$this->assertEquals( 1, count( $view->addressDeliveryError ) ); |
130
|
|
|
$this->assertArrayHasKey( 'order.base.address.languageid', $view->addressDeliveryError ); |
131
|
|
|
return; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
$this->fail( 'Expected exception not thrown' ); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
|
138
|
|
|
public function testInitNewAddressUnknown() |
139
|
|
|
{ |
140
|
|
|
$view = \TestHelperHtml::getView(); |
141
|
|
|
|
142
|
|
|
$param = array( |
143
|
|
|
'ca_deliveryoption' => 'null', |
144
|
|
|
'ca_delivery' => array( |
145
|
|
|
'order.base.address.salutation' => 'mr', |
146
|
|
|
'order.base.address.firstname' => 'test', |
147
|
|
|
'order.base.address.lastname' => 'user', |
148
|
|
|
'order.base.address.address1' => 'mystreet 1', |
149
|
|
|
'order.base.address.postal' => '20000', |
150
|
|
|
'order.base.address.city' => 'hamburg', |
151
|
|
|
'order.base.address.languageid' => 'en', |
152
|
|
|
), |
153
|
|
|
); |
154
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param ); |
155
|
|
|
$view->addHelper( 'param', $helper ); |
156
|
|
|
|
157
|
|
|
$this->object->setView( $view ); |
158
|
|
|
$this->object->init(); |
159
|
|
|
|
160
|
|
|
$basket = \Aimeos\Controller\Frontend\Basket\Factory::create( $this->context )->get(); |
161
|
|
|
$this->assertEquals( 'test', $basket->getAddress( 'delivery', 0 )->getFirstName() ); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
|
165
|
|
|
public function testInitNewAddressInvalid() |
166
|
|
|
{ |
167
|
|
|
$view = \TestHelperHtml::getView(); |
168
|
|
|
|
169
|
|
|
$config = $this->context->getConfig(); |
170
|
|
|
$config->set( 'client/html/checkout/standard/address/validate/postal', '^[0-9]{5}$' ); |
171
|
|
|
$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $config ); |
172
|
|
|
$view->addHelper( 'config', $helper ); |
173
|
|
|
|
174
|
|
|
$param = array( |
175
|
|
|
'ca_deliveryoption' => 'null', |
176
|
|
|
'ca_delivery' => array( |
177
|
|
|
'order.base.address.salutation' => 'mr', |
178
|
|
|
'order.base.address.firstname' => 'test', |
179
|
|
|
'order.base.address.lastname' => 'user', |
180
|
|
|
'order.base.address.address1' => 'mystreet 1', |
181
|
|
|
'order.base.address.postal' => '20AB', |
182
|
|
|
'order.base.address.city' => 'hamburg', |
183
|
|
|
'order.base.address.email' => '[email protected]', |
184
|
|
|
'order.base.address.languageid' => 'en', |
185
|
|
|
), |
186
|
|
|
); |
187
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param ); |
188
|
|
|
$view->addHelper( 'param', $helper ); |
189
|
|
|
|
190
|
|
|
$this->object->setView( $view ); |
191
|
|
|
|
192
|
|
|
try |
193
|
|
|
{ |
194
|
|
|
$this->object->init(); |
195
|
|
|
} |
196
|
|
|
catch( \Aimeos\Client\Html\Exception $e ) |
197
|
|
|
{ |
198
|
|
|
$this->assertEquals( 1, count( $view->addressDeliveryError ) ); |
199
|
|
|
$this->assertArrayHasKey( 'order.base.address.postal', $view->addressDeliveryError ); |
200
|
|
|
return; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
$this->fail( 'Expected exception not thrown' ); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
|
207
|
|
|
public function testInitAddressDelete() |
208
|
|
|
{ |
209
|
|
|
$customer = \Aimeos\MShop::create( $this->context, 'customer' )->find( '[email protected]', ['customer/address'] ); |
210
|
|
|
$id = $customer->getAddressItems()->first()->getId(); |
211
|
|
|
|
212
|
|
|
$view = \TestHelperHtml::getView(); |
213
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, ['ca_delivery_delete' => $id] ); |
214
|
|
|
$view->addHelper( 'param', $helper ); |
215
|
|
|
$this->object->setView( $view ); |
216
|
|
|
|
217
|
|
|
$customerStub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Customer\Standard::class ) |
218
|
|
|
->setConstructorArgs( array( $this->context ) ) |
219
|
|
|
->setMethods( array( 'deleteAddressItem', 'store' ) ) |
220
|
|
|
->getMock(); |
221
|
|
|
|
222
|
|
|
$customerStub->expects( $this->once() )->method( 'deleteAddressItem' )->will( $this->returnValue( $customerStub ) ); |
223
|
|
|
$customerStub->expects( $this->once() )->method( 'store' )->will( $this->returnValue( $customerStub ) ); |
224
|
|
|
|
225
|
|
|
\Aimeos\Controller\Frontend::inject( 'customer', $customerStub ); |
226
|
|
|
|
227
|
|
|
$this->expectException( \Aimeos\Client\Html\Exception::class ); |
228
|
|
|
$this->object->init(); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
|
232
|
|
|
public function testInitExistingAddress() |
233
|
|
|
{ |
234
|
|
|
$customer = \Aimeos\MShop::create( $this->context, 'customer' )->find( '[email protected]', ['customer/address'] ); |
235
|
|
|
|
236
|
|
|
$view = \TestHelperHtml::getView(); |
237
|
|
|
$param = array( 'ca_deliveryoption' => $customer->getAddressItems()->first()->getId() ); |
238
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param ); |
239
|
|
|
$view->addHelper( 'param', $helper ); |
240
|
|
|
$this->object->setView( $view ); |
241
|
|
|
|
242
|
|
|
$this->object->init(); |
243
|
|
|
|
244
|
|
|
$basket = \Aimeos\Controller\Frontend\Basket\Factory::create( $this->context )->get(); |
245
|
|
|
$this->assertEquals( 'Example company', $basket->getAddress( 'delivery', 0 )->getCompany() ); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
|
249
|
|
|
public function testInitExistingAddressInvalid() |
250
|
|
|
{ |
251
|
|
|
$view = \TestHelperHtml::getView(); |
252
|
|
|
$param = [ |
253
|
|
|
'ca_deliveryoption' => -2, |
254
|
|
|
'ca_delivery_-2' => [ |
255
|
|
|
'order.base.address.languageid' => 'de', |
256
|
|
|
'order.base.address.salutation' => 'mr', |
257
|
|
|
'order.base.address.firstname' => 'test', |
258
|
|
|
'order.base.address.lastname' => 'user', |
259
|
|
|
'order.base.address.address1' => 'street', |
260
|
|
|
'order.base.address.postal' => '1234', |
261
|
|
|
'order.base.address.city' => 'test city', |
262
|
|
|
] |
263
|
|
|
]; |
264
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param ); |
265
|
|
|
$view->addHelper( 'param', $helper ); |
266
|
|
|
$this->object->setView( $view ); |
267
|
|
|
|
268
|
|
|
$this->object->init(); |
269
|
|
|
|
270
|
|
|
$basket = \Aimeos\Controller\Frontend\Basket\Factory::create( $this->context )->get(); |
271
|
|
|
$this->assertEquals( 'mr', $basket->getAddress( 'delivery', 0 )->getSalutation() ); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
|
275
|
|
|
public function testInitRemoveAddress() |
276
|
|
|
{ |
277
|
|
|
$view = \TestHelperHtml::getView(); |
278
|
|
|
$param = array( 'ca_delivery_delete' => -1 ); |
279
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param ); |
280
|
|
|
$view->addHelper( 'param', $helper ); |
281
|
|
|
$this->object->setView( $view ); |
282
|
|
|
|
283
|
|
|
$this->object->init(); |
284
|
|
|
|
285
|
|
|
$basket = \Aimeos\Controller\Frontend\Basket\Factory::create( $this->context )->get(); |
286
|
|
|
$this->assertCount( 0, $basket->getAddress( 'delivery' ) ); |
287
|
|
|
} |
288
|
|
|
} |
289
|
|
|
|