Completed
Push — 2016.04 ( 690368...e61816 )
by Aimeos
04:37
created

Typo3Test::testSearchItems()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 99
Code Lines 83

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 83
nc 2
nop 0
dl 0
loc 99
rs 8.3103
c 1
b 0
f 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
7
 */
8
9
namespace Aimeos\MShop\Customer\Manager;
10
11
12
/**
13
 * Test class for \Aimeos\MShop\Customer\Manager\Typo3
14
 */
15
class Typo3Test extends \PHPUnit_Framework_TestCase
16
{
17
	private $context;
18
	private $object;
19
	private $editor;
20
	private $item;
21
22
23
	/**
24
	 * Sets up the fixture. This method is called before a test is executed.
25
	 */
26
	protected function setUp()
27
	{
28
		$this->context = \TestHelper::getContext();
29
		$this->editor = $this->context->getEditor();
30
		$this->context->getConfig()->set( 'mshop/customer/manager/typo3/pid-default', 999999 );
31
		$this->object = new \Aimeos\MShop\Customer\Manager\Typo3( $this->context );
32
	}
33
34
35
	/**
36
	 * Tears down the fixture. This method is called after a test is executed.
37
	 */
38
	protected function tearDown()
39
	{
40
		unset($this->object, $this->item);
41
		\Aimeos\MShop\Factory::clear();
42
	}
43
44
45
	public function testGetSearchAttributes()
46
	{
47
		foreach( $this->object->getSearchAttributes() as $attribute )
48
		{
49
			$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Attribute\\Iface', $attribute );
50
		}
51
	}
52
53
54
	public function testCreateItem()
55
	{
56
		$item = $this->object->createItem();
57
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Customer\\Item\\Iface', $item );
58
	}
59
60
61
	public function testGetItem()
62
	{
63
		$search = $this->object->createSearch();
64
		$search->setConditions( $search->compare( '==', 'customer.code', '[email protected]' ) );
65
		$items = $this->object->searchItems( $search );
66
67
		if( ( $expected = reset( $items ) ) === false ) {
68
			throw new \Exception( 'No customer found.' );
69
		}
70
71
		$actual = $this->object->getItem( $expected->getId() );
72
		$billing = $actual->getPaymentAddress();
73
74
		$this->assertEquals( $expected, $actual );
75
76
		$this->assertEquals( 'Max Mustermann', $actual->getLabel() );
77
		$this->assertEquals( '[email protected]', $actual->getCode() );
78
		$this->assertEquals( 'mr', $billing->getSalutation() );
79
		$this->assertEquals( 'Example company LLC', $billing->getCompany() );
80
		$this->assertEquals( 'Dr.', $billing->getTitle() );
81
		$this->assertEquals( 'Max', $billing->getFirstname() );
82
		$this->assertEquals( 'Mustermann', $billing->getLastname() );
83
		$this->assertEquals( 'Musterstraße 1a', $billing->getAddress1() );
84
		$this->assertEquals( '', $billing->getAddress2() );
85
		$this->assertEquals( '', $billing->getAddress3() );
86
		$this->assertEquals( '20001', $billing->getPostal() );
87
		$this->assertEquals( 'Musterstadt', $billing->getCity() );
88
		$this->assertEquals( 'Hamburg', $billing->getState() );
89
		$this->assertEquals( 'de', $billing->getLanguageId() );
90
		$this->assertEquals( 'DE', $billing->getCountryId() );
91
		$this->assertEquals( '01234567890', $billing->getTelephone() );
92
		$this->assertEquals( '[email protected]', $billing->getEMail() );
93
		$this->assertEquals( '01234567890', $billing->getTelefax() );
94
		$this->assertEquals( 'www.example.com', $billing->getWebsite() );
95
		$this->assertEquals( 1, $actual->getStatus() );
96
		$this->assertEquals( '5f4dcc3b5aa765d61d8327deb882cf99', $actual->getPassword() );
97
		$this->assertEquals( '2011-01-13 11:03:36', $actual->getTimeCreated() );
98
		$this->assertEquals( '2011-01-13 11:03:46', $actual->getTimeModified() );
99
		$this->assertEquals( '', $actual->getEditor() );
100
	}
101
102
103
	public function testSaveUpdateDeleteItem()
104
	{
105
		$search = $this->object->createSearch();
106
		$search->setConditions( $search->compare( '==', 'customer.code', '[email protected]' ) );
107
		$results = $this->object->searchItems( $search );
108
109
		if( ( $item = reset( $results ) ) === false ) {
110
			throw new \Exception( 'No customer found.' );
111
		}
112
113
		$item->setId( null );
114
		$item->setCode( 'unitTest' );
115
		$item->setLabel( 'unitTest' );
116
		$item->setGroups( array( 1, 2, 3 ) );
117
		$this->object->saveItem( $item );
118
		$itemSaved = $this->object->getItem( $item->getId() );
119
120
		$itemExp = clone $itemSaved;
121
		$itemExp->setCode( 'unitTest2' );
122
		$itemExp->setLabel( 'unitTest2' );
123
		$itemExp->setGroups( array( 2, 4 ) );
124
		$this->object->saveItem( $itemExp );
125
		$itemUpd = $this->object->getItem( $itemExp->getId() );
126
127
		$this->object->deleteItem( $item->getId() );
128
129
130
		$this->assertTrue( $item->getId() !== null );
131
		$this->assertEquals( $item->getId(), $itemSaved->getId() );
132
		$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() );
133
		$this->assertEquals( $item->getStatus(), $itemSaved->getStatus() );
134
		$this->assertEquals( $item->getCode(), $itemSaved->getCode() );
135
		$this->assertEquals( $item->getLabel(), $itemSaved->getLabel() );
136
		$this->assertEquals( $item->getPaymentAddress(), $itemSaved->getPaymentAddress() );
137
		$this->assertEquals( $item->getBirthday(), $itemSaved->getBirthday() );
138
		$this->assertEquals( $item->getPassword(), $itemSaved->getPassword() );
139
		$this->assertEquals( $item->getGroups(), $itemSaved->getGroups() );
140
141
		$this->assertEquals( '', $itemSaved->getEditor() );
142
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() );
143
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() );
144
145
		$this->assertEquals( $itemExp->getId(), $itemUpd->getId() );
