|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2011 |
|
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2024 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
namespace Aimeos\MShop\Order\Manager\Address; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
private $context; |
|
16
|
|
|
private $object = null; |
|
17
|
|
|
private $editor = ''; |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
protected function setUp() : void |
|
21
|
|
|
{ |
|
22
|
|
|
$this->editor = \TestHelper::context()->editor(); |
|
23
|
|
|
$this->context = \TestHelper::context(); |
|
24
|
|
|
|
|
25
|
|
|
$this->object = new \Aimeos\MShop\Order\Manager\Address\Standard( $this->context ); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
protected function tearDown() : void |
|
30
|
|
|
{ |
|
31
|
|
|
unset( $this->object ); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
public function testAggregate() |
|
36
|
|
|
{ |
|
37
|
|
|
$search = $this->object->filter(); |
|
38
|
|
|
$search->setConditions( $search->compare( '==', 'order.address.editor', 'core' ) ); |
|
39
|
|
|
$result = $this->object->aggregate( $search, 'order.address.salutation' )->toArray(); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertEquals( 2, count( $result ) ); |
|
42
|
|
|
$this->assertArrayHasKey( 'ms', $result ); |
|
43
|
|
|
$this->assertEquals( 4, $result['ms'] ); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
public function testClear() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->clear( [-1] ) ); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
public function testDelete() |
|
54
|
|
|
{ |
|
55
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->delete( [-1] ) ); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
public function testCreate() |
|
60
|
|
|
{ |
|
61
|
|
|
$item = $this->object->create(); |
|
62
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Address\Iface::class, $item ); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
public function testFilter() |
|
67
|
|
|
{ |
|
68
|
|
|
$this->assertInstanceOf( \Aimeos\Base\Criteria\Iface::class, $this->object->filter() ); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
public function testGetResourceType() |
|
73
|
|
|
{ |
|
74
|
|
|
$result = $this->object->getResourceType(); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertContains( 'order/address', $result ); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
public function testGetSearchAttributes() |
|
81
|
|
|
{ |
|
82
|
|
|
foreach( $this->object->getSearchAttributes() as $attribute ) { |
|
83
|
|
|
$this->assertInstanceOf( \Aimeos\Base\Criteria\Attribute\Iface::class, $attribute ); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
public function testGet() |
|
89
|
|
|
{ |
|
90
|
|
|
$type = \Aimeos\MShop\Order\Item\Address\Base::TYPE_DELIVERY; |
|
91
|
|
|
|
|
92
|
|
|
$search = $this->object->filter()->slice( 0, 1 ); |
|
93
|
|
|
$conditions = array( |
|
94
|
|
|
$search->compare( '==', 'order.address.type', $type ), |
|
95
|
|
|
$search->compare( '==', 'order.address.editor', $this->editor ) |
|
96
|
|
|
); |
|
97
|
|
|
$search->setConditions( $search->and( $conditions ) ); |
|
98
|
|
|
$items = $this->object->search( $search )->toArray(); |
|
99
|
|
|
|
|
100
|
|
|
if( ( $item = reset( $items ) ) === false ) { |
|
101
|
|
|
throw new \RuntimeException( sprintf( 'No order base address item found for type "%1$s".', $type ) ); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
$this->assertEquals( $item, $this->object->get( $item->getId() ) ); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
|
|
109
|
|
|
public function testSaveUpdateDelete() |
|
110
|
|
|
{ |
|
111
|
|
|
$type = \Aimeos\MShop\Order\Item\Address\Base::TYPE_DELIVERY; |
|
112
|
|
|
|
|
113
|
|
|
$search = $this->object->filter(); |
|
114
|
|
|
$conditions = array( |
|
115
|
|
|
$search->compare( '==', 'order.address.type', $type ), |
|
116
|
|
|
$search->compare( '==', 'order.address.editor', $this->editor ) |
|
117
|
|
|
); |
|
118
|
|
|
$search->setConditions( $search->and( $conditions ) ); |
|
119
|
|
|
$items = $this->object->search( $search )->toArray(); |
|
120
|
|
|
|
|
121
|
|
|
if( ( $item = reset( $items ) ) === false ) { |
|
122
|
|
|
throw new \RuntimeException( sprintf( 'No order base address item found for type "%1$s".', $type ) ); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
$this->object->delete( $item->getId() ); |
|
126
|
|
|
$firstname = $item->getFirstname(); |
|
127
|
|
|
$oldId = $item->getId(); |
|
128
|
|
|
|
|
129
|
|
|
$item->setId( null ); |
|
130
|
|
|
$item->setFirstname( 'unittestdata' ); |
|
131
|
|
|
$resultSaved = $this->object->save( $item ); |
|
132
|
|
|
$itemSaved = $this->object->get( $item->getId() ); |
|
133
|
|
|
|
|
134
|
|
|
$itemExp = clone $itemSaved; |
|
135
|
|
|
$itemExp->setFirstname( $firstname ); |
|
136
|
|
|
$resultUpd = $this->object->save( $itemExp ); |
|
137
|
|
|
$itemUpd = $this->object->get( $itemExp->getId() ); |
|
138
|
|
|
|
|
139
|
|
|
|
|
140
|
|
|
$this->assertTrue( $item->getId() !== null ); |
|
141
|
|
|
$this->assertEquals( $item->getId(), $itemSaved->getId() ); |
|
142
|
|
|
$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
|
143
|
|
|
$this->assertEquals( $item->getParentId(), $itemSaved->getParentId() ); |
|
144
|
|
|
$this->assertEquals( $item->getAddressId(), $itemSaved->getAddressId() ); |
|
145
|
|
|
$this->assertEquals( $item->getType(), $itemSaved->getType() ); |
|
146
|
|
|
$this->assertEquals( $item->getCompany(), $itemSaved->getCompany() ); |
|
147
|
|
|
$this->assertEquals( $item->getVatID(), $itemSaved->getVatID() ); |
|
148
|
|
|
$this->assertEquals( $item->getSalutation(), $itemSaved->getSalutation() ); |
|
149
|
|
|
$this->assertEquals( $item->getTitle(), $itemSaved->getTitle() ); |
|
150
|
|
|
$this->assertEquals( $item->getFirstname(), $itemSaved->getFirstname() ); |
|
151
|
|
|
$this->assertEquals( $item->getLastname(), $itemSaved->getLastname() ); |
|
152
|
|
|
$this->assertEquals( $item->getAddress1(), $itemSaved->getAddress1() ); |
|
153
|
|
|
$this->assertEquals( $item->getAddress2(), $itemSaved->getAddress2() ); |
|
154
|
|
|
$this->assertEquals( $item->getAddress3(), $itemSaved->getAddress3() ); |
|
155
|
|
|
$this->assertEquals( $item->getPostal(), $itemSaved->getPostal() ); |
|
156
|
|
|
$this->assertEquals( $item->getCity(), $itemSaved->getCity() ); |
|
157
|
|
|
$this->assertEquals( $item->getState(), $itemSaved->getState() ); |
|
158
|
|
|
$this->assertEquals( $item->getCountryId(), $itemSaved->getCountryId() ); |
|
159
|
|
|
$this->assertEquals( $item->getLanguageId(), $itemSaved->getLanguageId() ); |
|
160
|
|
|
$this->assertEquals( $item->getTelephone(), $itemSaved->getTelephone() ); |
|
161
|
|
|
$this->assertEquals( $item->getMobile(), $itemSaved->getMobile() ); |
|
162
|
|
|
$this->assertEquals( $item->getEmail(), $itemSaved->getEmail() ); |
|
163
|
|
|
$this->assertEquals( $item->getTelefax(), $itemSaved->getTelefax() ); |
|
164
|
|
|
$this->assertEquals( $item->getWebsite(), $itemSaved->getWebsite() ); |
|
165
|
|
|
$this->assertEquals( $item->getLongitude(), $itemSaved->getLongitude() ); |
|
166
|
|
|
$this->assertEquals( $item->getLatitude(), $itemSaved->getLatitude() ); |
|
167
|
|
|
$this->assertEquals( $item->getPosition(), $itemSaved->getPosition() ); |
|
168
|
|
|
$this->assertEquals( $item->getBirthday(), $itemSaved->getBirthday() ); |
|
169
|
|
|
|
|
170
|
|
|
$this->assertEquals( $this->editor, $itemSaved->editor() ); |
|
171
|
|
|
$this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
|
172
|
|
|
$this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
|
173
|
|
|
|
|
174
|
|
|
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
|
175
|
|
|
$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
|
176
|
|
|
$this->assertEquals( $itemExp->getParentId(), $itemUpd->getParentId() ); |
|
177
|
|
|
$this->assertEquals( $itemExp->getAddressId(), $itemUpd->getAddressId() ); |
|
178
|
|
|
$this->assertEquals( $itemExp->getType(), $itemUpd->getType() ); |
|
179
|
|
|
$this->assertEquals( $itemExp->getCompany(), $itemUpd->getCompany() ); |
|
180
|
|
|
$this->assertEquals( $itemExp->getVatID(), $itemUpd->getVatID() ); |
|
181
|
|
|
$this->assertEquals( $itemExp->getSalutation(), $itemUpd->getSalutation() ); |
|
182
|
|
|
$this->assertEquals( $itemExp->getTitle(), $itemUpd->getTitle() ); |
|
183
|
|
|
$this->assertEquals( $itemExp->getFirstname(), $itemUpd->getFirstname() ); |
|
184
|
|
|
$this->assertEquals( $itemExp->getLastname(), $itemUpd->getLastname() ); |
|
185
|
|
|
$this->assertEquals( $itemExp->getAddress1(), $itemUpd->getAddress1() ); |
|
186
|
|
|
$this->assertEquals( $itemExp->getAddress2(), $itemUpd->getAddress2() ); |
|
187
|
|
|
$this->assertEquals( $itemExp->getAddress3(), $itemUpd->getAddress3() ); |
|
188
|
|
|
$this->assertEquals( $itemExp->getPostal(), $itemUpd->getPostal() ); |
|
189
|
|
|
$this->assertEquals( $itemExp->getCity(), $itemUpd->getCity() ); |
|
190
|
|
|
$this->assertEquals( $itemExp->getState(), $itemUpd->getState() ); |
|
191
|
|
|
$this->assertEquals( $itemExp->getCountryId(), $itemUpd->getCountryId() ); |
|
192
|
|
|
$this->assertEquals( $itemExp->getLanguageId(), $itemUpd->getLanguageId() ); |
|
193
|
|
|
$this->assertEquals( $itemExp->getTelephone(), $itemUpd->getTelephone() ); |
|
194
|
|
|
$this->assertEquals( $itemExp->getMobile(), $itemUpd->getMobile() ); |
|
195
|
|
|
$this->assertEquals( $itemExp->getEmail(), $itemUpd->getEmail() ); |
|
196
|
|
|
$this->assertEquals( $itemExp->getTelefax(), $itemUpd->getTelefax() ); |
|
197
|
|
|
$this->assertEquals( $itemExp->getWebsite(), $itemUpd->getWebsite() ); |
|
198
|
|
|
$this->assertEquals( $itemExp->getLongitude(), $itemUpd->getLongitude() ); |
|
199
|
|
|
$this->assertEquals( $itemExp->getLatitude(), $itemUpd->getLatitude() ); |
|
200
|
|
|
$this->assertEquals( $itemExp->getPosition(), $itemUpd->getPosition() ); |
|
201
|
|
|
$this->assertEquals( $itemExp->getBirthday(), $itemUpd->getBirthday() ); |
|
202
|
|
|
|
|
203
|
|
|
$this->assertEquals( $this->editor, $itemUpd->editor() ); |
|
204
|
|
|
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
|
205
|
|
|
$this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
|
206
|
|
|
|
|
207
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved ); |
|
208
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd ); |
|
209
|
|
|
|
|
210
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
|
211
|
|
|
$this->object->get( $oldId ); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
|
|
215
|
|
|
public function testSearchItem() |
|
216
|
|
|
{ |
|
217
|
|
|
$siteid = $this->context->locale()->getSiteId(); |
|
218
|
|
|
|
|
219
|
|
|
$total = 0; |
|
220
|
|
|
$search = $this->object->filter(); |
|
221
|
|
|
|
|
222
|
|
|
$expr = []; |
|
223
|
|
|
$expr[] = $search->compare( '!=', 'order.address.id', null ); |
|
224
|
|
|
$expr[] = $search->compare( '==', 'order.address.siteid', $siteid ); |
|
225
|
|
|
$expr[] = $search->compare( '!=', 'order.address.parentid', null ); |
|
226
|
|
|
$expr[] = $search->compare( '==', 'order.address.addressid', '103' ); |
|
227
|
|
|
$expr[] = $search->compare( '==', 'order.address.type', 'payment' ); |
|
228
|
|
|
$expr[] = $search->compare( '==', 'order.address.company', 'Example company' ); |
|
229
|
|
|
$expr[] = $search->compare( '==', 'order.address.vatid', 'DE999999999' ); |
|
230
|
|
|
$expr[] = $search->compare( '==', 'order.address.salutation', 'mr' ); |
|
231
|
|
|
$expr[] = $search->compare( '==', 'order.address.title', '' ); |
|
232
|
|
|
$expr[] = $search->compare( '==', 'order.address.firstname', 'Our' ); |
|
233
|
|
|
$expr[] = $search->compare( '==', 'order.address.lastname', 'Unittest' ); |
|
234
|
|
|
$expr[] = $search->compare( '==', 'order.address.address1', 'Durchschnitt' ); |
|
235
|
|
|
$expr[] = $search->compare( '==', 'order.address.address2', '1' ); |
|
236
|
|
|
$expr[] = $search->compare( '==', 'order.address.address3', '' ); |
|
237
|
|
|
$expr[] = $search->compare( '==', 'order.address.postal', '20146' ); |
|
238
|
|
|
$expr[] = $search->compare( '==', 'order.address.city', 'Hamburg' ); |
|
239
|
|
|
$expr[] = $search->compare( '==', 'order.address.state', 'Hamburg' ); |
|
240
|
|
|
$expr[] = $search->compare( '==', 'order.address.countryid', 'DE' ); |
|
241
|
|
|
$expr[] = $search->compare( '==', 'order.address.languageid', 'de' ); |
|
242
|
|
|
$expr[] = $search->compare( '==', 'order.address.telephone', '055544332211' ); |
|
243
|
|
|
$expr[] = $search->compare( '==', 'order.address.telefax', '055544332212' ); |
|
244
|
|
|
$expr[] = $search->compare( '==', 'order.address.mobile', '055544332213' ); |
|
245
|
|
|
$expr[] = $search->compare( '==', 'order.address.email', '[email protected]' ); |
|
246
|
|
|
$expr[] = $search->compare( '==', 'order.address.website', 'www.example.net' ); |
|
247
|
|
|
$expr[] = $search->compare( '==', 'order.address.longitude', '11.0' ); |
|
248
|
|
|
$expr[] = $search->compare( '==', 'order.address.latitude', '52.0' ); |
|
249
|
|
|
$expr[] = $search->compare( '==', 'order.address.position', 0 ); |
|
250
|
|
|
$expr[] = $search->compare( '==', 'order.address.birthday', '2001-01-01' ); |
|
251
|
|
|
$expr[] = $search->compare( '>=', 'order.address.mtime', '1970-01-01 00:00:00' ); |
|
252
|
|
|
$expr[] = $search->compare( '>=', 'order.address.ctime', '1970-01-01 00:00:00' ); |
|
253
|
|
|
$expr[] = $search->compare( '==', 'order.address.editor', $this->editor ); |
|
254
|
|
|
|
|
255
|
|
|
$search->setConditions( $search->and( $expr ) ); |
|
256
|
|
|
$result = $this->object->search( $search, [], $total )->toArray(); |
|
257
|
|
|
|
|
258
|
|
|
$this->assertEquals( 1, count( $result ) ); |
|
259
|
|
|
$this->assertEquals( 1, $total ); |
|
260
|
|
|
|
|
261
|
|
|
$conditions = array( |
|
262
|
|
|
$search->compare( '==', 'order.address.lastname', 'Unittest' ), |
|
263
|
|
|
$search->compare( '==', 'order.address.editor', $this->editor ) |
|
264
|
|
|
); |
|
265
|
|
|
$search->setConditions( $search->and( $conditions ) ); |
|
266
|
|
|
$search->slice( 0, 1 ); |
|
267
|
|
|
$items = $this->object->search( $search, [], $total )->toArray(); |
|
268
|
|
|
|
|
269
|
|
|
$this->assertEquals( 1, count( $items ) ); |
|
270
|
|
|
$this->assertEquals( 4, $total ); |
|
271
|
|
|
|
|
272
|
|
|
foreach( $items as $itemId => $item ) { |
|
273
|
|
|
$this->assertEquals( $itemId, $item->getId() ); |
|
274
|
|
|
} |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
|
|
278
|
|
|
public function testGetSubManager() |
|
279
|
|
|
{ |
|
280
|
|
|
$this->expectException( \LogicException::class ); |
|
281
|
|
|
$this->object->getSubManager( 'unknown' ); |
|
282
|
|
|
} |
|
283
|
|
|
} |
|
284
|
|
|
|