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 testConstructException() |
40
|
|
|
{ |
41
|
|
|
$stub = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Iface' )->getMock(); |
42
|
|
|
|
43
|
|
|
$this->setExpectedException( '\Aimeos\Controller\Frontend\Exception' ); |
44
|
|
|
|
45
|
|
|
$this->getMockBuilder( '\Aimeos\Controller\Frontend\Catalog\Decorator\Base' ) |
46
|
|
|
->setConstructorArgs( [$stub, $this->context] ) |
47
|
|
|
->getMockForAbstractClass(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
public function testCall() |
52
|
|
|
{ |
53
|
|
|
$stub = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Catalog\Standard' ) |
54
|
|
|
->disableOriginalConstructor() |
55
|
|
|
->setMethods( ['invalid'] ) |
56
|
|
|
->getMock(); |
57
|
|
|
|
58
|
|
|
$object = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Catalog\Decorator\Base' ) |
59
|
|
|
->setConstructorArgs( [$stub, $this->context] ) |
60
|
|
|
->getMockForAbstractClass(); |
61
|
|
|
|
62
|
|
|
$stub->expects( $this->once() )->method( 'invalid' )->will( $this->returnValue( true ) ); |
63
|
|
|
|
64
|
|
|
$this->assertTrue( $object->invalid() ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
public function testCreateManager() |
69
|
|
|
{ |
70
|
|
|
$catalogManager = \Aimeos\MShop\Factory::createManager( $this->context, 'catalog' ); |
71
|
|
|
|
72
|
|
|
$this->stub->expects( $this->once() )->method( 'createManager' ) |
73
|
|
|
->will( $this->returnValue( $catalogManager ) ); |
74
|
|
|
|
75
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Manager\Iface', $this->object->createManager( 'catalog' ) ); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
public function testCreateFilter() |
80
|
|
|
{ |
81
|
|
|
$search = \Aimeos\MShop\Factory::createManager( $this->context, 'catalog' )->createSearch(); |
82
|
|
|
|
83
|
|
|
$this->stub->expects( $this->once() )->method( 'createFilter' ) |
84
|
|
|
->will( $this->returnValue( $search ) ); |
85
|
|
|
|
86
|
|
|
$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->createFilter() ); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
public function testGetPath() |
91
|
|
|
{ |
92
|
|
|
$this->stub->expects( $this->once() )->method( 'getPath' ) |
93
|
|
|
->will( $this->returnValue( [] ) ); |
94
|
|
|
|
95
|
|
|
$this->assertEquals( [], $this->object->getPath( -1 ) ); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
public function testGetTree() |
100
|
|
|
{ |
101
|
|
|
$catItem = \Aimeos\MShop\Factory::createManager( $this->context, 'catalog' )->createItem(); |
102
|
|
|
|
103
|
|
|
$this->stub->expects( $this->once() )->method( 'getTree' ) |
104
|
|
|
->will( $this->returnValue( $catItem ) ); |
105
|
|
|
|
106
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Catalog\Item\Iface', $this->object->getTree() ); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
public function testCreateCatalogFilter() |
111
|
|
|
{ |
112
|
|
|
$search = \Aimeos\MShop\Factory::createManager( $this->context, 'catalog' )->createSearch(); |
113
|
|
|
|
114
|
|
|
$this->stub->expects( $this->once() )->method( 'createCatalogFilter' ) |
115
|
|
|
->will( $this->returnValue( $search ) ); |
116
|
|
|
|
117
|
|
|
$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->createCatalogFilter() ); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
public function testGetCatalogPath() |
122
|
|
|
{ |
123
|
|
|
$this->stub->expects( $this->once() )->method( 'getCatalogPath' ) |
124
|
|
|
->will( $this->returnValue( [] ) ); |
125
|
|
|
|
126
|
|
|
$this->assertEquals( [], $this->object->getCatalogPath( -1 ) ); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
public function testGetCatalogTree() |
131
|
|
|
{ |
132
|
|
|
$catItem = \Aimeos\MShop\Factory::createManager( $this->context, 'catalog' )->createItem(); |
133
|
|
|
|
134
|
|
|
$this->stub->expects( $this->once() )->method( 'getCatalogTree' ) |
135
|
|
|
->will( $this->returnValue( $catItem ) ); |
136
|
|
|
|
137
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Catalog\Item\Iface', $this->object->getCatalogTree() ); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
|
141
|
|
|
public function testAggregateIndex() |
142
|
|
|
{ |
143
|
|
|
$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch(); |
144
|
|
|
|
145
|
|
|
$this->stub->expects( $this->once() )->method( 'aggregateIndex' ) |
146
|
|
|
->will( $this->returnValue( [] ) ); |
147
|
|
|
|
148
|
|
|
$this->assertEquals( [], $this->object->aggregateIndex( $search, 'test' ) ); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
public function testAddIndexFilterCategory() |
153
|
|
|
{ |
154
|
|
|
$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch(); |
155
|
|
|
|
156
|
|
|
$this->stub->expects( $this->once() )->method( 'addIndexFilterCategory' ) |
157
|
|
|
->will( $this->returnArgument( 0 ) ); |
158
|
|
|
|
159
|
|
|
$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->addIndexFilterCategory( $search, -1 ) ); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
|
163
|
|
|
public function testAddIndexFilterText() |
164
|
|
|
{ |
165
|
|
|
$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch(); |
166
|
|
|
|
167
|
|
|
$this->stub->expects( $this->once() )->method( 'addIndexFilterText' ) |
168
|
|
|
->will( $this->returnArgument( 0 ) ); |
169
|
|
|
|
170
|
|
|
$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->addIndexFilterText( $search, 'test' ) ); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
|
174
|
|
|
public function testCreateIndexFilter() |
175
|
|
|
{ |
176
|
|
|
$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch(); |
177
|
|
|
|
178
|
|
|
$this->stub->expects( $this->once() )->method( 'createIndexFilter' ) |
179
|
|
|
->will( $this->returnValue( $search ) ); |
180
|
|
|
|
181
|
|
|
$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->createIndexFilter() ); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
|
185
|
|
|
public function testCreateIndexFilterCategory() |
186
|
|
|
{ |
187
|
|
|
$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch(); |
188
|
|
|
|
189
|
|
|
$this->stub->expects( $this->once() )->method( 'createIndexFilterCategory' ) |
190
|
|
|
->will( $this->returnValue( $search ) ); |
191
|
|
|
|
192
|
|
|
$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->createIndexFilterCategory( -1 ) ); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
|
196
|
|
|
public function testCreateIndexFilterText() |
197
|
|
|
{ |
198
|
|
|
$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch(); |
199
|
|
|
|
200
|
|
|
$this->stub->expects( $this->once() )->method( 'createIndexFilterText' ) |
201
|
|
|
->will( $this->returnValue( $search ) ); |
202
|
|
|
|
203
|
|
|
$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->createIndexFilterText( 'test' ) ); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
|
207
|
|
|
public function testGetIndexItems() |
208
|
|
|
{ |
209
|
|
|
$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch(); |
210
|
|
|
|
211
|
|
|
$this->stub->expects( $this->once() )->method( 'getIndexItems' ) |
212
|
|
|
->will( $this->returnValue( [] ) ); |
213
|
|
|
|
214
|
|
|
$this->assertEquals( [], $this->object->getIndexItems( $search ) ); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
|
218
|
|
|
public function testGetProductItems() |
219
|
|
|
{ |
220
|
|
|
$this->stub->expects( $this->once() )->method( 'getProductItems' ) |
221
|
|
|
->will( $this->returnValue( [] ) ); |
222
|
|
|
|
223
|
|
|
$this->assertEquals( [], $this->object->getProductItems( [-1] ) ); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
|
227
|
|
|
public function testCreateTextFilter() |
228
|
|
|
{ |
229
|
|
|
$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch(); |
230
|
|
|
|
231
|
|
|
$this->stub->expects( $this->once() )->method( 'createTextFilter' ) |
232
|
|
|
->will( $this->returnValue( $search ) ); |
233
|
|
|
|
234
|
|
|
$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->createTextFilter( 'test' ) ); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
|
238
|
|
|
public function testGetTextList() |
239
|
|
|
{ |
240
|
|
|
$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch(); |
241
|
|
|
|
242
|
|
|
$this->stub->expects( $this->once() )->method( 'getTextList' ) |
243
|
|
|
->will( $this->returnValue( [] ) ); |
244
|
|
|
|
245
|
|
|
$this->assertEquals( [], $this->object->getTextList( $search ) ); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
|
249
|
|
|
public function testGetController() |
250
|
|
|
{ |
251
|
|
|
$result = $this->access( 'getController' )->invokeArgs( $this->object, [] ); |
252
|
|
|
|
253
|
|
|
$this->assertSame( $this->stub, $result ); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
|
257
|
|
|
protected function access( $name ) |
258
|
|
|
{ |
259
|
|
|
$class = new \ReflectionClass( '\Aimeos\Controller\Frontend\Catalog\Decorator\Base' ); |
260
|
|
|
$method = $class->getMethod( $name ); |
261
|
|
|
$method->setAccessible( true ); |
262
|
|
|
|
263
|
|
|
return $method; |
264
|
|
|
} |
265
|
|
|
} |
266
|
|
|
|