1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2014 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2016 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Plugin\Provider\Order; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class AutofillTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $plugin; |
15
|
|
|
private $order; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
protected function setUp() |
19
|
|
|
{ |
20
|
|
|
$context = \TestHelperMShop::getContext(); |
21
|
|
|
|
22
|
|
|
$pluginManager = \Aimeos\MShop\Plugin\Manager\Factory::createManager( $context ); |
23
|
|
|
$this->plugin = $pluginManager->createItem(); |
24
|
|
|
$this->plugin->setProvider( 'Autofill' ); |
25
|
|
|
$this->plugin->setStatus( 1 ); |
26
|
|
|
|
27
|
|
|
$orderBaseManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' ); |
28
|
|
|
$this->order = $orderBaseManager->createItem(); |
29
|
|
|
$this->order->__sleep(); // remove event listeners |
30
|
|
|
|
31
|
|
|
$this->object = new \Aimeos\MShop\Plugin\Provider\Order\Autofill( $context, $this->plugin ); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
protected function tearDown() |
36
|
|
|
{ |
37
|
|
|
unset( $this->plugin, $this->order, $this->object ); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
public function testCheckConfigBE() |
42
|
|
|
{ |
43
|
|
|
$attributes = array( |
44
|
|
|
'autofill.address' => '1', |
45
|
|
|
'autofill.delivery' => '0', |
46
|
|
|
'autofill.deliverycode' => 'ship', |
47
|
|
|
'autofill.payment' => '1', |
48
|
|
|
'autofill.paymentcode' => 'pay', |
49
|
|
|
'autofill.useorder' => '0', |
50
|
|
|
'autofill.orderaddress' => '1', |
51
|
|
|
'autofill.orderservice' => '0', |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$result = $this->object->checkConfigBE( $attributes ); |
|
|
|
|
55
|
|
|
|
56
|
|
|
$this->assertEquals( 8, count( $result ) ); |
57
|
|
|
$this->assertEquals( null, $result['autofill.address'] ); |
58
|
|
|
$this->assertEquals( null, $result['autofill.delivery'] ); |
59
|
|
|
$this->assertEquals( null, $result['autofill.deliverycode'] ); |
60
|
|
|
$this->assertEquals( null, $result['autofill.payment'] ); |
61
|
|
|
$this->assertEquals( null, $result['autofill.paymentcode'] ); |
62
|
|
|
$this->assertEquals( null, $result['autofill.useorder'] ); |
63
|
|
|
$this->assertEquals( null, $result['autofill.orderaddress'] ); |
64
|
|
|
$this->assertEquals( null, $result['autofill.orderservice'] ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
public function testGetConfigBE() |
69
|
|
|
{ |
70
|
|
|
$list = $this->object->getConfigBE(); |
|
|
|
|
71
|
|
|
|
72
|
|
|
$this->assertEquals( 8, count( $list ) ); |
73
|
|
|
$this->assertArrayHasKey( 'autofill.address', $list ); |
74
|
|
|
$this->assertArrayHasKey( 'autofill.delivery', $list ); |
75
|
|
|
$this->assertArrayHasKey( 'autofill.deliverycode', $list ); |
76
|
|
|
$this->assertArrayHasKey( 'autofill.payment', $list ); |
77
|
|
|
$this->assertArrayHasKey( 'autofill.paymentcode', $list ); |
78
|
|
|
$this->assertArrayHasKey( 'autofill.useorder', $list ); |
79
|
|
|
$this->assertArrayHasKey( 'autofill.orderaddress', $list ); |
80
|
|
|
$this->assertArrayHasKey( 'autofill.orderservice', $list ); |
81
|
|
|
|
82
|
|
|
foreach( $list as $entry ) { |
83
|
|
|
$this->assertInstanceOf( '\Aimeos\MW\Criteria\Attribute\Iface', $entry ); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
public function testRegister() |
89
|
|
|
{ |
90
|
|
|
$this->object->register( $this->order ); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
public function testUpdateNone() |
95
|
|
|
{ |
96
|
|
|
$this->assertTrue( $this->object->update( $this->order, 'addProduct.after' ) ); |
|
|
|
|
97
|
|
|
$this->assertEquals( [], $this->order->getAddresses() ); |
98
|
|
|
$this->assertEquals( [], $this->order->getServices() ); |
99
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
public function testUpdateOrderNoItem() |
104
|
|
|
{ |
105
|
|
|
$context = \TestHelperMShop::getContext(); |
106
|
|
|
$context->setUserId( '' ); |
107
|
|
|
|
108
|
|
|
$this->plugin->setConfig( array( 'autofill.useorder' => '1' ) ); |
109
|
|
|
|
110
|
|
|
$this->assertTrue( $this->object->update( $this->order, 'addProduct.after' ) ); |
|
|
|
|
111
|
|
|
$this->assertEquals( [], $this->order->getAddresses() ); |
112
|
|
|
$this->assertEquals( [], $this->order->getServices() ); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
public function testUpdateOrderNone() |
117
|
|
|
{ |
118
|
|
|
$context = \TestHelperMShop::getContext(); |
119
|
|
|
|
120
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $context, 'customer' ); |
121
|
|
|
$context->setUserId( $manager->findItem( 'UTC001' )->getId() ); |
122
|
|
|
|
123
|
|
|
$this->plugin->setConfig( array( |
124
|
|
|
'autofill.useorder' => '1', |
125
|
|
|
'autofill.orderaddress' => '0', |
126
|
|
|
'autofill.orderservice' => '0' |
127
|
|
|
) ); |
128
|
|
|
|
129
|
|
|
$this->assertTrue( $this->object->update( $this->order, 'addProduct.after' ) ); |
|
|
|
|
130
|
|
|
$this->assertEquals( [], $this->order->getAddresses() ); |
131
|
|
|
$this->assertEquals( [], $this->order->getServices() ); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
public function testUpdateOrderAddress() |
136
|
|
|
{ |
137
|
|
|
$context = \TestHelperMShop::getContext(); |
138
|
|
|
|
139
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $context, 'customer' ); |
140
|
|
|
$context->setUserId( $manager->findItem( 'UTC001' )->getId() ); |
141
|
|
|
|
142
|
|
|
|
143
|
|
|
$orderStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Standard' ) |
144
|
|
|
->setConstructorArgs( array( $context ) )->setMethods( array( 'getSubManager' ) )->getMock(); |
145
|
|
|
|
146
|
|
|
$orderBaseStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Base\\Standard' ) |
147
|
|
|
->setConstructorArgs( array( $context ) )->setMethods( array( 'getSubManager' ) )->getMock(); |
148
|
|
|
|
149
|
|
|
$orderBaseAddressStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Base\\Address\\Standard' ) |
150
|
|
|
->setConstructorArgs( array( $context ) )->setMethods( array( 'searchItems' ) )->getMock(); |
151
|
|
|
|
152
|
|
|
$item1 = $orderBaseAddressStub->createItem(); |
153
|
|
|
$item1->setType( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY ); |
154
|
|
|
$item2 = $orderBaseAddressStub->createItem(); |
155
|
|
|
$item2->setType( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT ); |
156
|
|
|
|
157
|
|
|
$orderStub->expects( $this->any() )->method( 'getSubManager' )->will( $this->returnValue( $orderBaseStub ) ); |
158
|
|
|
$orderBaseStub->expects( $this->any() )->method( 'getSubManager' )->will( $this->returnValue( $orderBaseAddressStub ) ); |
159
|
|
|
$orderBaseAddressStub->expects( $this->once() )->method( 'searchItems' )->will( $this->returnValue( array( $item1, $item2 ) ) ); |
160
|
|
|
|
161
|
|
|
\Aimeos\MShop\Order\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Order\\Manager\\PluginAutofill', $orderStub ); |
162
|
|
|
$context->getConfig()->set( 'mshop/order/manager/name', 'PluginAutofill' ); |
163
|
|
|
|
164
|
|
|
|
165
|
|
|
$this->plugin->setConfig( array( |
166
|
|
|
'autofill.useorder' => '1', |
167
|
|
|
'autofill.orderaddress' => '1', |
168
|
|
|
'autofill.orderservice' => '0' |
169
|
|
|
) ); |
170
|
|
|
$object = new \Aimeos\MShop\Plugin\Provider\Order\Autofill( $context, $this->plugin ); |
171
|
|
|
|
172
|
|
|
$this->assertTrue( $object->update( $this->order, 'addProduct.after' ) ); |
173
|
|
|
$this->assertEquals( 2, count( $this->order->getAddresses() ) ); |
174
|
|
|
$this->assertEquals( [], $this->order->getServices() ); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
|
178
|
|
|
public function testUpdateOrderService() |
179
|
|
|
{ |
180
|
|
|
$context = \TestHelperMShop::getContext(); |
181
|
|
|
|
182
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $context, 'customer' ); |
183
|
|
|
$context->setUserId( $manager->findItem( 'UTC001' )->getId() ); |
184
|
|
|
|
185
|
|
|
|
186
|
|
|
$orderStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Standard' ) |
187
|
|
|
->setConstructorArgs( array( $context ) )->setMethods( array( 'getSubManager' ) )->getMock(); |
188
|
|
|
|
189
|
|
|
$orderBaseStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Base\\Standard' ) |
190
|
|
|
->setConstructorArgs( array( $context ) )->setMethods( array( 'getSubManager' ) )->getMock(); |
191
|
|
|
|
192
|
|
|
$orderBaseServiceStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Base\\Service\\Standard' ) |
193
|
|
|
->setConstructorArgs( array( $context ) )->setMethods( array( 'searchItems' ) )->getMock(); |
194
|
|
|
|
195
|
|
|
$item1 = $orderBaseServiceStub->createItem(); |
196
|
|
|
$item1->setType( \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_DELIVERY ); |
197
|
|
|
$item1->setCode( 'unitcode' ); |
198
|
|
|
|
199
|
|
|
$item2 = $orderBaseServiceStub->createItem(); |
200
|
|
|
$item2->setType( \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT ); |
201
|
|
|
$item2->setCode( 'unitpaymentcode' ); |
202
|
|
|
|
203
|
|
|
$orderStub->expects( $this->any() )->method( 'getSubManager' )->will( $this->returnValue( $orderBaseStub ) ); |
204
|
|
|
$orderBaseStub->expects( $this->any() )->method( 'getSubManager' )->will( $this->returnValue( $orderBaseServiceStub ) ); |
205
|
|
|
$orderBaseServiceStub->expects( $this->once() )->method( 'searchItems' )->will( $this->returnValue( array( $item1, $item2 ) ) ); |
206
|
|
|
|
207
|
|
|
\Aimeos\MShop\Order\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Order\\Manager\\PluginAutofill', $orderStub ); |
208
|
|
|
$context->getConfig()->set( 'mshop/order/manager/name', 'PluginAutofill' ); |
209
|
|
|
|
210
|
|
|
|
211
|
|
|
$this->plugin->setConfig( array( |
212
|
|
|
'autofill.useorder' => '1', |
213
|
|
|
'autofill.orderaddress' => '0', |
214
|
|
|
'autofill.orderservice' => '1' |
215
|
|
|
) ); |
216
|
|
|
$object = new \Aimeos\MShop\Plugin\Provider\Order\Autofill( $context, $this->plugin ); |
217
|
|
|
|
218
|
|
|
$this->assertTrue( $object->update( $this->order, 'addProduct.after' ) ); |
219
|
|
|
$this->assertEquals( 2, count( $this->order->getServices() ) ); |
220
|
|
|
$this->assertEquals( [], $this->order->getAddresses() ); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
|
224
|
|
|
public function testUpdateAddress() |
225
|
|
|
{ |
226
|
|
|
$context = \TestHelperMShop::getContext(); |
227
|
|
|
|
228
|
|
|
$customerManager = \Aimeos\MShop\Customer\Manager\Factory::createManager( $context ); |
229
|
|
|
$context->setUserId( $customerManager->findItem( 'UTC001' )->getId() ); |
230
|
|
|
|
231
|
|
|
$type = \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT; |
232
|
|
|
$this->plugin->setConfig( array( 'autofill.address' => '1' ) ); |
233
|
|
|
$object = new \Aimeos\MShop\Plugin\Provider\Order\Autofill( $context, $this->plugin ); |
234
|
|
|
|
235
|
|
|
$this->assertTrue( $object->update( $this->order, 'addProduct.after' ) ); |
236
|
|
|
$this->assertEquals( [], $this->order->getServices() ); |
237
|
|
|
$this->assertEquals( 1, count( $this->order->getAddresses() ) ); |
238
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Order\\Item\\Base\\Address\\Iface', $this->order->getAddress( $type ) ); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
|
242
|
|
|
public function testUpdateDelivery() |
243
|
|
|
{ |
244
|
|
|
$type = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_DELIVERY; |
245
|
|
|
$this->plugin->setConfig( array( 'autofill.delivery' => '1' ) ); |
246
|
|
|
|
247
|
|
|
$this->assertTrue( $this->object->update( $this->order, 'addProduct.after' ) ); |
|
|
|
|
248
|
|
|
$this->assertEquals( [], $this->order->getAddresses() ); |
249
|
|
|
$this->assertEquals( 1, count( $this->order->getServices() ) ); |
250
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Order\\Item\\Base\\Service\\Iface', $this->order->getService( $type ) ); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
|
254
|
|
|
public function testUpdateDeliveryCode() |
255
|
|
|
{ |
256
|
|
|
$type = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_DELIVERY; |
257
|
|
|
$this->plugin->setConfig( array( 'autofill.delivery' => '1', 'autofill.deliverycode' => 'unitcode' ) ); |
258
|
|
|
|
259
|
|
|
$this->assertTrue( $this->object->update( $this->order, 'addProduct.after' ) ); |
|
|
|
|
260
|
|
|
$this->assertEquals( [], $this->order->getAddresses() ); |
261
|
|
|
$this->assertEquals( 1, count( $this->order->getServices() ) ); |
262
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Order\\Item\\Base\\Service\\Iface', $this->order->getService( $type ) ); |
263
|
|
|
$this->assertEquals( 'unitcode', $this->order->getService( $type )->getCode() ); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
|
267
|
|
|
public function testUpdateDeliveryCodeNotExists() |
268
|
|
|
{ |
269
|
|
|
$type = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_DELIVERY; |
270
|
|
|
$this->plugin->setConfig( array( 'autofill.delivery' => '1', 'autofill.deliverycode' => 'xyz' ) ); |
271
|
|
|
|
272
|
|
|
$this->assertTrue( $this->object->update( $this->order, 'addProduct.after' ) ); |
|
|
|
|
273
|
|
|
$this->assertEquals( [], $this->order->getAddresses() ); |
274
|
|
|
$this->assertEquals( 1, count( $this->order->getServices() ) ); |
275
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Order\\Item\\Base\\Service\\Iface', $this->order->getService( $type ) ); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
|
279
|
|
|
public function testUpdatePayment() |
280
|
|
|
{ |
281
|
|
|
$type = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT; |
282
|
|
|
$this->plugin->setConfig( array( 'autofill.payment' => '1' ) ); |
283
|
|
|
|
284
|
|
|
$this->assertTrue( $this->object->update( $this->order, 'addProduct.after' ) ); |
|
|
|
|
285
|
|
|
$this->assertEquals( [], $this->order->getAddresses() ); |
286
|
|
|
$this->assertEquals( 1, count( $this->order->getServices() ) ); |
287
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Order\\Item\\Base\\Service\\Iface', $this->order->getService( $type ) ); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
|
291
|
|
|
public function testUpdatePaymentCode() |
292
|
|
|
{ |
293
|
|
|
$type = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT; |
294
|
|
|
$this->plugin->setConfig( array( 'autofill.payment' => '1', 'autofill.paymentcode' => 'unitpaymentcode' ) ); |
295
|
|
|
|
296
|
|
|
$this->assertTrue( $this->object->update( $this->order, 'addProduct.after' ) ); |
|
|
|
|
297
|
|
|
$this->assertEquals( [], $this->order->getAddresses() ); |
298
|
|
|
$this->assertEquals( 1, count( $this->order->getServices() ) ); |
299
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Order\\Item\\Base\\Service\\Iface', $this->order->getService( $type ) ); |
300
|
|
|
$this->assertEquals( 'unitpaymentcode', $this->order->getService( $type )->getCode() ); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
|
304
|
|
|
public function testUpdatePaymentCodeNotExists() |
305
|
|
|
{ |
306
|
|
|
$type = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT; |
307
|
|
|
$this->plugin->setConfig( array( 'autofill.payment' => '1', 'autofill.paymentcode' => 'xyz' ) ); |
308
|
|
|
|
309
|
|
|
$this->assertTrue( $this->object->update( $this->order, 'addProduct.after' ) ); |
|
|
|
|
310
|
|
|
$this->assertEquals( [], $this->order->getAddresses() ); |
311
|
|
|
$this->assertEquals( 1, count( $this->order->getServices() ) ); |
312
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Order\\Item\\Base\\Service\\Iface', $this->order->getService( $type ) ); |
313
|
|
|
} |
314
|
|
|
} |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.