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