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