Completed
Push — master ( cc87a0...64b84e )
by Aimeos
07:07
created

StandardTest   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 339
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 25
c 3
b 0
f 0
lcom 1
cbo 10
dl 0
loc 339
rs 10

24 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A tearDown() 0 4 1
A testGetHeader() 0 14 1
A testGetHeaderSearch() 0 14 1
A testGetHeaderException() 0 14 1
A testGetBody() 0 14 1
A testGetBodyNoDefaultCat() 0 13 1
A testGetBodyDefaultCat() 0 16 1
A testGetBodyCategoryLevels() 0 19 1
A testGetBodySearchText() 0 9 1
A testGetBodySearchAttribute() 0 9 1
A testGetBodyHtmlException() 0 14 1
A testGetBodyFrontendException() 0 14 1
A testGetBodyMShopException() 0 14 1
A testGetBodyException() 0 14 1
A testGetSubClient() 0 5 1
A testGetSubClientInvalid() 0 5 1
A testGetSubClientInvalidName() 0 5 1
A testProcess() 0 4 1
A testProcessHtmlException() 0 16 1
A testProcessFrontendException() 0 16 1
A testProcessMShopException() 0 16 1
A testProcessException() 0 16 1
A getCatalogItem() 0 13 2
1
<?php
2
3
namespace Aimeos\Client\Html\Catalog\Lists;
4
5
6
/**
7
 * @copyright Metaways Infosystems GmbH, 2012
8
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
9
 * @copyright Aimeos (aimeos.org), 2015
10
 */
11
class StandardTest extends \PHPUnit_Framework_TestCase
12
{
13
	private $object;
14
	private $context;
15
16
17
	protected function setUp()
18
	{
19
		$this->context = \TestHelperHtml::getContext();
20
		$paths = \TestHelperHtml::getHtmlTemplatePaths();
21
22
		$this->object = new \Aimeos\Client\Html\Catalog\Lists\Standard( $this->context, $paths );
23
		$this->object->setView( \TestHelperHtml::getView() );
24
	}
25
26
27
	protected function tearDown()
28
	{
29
		unset( $this->object );
30
	}
31
32
33
	public function testGetHeader()
34
	{
35
		$view = $this->object->getView();
36
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array( 'f_catid' => $this->getCatalogItem()->getId() ) );
37
		$view->addHelper( 'param', $helper );
38
39
		$tags = array();
40
		$expire = null;
41
		$output = $this->object->getHeader( 1, $tags, $expire );
42
43
		$this->assertStringStartsWith( '	<title>Kaffee</title>', $output );
44
		$this->assertEquals( '2022-01-01 00:00:00', $expire );
45
		$this->assertEquals( 4, count( $tags ) );
46
	}
47
48
49
	public function testGetHeaderSearch()
50
	{
51
		$view = $this->object->getView();
52
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array( 'f_search' => '<b>Search result</b>' ) );
53
		$view->addHelper( 'param', $helper );
54
55
		$tags = array();
56
		$expire = null;
57
		$output = $this->object->getHeader( 1, $tags, $expire );
58
59
		$this->assertRegexp( '#<title>[^>]*Search result[^<]*</title>#', $output );
60
		$this->assertEquals( null, $expire );
61
		$this->assertEquals( 1, count( $tags ) );
62
	}
63
64
65
	public function testGetHeaderException()
66
	{
67
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Catalog\Lists\Standard' )
68
			->setConstructorArgs( array( $this->context, array() ) )
69
			->setMethods( array( 'setViewParams' ) )
70
			->getMock();
71
72
		$object->expects( $this->once() )->method( 'setViewParams' )
73
			->will( $this->throwException( new \Exception() ) );
74
75
		$object->setView( \TestHelperHtml::getView() );
76
77
		$this->assertContains( '<meta name="application-name" content="Aimeos" />', $object->getHeader() );
78
	}
79
80
81
	public function testGetBody()
82
	{
83
		$view = $this->object->getView();
84
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array( 'f_catid' => $this->getCatalogItem()->getId() ) );
85
		$view->addHelper( 'param', $helper );
86
87
		$tags = array();
88
		$expire = null;
89
		$output = $this->object->getBody( 1, $tags, $expire );
90
91
		$this->assertStringStartsWith( '<section class="aimeos catalog-list home categories coffee">', $output );
92
		$this->assertEquals( '2022-01-01 00:00:00', $expire );
93
		$this->assertEquals( 4, count( $tags ) );
94
	}
95
96
97
	public function testGetBodyNoDefaultCat()
98
	{
99
		$view = $this->object->getView();
100
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array() );
101
		$view->addHelper( 'param', $helper );
