1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2011 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2020 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\MShop\Order\Manager\Base\Service; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $context; |
16
|
|
|
private $object; |
17
|
|
|
private $editor = ''; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
protected function setUp() : void |
21
|
|
|
{ |
22
|
|
|
$this->editor = \TestHelperMShop::getContext()->getEditor(); |
23
|
|
|
$this->context = \TestHelperMShop::getContext(); |
24
|
|
|
$this->object = new \Aimeos\MShop\Order\Manager\Base\Service\Standard( $this->context ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
protected function tearDown() : void |
29
|
|
|
{ |
30
|
|
|
unset( $this->object ); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
public function testAggregate() |
35
|
|
|
{ |
36
|
|
|
$search = $this->object->createSearch(); |
37
|
|
|
$search->setConditions( $search->compare( '==', 'order.base.service.editor', 'core:lib/mshoplib' ) ); |
38
|
|
|
$result = $this->object->aggregate( $search, 'order.base.service.code' )->toArray(); |
39
|
|
|
|
40
|
|
|
$this->assertEquals( 4, count( $result ) ); |
41
|
|
|
$this->assertArrayHasKey( 'OGONE', $result ); |
42
|
|
|
$this->assertEquals( 2, $result['OGONE'] ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public function testAggregateAvg() |
47
|
|
|
{ |
48
|
|
|
$search = $this->object->createSearch(); |
49
|
|
|
$search->setConditions( $search->compare( '==', 'order.base.service.editor', 'core:lib/mshoplib' ) ); |
50
|
|
|
$result = $this->object->aggregate( $search, 'order.base.service.type', 'order.base.service.costs', 'avg' )->toArray(); |
51
|
|
|
|
52
|
|
|
$this->assertEquals( 2, count( $result ) ); |
53
|
|
|
$this->assertArrayHasKey( 'delivery', $result ); |
54
|
|
|
$this->assertEquals( '5.00', round( $result['delivery'], 2 ) ); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
public function testAggregateSum() |
59
|
|
|
{ |
60
|
|
|
$search = $this->object->createSearch(); |
61
|
|
|
$search->setConditions( $search->compare( '==', 'order.base.service.editor', 'core:lib/mshoplib' ) ); |
62
|
|
|
$result = $this->object->aggregate( $search, 'order.base.service.type', 'order.base.service.costs', 'sum' )->toArray(); |
63
|
|
|
|
64
|
|
|
$this->assertEquals( 2, count( $result ) ); |
65
|
|
|
$this->assertArrayHasKey( 'delivery', $result ); |
66
|
|
|
$this->assertEquals( '20.00', $result['delivery'] ); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
public function testClear() |
71
|
|
|
{ |
72
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->clear( [-1] ) ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
public function testDeleteItems() |
77
|
|
|
{ |
78
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->deleteItems( [-1] ) ); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
public function testGetResourceType() |
83
|
|
|
{ |
84
|
|
|
$result = $this->object->getResourceType(); |
85
|
|
|
|
86
|
|
|
$this->assertContains( 'order/base/service', $result ); |
87
|
|
|
$this->assertContains( 'order/base/service/attribute', $result ); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
public function testGetSearchAttributes() |
92
|
|
|
{ |
93
|
|
|
foreach( $this->object->getSearchAttributes() as $attribute ) |
94
|
|
|
{ |
95
|
|
|
$this->assertInstanceOf( \Aimeos\MW\Criteria\Attribute\Iface::class, $attribute ); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
public function testCreateItem() |
101
|
|
|
{ |
102
|
|
|
$actual = $this->object->createItem(); |
103
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Iface::class, $actual ); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
public function testCreateSearch() |
108
|
|
|
{ |
109
|
|
|
$this->assertInstanceOf( \Aimeos\MW\Criteria\Iface::class, $this->object->createSearch() ); |
110
|
|
|
$this->assertInstanceOf( \Aimeos\MW\Criteria\Iface::class, $this->object->createSearch( true ) ); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
public function testSearchItems() |
115
|
|
|
{ |
116
|
|
|
$siteid = $this->context->getLocale()->getSiteId(); |
117
|
|
|
|
118
|
|
|
$total = 0; |
119
|
|
|
$search = $this->object->createSearch(); |
120
|
|
|
|
121
|
|
|
$expr = []; |
122
|
|
|
$expr[] = $search->compare( '!=', 'order.base.service.id', null ); |
123
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.siteid', $siteid ); |
124
|
|
|
$expr[] = $search->compare( '!=', 'order.base.service.baseid', null ); |
125
|
|
|
$expr[] = $search->compare( '!=', 'order.base.service.serviceid', null ); |
126
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.type', 'payment' ); |
127
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.code', 'OGONE' ); |
128
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.name', 'ogone' ); |
129
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.mediaurl', 'somewhere/thump1.jpg' ); |
130
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.price', '0.00' ); |
131
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.costs', '0.00' ); |
132
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.rebate', '0.00' ); |
133
|
|
|
$expr[] = $search->compare( '=~', 'order.base.service.taxrates', '{' ); |
134
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.taxflag', 1 ); |
135
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.taxvalue', '0.00' ); |
136
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.position', 0 ); |
137
|
|
|
$expr[] = $search->compare( '>=', 'order.base.service.mtime', '1970-01-01 00:00:00' ); |
138
|
|
|
$expr[] = $search->compare( '>=', 'order.base.service.ctime', '1970-01-01 00:00:00' ); |
139
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.editor', $this->editor ); |
140
|
|
|
|
141
|
|
|
$expr[] = $search->compare( '!=', 'order.base.service.attribute.id', null ); |
142
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.attribute.siteid', $siteid ); |
143
|
|
|
$expr[] = $search->compare( '!=', 'order.base.service.attribute.parentid', null ); |
144
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.attribute.code', 'NAME' ); |
145
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.attribute.value', '"CreditCard"' ); |
146
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.attribute.quantity', 1 ); |
147
|
|
|
$expr[] = $search->compare( '>=', 'order.base.service.attribute.mtime', '1970-01-01 00:00:00' ); |
148
|
|
|
$expr[] = $search->compare( '>=', 'order.base.service.attribute.ctime', '1970-01-01 00:00:00' ); |
149
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.attribute.editor', $this->editor ); |
150
|
|
|
|
151
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
152
|
|
|
$result = $this->object->searchItems( $search, [], $total )->toArray(); |
153
|
|
|
|
154
|
|
|
$this->assertEquals( 1, count( $result ) ); |
155
|
|
|
$this->assertEquals( 1, $total ); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
|
159
|
|
|
public function testSearchItemRef() |
160
|
|
|
{ |
161
|
|
|
$search = $this->object->createSearch()->setSlice( 0, 1 ); |
162
|
|
|
$search->setConditions( $search->compare( '==', 'order.base.service.code', 'OGONE' ) ); |
163
|
|
|
$result = $this->object->searchItems( $search, ['service'] ); |
164
|
|
|
|
165
|
|
|
$this->assertEquals( 1, count( $result ) ); |
166
|
|
|
$this->assertNotNull( $result->first()->getServiceItem() ); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
public function testSearchItemTotal() |
171
|
|
|
{ |
172
|
|
|
$total = 0; |
173
|
|
|
$search = $this->object->createSearch()->setSlice( 0, 1 ); |
174
|
|
|
|
175
|
|
|
$search->setConditions( $search->combine( '&&', [ |
176
|
|
|
$search->compare( '==', 'order.base.service.code', array( 'OGONE', 'not exists' ) ), |
177
|
|
|
$search->compare( '==', 'order.base.service.editor', $this->editor ) |
178
|
|
|
] ) ); |
179
|
|
|
|
180
|
|
|
$results = $this->object->searchItems( $search, [], $total )->toArray(); |
181
|
|
|
|
182
|
|
|
$this->assertEquals( 1, count( $results ) ); |
183
|
|
|
$this->assertEquals( 2, $total ); |
184
|
|
|
|
185
|
|
|
foreach( $results as $itemId => $item ) { |
186
|
|
|
$this->assertEquals( $itemId, $item->getId() ); |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
|
191
|
|
|
public function testGetSubManager() |
192
|
|
|
{ |
193
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'attribute' ) ); |
194
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'attribute', 'Standard' ) ); |
195
|
|
|
|
196
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
197
|
|
|
$this->object->getSubManager( 'unknown' ); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
|
201
|
|
|
public function testGetSubManagerInvalidName() |
202
|
|
|
{ |
203
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
204
|
|
|
$this->object->getSubManager( 'attribute', 'unknown' ); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
|
208
|
|
|
public function testGetSubManagerInvalidType() |
209
|
|
|
{ |
210
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
211
|
|
|
$this->object->getSubManager( '$$$' ); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
|
215
|
|
|
public function testGetSubManagerInvalidDefaultName() |
216
|
|
|
{ |
217
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
218
|
|
|
$this->object->getSubManager( 'attribute', '$$$' ); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
|
222
|
|
|
public function testGetItem() |
223
|
|
|
{ |
224
|
|
|
$search = $this->object->createSearch()->setSlice( 0, 1 ); |
225
|
|
|
$conditions = array( |
226
|
|
|
$search->compare( '==', 'order.base.service.code', 'OGONE' ), |
227
|
|
|
$search->compare( '==', 'order.base.service.editor', $this->editor ), |
228
|
|
|
); |
229
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
230
|
|
|
$results = $this->object->searchItems( $search )->toArray(); |
231
|
|
|
|
232
|
|
|
if( !( $item = reset( $results ) ) ) { |
233
|
|
|
throw new \RuntimeException( 'empty results' ); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
$actual = $this->object->getItem( $item->getId() ); |
237
|
|
|
$this->assertEquals( $item, $actual ); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
|
241
|
|
|
public function testSaveUpdateDeleteItem() |
242
|
|
|
{ |
243
|
|
|
$search = $this->object->createSearch(); |
244
|
|
|
$conditions = array( |
245
|
|
|
$search->compare( '==', 'order.base.service.code', 'OGONE' ), |
246
|
|
|
$search->compare( '==', 'order.base.service.editor', $this->editor ), |
247
|
|
|
$search->compare( '==', 'order.base.service.attribute.code', 'NAME' ), |
248
|
|
|
); |
249
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
250
|
|
|
$orderItems = $this->object->searchItems( $search )->toArray(); |
251
|
|
|
|
252
|
|
|
if( !( $item = reset( $orderItems ) ) ) { |
253
|
|
|
throw new \RuntimeException( 'empty search result' ); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
$item->setId( null ); |
257
|
|
|
$item->setCode( 'unittest1' ); |
258
|
|
|
$resultSaved = $this->object->saveItem( $item ); |
259
|
|
|
$itemSaved = $this->object->getItem( $item->getId() ); |
260
|
|
|
|
261
|
|
|
|
262
|
|
|
$itemExp = clone $itemSaved; |
263
|
|
|
$itemExp->setCode( 'unittest1' ); |
264
|
|
|
$resultUpd = $this->object->saveItem( $itemExp ); |
265
|
|
|
$itemUpd = $this->object->getItem( $itemExp->getId() ); |
266
|
|
|
|
267
|
|
|
$this->object->deleteItem( $itemSaved->getId() ); |
268
|
|
|
|
269
|
|
|
|
270
|
|
|
$this->assertTrue( $item->getId() !== null ); |
271
|
|
|
$this->assertNotEquals( [], $item->getAttributeItems() ); |
272
|
|
|
$this->assertEquals( $item->getId(), $itemSaved->getId() ); |
273
|
|
|
$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
274
|
|
|
$this->assertEquals( $item->getBaseId(), $itemSaved->getBaseId() ); |
275
|
|
|
$this->assertEquals( $item->getServiceId(), $itemSaved->getServiceId() ); |
276
|
|
|
$this->assertEquals( $item->getType(), $itemSaved->getType() ); |
277
|
|
|
$this->assertEquals( $item->getCode(), $itemSaved->getCode() ); |
278
|
|
|
$this->assertEquals( $item->getName(), $itemSaved->getName() ); |
279
|
|
|
$this->assertEquals( $item->getMediaUrl(), $itemSaved->getMediaUrl() ); |
280
|
|
|
$this->assertEquals( $item->getPrice()->getValue(), $itemSaved->getPrice()->getValue() ); |
281
|
|
|
$this->assertEquals( $item->getPrice()->getCosts(), $itemSaved->getPrice()->getCosts() ); |
282
|
|
|
$this->assertEquals( $item->getPrice()->getRebate(), $itemSaved->getPrice()->getRebate() ); |
283
|
|
|
$this->assertEquals( $item->getPrice()->getTaxflag(), $itemSaved->getPrice()->getTaxflag() ); |
284
|
|
|
$this->assertEquals( $item->getPrice()->getTaxValue(), $itemSaved->getPrice()->getTaxValue() ); |
285
|
|
|
|
286
|
|
|
$this->assertEquals( $this->editor, $itemSaved->getEditor() ); |
287
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
288
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
289
|
|
|
|
290
|
|
|
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
291
|
|
|
$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
292
|
|
|
$this->assertEquals( $itemExp->getBaseId(), $itemUpd->getBaseId() ); |
293
|
|
|
$this->assertEquals( $itemExp->getServiceId(), $itemUpd->getServiceID() ); |
294
|
|
|
$this->assertEquals( $itemExp->getType(), $itemUpd->getType() ); |
295
|
|
|
$this->assertEquals( $itemExp->getCode(), $itemUpd->getCode() ); |
296
|
|
|
$this->assertEquals( $itemExp->getName(), $itemUpd->getName() ); |
297
|
|
|
$this->assertEquals( $itemExp->getMediaUrl(), $itemUpd->getMediaUrl() ); |
298
|
|
|
$this->assertEquals( $itemExp->getPrice()->getValue(), $itemUpd->getPrice()->getValue() ); |
299
|
|
|
$this->assertEquals( $itemExp->getPrice()->getCosts(), $itemUpd->getPrice()->getCosts() ); |
300
|
|
|
$this->assertEquals( $itemExp->getPrice()->getRebate(), $itemUpd->getPrice()->getRebate() ); |
301
|
|
|
$this->assertEquals( $itemExp->getPrice()->getTaxflag(), $itemUpd->getPrice()->getTaxflag() ); |
302
|
|
|
$this->assertEquals( $itemExp->getPrice()->getTaxValue(), $itemUpd->getPrice()->getTaxValue() ); |
303
|
|
|
$this->assertEquals( [], $itemUpd->getAttributeItems()->toArray() ); |
304
|
|
|
|
305
|
|
|
$this->assertEquals( $this->editor, $itemUpd->getEditor() ); |
306
|
|
|
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
307
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
308
|
|
|
|
309
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved ); |
310
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd ); |
311
|
|
|
|
312
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
313
|
|
|
$this->object->getItem( $itemSaved->getId() ); |
314
|
|
|
} |
315
|
|
|
} |
316
|
|
|
|