Passed
Push — master ( 8bf70e...6a7093 )
by Aimeos
03:42
created

StandardTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
c 1
b 0
f 0
dl 0
loc 62
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testHeader() 0 4 1
A tearDown() 0 3 1
A testBodyUseCodes() 0 15 2
A testBody() 0 13 2
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2013
6
 * @copyright Aimeos (aimeos.org), 2015-2022
7
 */
8
9
10
namespace Aimeos\Client\Html\Catalog\Suggest;
11
12
13
class StandardTest extends \PHPUnit\Framework\TestCase
14
{
15
	private $object;
16
	private $context;
17
	private $view;
18
19
20
	protected function setUp() : void
21
	{
22
		$this->view = \TestHelperHtml::view();
23
		$this->context = \TestHelperHtml::context();
24
25
		$this->object = new \Aimeos\Client\Html\Catalog\Suggest\Standard( $this->context );
26
		$this->object->setView( $this->view );
27
	}
28
29
30
	protected function tearDown() : void
31
	{
32
		unset( $this->object, $this->context, $this->view );
33
	}
34
35
36
	public function testHeader()
37
	{
38
		$output = $this->object->header();
39
		$this->assertNotNull( $output );
40
	}
41
42
43
	public function testBody()
44
	{
45
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, array( 'f_search' => 'Unterpro' ) );
46
		$this->view->addHelper( 'param', $helper );
47
48
		$output = $this->object->body();
49
		$suggestItems = $this->view->suggestItems;
50
51
		$this->assertRegExp( '#\[\{"label":"Unterpro.*","html":".*Unterpro.*"\}\]#smU', $output );
52
		$this->assertNotEquals( [], $suggestItems );
53
54
		foreach( $suggestItems as $item ) {
55
			$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $item );
56
		}
57
	}
58
59
60
	public function testBodyUseCodes()
61
	{
62
		$this->context->config()->set( 'client/html/catalog/suggest/usecode', true );
63
64
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, array( 'f_search' => 'CNC' ) );
65
		$this->view->addHelper( 'param', $helper );
66
67
		$output = $this->object->body();
68
		$suggestItems = $this->view->suggestItems;
69
70
		$this->assertRegExp( '#\[.*\{"label":"Cafe.*","html":".*Cafe.*"\}.*\]#smU', $output );
71
		$this->assertNotEquals( [], $suggestItems );
72
73
		foreach( $suggestItems as $item ) {
74
			$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $item );
75
		}
76
	}
77
}
78