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