102
103
		$output = $this->object->getBody();
104
		$this->assertStringStartsWith( '<section class="aimeos catalog-list">', $output );
105
		$this->assertNotRegExp( '#.*U:TESTPSUB01.*#smu', $output );
106
		$this->assertNotRegExp( '#.*U:TESTSUB03.*#smu', $output );
107
		$this->assertNotRegExp( '#.*U:TESTSUB04.*#smu', $output );
108
		$this->assertNotRegExp( '#.*U:TESTSUB05.*#smu', $output );
109
	}
110
111
112
	public function testGetBodyDefaultCat()
113
	{
114
		$context = clone $this->context;
115
		$context->getConfig()->set( 'client/html/catalog/lists/catid-default', $this->getCatalogItem()->getId() );
116
117
		$paths = \TestHelperHtml::getHtmlTemplatePaths();
118
		$this->object = new \Aimeos\Client\Html\Catalog\Lists\Standard( $context, $paths );
119
		$this->object->setView( \TestHelperHtml::getView() );
120
121
		$view = $this->object->getView();
122
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array() );
123
		$view->addHelper( 'param', $helper );
124
125
		$output = $this->object->getBody();
126
		$this->assertStringStartsWith( '<section class="aimeos catalog-list home categories coffee">', $output );
127
	}
128
129
130
	public function testGetBodyCategoryLevels()
131
	{
132
		$context = clone $this->context;
133
		$context->getConfig()->set( 'client/html/catalog/lists/levels', \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
134
135
		$paths = \TestHelperHtml::getHtmlTemplatePaths();
136
		$this->object = new \Aimeos\Client\Html\Catalog\Lists\Standard( $context, $paths );
137
		$this->object->setView( \TestHelperHtml::getView() );
138
139
		$view = $this->object->getView();
140
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array( 'f_catid' => $this->getCatalogItem( 'root' )->getId() ) );
141
		$view->addHelper( 'param', $helper );
142
143
		$output = $this->object->getBody();
144
		$this->assertRegExp( '#.*Cafe Noire Cappuccino.*#smu', $output );
145
		$this->assertRegExp( '#.*Cafe Noire Expresso.*#smu', $output );
146
		$this->assertRegExp( '#.*Unittest: Bundle.*#smu', $output );
147
		$this->assertRegExp( '#.*Unittest: Test priced Selection.*#smu', $output );
148
	}
149
150
151
	public function testGetBodySearchText()
152
	{
153
		$view = $this->object->getView();
154
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array( 'f_search' => 'Kaffee' ) );
155
		$view->addHelper( 'param', $helper );
156
157
		$output = $this->object->getBody();
158
		$this->assertStringStartsWith( '<section class="aimeos catalog-list">', $output );
159
	}
160
161
162
	public function testGetBodySearchAttribute()
163
	{
164
		$view = $this->object->getView();
165
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array( 'f_attrid' => array( -1, -2 ) ) );
166
		$view->addHelper( 'param', $helper );
167
168
		$output = $this->object->getBody();
169
		$this->assertStringStartsWith( '<section class="aimeos catalog-list">', $output );
170
	}
171
172
173
	public function testGetBodyHtmlException()
174
	{
175
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Catalog\Lists\Standard' )
176
			->setConstructorArgs( array( $this->context, array() ) )
177
			->setMethods( array( 'setViewParams' ) )
178
			->getMock();
179
180
		$object->expects( $this->once() )->method( 'setViewParams' )
181
			->will( $this->throwException( new \Aimeos\Client\Html\Exception( 'test exception' ) ) );
182
183
		$object->setView( \TestHelperHtml::getView() );
184
185
		$this->assertContains( 'test exception', $object->getBody() );
186
	}
187
188
189
	public function testGetBodyFrontendException()
190
	{
191
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Catalog\Lists\Standard' )
192
			->setConstructorArgs( array( $this->context, array() ) )
193
			->setMethods( array( 'setViewParams' ) )
194
			->getMock();
195
196
		$object->expects( $this->once() )->method( 'setViewParams' )
197
			->will( $this->throwException( new \Aimeos\Controller\Frontend\Exception( 'test exception' ) ) );
198
199
		$object->setView( \TestHelperHtml::getView() );
200
201
		$this->assertContains( 'test exception', $object->getBody() );
202
	}
203
204
205
	public function testGetBodyMShopException()
206
	{
207
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Catalog\Lists\Standard' )
208
			->setConstructorArgs( array( $this->context, array() ) )
209
			->setMethods( array( 'setViewParams' ) )
210
			->getMock();
211
212
		$object->expects( $this->once() )->method( 'setViewParams' )
213
			->will( $this->throwException( new \Aimeos\MShop\Exception( 'test exception' ) ) );
214
215
		$object->setView( \TestHelperHtml::getView() );
216
217
		$this->assertContains( 'test exception', $object->getBody() );
218
	}
