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-2017 |
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() |
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() |
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:unittest' ) ); |
38
|
|
|
$result = $this->object->aggregate( $search, 'order.base.service.code' ); |
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:unittest' ) ); |
50
|
|
|
$result = $this->object->aggregate( $search, 'order.base.service.type', 'order.base.service.costs', 'avg' ); |
51
|
|
|
|
52
|
|
|
$this->assertEquals( 2, count( $result ) ); |
53
|
|
|
$this->assertArrayHasKey( 'delivery', $result ); |
54
|
|
|
$this->assertEquals( '5.00', $result['delivery'] ); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
public function testAggregateSum() |
59
|
|
|
{ |
60
|
|
|
$search = $this->object->createSearch(); |
61
|
|
|
$search->setConditions( $search->compare( '==', 'order.base.service.editor', 'core:unittest' ) ); |
62
|
|
|
$result = $this->object->aggregate( $search, 'order.base.service.type', 'order.base.service.costs', 'sum' ); |
63
|
|
|
|
64
|
|
|
$this->assertEquals( 2, count( $result ) ); |
65
|
|
|
$this->assertArrayHasKey( 'delivery', $result ); |
66
|
|
|
$this->assertEquals( '5.00', $result['delivery'] ); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
public function testCleanup() |
71
|
|
|
{ |
72
|
|
|
$this->object->cleanup( array( -1 ) ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
public function testGetResourceType() |
77
|
|
|
{ |
78
|
|
|
$result = $this->object->getResourceType(); |
79
|
|
|
|
80
|
|
|
$this->assertContains( 'order/base/service', $result ); |
81
|
|
|
$this->assertContains( 'order/base/service/attribute', $result ); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
public function testGetSearchAttributes() |
86
|
|
|
{ |
87
|
|
|
foreach( $this->object->getSearchAttributes() as $attribute ) |
88
|
|
|
{ |
89
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Attribute\\Iface', $attribute ); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
public function testCreateItem() |
95
|
|
|
{ |
96
|
|
|
$actual = $this->object->createItem(); |
97
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Order\\Item\\Base\\Service\\Iface', $actual ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
public function testCreateSearch() |
102
|
|
|
{ |
103
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $this->object->createSearch() ); |
104
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $this->object->createSearch( true ) ); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
public function testSearchItems() |
109
|
|
|
{ |
110
|
|
|
$siteid = $this->context->getLocale()->getSiteId(); |
111
|
|
|
|
112
|
|
|
$total = 0; |
113
|
|
|
$search = $this->object->createSearch(); |
114
|
|
|
|
115
|
|
|
$expr = []; |
116
|
|
|
$expr[] = $search->compare( '!=', 'order.base.service.id', null ); |
117
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.siteid', $siteid ); |
118
|
|
|
$expr[] = $search->compare( '!=', 'order.base.service.baseid', null ); |
119
|
|
|
$expr[] = $search->compare( '!=', 'order.base.service.serviceid', null ); |
120
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.type', 'payment' ); |
121
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.code', 'OGONE' ); |
122
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.name', 'ogone' ); |
123
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.mediaurl', 'somewhere/thump1.jpg' ); |
124
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.price', '0.00' ); |
125
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.costs', '0.00' ); |
126
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.rebate', '0.00' ); |
127
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.taxrate', '0.00' ); |
128
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.taxflag', 1 ); |
129
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.taxvalue', '0.00' ); |
130
|
|
|
$expr[] = $search->compare( '>=', 'order.base.service.mtime', '1970-01-01 00:00:00' ); |
131
|
|
|
$expr[] = $search->compare( '>=', 'order.base.service.ctime', '1970-01-01 00:00:00' ); |
132
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.editor', $this->editor ); |
133
|
|
|
|
134
|
|
|
$expr[] = $search->compare( '!=', 'order.base.service.attribute.id', null ); |
135
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.attribute.siteid', $siteid ); |
136
|
|
|
$expr[] = $search->compare( '!=', 'order.base.service.attribute.parentid', null ); |
137
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.attribute.code', 'NAME' ); |
138
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.attribute.value', '"CreditCard"' ); |
139
|
|
|
$expr[] = $search->compare( '>=', 'order.base.service.attribute.mtime', '1970-01-01 00:00:00' ); |
140
|
|
|
$expr[] = $search->compare( '>=', 'order.base.service.attribute.ctime', '1970-01-01 00:00:00' ); |
141
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.attribute.editor', $this->editor ); |
142
|
|
|
|
143
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
144
|
|
|
$result = $this->object->searchItems( $search, [], $total ); |
145
|
|
|
|
146
|
|
|
$this->assertEquals( 1, count( $result ) ); |
147
|
|
|
$this->assertEquals( 1, $total ); |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
$search = $this->object->createSearch(); |
151
|
|
|
$conditions = array( |
152
|
|
|
$search->compare( '==', 'order.base.service.code', array( 'OGONE', 'not exists' ) ), |
153
|
|
|
$search->compare( '==', 'order.base.service.editor', $this->editor ) |
154
|
|
|
); |
155
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
156
|
|
|
$search->setSlice( 0, 1 ); |
157
|
|
|
$results = $this->object->searchItems( $search, [], $total ); |
158
|
|
|
|
159
|
|
|
$this->assertEquals( 1, count( $results ) ); |
160
|
|
|
$this->assertEquals( 2, $total ); |
161
|
|
|
|
162
|
|
|
foreach( $results as $itemId => $item ) { |
163
|
|
|
$this->assertEquals( $itemId, $item->getId() ); |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
|
168
|
|
|
public function testGetSubManager() |
169
|
|
|
{ |
170
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'attribute' ) ); |
171
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'attribute', 'Standard' ) ); |
172
|
|
|
|
173
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
174
|
|
|
$this->object->getSubManager( 'unknown' ); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
|
178
|
|
|
public function testGetSubManagerInvalidName() |
179
|
|
|
{ |
180
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
181
|
|
|
$this->object->getSubManager( 'attribute', 'unknown' ); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
|
185
|
|
|
public function testGetSubManagerInvalidType() |
186
|
|
|
{ |
187
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
188
|
|
|
$this->object->getSubManager( '$$$' ); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
|
192
|
|
|
public function testGetSubManagerInvalidDefaultName() |
193
|
|
|
{ |
194
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
195
|
|
|
$this->object->getSubManager( 'attribute', '$$$' ); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
|
199
|
|
|
public function testGetItem() |
200
|
|
|
{ |
201
|
|
|
$search = $this->object->createSearch(); |
202
|
|
|
$conditions = array( |
203
|
|
|
$search->compare( '==', 'order.base.service.code', 'OGONE' ), |
204
|
|
|
$search->compare( '==', 'order.base.service.editor', $this->editor ), |
205
|
|
|
); |
206
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
207
|
|
|
$results = $this->object->searchItems( $search ); |
208
|
|
|
|
209
|
|
|
if( !( $item = reset( $results ) ) ) { |
210
|
|
|
throw new \RuntimeException( 'empty results' ); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
$actual = $this->object->getItem( $item->getId() ); |
214
|
|
|
$this->assertEquals( $item, $actual ); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
|
218
|
|
|
public function testSaveInvalid() |
219
|
|
|
{ |
220
|
|
|
$this->setExpectedException( '\Aimeos\MShop\Order\Exception' ); |
221
|
|
|
$this->object->saveItem( new \Aimeos\MShop\Locale\Item\Standard() ); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
|
225
|
|
|
public function testSaveUpdateDeleteItem() |
226
|
|
|
{ |
227
|
|
|
$search = $this->object->createSearch(); |
228
|
|
|
$conditions = array( |
229
|
|
|
$search->compare( '==', 'order.base.service.code', 'OGONE' ), |
230
|
|
|
$search->compare( '==', 'order.base.service.editor', $this->editor ), |
231
|
|
|
$search->compare( '==', 'order.base.service.attribute.code', 'NAME' ), |
232
|
|
|
); |
233
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
234
|
|
|
$orderItems = $this->object->searchItems( $search ); |
235
|
|
|
|
236
|
|
|
if( !( $item = reset( $orderItems ) ) ) { |
237
|
|
|
throw new \RuntimeException( 'empty search result' ); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
$item->setId( null ); |
241
|
|
|
$item->setCode( 'unittest1' ); |
242
|
|
|
$resultSaved = $this->object->saveItem( $item ); |
243
|
|
|
$itemSaved = $this->object->getItem( $item->getId() ); |
244
|
|
|
|
245
|
|
|
|
246
|
|
|
$itemExp = clone $itemSaved; |
247
|
|
|
$itemExp->setCode( 'unittest1' ); |
248
|
|
|
$resultUpd = $this->object->saveItem( $itemExp ); |
249
|
|
|
$itemUpd = $this->object->getItem( $itemExp->getId() ); |
250
|
|
|
|
251
|
|
|
$this->object->deleteItem( $itemSaved->getId() ); |
252
|
|
|
|
253
|
|
|
|
254
|
|
|
$this->assertTrue( $item->getId() !== null ); |
255
|
|
|
$this->assertNotEquals( [], $item->getAttributes() ); |
256
|
|
|
$this->assertEquals( $item->getId(), $itemSaved->getId() ); |
257
|
|
|
$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
258
|
|
|
$this->assertEquals( $item->getBaseId(), $itemSaved->getBaseId() ); |
259
|
|
|
$this->assertEquals( $item->getServiceId(), $itemSaved->getServiceId() ); |
260
|
|
|
$this->assertEquals( $item->getType(), $itemSaved->getType() ); |
261
|
|
|
$this->assertEquals( $item->getCode(), $itemSaved->getCode() ); |
262
|
|
|
$this->assertEquals( $item->getName(), $itemSaved->getName() ); |
263
|
|
|
$this->assertEquals( $item->getMediaUrl(), $itemSaved->getMediaUrl() ); |
264
|
|
|
$this->assertEquals( $item->getPrice(), $itemSaved->getPrice() ); |
265
|
|
|
|
266
|
|
|
$this->assertEquals( $this->editor, $itemSaved->getEditor() ); |
267
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
268
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
269
|
|
|
|
270
|
|
|
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
271
|
|
|
$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
272
|
|
|
$this->assertEquals( $itemExp->getBaseId(), $itemUpd->getBaseId() ); |
273
|
|
|
$this->assertEquals( $itemExp->getServiceId(), $itemUpd->getServiceID() ); |
274
|
|
|
$this->assertEquals( $itemExp->getType(), $itemUpd->getType() ); |
275
|
|
|
$this->assertEquals( $itemExp->getCode(), $itemUpd->getCode() ); |
276
|
|
|
$this->assertEquals( $itemExp->getName(), $itemUpd->getName() ); |
277
|
|
|
$this->assertEquals( $itemExp->getMediaUrl(), $itemUpd->getMediaUrl() ); |
278
|
|
|
$this->assertEquals( $itemExp->getPrice(), $itemUpd->getPrice() ); |
279
|
|
|
$this->assertEquals( [], $itemUpd->getAttributes() ); |
280
|
|
|
|
281
|
|
|
$this->assertEquals( $this->editor, $itemUpd->getEditor() ); |
282
|
|
|
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
283
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
284
|
|
|
|
285
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultSaved ); |
286
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultUpd ); |
287
|
|
|
|
288
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
289
|
|
|
$this->object->getItem( $itemSaved->getId() ); |
290
|
|
|
} |
291
|
|
|
} |
292
|
|
|
|