146
		$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() );
147
		$this->assertEquals( $itemExp->getStatus(), $itemUpd->getStatus() );
148
		$this->assertEquals( $itemExp->getCode(), $itemUpd->getCode() );
149
		$this->assertEquals( $itemExp->getLabel(), $itemUpd->getLabel() );
150
		$this->assertEquals( $itemExp->getPaymentAddress(), $itemUpd->getPaymentAddress() );
151
		$this->assertEquals( $itemExp->getBirthday(), $itemUpd->getBirthday() );
152
		$this->assertEquals( $itemExp->getPassword(), $itemUpd->getPassword() );
153
		$this->assertEquals( $itemExp->getGroups(), $itemUpd->getGroups() );
154
155
		$this->assertEquals( '', $itemUpd->getEditor() );
156
		$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() );
157
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() );
158
159
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
160
		$this->object->getItem( $item->getId() );
161
	}
162
163
164
	public function testCreateSearch()
165
	{
166
		$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $this->object->createSearch() );
167
	}
168
169
170
	public function testSearchItems()
171
	{
172
		$total = 0;
173
		$search = $this->object->createSearch();
174
175
		$expr = array();
176
		$expr[] = $search->compare( '!=', 'customer.id', null );
177
		$expr[] = $search->compare( '==', 'customer.label', 'Franz-Xaver Gabler' );
178
		$expr[] = $search->compare( '==', 'customer.code', '[email protected]' );
179
		$expr[] = $search->compare( '==', 'customer.salutation', 'mr' );
180
		$expr[] = $search->compare( '==', 'customer.company', 'Example company LLC' );
181
		$expr[] = $search->compare( '==', 'customer.title', '' );
182
		$expr[] = $search->compare( '==', 'customer.firstname', 'Franz-Xaver' );
183
		$expr[] = $search->compare( '==', 'customer.lastname', 'Gabler' );
184
		$expr[] = $search->compare( '==', 'customer.address1', 'Phantasiestraße 2' );
185
		$expr[] = $search->compare( '==', 'customer.postal', '23643' );
186
		$expr[] = $search->compare( '==', 'customer.city', 'Berlin' );
187
		$expr[] = $search->compare( '==', 'customer.state', 'Berlin' );
188
		$expr[] = $search->compare( '==', 'customer.telephone', '01234509876' );
189
		$expr[] = $search->compare( '==', 'customer.email', '[email protected]' );
190
		$expr[] = $search->compare( '==', 'customer.telefax', '055544333212' );
191
		$expr[] = $search->compare( '==', 'customer.website', 'www.example.com' );
192
		$expr[] = $search->compare( '==', 'customer.status', 1 );
193
		$expr[] = $search->compare( '!=', 'customer.password', '' );
194
		$expr[] = $search->compare( '>', 'customer.mtime', '1970-01-01 00:00:00' );
195
		$expr[] = $search->compare( '>', 'customer.ctime', '1970-01-01 00:00:00' );
196
197
		$expr[] = $search->compare( '!=', 'customer.address.id', null );
198
		$expr[] = $search->compare( '!=', 'customer.address.siteid', null );
199
		$expr[] = $search->compare( '!=', 'customer.address.parentid', null );
200
		$expr[] = $search->compare( '==', 'customer.address.salutation', 'company' );
201
		$expr[] = $search->compare( '==', 'customer.address.company', 'unitcompany' );
202
		$expr[] = $search->compare( '==', 'customer.address.title', 'unittitle' );
203
		$expr[] = $search->compare( '==', 'customer.address.firstname', 'unitfirstname' );
204
		$expr[] = $search->compare( '==', 'customer.address.lastname', 'unitlastname' );
205
		$expr[] = $search->compare( '==', 'customer.address.address1', 'unitaddress1' );
206
		$expr[] = $search->compare( '==', 'customer.address.address2', 'unitaddress2' );
207
		$expr[] = $search->compare( '==', 'customer.address.address3', 'unitaddress3' );
208
		$expr[] = $search->compare( '==', 'customer.address.postal', 'unitpostal' );
209
		$expr[] = $search->compare( '==', 'customer.address.city', 'unitcity' );
210
		$expr[] = $search->compare( '==', 'customer.address.state', 'unitstate' );
211
		$expr[] = $search->compare( '==', 'customer.address.countryid', 'DE' );
212
		$expr[] = $search->compare( '==', 'customer.address.languageid', 'de' );
213
		$expr[] = $search->compare( '==', 'customer.address.telephone', '1234567890' );
214
		$expr[] = $search->compare( '==', 'customer.address.email', '[email protected]' );
215
		$expr[] = $search->compare( '==', 'customer.address.telefax', '1234567891' );
216
		$expr[] = $search->compare( '==', 'customer.address.website', 'unit.web.site' );
217
		$expr[] = $search->compare( '==', 'customer.address.flag', 0 );
218
		$expr[] = $search->compare( '==', 'customer.address.position', 2 );
219
		$expr[] = $search->compare( '==', 'customer.address.editor', $this->editor );
220
		$expr[] = $search->compare( '>', 'customer.address.mtime', '1970-01-01 00:00:00' );
221
		$expr[] = $search->compare( '>', 'customer.address.ctime', '1970-01-01 00:00:00' );
222
223
		$expr[] = $search->compare( '!=', 'customer.lists.id', null );
224
		$expr[] = $search->compare( '!=', 'customer.lists.siteid', null );
225
		$expr[] = $search->compare( '!=', 'customer.lists.parentid', null );
226
		$expr[] = $search->compare( '==', 'customer.lists.domain', 'text' );
227
		$expr[] = $search->compare( '>', 'customer.lists.typeid', 0 );
228
		$expr[] = $search->compare( '>', 'customer.lists.refid', 0 );
229
		$expr[] = $search->compare( '==', 'customer.lists.datestart', '2010-01-01 00:00:00' );
230
		$expr[] = $search->compare( '==', 'customer.lists.dateend', '2022-01-01 00:00:00' );
231
		$expr[] = $search->compare( '>', 'customer.lists.position', 0 );
232
		$expr[] = $search->compare( '>=', 'customer.lists.mtime', '1970-01-01 00:00:00' );
233
		$expr[] = $search->compare( '>=', 'customer.lists.ctime', '1970-01-01 00:00:00' );
234
		$expr[] = $search->compare( '==', 'customer.lists.editor', $this->editor );
235
236
		$expr[] = $search->compare( '!=', 'customer.lists.type.id', null );
237
		$expr[] = $search->compare( '!=', 'customer.lists.type.siteid', null );
238
		$expr[] = $search->compare( '==', 'customer.lists.type.code', 'default' );
239
		$expr[] = $search->compare( '==', 'customer.lists.type.domain', 'text' );
240
		$expr[] = $search->compare( '==', 'customer.lists.type.label', 'Standard' );
241
		$expr[] = $search->compare( '==', 'customer.lists.type.status', 1 );
242
		$expr[] = $search->compare( '>=', 'customer.lists.type.mtime', '1970-01-01 00:00:00' );
243
		$expr[] = $search->compare( '>=', 'customer.lists.type.ctime', '1970-01-01 00:00:00' );
244
		$expr[] = $search->compare( '==', 'customer.lists.type.editor', $this->editor );
245
246
		$search->setConditions( $search->combine( '&&', $expr ) );
247
		$result = $this->object->searchItems( $search, array(), $total );
248
249
		$this->assertEquals( 1, count( $result ) );
250
		$this->assertEquals( 1, $total );
251
		$this->assertEquals( array( 1, 2, 3 ), reset( $result )->getGroups() );
252
253
254
		// search without base criteria
255
		$search = $this->object->createSearch();
256
		$results = $this->object->searchItems( $search );
257
		$this->assertEquals( 3, count( $results ) );
258
259
260
		// search with base criteria
261
		$search = $this->object->createSearch(true);
262
		$results = $this->object->searchItems( $search );
263
		$this->assertEquals( 2, count( $results ) );
264
265
		foreach( $results as $itemId => $item ) {
266
			$this->assertEquals( $itemId, $item->getId() );
267
		}
268
	}
269
270
271
	public function testGetSubManager()
272
	{
273
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
274
		$this->object->getSubManager( 'unknown' );
275
	}
276
277
278
	public function testGetSubManagerInvalidName()
279
	{
280
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
281
		$this->object->getSubManager( 'address', 'unknown' );
282
	}
283
}
284