219
220
221
	public function testGetBodyException()
222
	{
223
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Catalog\Lists\Standard' )
224
			->setConstructorArgs( array( $this->context, array() ) )
225
			->setMethods( array( 'setViewParams' ) )
226
			->getMock();
227
228
		$object->expects( $this->once() )->method( 'setViewParams' )
229
			->will( $this->throwException( new \Exception( 'test exception' ) ) );
230
231
		$object->setView( \TestHelperHtml::getView() );
232
233
		$this->assertContains( 'A non-recoverable error occured', $object->getBody() );
234
	}
235
236
237
	public function testGetSubClient()
238
	{
239
		$client = $this->object->getSubClient( 'items', 'Standard' );
240
		$this->assertInstanceOf( '\\Aimeos\\Client\\HTML\\Iface', $client );
241
	}
242
243
244
	public function testGetSubClientInvalid()
245
	{
246
		$this->setExpectedException( '\\Aimeos\\Client\\Html\\Exception' );
247
		$this->object->getSubClient( 'invalid', 'invalid' );
248
	}
249
250
251
	public function testGetSubClientInvalidName()
252
	{
253
		$this->setExpectedException( '\\Aimeos\\Client\\Html\\Exception' );
254
		$this->object->getSubClient( '$$$', '$$$' );
255
	}
256
257
258
	public function testProcess()
259
	{
260
		$this->object->process();
261
	}
262
263
264
	public function testProcessHtmlException()
265
	{
266
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Catalog\Lists\Standard' )
267
			->setConstructorArgs( array( $this->context, array() ) )
268
			->setMethods( array( 'getClientParams' ) )
269
			->getMock();
270
271
		$object->expects( $this->once() )->method( 'getClientParams' )
272
			->will( $this->throwException( new \Aimeos\Client\Html\Exception( 'text exception') ) );
273
274
		$object->setView( \TestHelperHtml::getView() );
275
276
		$object->process();
277
278
		$this->assertInternalType( 'array', $object->getView()->listErrorList );
279
	}
280
281
282
	public function testProcessFrontendException()
283
	{
284
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Catalog\Lists\Standard' )
285
			->setConstructorArgs( array( $this->context, array() ) )
286
			->setMethods( array( 'getClientParams' ) )
287
			->getMock();
288
289
		$object->expects( $this->once() )->method( 'getClientParams' )
290
			->will( $this->throwException( new \Aimeos\Controller\Frontend\Exception( 'text exception') ) );
291
292
		$object->setView( \TestHelperHtml::getView() );
293
294
		$object->process();
295
296
		$this->assertInternalType( 'array', $object->getView()->listErrorList );
297
	}
298
299
300
	public function testProcessMShopException()
301
	{
302
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Catalog\Lists\Standard' )
303
			->setConstructorArgs( array( $this->context, array() ) )
304
			->setMethods( array( 'getClientParams' ) )
305
			->getMock();
306
307
		$object->expects( $this->once() )->method( 'getClientParams' )
308
			->will( $this->throwException( new \Aimeos\MShop\Exception( 'text exception') ) );
309
310
		$object->setView( \TestHelperHtml::getView() );
311
312
		$object->process();
313
314
		$this->assertInternalType( 'array', $object->getView()->listErrorList );
315
	}
316
317
318
	public function testProcessException()
319
	{
320
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Catalog\Lists\Standard' )
321
		->setConstructorArgs( array( $this->context, array() ) )
322
		->setMethods( array( 'getClientParams' ) )
323
		->getMock();
324
325
		$object->expects( $this->once() )->method( 'getClientParams' )
326
		->will( $this->throwException( new \Exception( 'text exception') ) );
327
328
		$object->setView( \TestHelperHtml::getView() );
329
330
		$object->process();
331
332
		$this->assertInternalType( 'array', $object->getView()->listErrorList );
333
	}
334
335
336
	protected function getCatalogItem( $code = 'cafe' )
337
	{
338
		$catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager( $this->context );
339
		$search = $catalogManager->createSearch();
340
		$search->setConditions( $search->compare( '==', 'catalog.code', $code ) );
341
		$items = $catalogManager->searchItems( $search );
342
343
		if( ( $item = reset( $items ) ) === false ) {
344
			throw new \Exception( sprintf( 'No catalog item with code "%1$s" found', $code ) );
345
		}
346
347
		return $item;
348
	}
349
}
350