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