1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2021-2025 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Admin\JQAdm\Cms; |
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 = \TestHelper::view(); |
22
|
|
|
$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock(); |
23
|
|
|
$request->expects( $this->any() )->method( 'getUploadedFiles' )->willReturn( [] ); |
24
|
|
|
|
25
|
|
|
$helper = new \Aimeos\Base\View\Helper\Request\Standard( $this->view, $request, '127.0.0.1', 'test' ); |
26
|
|
|
$this->view ->addHelper( 'request', $helper ); |
27
|
|
|
|
28
|
|
|
$this->context = \TestHelper::context(); |
29
|
|
|
|
30
|
|
|
$this->object = new \Aimeos\Admin\JQAdm\Cms\Standard( $this->context ); |
31
|
|
|
$this->object = new \Aimeos\Admin\JQAdm\Common\Decorator\Page( $this->object, $this->context ); |
32
|
|
|
$this->object->setAimeos( \TestHelper::getAimeos() ); |
33
|
|
|
$this->object->setView( $this->view ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
protected function tearDown() : void |
38
|
|
|
{ |
39
|
|
|
unset( $this->object, $this->view, $this->context ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
public function testCreate() |
44
|
|
|
{ |
45
|
|
|
$result = $this->object->create(); |
46
|
|
|
|
47
|
|
|
$this->assertStringContainsString( 'cms', $result ); |
48
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
public function testCreateException() |
53
|
|
|
{ |
54
|
|
|
$object = $this->getClientMock( 'getSubClients' ); |
55
|
|
|
|
56
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
57
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
58
|
|
|
|
59
|
|
|
$object->create(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
public function testCopy() |
64
|
|
|
{ |
65
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'cms' ); |
66
|
|
|
|
67
|
|
|
$param = ['site' => 'unittest', 'id' => $manager->find( '/contact' )->getId()]; |
|
|
|
|
68
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
69
|
|
|
$this->view->addHelper( 'param', $helper ); |
70
|
|
|
|
71
|
|
|
$result = $this->object->copy(); |
72
|
|
|
|
73
|
|
|
$this->assertStringContainsString( '/contact_copy', $result ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
public function testCopyException() |
78
|
|
|
{ |
79
|
|
|
$object = $this->getClientMock( 'getSubClients' ); |
80
|
|
|
|
81
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
82
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
83
|
|
|
|
84
|
|
|
$object->copy(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
public function testDelete() |
89
|
|
|
{ |
90
|
|
|
$this->assertNull( $this->getClientMock( ['redirect'], false )->delete() ); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
public function testDeleteException() |
95
|
|
|
{ |
96
|
|
|
$object = $this->getClientMock( ['getSubClients', 'search'] ); |
97
|
|
|
|
98
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
99
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
100
|
|
|
$object->expects( $this->once() )->method( 'search' ); |
101
|
|
|
|
102
|
|
|
$object->delete(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
public function testGet() |
107
|
|
|
{ |
108
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'cms' ); |
109
|
|
|
|
110
|
|
|
$param = ['site' => 'unittest', 'id' => $manager->find( '/contact' )->getId()]; |
111
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
112
|
|
|
$this->view->addHelper( 'param', $helper ); |
113
|
|
|
|
114
|
|
|
$result = $this->object->get(); |
115
|
|
|
|
116
|
|
|
$this->assertStringContainsString( '/contact', $result ); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
public function testGetException() |
121
|
|
|
{ |
122
|
|
|
$object = $this->getClientMock( 'getSubClients' ); |
123
|
|
|
|
124
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
125
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
126
|
|
|
|
127
|
|
|
$object->get(); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
public function testSave() |
132
|
|
|
{ |
133
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'cms' ); |
134
|
|
|
|
135
|
|
|
$param = array( |
136
|
|
|
'site' => 'unittest', |
137
|
|
|
'item' => array( |
138
|
|
|
'cms.id' => '', |
139
|
|
|
'cms.url' => '/contact-jqadm', |
140
|
|
|
'cms.label' => 'jqadm test url', |
141
|
|
|
'cms.status' => 0 |
142
|
|
|
), |
143
|
|
|
); |
144
|
|
|
|
145
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
146
|
|
|
$this->view->addHelper( 'param', $helper ); |
147
|
|
|
|
148
|
|
|
$result = $this->object->save(); |
149
|
|
|
|
150
|
|
|
$manager->delete( $manager->find( '/contact-jqadm' ) ); |
151
|
|
|
|
152
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
153
|
|
|
$this->assertNull( $result ); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
public function testSaveException() |
158
|
|
|
{ |
159
|
|
|
$object = $this->getClientMock( 'fromArray' ); |
160
|
|
|
|
161
|
|
|
$object->expects( $this->once() )->method( 'fromArray' ) |
162
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
163
|
|
|
|
164
|
|
|
$object->save(); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
|
168
|
|
|
public function testSearch() |
169
|
|
|
{ |
170
|
|
|
$param = array( |
171
|
|
|
'site' => 'unittest', 'lang' => 'de', |
172
|
|
|
'filter' => array( |
173
|
|
|
'key' => array( 0 => 'cms.url' ), |
174
|
|
|
'op' => array( 0 => '==' ), |
175
|
|
|
'val' => array( 0 => '/contact' ), |
176
|
|
|
), |
177
|
|
|
'sort' => array( 'cms.label', '-cms.id' ), |
178
|
|
|
); |
179
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
180
|
|
|
$this->view->addHelper( 'param', $helper ); |
181
|
|
|
|
182
|
|
|
$result = $this->object->search(); |
183
|
|
|
|
184
|
|
|
$this->assertStringContainsString( '/contact', $result ); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
|
188
|
|
|
public function testSearchException() |
189
|
|
|
{ |
190
|
|
|
$object = $this->getClientMock( 'initCriteria' ); |
191
|
|
|
|
192
|
|
|
$object->expects( $this->once() )->method( 'initCriteria' ) |
193
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
194
|
|
|
|
195
|
|
|
$object->search(); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
|
199
|
|
|
public function testGetSubClient() |
200
|
|
|
{ |
201
|
|
|
$result = $this->object->getSubClient( 'seo' ); |
202
|
|
|
$this->assertInstanceOf( \Aimeos\Admin\JQAdm\Iface::class, $result ); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
|
206
|
|
|
public function testGetSubClientInvalid() |
207
|
|
|
{ |
208
|
|
|
$this->expectException( \LogicException::class ); |
209
|
|
|
$this->object->getSubClient( '$unknown$' ); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
|
213
|
|
|
public function testGetSubClientUnknown() |
214
|
|
|
{ |
215
|
|
|
$this->expectException( \LogicException::class ); |
216
|
|
|
$this->object->getSubClient( 'unknown' ); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
|
220
|
|
|
public function getClientMock( $methods, $real = true ) |
221
|
|
|
{ |
222
|
|
|
$templates = \TestHelper::getAimeos()->getTemplatePaths( 'admin/jqadm/templates' ); |
223
|
|
|
|
224
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Cms\Standard::class ) |
225
|
|
|
->setConstructorArgs( array( $this->context, $templates ) ) |
226
|
|
|
->onlyMethods( (array) $methods ) |
227
|
|
|
->getMock(); |
228
|
|
|
|
229
|
|
|
$object->setAimeos( \TestHelper::getAimeos() ); |
230
|
|
|
$object->setView( $this->getViewNoRender( $real ) ); |
231
|
|
|
|
232
|
|
|
return $object; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
|
236
|
|
|
protected function getViewNoRender( $real = true ) |
237
|
|
|
{ |
238
|
|
|
$view = $this->getMockBuilder( \Aimeos\Base\View\Standard::class ) |
239
|
|
|
->setConstructorArgs( array( [] ) ) |
240
|
|
|
->onlyMethods( array( 'render' ) ) |
241
|
|
|
->getMock(); |
242
|
|
|
|
243
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'cms' ); |
244
|
|
|
|
245
|
|
|
$param = ['site' => 'unittest', 'id' => $real ? $manager->find( '/contact' )->getId() : -1]; |
246
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $view, $param ); |
247
|
|
|
$view->addHelper( 'param', $helper ); |
248
|
|
|
|
249
|
|
|
$helper = new \Aimeos\Base\View\Helper\Config\Standard( $view, $this->context->config() ); |
250
|
|
|
$view->addHelper( 'config', $helper ); |
251
|
|
|
|
252
|
|
|
$helper = new \Aimeos\Base\View\Helper\Access\Standard( $view, [] ); |
253
|
|
|
$view->addHelper( 'access', $helper ); |
254
|
|
|
|
255
|
|
|
return $view; |
256
|
|
|
} |
257
|
|
|
} |
258
|
|
|
|