Passed
Pull Request — master (#73)
by
unknown
02:49
created

StandardTest::testGetSubClientInvalidName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
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-2018
7
 */
8
9
10
namespace Aimeos\Client\Html\Catalog\Product;
11
12
13
class StandardTest extends \PHPUnit\Framework\TestCase
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
{
15
	private $object;
16
	private $context;
17
18
19
	protected function setUp()
20
	{
21
		$this->context = \TestHelperHtml::getContext();
22
		$this->context->getConfig()->set( 'client/html/catalog/product/product-codes', ['CNE', 'IJKL', 'CNC'] );
23
24
		$this->object = new \Aimeos\Client\Html\Catalog\Product\Standard( $this->context );
25
		$this->object->setView( \TestHelperHtml::getView() );
26
	}
27
28
29
	protected function tearDown()
30
	{
31
		unset( $this->object );
32
	}
33
34
35
	public function testGetHeader()
36
	{
37
		$view = $this->object->getView();
38
39
		$tags = [];
40
		$expire = null;
41
42
		$this->object->setView( $this->object->addData( $view, $tags, $expire ) );
43
		$output = $this->object->getHeader();
44
45
		$this->assertContains( '<script type="text/javascript"', $output );
46
		$prodCodeParam = '/s_prodcode%5B[0-9]%5D=';
47
		$this->assertRegExp( $prodCodeParam . 'CNE/', $output );
48
		$this->assertRegExp( $prodCodeParam . 'IJKL/', $output );
49
		$this->assertRegExp( $prodCodeParam . 'CNC/', $output );
50
		$this->assertEquals( '2098-01-01 00:00:00', $expire );
51
	}
52
53
54
	public function testGetHeaderException()
55
	{
56
		$object = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Product\Standard::class )
57
			->setConstructorArgs( array( $this->context, [] ) )
58
			->setMethods( array( 'addData' ) )
59
			->getMock();
60
61
		$object->expects( $this->once() )->method( 'addData' )
62
			->will( $this->throwException( new \RuntimeException() ) );
63
64
		$object->setView( \TestHelperHtml::getView() );
65
66
		$this->assertNull( $object->getHeader() );
67
	}
68
69
70
	public function testGetBody()
71
	{
72
		$view = $this->object->getView();
73
74
		$tags = [];
75
		$expire = null;
76
77
		$this->object->setView( $this->object->addData( $view, $tags, $expire ) );
78
		$output = $this->object->getBody();
79
80
		$productNameCNE = '<h2 itemprop="name">Cafe Noire Expresso</h2>';
81
		$productNameIJKL = '<h2 itemprop="name">Unterproduct 3</h2>';
82
		$productNameCNC = '<h2 itemprop="name">Cafe Noire Cappuccino</h2>';
83
		$this->assertContains( $productNameCNE, $output );
84
		$this->assertContains( $productNameIJKL, $output );
85
		$this->assertContains( $productNameCNC, $output );
86
87
		$outputPosCNE = strpos( $output, $productNameCNE );
88
		$outputPosIJKL = strpos( $output, $productNameIJKL );
89
		$outputPosCNC = strpos( $output, $productNameCNC );
90
		$this->assertGreaterThan( $outputPosCNE, $outputPosIJKL );
91
		$this->assertGreaterThan( $productNameIJKL, $outputPosCNC );
92
93
		$this->assertEquals( '2098-01-01 00:00:00', $expire );
94
	}
95
96
97
	public function testGetBodyHtmlException()
98
	{
99
		$object = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Product\Standard::class )
100
			->setConstructorArgs( array( $this->context, [] ) )
101
			->setMethods( array( 'addData' ) )
102
			->getMock();
103
104
		$object->expects( $this->once() )->method( 'addData' )
105
			->will( $this->throwException( new \Aimeos\Client\Html\Exception( 'test exception' ) ) );
106
107
		$object->setView( \TestHelperHtml::getView() );
108
109
		$this->assertContains( 'test exception', $object->getBody() );
110
	}
111
112
113
	public function testGetBodyFrontendException()
114
	{
115
		$object = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Product\Standard::class )
116
			->setConstructorArgs( array( $this->context, [] ) )
117
			->setMethods( array( 'addData' ) )
118
			->getMock();
119
120
		$object->expects( $this->once() )->method( 'addData' )
121
			->will( $this->throwException( new \Aimeos\Controller\Frontend\Exception( 'test exception' ) ) );
122
123
		$object->setView( \TestHelperHtml::getView() );
124
125
		$this->assertContains( 'test exception', $object->getBody() );
126
	}
127
128
129
	public function testGetBodyMShopException()
130
	{
131
		$object = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Product\Standard::class )
132
			->setConstructorArgs( array( $this->context, [] ) )
133
			->setMethods( array( 'addData' ) )
134
			->getMock();
135
136
		$object->expects( $this->once() )->method( 'addData' )
137
			->will( $this->throwException( new \Aimeos\MShop\Exception( 'test exception' ) ) );
138
139
		$object->setView( \TestHelperHtml::getView() );
140
141
		$this->assertContains( 'test exception', $object->getBody() );
142
	}
143
144
145
	public function testGetBodyException()
146
	{
147
		$object = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Product\Standard::class )
148
			->setConstructorArgs( array( $this->context, [] ) )
149
			->setMethods( array( 'addData' ) )
150
			->getMock();
151
152
		$object->expects( $this->once() )->method( 'addData' )
153
			->will( $this->throwException( new \RuntimeException( 'test exception' ) ) );
154
155
		$object->setView( \TestHelperHtml::getView() );
156
157
		$this->assertContains( 'A non-recoverable error occured', $object->getBody() );
158
	}
159
160
161
	public function testGetSubClientInvalid()
162
	{
163
		$this->setExpectedException( '\\Aimeos\\Client\\Html\\Exception' );
164
		$this->object->getSubClient( 'invalid', 'invalid' );
165
	}
166
167
168
	public function testGetSubClientInvalidName()
169
	{
170
		$this->setExpectedException( '\\Aimeos\\Client\\Html\\Exception' );
171
		$this->object->getSubClient( '$$$', '$$$' );
172
	}
173
174
175
	public function testProcess()
176
	{
177
		$this->object->process();
178
	}
179
}
180