Completed
Push — master ( a4e8a9...31faa3 )
by Aimeos
02:22
created

BaseTest::testGetCatalogTree()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Catalog\Decorator;
10
11
12
class BaseTest extends \PHPUnit_Framework_TestCase
13
{
14
	private $context;
15
	private $object;
16
	private $stub;
17
18
19
	protected function setUp()
20
	{
21
		$this->context = \TestHelperFrontend::getContext();
22
23
		$this->stub = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Catalog\Standard' )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Catalog\Decorator\Base' )
28
			->setConstructorArgs( [$this->stub, $this->context] )
29
			->getMockForAbstractClass();
30
	}
31
32
33
	protected function tearDown()
34
	{
35
		unset( $this->context, $this->object, $this->stub );
36
	}
37
38
39
	public function testCreateManager()
40
	{
41
		$catalogManager = \Aimeos\MShop\Factory::createManager( $this->context, 'catalog' );
42
43
		$this->stub->expects( $this->once() )->method( 'createManager' )
44
			->will( $this->returnValue( $catalogManager ) );
45
46
		$this->assertInstanceOf( '\Aimeos\MShop\Common\Manager\Iface', $this->object->createManager( 'catalog' ) );
47
	}
48
49
50
	public function testCreateFilter()
51
	{
52
		$search = \Aimeos\MShop\Factory::createManager( $this->context, 'catalog' )->createSearch();
53
54
		$this->stub->expects( $this->once() )->method( 'createFilter' )
55
			->will( $this->returnValue( $search ) );
56
57
		$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->createFilter() );
58
	}
59
60
61
	public function testGetPath()
62
	{
63
		$search = \Aimeos\MShop\Factory::createManager( $this->context, 'catalog' )->createSearch();
0 ignored issues
show
Unused Code introduced by
$search is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
64
65
		$this->stub->expects( $this->once() )->method( 'getPath' )
66
			->will( $this->returnValue( [] ) );
67
68
		$this->assertEquals( [], $this->object->getPath( -1 ) );
69
	}
70
71
72
	public function testGetTree()
73
	{
74
		$catItem = \Aimeos\MShop\Factory::createManager( $this->context, 'catalog' )->createItem();
75
76
		$this->stub->expects( $this->once() )->method( 'getTree' )
77
			->will( $this->returnValue( $catItem ) );
78
79
		$this->assertInstanceOf( '\Aimeos\MShop\Catalog\Item\Iface', $this->object->getTree() );
80
	}
81
82
83
	public function testCreateCatalogFilter()
84
	{
85
		$search = \Aimeos\MShop\Factory::createManager( $this->context, 'catalog' )->createSearch();
86
87
		$this->stub->expects( $this->once() )->method( 'createCatalogFilter' )
88
			->will( $this->returnValue( $search ) );
89
90
		$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->createCatalogFilter() );
91
	}
92
93
94
	public function testGetCatalogPath()
95
	{
96
		$search = \Aimeos\MShop\Factory::createManager( $this->context, 'catalog' )->createSearch();
0 ignored issues
show
Unused Code introduced by
$search is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
97
98
		$this->stub->expects( $this->once() )->method( 'getCatalogPath' )
99
			->will( $this->returnValue( [] ) );
100
101
		$this->assertEquals( [], $this->object->getCatalogPath( -1 ) );
102
	}
103
104
105
	public function testGetCatalogTree()
106
	{
107
		$catItem = \Aimeos\MShop\Factory::createManager( $this->context, 'catalog' )->createItem();
108
109
		$this->stub->expects( $this->once() )->method( 'getCatalogTree' )
110
			->will( $this->returnValue( $catItem ) );
111
112
		$this->assertInstanceOf( '\Aimeos\MShop\Catalog\Item\Iface', $this->object->getCatalogTree() );
113
	}
114
115
116
	public function testAggregateIndex()
117
	{
118
		$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch();
119
120
		$this->stub->expects( $this->once() )->method( 'aggregateIndex' )
121
			->will( $this->returnValue( [] ) );
122
123
		$this->assertEquals( [], $this->object->aggregateIndex( $search, 'test' ) );
124
	}
125
126
127
	public function testAddIndexFilterCategory()
128
	{
129
		$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch();
130
131
		$this->stub->expects( $this->once() )->method( 'addIndexFilterCategory' )
132
			->will( $this->returnArgument( 0 ) );
133
134
		$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->addIndexFilterCategory( $search, -1 ) );
135
	}
136
137
138
	public function testAddIndexFilterText()
139
	{
140
		$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch();
141
142
		$this->stub->expects( $this->once() )->method( 'addIndexFilterText' )
143
			->will( $this->returnArgument( 0 ) );
144
145
		$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->addIndexFilterText( $search, 'test' ) );
146
	}
147
148
149
	public function testCreateIndexFilter()
150
	{
151
		$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch();
152
153
		$this->stub->expects( $this->once() )->method( 'createIndexFilter' )
154
			->will( $this->returnValue( $search ) );
155
156
		$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->createIndexFilter() );
157
	}
158
159
160
	public function testCreateIndexFilterCategory()
161
	{
162
		$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch();
163
164
		$this->stub->expects( $this->once() )->method( 'createIndexFilterCategory' )
165
			->will( $this->returnValue( $search ) );
166
167
		$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->createIndexFilterCategory( -1 ) );
168
	}
169
170
171
	public function testCreateIndexFilterText()
172
	{
173
		$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch();
174
175
		$this->stub->expects( $this->once() )->method( 'createIndexFilterText' )
176
			->will( $this->returnValue( $search ) );
177
178
		$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->createIndexFilterText( 'test' ) );
179
	}
180
181
182
	public function testGetIndexItems()
183
	{
184
		$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch();
185
186
		$this->stub->expects( $this->once() )->method( 'getIndexItems' )
187
			->will( $this->returnValue( [] ) );
188
189
		$this->assertEquals( [], $this->object->getIndexItems( $search ) );
190
	}
191
192
193
	public function testGetProductItems()
194
	{
195
		$this->stub->expects( $this->once() )->method( 'getProductItems' )
196
			->will( $this->returnValue( [] ) );
197
198
		$this->assertEquals( [], $this->object->getProductItems( [-1] ) );
199
	}
200
201
202
	public function testCreateTextFilter()
203
	{
204
		$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch();
205
206
		$this->stub->expects( $this->once() )->method( 'createTextFilter' )
207
			->will( $this->returnValue( $search ) );
208
209
		$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->createTextFilter( 'test' ) );
210
	}
211
212
213
	public function testGetTextList()
214
	{
215
		$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch();
216
217
		$this->stub->expects( $this->once() )->method( 'getTextList' )
218
			->will( $this->returnValue( [] ) );
219
220
		$this->assertEquals( [], $this->object->getTextList( $search ) );
221
	}
222
223
224
	public function testGetController()
225
	{
226
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
227
228
		$this->assertSame( $this->stub, $result );
229
	}
230
231
232
	public function testGetContext()
233
	{
234
		$result = $this->access( 'getContext' )->invokeArgs( $this->object, [] );
235
236
		$this->assertInstanceOf( '\Aimeos\MShop\Context\Item\Iface', $result );
237
	}
238
239
240
	protected function access( $name )
241
	{
242
		$class = new \ReflectionClass( '\Aimeos\Controller\Frontend\Catalog\Decorator\Base' );
243
		$method = $class->getMethod( $name );
244
		$method->setAccessible( true );
245
246
		return $method;
247
	}
248
}
249