Passed
Branch master (ba77f4)
by Aimeos
03:57
created

Typo3Test::testSaveUpdateDeleteItem()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 62
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 47
dl 0
loc 62
rs 9.1563
c 0
b 0
f 0
cc 2
nc 2
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
1 ignored issue
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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
		$item = $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
		$itemExp = $this->object->saveItem( $itemExp );
119
		$itemUpd = $this->object->getItem( $itemExp->getId() );
120
121
		$this->object->deleteItem( $item->getId() );
122
123
124
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $item );
125
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $itemExp );
126
127
		$this->assertTrue( $item->getId() !== null );
128
		$this->assertEquals( $item->getId(), $itemSaved->getId() );
129
		$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() );
130
		$this->assertEquals( $item->getStatus(), $itemSaved->getStatus() );
131
		$this->assertEquals( $item->getCode(), $itemSaved->getCode() );
132
		$this->assertEquals( $item->getLabel(), $itemSaved->getLabel() );
133
		$this->assertEquals( $item->getBirthday(), $itemSaved->getBirthday() );
134
		$this->assertEquals( $item->getPassword(), $itemSaved->getPassword() );
135
		$this->assertEquals( $item->getGroups(), $itemSaved->getGroups() );
136
		$this->assertEquals( $item->getPageId(), $itemSaved->getPageId() );
137
138
		$this->assertEquals( '', $itemSaved->getEditor() );
139
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() );
140
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() );
141
142
		$this->assertEquals( $itemExp->getId(), $itemUpd->getId() );
143
		$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() );
144
		$this->assertEquals( $itemExp->getStatus(), $itemUpd->getStatus() );
145
		$this->assertEquals( $itemExp->getCode(), $itemUpd->getCode() );
146
		$this->assertEquals( $itemExp->getLabel(), $itemUpd->getLabel() );
147
		$this->assertEquals( $itemExp->getBirthday(), $itemUpd->getBirthday() );
148
		$this->assertEquals( $itemExp->getPassword(), $itemUpd->getPassword() );
149
		$this->assertEquals( $itemExp->getGroups(), $itemUpd->getGroups() );
150
		$this->assertEquals( $itemExp->getPageId(), $itemUpd->getPageId() );
151
152
		$this->assertEquals( '', $itemUpd->getEditor() );
153
		$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() );
154
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() );
155
156
157
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
158
		$this->object->getItem( $item->getId() );
159
	}
160
161
162
	public function testGetSaveAddressItems()
163
	{
164
		$item = $this->object->findItem( 'UTC001', ['customer/address'] );
165
166
		$item->setId( null )->setCode( 'xyz' );
167
		$item->getPaymentAddress()->setEmail( '[email protected]' );
168
		$item->addAddressItem( new \Aimeos\MShop\Common\Item\Address\Standard( 'customer.address.' ) );
169
		$this->object->saveItem( $item );
170
171
		$item2 = $this->object->findItem( 'xyz', ['customer/address'] );
172
173
		$this->object->deleteItem( $item->getId() );
174
175
		$this->assertEquals( 2, count( $item->getAddressItems() ) );
176
		$this->assertEquals( 2, count( $item2->getAddressItems() ) );
177
	}
178
179
180
	public function testGetSavePropertyItems()
181
	{
182
		$item = $this->object->findItem( 'UTC001', ['customer/property'] );
183
184
		$item->setId( null )->setCode( 'xyz' );
185
		$item->getPaymentAddress()->setEmail( '[email protected]' );
186
		$this->object->saveItem( $item );
187
188
		$item2 = $this->object->findItem( 'xyz', ['customer/property'] );
189
190
		$this->object->deleteItem( $item->getId() );
191
192
		$this->assertEquals( 1, count( $item->getPropertyItems() ) );
193
		$this->assertEquals( 1, count( $item2->getPropertyItems() ) );
194
	}
195
196
197
	public function testCreateSearch()
198
	{
199
		$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $this->object->createSearch() );
200
	}
201
202
203
	public function testSearchItems()
