Completed
Push — master ( ac66b3...ab3b6f )
by Aimeos
07:35 queued 01:23
created

EzpublishTest::testGetItem()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 20
rs 9.4285
cc 2
eloc 13
nc 2
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016
6
 */
7
8
9
namespace Aimeos\MShop\Customer\Manager;
10
11
12
class EzpublishTest extends \PHPUnit_Framework_TestCase
13
{
14
	private $object;
15
	private $fixture;
16
	private $address;
17
	private $editor = '';
18
19
20
	protected function setUp()
21
	{
22
		$context = \TestHelper::getContext();
23
		$this->editor = $context->getEditor();
24
		$this->object = new \Aimeos\MShop\Customer\Manager\Ezpublish( $context );
25
26
		$this->fixture = array(
27
			'label' => 'unitTest',
28
			'status' => 2,
29
		);
30
31
		$this->address = new \Aimeos\MShop\Common\Item\Address\Standard( 'common.address.' );
32
	}
33
34
35
	protected function tearDown()
36
	{
37
		unset( $this->object, $this->fixture, $this->address );
38
	}
39
40
41
	public function testCleanup()
42
	{
43
		$this->object->cleanup( array( -1 ) );
44
	}
45
46
47
	public function testGetSearchAttributes()
48
	{
49
		foreach( $this->object->getSearchAttributes() as $attribute )
50
		{
51
			$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Attribute\\Iface', $attribute );
52
		}
53
	}
54
55
56
	public function testCreateItem()
57
	{
58
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Customer\\Item\\Iface', $this->object->createItem() );
59
	}
60
61
62
	public function testGetItem()
63
	{
64
		$search = $this->object->createSearch();
65
		$conditions = array(
66
			$search->compare( '==', 'customer.code', 'UTC003' ),
67
			$search->compare( '==', 'customer.editor', $this->editor )
68
		);
69
		$search->setConditions( $search->combine( '&&', $conditions ) );
70
		$items = $this->object->searchItems( $search, array( 'text' ) );
71
72
		if( ( $expected = reset( $items ) ) === false ) {
73
			throw new \Exception( 'No customer item with code "UTC003" found' );
74
		}
75
76
		$actual = $this->object->getItem( $expected->getId(), array( 'text' ) );
77
78
		$this->assertEquals( $expected, $actual );
79
		$this->assertEquals( 3, count( $actual->getListItems( 'text' ) ) );
80
		$this->assertEquals( 3, count( $actual->getRefItems( 'text' ) ) );
81
	}
82
83
84
	public function testSaveUpdateDeleteItem()
85
	{
86
		$item = $this->object->createItem();
87
88
		$item->setCode( 'unitTest' );
89
		$item->setLabel( 'unitTest' );
90
		$this->object->saveItem( $item );
91
		$itemSaved = $this->object->getItem( $item->getId() );
92
93
		$itemExp = clone $itemSaved;
94
		$itemExp->setCode( 'unitTest2' );
95
		$itemExp->setLabel( 'unitTest2' );
96
		$this->object->saveItem( $itemExp );
97
		$itemUpd = $this->object->getItem( $itemExp->getId() );
98
99
		$this->object->deleteItem( $item->getId() );
100
101
		$this->assertTrue( $item->getId() !== null );
102
		$this->assertEquals( $item->getId(), $itemSaved->getId() );
103
		$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() );
104
		$this->assertEquals( $item->getStatus(), $itemSaved->getStatus() );
105
		$this->assertEquals( $item->getCode(), $itemSaved->getCode() );
106
		$this->assertEquals( $item->getLabel(), $itemSaved->getLabel() );
107
		$this->assertEquals( $item->getPaymentAddress(), $itemSaved->getPaymentAddress() );
108
		$this->assertEquals( $item->getBirthday(), $itemSaved->getBirthday() );
109
		$this->assertEquals( $item->getPassword(), $itemSaved->getPassword() );
110
111
		$this->assertEquals( $this->editor, $itemSaved->getEditor() );
112
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() );
113
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() );
114
115
		$this->assertEquals( $itemExp->getId(), $itemUpd->getId() );
116
		$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() );
117
		$this->assertEquals( $itemExp->getStatus(), $itemUpd->getStatus() );
118
		$this->assertEquals( $itemExp->getCode(), $itemUpd->getCode() );
119
		$this->assertEquals( $itemExp->getLabel(), $itemUpd->getLabel() );
120
		$this->assertEquals( $itemExp->getPaymentAddress(), $itemUpd->getPaymentAddress() );
121
		$this->assertEquals( $itemExp->getBirthday(), $itemUpd->getBirthday() );
122
		$this->assertEquals( $itemExp->getPassword(), $itemUpd->getPassword() );
123
124
		$this->assertEquals( $this->editor, $itemUpd->getEditor() );
125
		$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() );
126
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() );
127
128
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
129
		$this->object->getItem( $item->getId() );
130
	}
131
132
133
	public function testCreateSearch()
134
	{
135
		$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $this->object->createSearch() );
136
	}
137
138
139
	public function testSearchItems()
