1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2014 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2021 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\Client\Html\Locale\Select; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $context; |
16
|
|
|
private $object; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() : void |
20
|
|
|
{ |
21
|
|
|
$this->context = \TestHelperHtml::getContext(); |
22
|
|
|
|
23
|
|
|
$this->object = new \Aimeos\Client\Html\Locale\Select\Standard( $this->context ); |
24
|
|
|
$this->object->setView( \TestHelperHtml::getView() ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
protected function tearDown() : void |
29
|
|
|
{ |
30
|
|
|
unset( $this->object ); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
public function testHeader() |
35
|
|
|
{ |
36
|
|
|
$tags = []; |
37
|
|
|
$expire = null; |
38
|
|
|
$output = $this->object->header( 1, $tags, $expire ); |
39
|
|
|
|
40
|
|
|
$this->assertNotNull( $output ); |
41
|
|
|
$this->assertEquals( null, $expire ); |
42
|
|
|
$this->assertEquals( 0, count( $tags ) ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public function testHeaderException() |
47
|
|
|
{ |
48
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Locale\Select\Standard::class ) |
49
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
50
|
|
|
->setMethods( array( 'data' ) ) |
51
|
|
|
->getMock(); |
52
|
|
|
|
53
|
|
|
$object->expects( $this->once() )->method( 'data' ) |
54
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
55
|
|
|
|
56
|
|
|
$object->setView( \TestHelperHtml::getView() ); |
57
|
|
|
|
58
|
|
|
$this->assertEquals( null, $object->header() ); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
public function testBody() |
63
|
|
|
{ |
64
|
|
|
$view = $this->object->getView(); |
65
|
|
|
$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock(); |
66
|
|
|
$helper = new \Aimeos\MW\View\Helper\Request\Standard( $view, $request, '127.0.0.1', 'test' ); |
67
|
|
|
$view->addHelper( 'request', $helper ); |
68
|
|
|
|
69
|
|
|
$tags = []; |
70
|
|
|
$expire = null; |
71
|
|
|
$output = $this->object->body( 1, $tags, $expire ); |
72
|
|
|
|
73
|
|
|
$this->assertStringStartsWith( '<section class="aimeos locale-select"', $output ); |
74
|
|
|
$this->assertEquals( null, $expire ); |
75
|
|
|
$this->assertEquals( 0, count( $tags ) ); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
public function testBodyHtmlException() |
80
|
|
|
{ |
81
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Locale\Select\Standard::class ) |
82
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
83
|
|
|
->setMethods( array( 'data' ) ) |
84
|
|
|
->getMock(); |
85
|
|
|
|
86
|
|
|
$object->expects( $this->once() )->method( 'data' ) |
87
|
|
|
->will( $this->throwException( new \Aimeos\Client\Html\Exception( 'test exception' ) ) ); |
88
|
|
|
|
89
|
|
|
$object->setView( \TestHelperHtml::getView() ); |
90
|
|
|
|
91
|
|
|
$this->assertStringContainsString( 'test exception', $object->body() ); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
public function testBodyFrontendException() |
96
|
|
|
{ |
97
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Locale\Select\Standard::class ) |
98
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
99
|
|
|
->setMethods( array( 'data' ) ) |
100
|
|
|
->getMock(); |
101
|
|
|
|
102
|
|
|
$object->expects( $this->once() )->method( 'data' ) |
103
|
|
|
->will( $this->throwException( new \Aimeos\Controller\Frontend\Exception( 'test exception' ) ) ); |
104
|
|
|
|
105
|
|
|
$object->setView( \TestHelperHtml::getView() ); |
106
|
|
|
|
107
|
|
|
$this->assertStringContainsString( 'test exception', $object->body() ); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
public function testBodyMShopException() |
112
|
|
|
{ |
113
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Locale\Select\Standard::class ) |
114
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
115
|
|
|
->setMethods( array( 'data' ) ) |
116
|
|
|
->getMock(); |
117
|
|
|
|
118
|
|
|
$object->expects( $this->once() )->method( 'data' ) |
119
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception( 'test exception' ) ) ); |
120
|
|
|
|
121
|
|
|
$object->setView( \TestHelperHtml::getView() ); |
122
|
|
|
|
123
|
|
|
$this->assertStringContainsString( 'test exception', $object->body() ); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
public function testBodyException() |
128
|
|
|
{ |
129
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Locale\Select\Standard::class ) |
130
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
131
|
|
|
->setMethods( array( 'data' ) ) |
132
|
|
|
->getMock(); |
133
|
|
|
|
134
|
|
|
$object->expects( $this->once() )->method( 'data' ) |
135
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
136
|
|
|
|
137
|
|
|
$object->setView( \TestHelperHtml::getView() ); |
138
|
|
|
|
139
|
|
|
$this->assertStringContainsString( 'A non-recoverable error occured', $object->body() ); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
|
143
|
|
|
public function testGetSubClient() |
144
|
|
|
{ |
145
|
|
|
$client = $this->object->getSubClient( 'language', 'Standard' ); |
146
|
|
|
$this->assertInstanceOf( '\\Aimeos\\Client\\HTML\\Iface', $client ); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
public function testGetSubClientInvalid() |
151
|
|
|
{ |
152
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
153
|
|
|
$this->object->getSubClient( 'invalid', 'invalid' ); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
public function testGetSubClientInvalidName() |
158
|
|
|
{ |
159
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
160
|
|
|
$this->object->getSubClient( '$$$', '$$$' ); |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|