Passed
Push — master ( 49f6b0...199364 )
by Aimeos
09:07
created

Typo3Test::testGetItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 7
c 4
b 0
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 0
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-2021
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() : void
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() : void
30
	{
31
		unset( $this->object, $this->item );
32
	}
33
34
35
	public function testAggregate()
36
	{
37
		$search = $this->object->filter();
38
		$result = $this->object->aggregate( $search, 'customer.salutation' );
39
40
		$this->assertEquals( 2, count( $result ) );
41
		$this->assertArrayHasKey( 'mr', $result );
42
		$this->assertEquals( 1, $result->get( 'mr' ) );
0 ignored issues
show
Bug introduced by
The method get() does not exist on ArrayAccess. It seems like you code against a sub-type of ArrayAccess such as Aimeos\MShop\Common\Item\Base or Aimeos\MShop\Order\Item\Base\Base or TYPO3Fluid\Fluid\Core\Va...riableProviderInterface or Yaf_Config_Simple or Aimeos\Map or Yaf\Session or TYPO3\CMS\Core\Resource\MetaDataAspect or HttpQueryString or Yaf_Session or Cassandra\Map or Yaf\Config\Simple or Yaf\Config\Ini or http\QueryString or Yaf_Config_Ini or TYPO3\CMS\Core\Routing\PageArguments or TYPO3\CMS\Extbase\Mvc\Controller\Arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

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