140
	{
141
		$total = 0;
142
		$search = $this->object->createSearch();
143
144
		$expr = array();
145
		$expr[] = $search->compare( '!=', 'customer.id', null );
146
		$expr[] = $search->compare( '==', 'customer.label', 'UTC002' );
147
		$expr[] = $search->compare( '==', 'customer.code', 'UTC002' );
148
149
		$expr[] = $search->compare( '>=', 'customer.salutation', '' );
150
		$expr[] = $search->compare( '>=', 'customer.company', '' );
151
		$expr[] = $search->compare( '>=', 'customer.vatid', '' );
152
		$expr[] = $search->compare( '>=', 'customer.title', '' );
153
		$expr[] = $search->compare( '>=', 'customer.firstname', '' );
154
		$expr[] = $search->compare( '>=', 'customer.lastname', '' );
155
		$expr[] = $search->compare( '>=', 'customer.address1', '' );
156
		$expr[] = $search->compare( '>=', 'customer.address2', '' );
157
		$expr[] = $search->compare( '>=', 'customer.address3', '' );
158
		$expr[] = $search->compare( '>=', 'customer.postal', '' );
159
		$expr[] = $search->compare( '>=', 'customer.city', '' );
160
		$expr[] = $search->compare( '>=', 'customer.state', '' );
161
		$expr[] = $search->compare( '!=', 'customer.languageid', null );
162
		$expr[] = $search->compare( '>=', 'customer.countryid', '' );
163
		$expr[] = $search->compare( '>=', 'customer.telephone', '' );
164
		$expr[] = $search->compare( '>=', 'customer.email', '' );
165
		$expr[] = $search->compare( '>=', 'customer.telefax', '' );
166
		$expr[] = $search->compare( '>=', 'customer.website', '' );
167
168
		$expr[] = $search->compare( '==', 'customer.birthday', '1970-01-01' );
169
		$expr[] = $search->compare( '>=', 'customer.password', '' );
170
		$expr[] = $search->compare( '==', 'customer.status', 0 );
171
		$expr[] = $search->compare( '!=', 'customer.mtime', '1970-01-01 00:00:00' );
172
		$expr[] = $search->compare( '!=', 'customer.ctime', '1970-01-01 00:00:00' );
173
		$expr[] = $search->compare( '==', 'customer.editor', $this->editor );
174
175
		$expr[] = $search->compare( '!=', 'customer.address.id', null );
176
		$expr[] = $search->compare( '!=', 'customer.address.parentid', null );
177
		$expr[] = $search->compare( '==', 'customer.address.company', 'ABC GmbH' );
178
		$expr[] = $search->compare( '==', 'customer.address.vatid', 'DE999999999' );
179
		$expr[] = $search->compare( '==', 'customer.address.salutation', 'mr' );
180
		$expr[] = $search->compare( '==', 'customer.address.title', 'Dr.' );
181
		$expr[] = $search->compare( '==', 'customer.address.firstname', 'Good' );
182
		$expr[] = $search->compare( '==', 'customer.address.lastname', 'Unittest' );
183
		$expr[] = $search->compare( '==', 'customer.address.address1', 'Pickhuben' );
184
		$expr[] = $search->compare( '==', 'customer.address.address2', '2-4' );
185
		$expr[] = $search->compare( '==', 'customer.address.address3', '' );
186
		$expr[] = $search->compare( '==', 'customer.address.postal', '11099' );
187
		$expr[] = $search->compare( '==', 'customer.address.city', 'Berlin' );
188
		$expr[] = $search->compare( '==', 'customer.address.state', 'Berlin' );
189
		$expr[] = $search->compare( '==', 'customer.address.languageid', 'de' );
190
		$expr[] = $search->compare( '==', 'customer.address.countryid', 'DE' );
191
		$expr[] = $search->compare( '==', 'customer.address.telephone', '055544332221' );
192
		$expr[] = $search->compare( '==', 'customer.address.email', '[email protected]' );
193
		$expr[] = $search->compare( '==', 'customer.address.telefax', '055544333212' );
194
		$expr[] = $search->compare( '==', 'customer.address.website', 'unittest.aimeos.org' );
195
		$expr[] = $search->compare( '==', 'customer.address.flag', 0 );
196
		$expr[] = $search->compare( '==', 'customer.address.position', 1 );
197
		$expr[] = $search->compare( '!=', 'customer.address.mtime', '1970-01-01 00:00:00' );
198
		$expr[] = $search->compare( '!=', 'customer.address.ctime', '1970-01-01 00:00:00' );
199
		$expr[] = $search->compare( '==', 'customer.address.editor', $this->editor );
200
201
		$search->setConditions( $search->combine( '&&', $expr ) );
202
		$result = $this->object->searchItems( $search, array(), $total );
203
		$this->assertEquals( 1, count( $result ) );
204
	}
205
206
207
	public function testSearchItemsNoCriteria()
208
	{
209
		$total = 0;
210
211
		$search = $this->object->createSearch();
212
		$search->setConditions( $search->compare( '==', 'customer.address.editor', $this->editor ) );
213
		$search->setSlice( 0, 2 );
214
215
		$results = $this->object->searchItems( $search, array(), $total );
216
		$this->assertEquals( 2, count( $results ) );
217
		$this->assertEquals( 3, $total );
218
219
		foreach($results as $itemId => $item) {
220
			$this->assertEquals( $itemId, $item->getId() );
221
		}
222
	}
223
224
225 View Code Duplication
	public function testSearchItemsBaseCriteria()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
226
	{
227
		$search = $this->object->createSearch( true );
228
		$conditions = array(
229
			$search->compare( '==', 'customer.address.editor', $this->editor ),
230
			$search->getConditions()
231
		);
232
		$search->setConditions( $search->combine( '&&', $conditions ) );
233
		$this->assertEquals( 2, count( $this->object->searchItems( $search, array(), $total ) ) );
234
	}
235
236
237 View Code Duplication
	public function testGetSubManager()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
238
	{
239
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'address' ) );
240
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'address', 'Standard' ) );
241
242
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
243
		$this->object->getSubManager( 'unknown' );
244
	}
245
246
247
	public function testGetSubManagerInvalidName()
248
	{
249
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
250
		$this->object->getSubManager( 'address', 'unknown' );
251
	}
252
}
253