Completed
Push — master ( 501b94...69ae10 )
by Aimeos
09:47
created

BaseTest::testGetListItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
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 testGetName()
86
	{
87
		$object = new \Aimeos\MShop\Common\Item\ListRef\Test( '' );
88
89
		$this->assertEquals( 'test label', $object->getName() );
90
		$this->assertEquals( 'test name', $this->object->getName() );
91
	}
92
93
94
	public function testGetListItem()
95
	{
96
		$result = $this->object->getListItem( 2, 'text', 'default' );
97
98
		$this->assertInstanceof( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $result );
99
	}
100
101
102
	public function testGetListItems()
103
	{
104
		$result = $this->object->getListItems();
105
		$expected = array(
106
			$this->listItem2->getId() => $this->listItem2,
107
			$this->listItem1->getId() => $this->listItem1,
108
		);
109
110
		$this->assertEquals( $expected, $result );
111
112
		foreach( $result as $listItem ) {
113
			$this->assertInstanceof( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $listItem );
114
		}
115
	}
116
117
118
	public function testGetListItemsWithDomain()
119
	{
120
		$result = $this->object->getListItems( 'text' );
121
		$expected = array(
122
			$this->listItem2->getId() => $this->listItem2,
123
			$this->listItem1->getId() => $this->listItem1,
124
		);
125
126
		$this->assertEquals( $expected, $result );
127
128
		foreach( $result as $listItem ) {
129
			$this->assertInstanceof( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $listItem );
130
		}
131
132
		$this->assertEquals( [], $this->object->getListItems( 'undefined' ) );
133
	}
134
135
136
	public function testGetListItemsWithListtype()
137
	{
138
		$result = $this->object->getListItems( 'text', 'test' );
139
		$expected = array( $this->listItem1->getId() => $this->listItem1 );
140
141
		$this->assertEquals( $expected, $result );
142
	}
143
144
145
	public function testGetListItemsWithListtypes()
146
	{
147
		$result = $this->object->getListItems( 'text', array( 'test' ) );
148
		$expected = array( $this->listItem1->getId() => $this->listItem1 );
149
150
		$this->assertEquals( $expected, $result );
151
	}
152
153
154
	public function testGetListItemsWithType()
155
	{
156
		$result = $this->object->getListItems( 'text', null, 'name' );
157
		$expected = array( $this->listItem1->getId() => $this->listItem1 );
158
159
		$this->assertEquals( $expected, $result );
160
	}
161
162
163
	public function testGetListItemsWithTypes()
164
	{
165
		$result = $this->object->getListItems( 'text', null, array( 'name', 'short' ) );
166
		$expected = array(
167
			$this->listItem1->getId() => $this->listItem1,
168
			$this->listItem2->getId() => $this->listItem2,
169
		);
170
171
		$this->assertEquals( $expected, $result );
172
	}
173
174
175
	public function testGetListItemsWithRefItems()
176
	{
177
		$result = $this->object->getListItems( 'text' );
178
		$expected = array(
179
			$this->textItem2->getId() => $this->textItem2,
180
			$this->textItem1->getId() => $this->textItem1,
181
		);
182
183
		foreach( $result as $listItem )
184
		{
185
			$this->assertInstanceof( '\\Aimeos\\MShop\\Text\\Item\\Iface', $listItem->getRefItem() );
186
			$this->assertSame( $expected[$listItem->getRefId()], $listItem->getRefItem() );
187
		}
188
	}
189
190
191
	public function testGetRefItems()
192
	{
193
		$result = $this->object->getRefItems();
194
		$expected = array(
195
			'text' => array(
196
				$this->textItem2->getId() => $this->textItem2,
197
				$this->textItem1->getId() => $this->textItem1,
198
			)
199
		);
200
201
		$this->assertEquals( $expected, $result );
202
203
		foreach( $result as $domain => $list )
204
		{
205
			foreach( $list as $item ) {
206
				$this->assertInstanceof( '\\Aimeos\\MShop\\Common\\Item\\Iface', $item );
207
			}
208
		}
209
	}
210
211
212
	public function testGetRefItemsWithDomain()
213
	{
214
		$result = $this->object->getRefItems( 'text' );
215
		$expected = array(
216
			$this->textItem2->getId() => $this->textItem2,
217
			$this->textItem1->getId() => $this->textItem1,
218
		);
219
220
		$this->assertEquals( $expected, $result );
221
222
		foreach( $result as $item ) {
223
			$this->assertInstanceof( '\\Aimeos\\MShop\\Common\\Item\\Iface', $item );
224
		}
225
226
		$this->assertEquals( [], $this->object->getRefItems( 'undefined' ) );
227
	}
228
229
230
	public function testGetRefItemsWithType()
231
	{
232
		$result = $this->object->getRefItems( 'text', 'name' );
233
		$expected = array( $this->textItem1->getId() => $this->textItem1 );
234
235
		$this->assertEquals( $expected, $result );
236
		$this->assertEquals( [], $this->object->getRefItems( 'text', 'undefined' ) );
237
	}
238
239
240
	public function testGetRefItemsWithTypes()
241
	{
242
		$result = $this->object->getRefItems( 'text', array( 'short', 'name' ) );
243
		$expected = array(
244
			$this->textItem2->getId() => $this->textItem2,
245
			$this->textItem1->getId() => $this->textItem1,
246
		);
247
248
		$this->assertEquals( $expected, $result );
249
		$this->assertEquals( [], $this->object->getRefItems( 'text', 'undefined' ) );
250
	}
251
252
253
	public function testGetRefItemsWithTypeAndListtype()
254
	{
255
		$result = $this->object->getRefItems( 'text', 'name', 'test' );
256
		$expected = array( $this->textItem1->getId() => $this->textItem1 );
257
258
		$this->assertEquals( $expected, $result );
259
		$this->assertEquals( [], $this->object->getRefItems( 'text', 'name', 'undefined' ) );
260
	}
261
}
262