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
|
|
|
namespace Aimeos\MShop\Customer\Manager; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $fixture; |
16
|
|
|
private $address; |
17
|
|
|
private $editor = ''; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
protected function setUp() |
21
|
|
|
{ |
22
|
|
|
$this->editor = \TestHelperMShop::getContext()->getEditor(); |
23
|
|
|
$this->object = new \Aimeos\MShop\Customer\Manager\Standard( \TestHelperMShop::getContext() ); |
24
|
|
|
|
25
|
|
|
$this->fixture = array( |
26
|
|
|
'customer.label' => 'unitTest', |
27
|
|
|
'customer.status' => 2, |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
$this->address = new \Aimeos\MShop\Common\Item\Address\Standard( 'customer.' ); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
protected function tearDown() |
35
|
|
|
{ |
36
|
|
|
unset( $this->object, $this->fixture, $this->address ); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
public function testCleanup() |
41
|
|
|
{ |
42
|
|
|
$this->object->cleanup( array( -1 ) ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public function testGetResourceType() |
47
|
|
|
{ |
48
|
|
|
$result = $this->object->getResourceType(); |
49
|
|
|
|
50
|
|
|
$this->assertContains( 'customer', $result ); |
51
|
|
|
$this->assertContains( 'customer/address', $result ); |
52
|
|
|
$this->assertContains( 'customer/group', $result ); |
53
|
|
|
$this->assertContains( 'customer/lists', $result ); |
54
|
|
|
$this->assertContains( 'customer/lists/type', $result ); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
public function testGetSearchAttributes() |
59
|
|
|
{ |
60
|
|
|
foreach( $this->object->getSearchAttributes() as $attribute ) |
61
|
|
|
{ |
62
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Attribute\\Iface', $attribute ); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
public function testCreateItem() |
68
|
|
|
{ |
69
|
|
|
$item = $this->object->createItem(); |
70
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Customer\\Item\\Iface', $item ); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
public function testFindItem() |
75
|
|
|
{ |
76
|
|
|
$item = $this->object->findItem( 'UTC003' ); |
77
|
|
|
|
78
|
|
|
$this->assertEquals( 'UTC003', $item->getCode() ); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
public function testGetItem() |
83
|
|
|
{ |
84
|
|
|
$search = $this->object->createSearch(); |
85
|
|
|
$conditions = array( |
86
|
|
|
$search->compare( '==', 'customer.code', 'UTC003' ), |
87
|
|
|
$search->compare( '==', 'customer.editor', $this->editor ) |
88
|
|
|
); |
89
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
90
|
|
|
$items = $this->object->searchItems( $search, array( 'text' ) ); |
91
|
|
|
|
92
|
|
|
if( ( $expected = reset( $items ) ) === false ) { |
93
|
|
|
throw new \RuntimeException( 'No customer item with code "UTC003" found' ); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$actual = $this->object->getItem( $expected->getId(), array( 'text' ) ); |
97
|
|
|
|
98
|
|
|
$this->assertEquals( $expected, $actual ); |
99
|
|
|
$this->assertEquals( 3, count( $actual->getListItems( 'text', null, null, false ) ) ); |
100
|
|
|
$this->assertEquals( 3, count( $actual->getRefItems( 'text', null, null, false ) ) ); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
public function testSaveInvalid() |
105
|
|
|
{ |
106
|
|
|
$this->setExpectedException( '\Aimeos\MShop\Customer\Exception' ); |
107
|
|
|
$this->object->saveItem( new \Aimeos\MShop\Locale\Item\Standard() ); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
public function testSaveUpdateDeleteItem() |
112
|
|
|
{ |
113
|
|
|
$item = $this->object->createItem(); |
114
|
|
|
|
115
|
|
|
$item->setCode( 'unitTest' ); |
116
|
|
|
$item->setLabel( 'unitTest' ); |
117
|
|
|
$item->setGroups( array( 1, 2, 3 ) ); |
118
|
|
|
$resultSaved = $this->object->saveItem( $item ); |
119
|
|
|
$itemSaved = $this->object->getItem( $item->getId(), array( 'customer/group' ) ); |
120
|
|
|
|
121
|
|
|
$itemExp = clone $itemSaved; |
122
|
|
|
$itemExp->setCode( 'unitTest2' ); |
123
|
|
|
$itemExp->setLabel( 'unitTest2' ); |
124
|
|
|
$itemExp->setGroups( array( 2, 4 ) ); |
125
|
|
|
$resultUpd = $this->object->saveItem( $itemExp ); |
126
|
|
|
$itemUpd = $this->object->getItem( $itemExp->getId(), array( 'customer/group' ) ); |
127
|
|
|
|
128
|
|
|
$this->object->deleteItem( $item->getId() ); |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
$this->assertTrue( $item->getId() !== null ); |
132
|
|
|
$this->assertEquals( $item->getId(), $itemSaved->getId() ); |
133
|
|
|
$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
134
|
|
|
$this->assertEquals( $item->getStatus(), $itemSaved->getStatus() ); |
135
|
|
|
$this->assertEquals( $item->getCode(), $itemSaved->getCode() ); |
136
|
|
|
$this->assertEquals( $item->getLabel(), $itemSaved->getLabel() ); |
137
|
|
|
$this->assertEquals( $item->getPaymentAddress(), $itemSaved->getPaymentAddress() ); |
138
|
|
|
$this->assertEquals( $item->getBirthday(), $itemSaved->getBirthday() ); |
139
|
|
|
$this->assertEquals( $item->getPassword(), $itemSaved->getPassword() ); |
140
|
|
|
$this->assertEquals( $item->getGroups(), $itemSaved->getGroups() ); |
141
|
|
|
$this->assertEquals( $itemSaved->getPaymentAddress()->getId(), $itemSaved->getId() ); |
142
|
|
|
|
143
|
|
|
$this->assertEquals( $this->editor, $itemSaved->getEditor() ); |
144
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
145
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
146
|
|
|
|
147
|
|
|
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
148
|
|
|
$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
149
|
|
|
$this->assertEquals( $itemExp->getStatus(), $itemUpd->getStatus() ); |
150
|
|
|
$this->assertEquals( $itemExp->getCode(), $itemUpd->getCode() ); |
151
|
|
|
$this->assertEquals( $itemExp->getLabel(), $itemUpd->getLabel() ); |
152
|
|
|
$this->assertEquals( $itemExp->getPaymentAddress(), $itemUpd->getPaymentAddress() ); |
153
|
|
|
$this->assertEquals( $itemExp->getBirthday(), $itemUpd->getBirthday() ); |
154
|
|
|
$this->assertEquals( $itemExp->getPassword(), $itemUpd->getPassword() ); |
155
|
|
|
$this->assertEquals( $itemExp->getGroups(), $itemUpd->getGroups() ); |
156
|
|
|
$this->assertEquals( $itemUpd->getPaymentAddress()->getId(), $itemUpd->getId() ); |
157
|
|
|
|
158
|
|
|
$this->assertEquals( $this->editor, $itemUpd->getEditor() ); |
159
|
|
|
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
160
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
161
|
|
|
|
162
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultSaved ); |
163
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultUpd ); |
164
|
|
|
|
165
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
166
|
|
|
$this->object->getItem( $item->getId() ); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
public function testGetSavePropertyItems() |
171
|
|
|
{ |
172
|
|
|
$item = $this->object->findItem( 'UTC001', ['customer/property'] ); |
173
|
|
|
|
174
|
|
|
$item->setId( null )->setCode( 'xyz' ); |
175
|
|
|
$this->object->saveItem( $item ); |
176
|
|
|
|
177
|
|
|
$item2 = $this->object->findItem( 'UTC001', ['customer/property'] ); |
178
|
|
|
|
179
|
|
|
$this->object->deleteItem( $item->getId() ); |
180
|
|
|
|
181
|
|
|
$this->assertEquals( 1, count( $item->getPropertyItems() ) ); |
182
|
|
|
$this->assertEquals( 1, count( $item2->getPropertyItems() ) ); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
|
186
|
|
|
public function testCreateSearch() |
187
|
|
|
{ |
188
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $this->object->createSearch() ); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
|
192
|
|
|
public function testSearchItems() |
193
|
|
|
{ |
194
|
|
|
$search = $this->object->createSearch(); |
195
|
|
|
|
196
|
|
|
$expr = []; |
197
|
|
|
$expr[] = $search->compare( '!=', 'customer.id', null ); |
198
|
|
|
$expr[] = $search->compare( '==', 'customer.label', 'unitCustomer002' ); |
199
|
|
|
$expr[] = $search->compare( '==', 'customer.code', 'UTC002' ); |
200
|
|
|
|
201
|
|
|
$expr[] = $search->compare( '>=', 'customer.salutation', '' ); |
202
|
|
|
$expr[] = $search->compare( '>=', 'customer.company', '' ); |
203
|
|
|
$expr[] = $search->compare( '>=', 'customer.vatid', '' ); |
204
|
|
|
$expr[] = $search->compare( '>=', 'customer.title', '' ); |
205
|
|
|
$expr[] = $search->compare( '>=', 'customer.firstname', '' ); |
206
|
|
|
$expr[] = $search->compare( '>=', 'customer.lastname', '' ); |
207
|
|
|
$expr[] = $search->compare( '>=', 'customer.address1', '' ); |
208
|
|
|
$expr[] = $search->compare( '>=', 'customer.address2', '' ); |
209
|
|
|
$expr[] = $search->compare( '>=', 'customer.address3', '' ); |
210
|
|
|
$expr[] = $search->compare( '>=', 'customer.postal', '' ); |
211
|
|
|
$expr[] = $search->compare( '>=', 'customer.city', '' ); |
212
|
|
|
$expr[] = $search->compare( '>=', 'customer.state', '' ); |
213
|
|
|
$expr[] = $search->compare( '!=', 'customer.languageid', null ); |
214
|
|
|
$expr[] = $search->compare( '==', 'customer.countryid', null ); |
215
|
|
|
$expr[] = $search->compare( '>=', 'customer.telephone', '' ); |
216
|
|
|
$expr[] = $search->compare( '>=', 'customer.email', '' ); |
217
|
|
|
$expr[] = $search->compare( '>=', 'customer.telefax', '' ); |
218
|
|
|
$expr[] = $search->compare( '>=', 'customer.website', '' ); |
219
|
|
|
|
220
|
|
|
$expr[] = $search->compare( '==', 'customer.birthday', null ); |
221
|
|
|
$expr[] = $search->compare( '>=', 'customer.password', '' ); |
222
|
|
|
$expr[] = $search->compare( '==', 'customer.status', 1 ); |
223
|
|
|
$expr[] = $search->compare( '>', 'customer.mtime', '1970-01-01 00:00:00' ); |
224
|
|
|
$expr[] = $search->compare( '>', 'customer.ctime', '1970-01-01 00:00:00' ); |
225
|
|
|
$expr[] = $search->compare( '==', 'customer.editor', $this->editor ); |
226
|
|
|
|
227
|
|
|
$expr[] = $search->compare( '!=', 'customer.address.id', null ); |
228
|
|
|
$expr[] = $search->compare( '!=', 'customer.address.parentid', null ); |
229
|
|
|
$expr[] = $search->compare( '==', 'customer.address.company', 'Example company LLC' ); |
230
|
|
|
$expr[] = $search->compare( '==', 'customer.address.vatid', 'DE999999999' ); |
231
|
|
|
$expr[] = $search->compare( '==', 'customer.address.salutation', 'mr' ); |
232
|
|
|
$expr[] = $search->compare( '==', 'customer.address.title', 'Dr.' ); |
233
|
|
|
$expr[] = $search->compare( '==', 'customer.address.firstname', 'Good' ); |
234
|
|
|
$expr[] = $search->compare( '==', 'customer.address.lastname', 'Unittest' ); |
235
|
|
|
$expr[] = $search->compare( '==', 'customer.address.address1', 'Pickhuben' ); |
236
|
|
|
$expr[] = $search->compare( '==', 'customer.address.address2', '2-4' ); |
237
|
|
|
$expr[] = $search->compare( '==', 'customer.address.address3', '' ); |
238
|
|
|
$expr[] = $search->compare( '==', 'customer.address.postal', '11099' ); |
239
|
|
|
$expr[] = $search->compare( '==', 'customer.address.city', 'Berlin' ); |
240
|
|
|
$expr[] = $search->compare( '==', 'customer.address.state', 'Berlin' ); |
241
|
|
|
$expr[] = $search->compare( '==', 'customer.address.languageid', 'de' ); |
242
|
|
|
$expr[] = $search->compare( '==', 'customer.address.countryid', 'DE' ); |
243
|
|
|
$expr[] = $search->compare( '==', 'customer.address.telephone', '055544332221' ); |
244
|
|
|
$expr[] = $search->compare( '==', 'customer.address.email', '[email protected]' ); |
245
|
|
|
$expr[] = $search->compare( '==', 'customer.address.telefax', '055544333212' ); |
246
|
|
|
$expr[] = $search->compare( '==', 'customer.address.website', 'www.example.com' ); |
247
|
|
|
$expr[] = $search->compare( '==', 'customer.address.flag', 0 ); |
248
|
|
|
$expr[] = $search->compare( '==', 'customer.address.position', 1 ); |
249
|
|
|
$expr[] = $search->compare( '>', 'customer.address.mtime', '1970-01-01 00:00:00' ); |
250
|
|
|
$expr[] = $search->compare( '>', 'customer.address.ctime', '1970-01-01 00:00:00' ); |
251
|
|
|
$expr[] = $search->compare( '==', 'customer.address.editor', $this->editor ); |
252
|
|
|
|
253
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
254
|
|
|
$result = $this->object->searchItems( $search ); |
255
|
|
|
$this->assertEquals( 1, count( $result ) ); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
|
259
|
|
|
public function testSearchItemsTotal() |
260
|
|
|
{ |
261
|
|
|
$search = $this->object->createSearch(); |
262
|
|
|
$search->setConditions( $search->compare( '==', 'customer.address.editor', $this->editor ) ); |
263
|
|
|
$search->setSlice( 0, 2 ); |
264
|
|
|
|
265
|
|
|
$total = 0; |
266
|
|
|
$results = $this->object->searchItems( $search, [], $total ); |
267
|
|
|
|
268
|
|
|
$this->assertEquals( 2, count( $results ) ); |
269
|
|
|
$this->assertEquals( 3, $total ); |
270
|
|
|
|
271
|
|
|
foreach( $results as $itemId => $item ) { |
272
|
|
|
$this->assertEquals( $itemId, $item->getId() ); |
273
|
|
|
} |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
|
277
|
|
|
public function testSearchItemsCriteria() |
278
|
|
|
{ |
279
|
|
|
$search = $this->object->createSearch( true ); |
280
|
|
|
$conditions = array( |
281
|
|
|
$search->compare( '==', 'customer.address.editor', $this->editor ), |
282
|
|
|
$search->getConditions() |
283
|
|
|
); |
284
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
285
|
|
|
$this->assertEquals( 2, count( $this->object->searchItems( $search ) ) ); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
|
289
|
|
|
public function testSearchItemsRef() |
290
|
|
|
{ |
291
|
|
|
$search = $this->object->createSearch(); |
292
|
|
|
$search->setConditions( $search->compare( '==', 'customer.code', 'UTC001' ) ); |
293
|
|
|
|
294
|
|
|
$results = $this->object->searchItems( $search, ['customer/address', 'text'] ); |
295
|
|
|
|
296
|
|
|
if( ( $item = reset( $results ) ) === false ) { |
297
|
|
|
throw new \Exception( 'No customer item for "UTC001" available' ); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
$this->assertEquals( 1, count( $item->getRefItems( 'text', null, null, false ) ) ); |
301
|
|
|
$this->assertEquals( 1, count( $item->getAddressItems() ) ); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
|
305
|
|
|
public function testGetSubManager() |
306
|
|
|
{ |
307
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'address' ) ); |
308
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'address', 'Standard' ) ); |
309
|
|
|
|
310
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
311
|
|
|
$this->object->getSubManager( 'unknown' ); |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
|
315
|
|
|
public function testGetSubManagerInvalidName() |
316
|
|
|
{ |
317
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
318
|
|
|
$this->object->getSubManager( 'address', 'unknown' ); |
319
|
|
|
} |
320
|
|
|
} |
321
|
|
|
|