FosUserTest::tearDown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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