1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2020 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Client\Html\Supplier\Detail; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $context; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
protected function setUp() : void |
19
|
|
|
{ |
20
|
|
|
$this->context = \TestHelperHtml::getContext(); |
21
|
|
|
|
22
|
|
|
$this->object = new \Aimeos\Client\Html\Supplier\Detail\Standard( $this->context ); |
23
|
|
|
$this->object->setView( \TestHelperHtml::getView() ); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
protected function tearDown() : void |
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( 's_supid' => $this->getSupplierItem()->getId() ) ); |
37
|
|
|
$view->addHelper( 'param', $helper ); |
38
|
|
|
|
39
|
|
|
$tags = []; |
40
|
|
|
$expire = null; |
41
|
|
|
|
42
|
|
|
$this->object->setView( $this->object->addData( $this->object->getView(), $tags, $expire ) ); |
43
|
|
|
$output = $this->object->getHeader(); |
44
|
|
|
|
45
|
|
|
$this->assertStringContainsString( '<title>Test supplier</title>', $output ); |
46
|
|
|
$this->assertEquals( '2100-01-01 00:00:00', $expire ); |
47
|
|
|
$this->assertEquals( 3, count( $tags ) ); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
public function testGetHeaderException() |
52
|
|
|
{ |
53
|
|
|
$mock = $this->getMockBuilder( \Aimeos\Client\Html\Supplier\Detail\Standard::class ) |
54
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperHtml::getHtmlTemplatePaths() ) ) |
55
|
|
|
->setMethods( array( 'addData' ) ) |
56
|
|
|
->getMock(); |
57
|
|
|
|
58
|
|
|
$view = $this->object->getView(); |
59
|
|
|
$view->addHelper( 'param', new \Aimeos\MW\View\Helper\Param\Standard( $view, ['s_supid' => -1] ) ); |
60
|
|
|
$mock->setView( $view ); |
61
|
|
|
|
62
|
|
|
$mock->expects( $this->once() )->method( 'addData' ) |
63
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
64
|
|
|
|
65
|
|
|
$mock->getHeader(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
public function testGetBody() |
70
|
|
|
{ |
71
|
|
|
$view = $this->object->getView(); |
72
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array( 's_supid' => $this->getSupplierItem()->getId() ) ); |
73
|
|
|
$view->addHelper( 'param', $helper ); |
74
|
|
|
|
75
|
|
|
$tags = []; |
76
|
|
|
$expire = null; |
77
|
|
|
|
78
|
|
|
$this->object->setView( $this->object->addData( $view, $tags, $expire ) ); |
79
|
|
|
$output = $this->object->getBody(); |
80
|
|
|
|
81
|
|
|
$this->assertStringStartsWith( '<section class="aimeos supplier-detail"', $output ); |
82
|
|
|
$this->assertStringContainsString( '<div class="supplier-detail-basic">', $output ); |
83
|
|
|
$this->assertStringContainsString( '<div class="supplier-detail-image', $output ); |
84
|
|
|
|
85
|
|
|
$this->assertStringContainsString( '<div class="supplier-detail-additional">', $output ); |
86
|
|
|
$this->assertStringContainsString( '<h2 class="header description">', $output ); |
87
|
|
|
|
88
|
|
|
$this->assertEquals( '2100-01-01 00:00:00', $expire ); |
89
|
|
|
$this->assertEquals( 3, count( $tags ) ); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
public function testGetBodyDefaultId() |
94
|
|
|
{ |
95
|
|
|
$context = clone $this->context; |
96
|
|
|
$context->getConfig()->set( 'client/html/supplier/detail/supid-default', $this->getSupplierItem()->getId() ); |
97
|
|
|
|
98
|
|
|
$paths = \TestHelperHtml::getHtmlTemplatePaths(); |
99
|
|
|
$this->object = new \Aimeos\Client\Html\Supplier\Detail\Standard( $context, $paths ); |
|
|
|
|
100
|
|
|
$this->object->setView( \TestHelperHtml::getView() ); |
101
|
|
|
|
102
|
|
|
$view = $this->object->getView(); |
103
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, [] ); |
104
|
|
|
$view->addHelper( 'param', $helper ); |
105
|
|
|
|
106
|
|
|
$this->object->setView( $this->object->addData( $view ) ); |
107
|
|
|
$output = $this->object->getBody(); |
108
|
|
|
|
109
|
|
|
$this->assertStringContainsString( '<h1 class="name" itemprop="name">Test supplier</h1>', $output ); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
public function testGetBodyClientHtmlException() |
114
|
|
|
{ |
115
|
|
|
$mock = $this->getMockBuilder( \Aimeos\Client\Html\Supplier\Detail\Standard::class ) |
116
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperHtml::getHtmlTemplatePaths() ) ) |
117
|
|
|
->setMethods( array( 'addData' ) ) |
118
|
|
|
->getMock(); |
119
|
|
|
|
120
|
|
|
$view = $this->object->getView(); |
121
|
|
|
$view->addHelper( 'param', new \Aimeos\MW\View\Helper\Param\Standard( $view, ['s_supid' => -1] ) ); |
122
|
|
|
$mock->setView( $view ); |
123
|
|
|
|
124
|
|
|
$mock->expects( $this->once() )->method( 'addData' ) |
125
|
|
|
->will( $this->throwException( new \Aimeos\Client\Html\Exception() ) ); |
126
|
|
|
|
127
|
|
|
$mock->getBody(); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
public function testGetBodyControllerFrontendException() |
132
|
|
|
{ |
133
|
|
|
$mock = $this->getMockBuilder( \Aimeos\Client\Html\Supplier\Detail\Standard::class ) |
134
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperHtml::getHtmlTemplatePaths() ) ) |
135
|
|
|
->setMethods( array( 'addData' ) ) |
136
|
|
|
->getMock(); |
137
|
|
|
|
138
|
|
|
$view = $this->object->getView(); |
139
|
|
|
$view->addHelper( 'param', new \Aimeos\MW\View\Helper\Param\Standard( $view, ['s_supid' => -1] ) ); |
140
|
|
|
$mock->setView( $view ); |
141
|
|
|
|
142
|
|
|
$mock->expects( $this->once() )->method( 'addData' ) |
143
|
|
|
->will( $this->throwException( new \Aimeos\Controller\Frontend\Exception() ) ); |
144
|
|
|
|
145
|
|
|
$mock->getBody(); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
|
149
|
|
|
public function testGetBodyMShopException() |
150
|
|
|
{ |
151
|
|
|
$mock = $this->getMockBuilder( \Aimeos\Client\Html\Supplier\Detail\Standard::class ) |
152
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperHtml::getHtmlTemplatePaths() ) ) |
153
|
|
|
->setMethods( array( 'addData' ) ) |
154
|
|
|
->getMock(); |
155
|
|
|
|
156
|
|
|
$view = $this->object->getView(); |
157
|
|
|
$view->addHelper( 'param', new \Aimeos\MW\View\Helper\Param\Standard( $view, ['s_supid' => -1] ) ); |
158
|
|
|
$mock->setView( $view ); |
159
|
|
|
|
160
|
|
|
$mock->expects( $this->once() )->method( 'addData' ) |
161
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
162
|
|
|
|
163
|
|
|
$mock->getBody(); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
|
167
|
|
|
public function testGetBodyException() |
168
|
|
|
{ |
169
|
|
|
$mock = $this->getMockBuilder( \Aimeos\Client\Html\Supplier\Detail\Standard::class ) |
170
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperHtml::getHtmlTemplatePaths() ) ) |
171
|
|
|
->setMethods( array( 'addData' ) ) |
172
|
|
|
->getMock(); |
173
|
|
|
|
174
|
|
|
$view = $this->object->getView(); |
175
|
|
|
$view->addHelper( 'param', new \Aimeos\MW\View\Helper\Param\Standard( $view, ['s_supid' => -1] ) ); |
176
|
|
|
$mock->setView( $view ); |
177
|
|
|
|
178
|
|
|
$mock->expects( $this->once() )->method( 'addData' ) |
179
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
180
|
|
|
|
181
|
|
|
$mock->getBody(); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
|
185
|
|
|
public function testGetSubClientInvalid() |
186
|
|
|
{ |
187
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
188
|
|
|
$this->object->getSubClient( 'invalid', 'invalid' ); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
|
192
|
|
|
public function testGetSubClientInvalidName() |
193
|
|
|
{ |
194
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
195
|
|
|
$this->object->getSubClient( '$$$', '$$$' ); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
|
199
|
|
|
public function testProcess() |
200
|
|
|
{ |
201
|
|
|
$this->object->process(); |
202
|
|
|
|
203
|
|
|
$this->assertEmpty( $this->object->getView()->get( 'detailErrorList' ) ); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
|
207
|
|
|
protected function getSupplierItem( $code = 'unitCode001', $domains = [] ) |
208
|
|
|
{ |
209
|
|
|
return \Aimeos\MShop\Supplier\Manager\Factory::create( $this->context )->find( $code, $domains ); |
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.