Completed
Push — master ( 5d98f5...246d8b )
by Aimeos
08:56
created

BaseTest::testAddRefItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 1
b 0
f 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2012
6
 * @copyright Aimeos (aimeos.org), 2015-2017
7
 */
8
9
10
namespace Aimeos\MShop\Common\Item\ListRef;
11
12
13
class Test extends \Aimeos\MShop\Common\Item\ListRef\Base
14
{
15
	public function getLabel()
16
	{
17
		return 'test label';
18
	}
19
20
	public function getResourceType()
21
	{
22
		return '';
23
	}
24
}
25
26
27
28
class BaseTest extends \PHPUnit\Framework\TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
29
{
30
	private $object;
31
	private $textItem1;
32
	private $textItem2;
33
	private $listItem1;
34
	private $listItem2;
35
36
37
	protected function setUp()
38
	{
39
		$values = ['languageid' => null, 'text.status' => 1];
40
41
		$this->textItem1 = new \Aimeos\MShop\Text\Item\Standard( array( 'text.type' => 'name' ) + $values );
42
		$this->textItem1->setContent( 'test name' );
43
		$this->textItem1->setStatus( 1 );
44
		$this->textItem1->setId( 1 );
45
46
		$this->textItem2 = new \Aimeos\MShop\Text\Item\Standard( array( 'text.type' => 'short' ) + $values );
47
		$this->textItem2->setContent( 'default name' );
48
		$this->textItem2->setStatus( 1 );
49
		$this->textItem2->setId( 2 );
50
51
		$this->listItem1 = new \Aimeos\MShop\Common\Item\Lists\Standard( 'text.lists.', array( 'text.lists.type' => 'test' ) + $values );
52
		$this->listItem1->setRefId( $this->textItem1->getId() );
53
		$this->listItem1->setDomain( 'text' );
54
		$this->listItem1->setPosition( 1 );
55
		$this->listItem1->setStatus( 1 );
56
		$this->listItem1->setId( 11 );
57
58
		$this->listItem2 = new \Aimeos\MShop\Common\Item\Lists\Standard( 'text.lists.', array( 'text.lists.type' => 'default' ) + $values );
59
		$this->listItem2->setRefId( $this->textItem2->getId() );
60
		$this->listItem2->setDomain( 'text' );
61
		$this->listItem2->setPosition( 0 );
62
		$this->listItem2->setStatus( 1 );
63
		$this->listItem2->setId( 10 );
64
65
		$listItems = array( 'text' => array(
66
			$this->listItem1->getId() => $this->listItem1,
67
			$this->listItem2->getId() => $this->listItem2,
68
		) );
69
70
		$refItems = array( 'text' => array(
71
			$this->textItem1->getId() => $this->textItem1,
72
			$this->textItem2->getId() => $this->textItem2,
73
		) );
74
75
		$this->object = new \Aimeos\MShop\Common\Item\ListRef\Test( 'text.', [], $listItems, $refItems );
76
	}
77
78
79
	protected function tearDown()
80
	{
81
		unset( $this->object );
82
	}
83
84
85
	public function testAddRefItem()
86
	{
87
		$this->object->addRefItem( 'test', $this->listItem1, $this->textItem1 );
88
89
		$this->assertEquals( [11 => $this->listItem1], $this->object->getListItems( 'test' ) );
90
		$this->assertEquals( [1 => $this->textItem1], $this->object->getRefItems( 'test' ) );
91
	}
92
93
94
	public function testAddRefItemNew()
95
	{
96
		$this->object->addRefItem( 'test', $this->listItem1->setId( null ), $this->textItem1->setId( null ) );
97
98
		$this->assertEquals( ['tmp-0' => $this->listItem1], $this->object->getListItems( 'test' ) );
99
		$this->assertEquals( ['tmp-1' => $this->textItem1], $this->object->getRefItems( 'test' ) );
100
	}
101
102
103
	public function testDeleteRefItem()
104
	{
105
		$this->object->deleteRefItem( 'text', $this->listItem1, $this->textItem1 );
106
107
		$this->assertEquals( [$this->listItem1], $this->object->getDeletedItems() );
108
	}
109
110
111
	public function testDeleteRefItemException()
112
	{
113
		$this->setExpectedException( '\Aimeos\MShop\Exception' );
114
		$this->object->deleteRefItem( 'test', $this->listItem1 );
115
	}
116
117
118
	public function testGetDeletedItems()
119
	{
120
		$this->assertEquals( [], $this->object->getDeletedItems() );
121
	}
122
123
124
	public function testGetName()
125
	{
126
		$object = new \Aimeos\MShop\Common\Item\ListRef\Test( '' );
127
128
		$this->assertEquals( 'test label', $object->getName() );
129
		$this->assertEquals( 'test name', $this->object->getName() );
130
	}
131
132
133
	public function testGetListItem()
134
	{
135
		$result = $this->object->getListItem( 2, 'text', 'default' );
136
137
		$this->assertInstanceof( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $result );
138
	}
139
140
141
	public function testGetListItems()
142
	{
143
		$result = $this->object->getListItems();
144
		$expected = array(
145
			$this->listItem2->getId() => $this->listItem2,
146
			$this->listItem1->getId() => $this->listItem1,
147
		);
148
149
		$this->assertEquals( $expected, $result );
150
151
		foreach( $result as $listItem ) {
152
			$this->assertInstanceof( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $listItem );
153
		}
154
	}
155
156
157
	public function testGetListItemsWithDomain()
158
	{
159
		$result = $this->object->getListItems( 'text' );
160
		$expected = array(
161
			$this->listItem2->getId() => $this->listItem2,
162
			$this->listItem1->getId() => $this->listItem1,
163
		);
164
165
		$this->assertEquals( $expected, $result );
166
167
		foreach( $result as $listItem ) {
168
			$this->assertInstanceof( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $listItem );
169
		}
170
171
		$this->assertEquals( [], $this->object->getListItems( 'undefined' ) );
172
	}
173
174
175
	public function testGetListItemsWithListtype()
176
	{
177
		$result = $this->object->getListItems( 'text', 'test' );
178
		$expected = array( $this->listItem1->getId() => $this->listItem1 );
179
180
		$this->assertEquals( $expected, $result );
181
	}
182
183
184
	public function testGetListItemsWithListtypes()
185
	{
186
		$result = $this->object->getListItems( 'text', array( 'test' ) );
187
		$expected = array( $this->listItem1->getId() => $this->listItem1 );
188
189
		$this->assertEquals( $expected, $result );
190
	}
191
192
193
	public function testGetListItemsWithType()
194
	{
195
		$result = $this->object->getListItems( 'text', null, 'name' );
196
		$expected = array( $this->listItem1->getId() => $this->listItem1 );
197
198
		$this->assertEquals( $expected, $result );
199
	}
200
201
202
	public function testGetListItemsWithTypes()
203
	{
204
		$result = $this->object->getListItems( 'text', null, array( 'name', 'short' ) );
205
		$expected = array(
206
			$this->listItem1->getId() => $this->listItem1,
207
			$this->listItem2->getId() => $this->listItem2,
208
		);
209
210
		$this->assertEquals( $expected, $result );
211
	}
212
213
214
	public function testGetListItemsWithRefItems()
215
	{
216
		$result = $this->object->getListItems( 'text' );
217
		$expected = array(
218
			$this->textItem2->getId() => $this->textItem2,
219
			$this->textItem1->getId() => $this->textItem1,
220
		);
221
222
		foreach( $result as $listItem )
223
		{
224
			$this->assertInstanceof( '\\Aimeos\\MShop\\Text\\Item\\Iface', $listItem->getRefItem() );
225
			$this->assertSame( $expected[$listItem->getRefId()], $listItem->getRefItem() );
226
		}
227
	}
228
229
230
	public function testGetRefItems()
231
	{
232
		$result = $this->object->getRefItems();
233
		$expected = array(
234
			'text' => array(
235
				$this->textItem2->getId() => $this->textItem2,
236
				$this->textItem1->getId() => $this->textItem1,
237
			)
238
		);
239
240
		$this->assertEquals( $expected, $result );
241
242
		foreach( $result as $domain => $list )
243
		{
244
			foreach( $list as $item ) {
245
				$this->assertInstanceof( '\\Aimeos\\MShop\\Common\\Item\\Iface', $item );
246
			}
247
		}
248
	}
249
250
251
	public function testGetRefItemsWithDomain()
252
	{
253
		$result = $this->object->getRefItems( 'text' );
254
		$expected = array(
255
			$this->textItem2->getId() => $this->textItem2,
256
			$this->textItem1->getId() => $this->textItem1,
257
		);
258
259
		$this->assertEquals( $expected, $result );
260
261
		foreach( $result as $item ) {
262
			$this->assertInstanceof( '\\Aimeos\\MShop\\Common\\Item\\Iface', $item );
263
		}
264
265
		$this->assertEquals( [], $this->object->getRefItems( 'undefined' ) );
266
	}
267
268
269
	public function testGetRefItemsWithType()
270
	{
271
		$result = $this->object->getRefItems( 'text', 'name' );
272
		$expected = array( $this->textItem1->getId() => $this->textItem1 );
273
274
		$this->assertEquals( $expected, $result );
275
		$this->assertEquals( [], $this->object->getRefItems( 'text', 'undefined' ) );
276
	}
277
278
279
	public function testGetRefItemsWithTypes()
280
	{
281
		$result = $this->object->getRefItems( 'text', array( 'short', 'name' ) );
282
		$expected = array(
283
			$this->textItem2->getId() => $this->textItem2,
284
			$this->textItem1->getId() => $this->textItem1,
285
		);
286
287
		$this->assertEquals( $expected, $result );
288
		$this->assertEquals( [], $this->object->getRefItems( 'text', 'undefined' ) );
289
	}
290
291
292
	public function testGetRefItemsWithTypeAndListtype()
293
	{
294
		$result = $this->object->getRefItems( 'text', 'name', 'test' );
295
		$expected = array( $this->textItem1->getId() => $this->textItem1 );
296
297
		$this->assertEquals( $expected, $result );
298
		$this->assertEquals( [], $this->object->getRefItems( 'text', 'name', 'undefined' ) );
299
	}
300
}
301