1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2022-2025 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Client\Html\Common\Decorator; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class ExceptionsTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $client; |
15
|
|
|
private $object; |
16
|
|
|
private $view; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() : void |
20
|
|
|
{ |
21
|
|
|
$context = \TestHelper::context(); |
22
|
|
|
$this->view = \TestHelper::view(); |
23
|
|
|
|
24
|
|
|
$this->client = $this->getMockBuilder( '\\Aimeos\\Client\\Html\\Catalog\\Filter\\Standard' ) |
25
|
|
|
->setConstructorArgs( [$context] ) |
26
|
|
|
->onlyMethods( ['body', 'header', 'init'] ) |
27
|
|
|
->getMock(); |
28
|
|
|
|
29
|
|
|
$this->object = new \Aimeos\Client\Html\Common\Decorator\Exceptions( $this->client, $context ); |
30
|
|
|
$this->object->setView( $this->view ); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
protected function tearDown() : void |
35
|
|
|
{ |
36
|
|
|
unset( $this->view, $this->object, $this->client ); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
public function testBody() |
41
|
|
|
{ |
42
|
|
|
$this->client->expects( $this->once() )->method( 'body' )->willReturn( 'test' ); |
43
|
|
|
|
44
|
|
|
$this->assertEquals( 'test', $this->object->body() ); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
public function testBodyClientException() |
49
|
|
|
{ |
50
|
|
|
$this->client->expects( $this->once() )->method( 'body' ) |
51
|
|
|
->will( $this->throwException( new \Aimeos\Client\Html\Exception( 'test exception' ) ) ); |
52
|
|
|
|
53
|
|
|
$this->assertStringContainsString( 'test exception', $this->object->body() ); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
public function testBodyFrontendException() |
58
|
|
|
{ |
59
|
|
|
$this->client->expects( $this->once() )->method( 'body' ) |
60
|
|
|
->will( $this->throwException( new \Aimeos\Controller\Frontend\Exception( 'test exception' ) ) ); |
61
|
|
|
|
62
|
|
|
$this->assertStringContainsString( 'test exception', $this->object->body() ); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
public function testBodyMShopException() |
67
|
|
|
{ |
68
|
|
|
$this->client->expects( $this->once() )->method( 'body' ) |
69
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception( 'test exception' ) ) ); |
70
|
|
|
|
71
|
|
|
$this->assertStringContainsString( 'test exception', $this->object->body() ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
public function testBodyException() |
76
|
|
|
{ |
77
|
|
|
$this->client->expects( $this->once() )->method( 'body' ) |
78
|
|
|
->will( $this->throwException( new \Exception() ) ); |
79
|
|
|
|
80
|
|
|
$this->assertStringContainsString( 'A non-recoverable error occured', $this->object->body() ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
public function testHeader() |
85
|
|
|
{ |
86
|
|
|
$this->client->expects( $this->once() )->method( 'header' )->willReturn( 'test' ); |
87
|
|
|
|
88
|
|
|
$this->assertEquals( 'test', $this->object->header() ); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
public function testHeaderClientException() |
93
|
|
|
{ |
94
|
|
|
$this->client->expects( $this->once() )->method( 'header' ) |
95
|
|
|
->will( $this->throwException( new \Aimeos\Client\Html\Exception( 'test exception' ) ) ); |
96
|
|
|
|
97
|
|
|
$this->assertStringContainsString( 'test exception', $this->object->header() ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
public function testHeaderFrontendException() |
102
|
|
|
{ |
103
|
|
|
$this->client->expects( $this->once() )->method( 'header' ) |
104
|
|
|
->will( $this->throwException( new \Aimeos\Controller\Frontend\Exception( 'test exception' ) ) ); |
105
|
|
|
|
106
|
|
|
$this->assertStringContainsString( 'test exception', $this->object->header() ); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
public function testHeaderMShopException() |
111
|
|
|
{ |
112
|
|
|
$this->client->expects( $this->once() )->method( 'header' ) |
113
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception( 'test exception' ) ) ); |
114
|
|
|
|
115
|
|
|
$this->assertStringContainsString( 'test exception', $this->object->header() ); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
public function testHeaderException() |
120
|
|
|
{ |
121
|
|
|
$this->client->expects( $this->once() )->method( 'header' ) |
122
|
|
|
->will( $this->throwException( new \Exception() ) ); |
123
|
|
|
|
124
|
|
|
$this->assertStringContainsString( 'A non-recoverable error occured', $this->object->header() ); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
public function testInit() |
129
|
|
|
{ |
130
|
|
|
$this->client->expects( $this->once() )->method( 'init' ); |
131
|
|
|
|
132
|
|
|
$this->object->init(); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
|
136
|
|
|
public function testInitClientException() |
137
|
|
|
{ |
138
|
|
|
$this->client->expects( $this->once() )->method( 'init' ) |
139
|
|
|
->will( $this->throwException( new \Aimeos\Client\Html\Exception( 'test exception' ) ) ); |
140
|
|
|
|
141
|
|
|
$this->object->init(); |
142
|
|
|
|
143
|
|
|
$this->assertStringContainsString( 'test exception', $this->object->body() ); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
|
147
|
|
|
public function testInitFrontendException() |
148
|
|
|
{ |
149
|
|
|
$this->client->expects( $this->once() )->method( 'init' ) |
150
|
|
|
->will( $this->throwException( new \Aimeos\Controller\Frontend\Exception( 'test exception' ) ) ); |
151
|
|
|
|
152
|
|
|
$this->object->init(); |
153
|
|
|
|
154
|
|
|
$this->assertStringContainsString( 'test exception', $this->object->body() ); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
|
158
|
|
|
public function testInitMShopException() |
159
|
|
|
{ |
160
|
|
|
$this->client->expects( $this->once() )->method( 'init' ) |
161
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception( 'test exception' ) ) ); |
162
|
|
|
|
163
|
|
|
$this->object->init(); |
164
|
|
|
|
165
|
|
|
$this->assertStringContainsString( 'test exception', $this->object->body() ); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
|
169
|
|
|
public function testInitException() |
170
|
|
|
{ |
171
|
|
|
$this->client->expects( $this->once() )->method( 'init' ) |
172
|
|
|
->will( $this->throwException( new \Exception() ) ); |
173
|
|
|
|
174
|
|
|
$this->object->init(); |
175
|
|
|
|
176
|
|
|
$this->assertStringContainsString( 'A non-recoverable error occured', $this->object->body() ); |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|