204
	{
205
		$total = 0;
206
		$search = $this->object->createSearch();
207
208
		$expr = [];
209
		$expr[] = $search->compare( '!=', 'customer.id', null );
210
		$expr[] = $search->compare( '==', 'customer.label', 'unitCustomer2' );
211
		$expr[] = $search->compare( '==', 'customer.code', 'UTC002' );
212
213
		$expr[] = $search->compare( '==', 'customer.salutation', 'mrs' );
214
		$expr[] = $search->compare( '>=', 'customer.company', '' );
215
		$expr[] = $search->compare( '>=', 'customer.vatid', '' );
216
		$expr[] = $search->compare( '>=', 'customer.title', '' );
217
		$expr[] = $search->compare( '>=', 'customer.firstname', '' );
218
		$expr[] = $search->compare( '>=', 'customer.lastname', '' );
219
		$expr[] = $search->compare( '>=', 'customer.address1', '' );
220
		$expr[] = $search->compare( '>=', 'customer.address2', '' );
221
		$expr[] = $search->compare( '>=', 'customer.address3', '' );
222
		$expr[] = $search->compare( '>=', 'customer.postal', '' );
223
		$expr[] = $search->compare( '>=', 'customer.city', '' );
224
		$expr[] = $search->compare( '>=', 'customer.state', '' );
225
		$expr[] = $search->compare( '!=', 'customer.languageid', null );
226
		$expr[] = $search->compare( '>=', 'customer.countryid', '' );
227
		$expr[] = $search->compare( '>=', 'customer.telephone', '' );
228
		$expr[] = $search->compare( '>=', 'customer.email', '' );
229
		$expr[] = $search->compare( '>=', 'customer.telefax', '' );
230
		$expr[] = $search->compare( '>=', 'customer.website', '' );
231
		$expr[] = $search->compare( '>=', 'customer.longitude', '10.0' );
232
		$expr[] = $search->compare( '>=', 'customer.latitude', '50.0' );
233
234
		$expr[] = $search->compare( '==', 'customer.birthday', '1970-01-01' );
235
		$expr[] = $search->compare( '>=', 'customer.password', '' );
236
		$expr[] = $search->compare( '==', 'customer.status', 0 );
237
		$expr[] = $search->compare( '!=', 'customer.mtime', '1970-01-01 00:00:00' );
238
		$expr[] = $search->compare( '!=', 'customer.ctime', '1970-01-01 00:00:00' );
239
240
		$expr[] = $search->compare( '!=', 'customer.address.id', null );
241
		$expr[] = $search->compare( '!=', 'customer.address.parentid', null );
242
		$expr[] = $search->compare( '==', 'customer.address.company', 'ABC GmbH' );
243
		$expr[] = $search->compare( '==', 'customer.address.vatid', 'DE999999999' );
244
		$expr[] = $search->compare( '==', 'customer.address.salutation', 'mr' );
245
		$expr[] = $search->compare( '==', 'customer.address.title', 'Dr.' );
246
		$expr[] = $search->compare( '==', 'customer.address.firstname', 'Good' );
247
		$expr[] = $search->compare( '==', 'customer.address.lastname', 'Unittest' );
248
		$expr[] = $search->compare( '==', 'customer.address.address1', 'Pickhuben' );
249
		$expr[] = $search->compare( '==', 'customer.address.address2', '2-4' );
250
		$expr[] = $search->compare( '==', 'customer.address.address3', '' );
251
		$expr[] = $search->compare( '==', 'customer.address.postal', '11099' );
252
		$expr[] = $search->compare( '==', 'customer.address.city', 'Berlin' );
253
		$expr[] = $search->compare( '==', 'customer.address.state', 'Berlin' );
254
		$expr[] = $search->compare( '==', 'customer.address.languageid', 'de' );
255
		$expr[] = $search->compare( '==', 'customer.address.countryid', 'DE' );
256
		$expr[] = $search->compare( '==', 'customer.address.telephone', '055544332221' );
257
		$expr[] = $search->compare( '==', 'customer.address.email', '[email protected]' );
258
		$expr[] = $search->compare( '==', 'customer.address.telefax', '055544333212' );
259
		$expr[] = $search->compare( '==', 'customer.address.website', 'unittest.aimeos.org' );
260
		$expr[] = $search->compare( '>=', 'customer.address.longitude', '11.0' );
261
		$expr[] = $search->compare( '>=', 'customer.address.latitude', '52.0' );
262
		$expr[] = $search->compare( '==', 'customer.address.position', 1 );
263
		$expr[] = $search->compare( '!=', 'customer.address.mtime', '1970-01-01 00:00:00' );
264
		$expr[] = $search->compare( '!=', 'customer.address.ctime', '1970-01-01 00:00:00' );
265
		$expr[] = $search->compare( '==', 'customer.address.editor', $this->editor );
266
267
		$search->setConditions( $search->combine( '&&', $expr ) );
268
		$result = $this->object->searchItems( $search, [], $total );
269
270
		$this->assertEquals( 1, count( $result ) );
271
		$this->assertEquals( [1], reset( $result )->getGroups() );
272
	}
273
274
275
	public function testSearchItemsTotal()
276
	{
277
		$search = $this->object->createSearch();
278
		$search->setSlice( 0, 2 );
279
280
		$total = 0;
281
		$results = $this->object->searchItems( $search, [], $total );
282
283
		$this->assertEquals( 2, count( $results ) );
284
		$this->assertEquals( 3, $total );
285
	}
286
287
288
	public function testSearchItemsCriteria()
289
	{
290
		$search = $this->object->createSearch( true );
291
		$results = $this->object->searchItems( $search );
292
293
		$this->assertEquals( 2, count( $results ) );
294
295
		foreach( $results as $itemId => $item ) {
296
			$this->assertEquals( $itemId, $item->getId() );
297
		}
298
	}
299
300
301
	public function testSearchItemsRef()
302
	{
303
		$search = $this->object->createSearch();
304
		$search->setConditions( $search->compare( '==', 'customer.code', 'UTC001' ) );
305
306
		$results = $this->object->searchItems( $search, ['customer/address', 'text'] );
307
308
		if( ( $item = reset( $results ) ) === false ) {
309
			throw new \Exception( 'No customer item for "UTC001" 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->setExpectedException( '\\Aimeos\\MShop\\Exception' );
320
		$this->object->getSubManager( 'unknown' );
321
	}
322
323
324
	public function testGetSubManagerInvalidName()
325
	{
326
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
327
		$this->object->getSubManager( 'address', 'unknown' );
328
	}
329
}
330