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