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\Admin\JQAdm\Review; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $context; |
15
|
|
|
private $object; |
16
|
|
|
private $view; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() : void |
20
|
|
|
{ |
21
|
|
|
$this->view = \TestHelperJqadm::getView(); |
22
|
|
|
$this->context = \TestHelperJqadm::getContext(); |
23
|
|
|
|
24
|
|
|
$this->object = new \Aimeos\Admin\JQAdm\Review\Standard( $this->context ); |
25
|
|
|
$this->object = new \Aimeos\Admin\JQAdm\Common\Decorator\Page( $this->object, $this->context ); |
26
|
|
|
$this->object->setAimeos( \TestHelperJqadm::getAimeos() ); |
27
|
|
|
$this->object->setView( $this->view ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
protected function tearDown() : void |
32
|
|
|
{ |
33
|
|
|
unset( $this->object, $this->view, $this->context ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
public function testDelete() |
38
|
|
|
{ |
39
|
|
|
$this->assertEmpty( $this->getClientMock( ['redirect'], false )->delete() ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
public function testDeleteException() |
44
|
|
|
{ |
45
|
|
|
$object = $this->getClientMock( ['getSubClients', 'search'] ); |
46
|
|
|
|
47
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
48
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
49
|
|
|
$object->expects( $this->once() )->method( 'search' ); |
50
|
|
|
|
51
|
|
|
$object->delete(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
public function testGet() |
56
|
|
|
{ |
57
|
|
|
$param = ['site' => 'unittest', 'id' => $this->getItem()->getId()]; |
58
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
59
|
|
|
$this->view->addHelper( 'param', $helper ); |
60
|
|
|
|
61
|
|
|
$result = $this->object->get(); |
62
|
|
|
|
63
|
|
|
$this->assertStringContainsString( 'an [email protected] comment', $result ); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
public function testGetException() |
68
|
|
|
{ |
69
|
|
|
$object = $this->getClientMock( 'getSubClients' ); |
70
|
|
|
|
71
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
72
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
73
|
|
|
|
74
|
|
|
$object->get(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
public function testGetViewException() |
79
|
|
|
{ |
80
|
|
|
$object = new \Aimeos\Admin\JQAdm\Review\Standard( $this->context, [] ); |
|
|
|
|
81
|
|
|
|
82
|
|
|
$this->expectException( \Aimeos\Admin\JQAdm\Exception::class ); |
83
|
|
|
$object->getView(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
public function testSave() |
88
|
|
|
{ |
89
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'review' ); |
90
|
|
|
|
91
|
|
|
$param = array( |
92
|
|
|
'site' => 'unittest', |
93
|
|
|
'item' => array( |
94
|
|
|
'review.id' => '', |
95
|
|
|
'review.domain' =>'product', |
96
|
|
|
'review.refid' => '123', |
97
|
|
|
'review.name' => 'test name', |
98
|
|
|
'review.rating' => '1', |
99
|
|
|
'review.comment' => 'test comment', |
100
|
|
|
'review.response' => 'test response', |
101
|
|
|
'review.status' => '-2', |
102
|
|
|
), |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
106
|
|
|
$this->view->addHelper( 'param', $helper ); |
107
|
|
|
|
108
|
|
|
$result = $this->object->save(); |
109
|
|
|
|
110
|
|
|
$manager->deleteItem( $this->getItem( '1' )->getId() ); |
111
|
|
|
|
112
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
113
|
|
|
$this->assertNull( $result ); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
|
117
|
|
|
public function testSaveException() |
118
|
|
|
{ |
119
|
|
|
$object = $this->getClientMock( 'fromArray' ); |
120
|
|
|
|
121
|
|
|
$object->expects( $this->once() )->method( 'fromArray' ) |
122
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
123
|
|
|
|
124
|
|
|
$object->save(); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
public function testSearch() |
129
|
|
|
{ |
130
|
|
|
$param = array( |
131
|
|
|
'site' => 'unittest', 'lang' => 'de', |
132
|
|
|
'filter' => array( |
133
|
|
|
'key' => array( 0 => 'review.rating' ), |
134
|
|
|
'op' => array( 0 => '==' ), |
135
|
|
|
'val' => array( 0 => '4' ), |
136
|
|
|
), |
137
|
|
|
'sort' => array( '-review.ctime', '-review.id' ), |
138
|
|
|
); |
139
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
140
|
|
|
$this->view->addHelper( 'param', $helper ); |
141
|
|
|
|
142
|
|
|
$result = $this->object->search(); |
143
|
|
|
|
144
|
|
|
$this->assertStringContainsString( '>an [email protected] comment<', $result ); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
|
148
|
|
|
public function testSearchException() |
149
|
|
|
{ |
150
|
|
|
$object = $this->getClientMock( 'initCriteria' ); |
151
|
|
|
|
152
|
|
|
$object->expects( $this->once() )->method( 'initCriteria' ) |
153
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
154
|
|
|
|
155
|
|
|
$object->search(); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
|
159
|
|
|
public function testGetSubClientInvalid() |
160
|
|
|
{ |
161
|
|
|
$this->expectException( \Aimeos\Admin\JQAdm\Exception::class ); |
162
|
|
|
$this->object->getSubClient( '$unknown$' ); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
|
166
|
|
|
public function testGetSubClientUnknown() |
167
|
|
|
{ |
168
|
|
|
$this->expectException( \Aimeos\Admin\JQAdm\Exception::class ); |
169
|
|
|
$this->object->getSubClient( 'unknown' ); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
|
173
|
|
|
public function getClientMock( $methods, $real = true ) |
174
|
|
|
{ |
175
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Review\Standard::class ) |
176
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
177
|
|
|
->setMethods( (array) $methods ) |
178
|
|
|
->getMock(); |
179
|
|
|
|
180
|
|
|
$object->setAimeos( \TestHelperJqadm::getAimeos() ); |
181
|
|
|
$object->setView( $this->getViewNoRender( $real ) ); |
182
|
|
|
|
183
|
|
|
return $object; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
|
187
|
|
|
protected function getViewNoRender( $real = true ) |
188
|
|
|
{ |
189
|
|
|
$view = $this->getMockBuilder( \Aimeos\MW\View\Standard::class ) |
190
|
|
|
->setConstructorArgs( [[]] ) |
191
|
|
|
->setMethods( ['render'] ) |
192
|
|
|
->getMock(); |
193
|
|
|
|
194
|
|
|
$param = ['site' => 'unittest', 'id' => $real ? $this->getItem()->getId() : -1]; |
195
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param ); |
196
|
|
|
$view->addHelper( 'param', $helper ); |
197
|
|
|
|
198
|
|
|
$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $this->context->getConfig() ); |
199
|
|
|
$view->addHelper( 'config', $helper ); |
200
|
|
|
|
201
|
|
|
$helper = new \Aimeos\MW\View\Helper\Access\Standard( $view, [] ); |
202
|
|
|
$view->addHelper( 'access', $helper ); |
203
|
|
|
|
204
|
|
|
return $view; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
|
208
|
|
|
protected function getItem( $rating = 0 ) |
209
|
|
|
{ |
210
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'review' ); |
211
|
|
|
$filter = $manager->filter()->add( ['review.rating' => $rating] )->slice( 0, 1 ); |
212
|
|
|
|
213
|
|
|
return $manager->search( $filter )->first( new \Exception( sprintf( 'No review with rating "%1$d" found', $rating ) ) ); |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
|
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.