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-2018 |
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() |
19
|
|
|
{ |
20
|
|
|
\Aimeos\Controller\Frontend::cache( true ); |
21
|
|
|
|
22
|
|
|
$this->context = \TestHelperHtml::getContext(); |
23
|
|
|
$this->context->setUserId( \Aimeos\MShop::create( $this->context, 'customer' )->findItem( 'UTC001' )->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() |
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 testGetBody() |
41
|
|
|
{ |
42
|
|
|
$view = $this->object->getView(); |
43
|
|
|
$view->standardBasket = \Aimeos\MShop::create( $this->context, 'order/base' )->createItem(); |
44
|
|
|
$this->object->setView( $this->object->addData( $view ) ); |
45
|
|
|
|
46
|
|
|
$output = $this->object->getBody(); |
47
|
|
|
$this->assertStringStartsWith( '<div class="checkout-standard-address-delivery', $output ); |
48
|
|
|
|
49
|
|
|
$this->assertGreaterThan( 0, count( $view->deliveryMandatory ) ); |
50
|
|
|
$this->assertGreaterThan( 0, count( $view->deliveryOptional ) ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
public function testGetSubClientInvalid() |
55
|
|
|
{ |
56
|
|
|
$this->setExpectedException( '\\Aimeos\\Client\\Html\\Exception' ); |
57
|
|
|
$this->object->getSubClient( 'invalid', 'invalid' ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
public function testGetSubClientInvalidName() |
62
|
|
|
{ |
63
|
|
|
$this->setExpectedException( '\\Aimeos\\Client\\Html\\Exception' ); |
64
|
|
|
$this->object->getSubClient( '$$$', '$$$' ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
public function testProcess() |
69
|
|
|
{ |
70
|
|
|
$this->object->process(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
public function testProcessNewAddress() |
75
|
|
|
{ |
76
|
|
|
$view = \TestHelperHtml::getView(); |
77
|
|
|
|
78
|
|
|
$param = array( |
79
|
|
|
'ca_deliveryoption' => 'null', |
80
|
|
|
'ca_delivery' => array( |
81
|
|
|
'order.base.address.salutation' => 'mr', |
82
|
|
|
'order.base.address.firstname' => 'test', |
83
|
|
|
'order.base.address.lastname' => 'user', |
84
|
|
|
'order.base.address.address1' => 'mystreet 1', |
85
|
|
|
'order.base.address.postal' => '20000', |
86
|
|
|
'order.base.address.city' => 'hamburg', |
87
|
|
|
'order.base.address.languageid' => 'en', |
88
|
|
|
), |
89
|
|
|
); |
90
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param ); |
91
|
|
|
$view->addHelper( 'param', $helper ); |
92
|
|
|
|
93
|
|
|
$this->object->setView( $view ); |
94
|
|
|
|
95
|
|
|
$this->object->process(); |
96
|
|
|
|
97
|
|
|
$basket = \Aimeos\Controller\Frontend\Basket\Factory::create( $this->context )->get(); |
98
|
|
|
$this->assertEquals( 'hamburg', $basket->getAddress( 'delivery', 0 )->getCity() ); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
public function testProcessNewAddressMissing() |
103
|
|
|
{ |
104
|
|
|
$view = \TestHelperHtml::getView(); |
105
|
|
|
|
106
|
|
|
$param = array( |
107
|
|
|
'ca_deliveryoption' => 'null', |
108
|
|
|
'ca_delivery' => array( |
109
|
|
|
'order.base.address.firstname' => 'test', |
110
|
|
|
'order.base.address.lastname' => 'user', |
111
|
|
|
'order.base.address.address1' => 'mystreet 1', |
112
|
|
|
'order.base.address.postal' => '20000', |
113
|
|
|
'order.base.address.city' => 'hamburg', |
114
|
|
|
), |
115
|
|
|
); |
116
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param ); |
117
|
|
|
$view->addHelper( 'param', $helper ); |
118
|
|
|
|
119
|
|
|
$this->object->setView( $view ); |
120
|
|
|
|
121
|
|
|
try |
122
|
|
|
{ |
123
|
|
|
$this->object->process(); |
124
|
|
|
} |
125
|
|
|
catch( \Aimeos\Client\Html\Exception $e ) |
126
|
|
|
{ |
127
|
|
|
$this->assertEquals( 2, count( $view->deliveryError ) ); |
128
|
|
|
$this->assertArrayHasKey( 'order.base.address.salutation', $view->deliveryError ); |
129
|
|
|
$this->assertArrayHasKey( 'order.base.address.languageid', $view->deliveryError ); |
130
|
|
|
return; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
$this->fail( 'Expected exception not thrown' ); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
public function testProcessNewAddressUnknown() |
138
|
|
|
{ |
139
|
|
|
$view = \TestHelperHtml::getView(); |
140
|
|
|
|
141
|
|
|
$param = array( |
142
|
|
|
'ca_deliveryoption' => 'null', |
143
|
|
|
'ca_delivery' => array( |
144
|
|
|
'order.base.address.salutation' => 'mr', |
145
|
|
|
'order.base.address.firstname' => 'test', |
146
|
|
|
'order.base.address.lastname' => 'user', |
147
|
|
|
'order.base.address.address1' => 'mystreet 1', |
148
|
|
|
'order.base.address.postal' => '20000', |
149
|
|
|
'order.base.address.city' => 'hamburg', |
150
|
|
|
'order.base.address.languageid' => 'en', |
151
|
|
|
), |
152
|
|
|
); |
153
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param ); |
154
|
|
|
$view->addHelper( 'param', $helper ); |
155
|
|
|
|
156
|
|
|
$this->object->setView( $view ); |
157
|
|
|
$this->object->process(); |
158
|
|
|
|
159
|
|
|
$basket = \Aimeos\Controller\Frontend\Basket\Factory::create( $this->context )->get(); |
160
|
|
|
$this->assertEquals( 'test', $basket->getAddress( 'delivery', 0 )->getFirstName() ); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
|
164
|
|
|
public function testProcessNewAddressInvalid() |
165
|
|
|
{ |
166
|
|
|
$view = \TestHelperHtml::getView(); |
167
|
|
|
|
168
|
|
|
$config = $this->context->getConfig(); |
169
|
|
|
$config->set( 'client/html/checkout/standard/address/validate/postal', '^[0-9]{5}$' ); |
170
|
|
|
$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $config ); |
171
|
|
|
$view->addHelper( 'config', $helper ); |
172
|
|
|
|
173
|
|
|
$param = array( |
174
|
|
|
'ca_deliveryoption' => 'null', |
175
|
|
|
'ca_delivery' => array( |
176
|
|
|
'order.base.address.salutation' => 'mr', |
177
|
|
|
'order.base.address.firstname' => 'test', |
178
|
|
|
'order.base.address.lastname' => 'user', |
179
|
|
|
'order.base.address.address1' => 'mystreet 1', |
180
|
|
|
'order.base.address.postal' => '20AB', |
181
|
|
|
'order.base.address.city' => 'hamburg', |
182
|
|
|
'order.base.address.email' => 'me@localhost', |
183
|
|
|
'order.base.address.languageid' => 'en', |
184
|
|
|
), |
185
|
|
|
); |
186
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param ); |
187
|
|
|
$view->addHelper( 'param', $helper ); |
188
|
|
|
|
189
|
|
|
$this->object->setView( $view ); |
190
|
|
|
|
191
|
|
|
try |
192
|
|
|
{ |
193
|
|
|
$this->object->process(); |
194
|
|
|
} |
195
|
|
|
catch( \Aimeos\Client\Html\Exception $e ) |
196
|
|
|
{ |
197
|
|
|
$this->assertEquals( 1, count( $view->deliveryError ) ); |
198
|
|
|
$this->assertArrayHasKey( 'order.base.address.postal', $view->deliveryError ); |
199
|
|
|
return; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
$this->fail( 'Expected exception not thrown' ); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
|
206
|
|
|
public function testProcessAddressDelete() |
207
|
|
|
{ |
208
|
|
|
$customer = \Aimeos\MShop::create( $this->context, 'customer' )->findItem( 'UTC001', ['customer/address'] ); |
209
|
|
|
$id = current( $customer->getAddressItems() )->getId(); |
210
|
|
|
|
211
|
|
|
$view = \TestHelperHtml::getView(); |
212
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, ['ca_delivery_delete' => $id] ); |
213
|
|
|
$view->addHelper( 'param', $helper ); |
214
|
|
|
$this->object->setView( $view ); |
215
|
|
|
|
216
|
|
|
$customerStub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Customer\Standard::class ) |
217
|
|
|
->setConstructorArgs( array( $this->context ) ) |
218
|
|
|
->setMethods( array( 'deleteAddressItem', 'store' ) ) |
219
|
|
|
->getMock(); |
220
|
|
|
|
221
|
|
|
$customerStub->expects( $this->once() )->method( 'deleteAddressItem' )->will( $this->returnValue( $customerStub ) ); |
222
|
|
|
$customerStub->expects( $this->once() )->method( 'store' )->will( $this->returnValue( $customerStub ) ); |
223
|
|
|
|
224
|
|
|
\Aimeos\Controller\Frontend::inject( 'customer', $customerStub ); |
225
|
|
|
|
226
|
|
|
$this->setExpectedException( \Aimeos\Client\Html\Exception::class ); |
227
|
|
|
$this->object->process(); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
|
231
|
|
|
public function testProcessExistingAddress() |
232
|
|
|
{ |
233
|
|
|
$customer = \Aimeos\MShop::create( $this->context, 'customer' )->findItem( 'UTC001', ['customer/address'] ); |
234
|
|
|
|
235
|
|
|
$view = \TestHelperHtml::getView(); |
236
|
|
|
$param = array( 'ca_deliveryoption' => current( $customer->getAddressItems() )->getId() ); |
237
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param ); |
238
|
|
|
$view->addHelper( 'param', $helper ); |
239
|
|
|
$this->object->setView( $view ); |
240
|
|
|
|
241
|
|
|
$this->object->process(); |
242
|
|
|
|
243
|
|
|
$basket = \Aimeos\Controller\Frontend\Basket\Factory::create( $this->context )->get(); |
244
|
|
|
$this->assertEquals( 'Example company', $basket->getAddress( 'delivery', 0 )->getCompany() ); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
|
248
|
|
|
public function testProcessExistingAddressInvalid() |
249
|
|
|
{ |
250
|
|
|
$view = \TestHelperHtml::getView(); |
251
|
|
|
$param = [ |
252
|
|
|
'ca_deliveryoption' => -2, |
253
|
|
|
'ca_delivery_-2' => [ |
254
|
|
|
'order.base.address.languageid' => 'de', |
255
|
|
|
'order.base.address.salutation' => 'mr', |
256
|
|
|
'order.base.address.firstname' => 'test', |
257
|
|
|
'order.base.address.lastname' => 'user', |
258
|
|
|
'order.base.address.address1' => 'street', |
259
|
|
|
'order.base.address.postal' => '1234', |
260
|
|
|
'order.base.address.city' => 'test city', |
261
|
|
|
] |
262
|
|
|
]; |
263
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param ); |
264
|
|
|
$view->addHelper( 'param', $helper ); |
265
|
|
|
$this->object->setView( $view ); |
266
|
|
|
|
267
|
|
|
$this->object->process(); |
268
|
|
|
|
269
|
|
|
$basket = \Aimeos\Controller\Frontend\Basket\Factory::create( $this->context )->get(); |
270
|
|
|
$this->assertEquals( 'mr', $basket->getAddress( 'delivery', 0 )->getSalutation() ); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
|
274
|
|
|
public function testProcessRemoveAddress() |
275
|
|
|
{ |
276
|
|
|
$view = \TestHelperHtml::getView(); |
277
|
|
|
$param = array( 'ca_deliveryoption' => -1 ); |
278
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param ); |
279
|
|
|
$view->addHelper( 'param', $helper ); |
280
|
|
|
$this->object->setView( $view ); |
281
|
|
|
|
282
|
|
|
$this->object->process(); |
283
|
|
|
|
284
|
|
|
$basket = \Aimeos\Controller\Frontend\Basket\Factory::create( $this->context )->get(); |
285
|
|
|
$this->assertCount( 0, $basket->getAddress( 'delivery' ) ); |
286
|
|
|
} |
287
|
|
|
} |
288
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths