|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Aimeos\Shop\Tests\Unit\Controller; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
class ExtadmControllerTest extends \TYPO3\Flow\Tests\UnitTestCase |
|
8
|
|
|
{ |
|
9
|
|
|
private $object; |
|
10
|
|
|
private $request; |
|
11
|
|
|
private $view; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
public function setUp() |
|
15
|
|
|
{ |
|
16
|
|
|
$this->object = $this->getMockBuilder( '\Aimeos\Shop\Controller\ExtadmController' ) |
|
17
|
|
|
->setMethods( null ) |
|
18
|
|
|
->disableOriginalConstructor() |
|
19
|
|
|
->getMock(); |
|
20
|
|
|
|
|
21
|
|
|
$this->view = $this->getMockBuilder( '\TYPO3\Flow\Mvc\View\JsonView' ) |
|
22
|
|
|
->setMethods( array( 'assign', 'assignMultiple' ) ) |
|
23
|
|
|
->disableOriginalConstructor() |
|
24
|
|
|
->getMock(); |
|
25
|
|
|
|
|
26
|
|
|
$this->inject( $this->object, 'view', $this->view ); |
|
27
|
|
|
|
|
28
|
|
|
$this->request = $this->getMockBuilder( '\TYPO3\Flow\Mvc\ActionRequest' ) |
|
29
|
|
|
->setMethods( array( 'getArguments', 'getHttpRequest' ) ) |
|
30
|
|
|
->disableOriginalConstructor() |
|
31
|
|
|
->getMock(); |
|
32
|
|
|
|
|
33
|
|
|
$this->inject( $this->object, 'request', $this->request ); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
public function tearDown() |
|
38
|
|
|
{ |
|
39
|
|
|
\Aimeos\MShop\Factory::clear(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @test |
|
45
|
|
|
*/ |
|
46
|
|
|
public function indexAction() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->object = $this->getMockBuilder( '\Aimeos\Shop\Controller\ExtadmController' ) |
|
49
|
|
|
->setMethods( array( 'getJsonLanguages', 'getJsonClientConfig', 'getJsonSiteItem', 'getJsonClientI18n' ) ) |
|
50
|
|
|
->disableOriginalConstructor() |
|
51
|
|
|
->getMock(); |
|
52
|
|
|
|
|
53
|
|
|
$this->inject( $this->object, 'view', $this->view ); |
|
54
|
|
|
$this->inject( $this->object, 'request', $this->request ); |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
$aimeos = new \Aimeos\Shop\Base\Aimeos(); |
|
58
|
|
|
$this->inject( $this->object, 'aimeos', $aimeos ); |
|
59
|
|
|
|
|
60
|
|
|
$locale = new \Aimeos\Shop\Base\Locale(); |
|
61
|
|
|
$this->inject( $this->object, 'locale', $locale ); |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
$context = $this->getMockBuilder( '\Aimeos\Shop\Base\Context' ) |
|
65
|
|
|
->setMethods( array( 'get' ) ) |
|
66
|
|
|
->disableOriginalConstructor() |
|
67
|
|
|
->getMock(); |
|
68
|
|
|
|
|
69
|
|
|
$ctx = new \Aimeos\MShop\Context\Item\Standard(); |
|
70
|
|
|
$ctx->setConfig( new \Aimeos\MW\Config\PHPArray() ); |
|
71
|
|
|
$ctx->setLocale( new \Aimeos\MShop\Locale\Item\Standard( array( 'langid' => 'de' ) ) ); |
|
72
|
|
|
|
|
73
|
|
|
$this->inject( $this->object, 'context', $context ); |
|
74
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
$uriBuilder = $this->getMockBuilder('\TYPO3\Flow\Mvc\Routing\UriBuilder') |
|
77
|
|
|
->setMethods( array( 'uriFor' ) ) |
|
78
|
|
|
->disableOriginalConstructor() |
|
79
|
|
|
->getMock(); |
|
80
|
|
|
|
|
81
|
|
|
$this->inject( $this->object, 'uriBuilder', $uriBuilder ); |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
$uriBuilder->expects( $this->exactly( 3 ) )->method( 'uriFor' ) |
|
85
|
|
|
->will( $this->returnValue( '/test/uri' ) ); |
|
86
|
|
|
|
|
87
|
|
|
$context->expects( $this->once() )->method( 'get' ) |
|
88
|
|
|
->will( $this->returnValue( $ctx ) ); |
|
89
|
|
|
|
|
90
|
|
|
$this->view->expects( $this->once() )->method( 'assignMultiple' ); |
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
$this->object->indexAction(); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @test |
|
99
|
|
|
*/ |
|
100
|
|
|
public function doAction() |
|
101
|
|
|
{ |
|
102
|
|
|
$this->object = $this->getMockBuilder( '\Aimeos\Shop\Controller\ExtadmController' ) |
|
103
|
|
|
->disableOriginalConstructor() |
|
104
|
|
|
->setMethods( array() ) |
|
105
|
|
|
->getMock(); |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
$context = $this->getMockBuilder( '\Aimeos\Shop\Base\Context' ) |
|
109
|
|
|
->setMethods( array( 'get' ) ) |
|
110
|
|
|
->disableOriginalConstructor() |
|
111
|
|
|
->getMock(); |
|
112
|
|
|
|
|
113
|
|
|
$ctx = new \Aimeos\MShop\Context\Item\Standard(); |
|
114
|
|
|
$ctx->setConfig( new \Aimeos\MW\Config\PHPArray() ); |
|
115
|
|
|
$ctx->setLocale( new \Aimeos\MShop\Locale\Item\Standard( array( 'langid' => 'de' ) ) ); |
|
116
|
|
|
|
|
117
|
|
|
$context->expects( $this->once() )->method( 'get' ) |
|
118
|
|
|
->will( $this->returnValue( $ctx ) ); |
|
119
|
|
|
$this->inject( $this->object, 'context', $context ); |
|
120
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
$aimeos = new \Aimeos\Shop\Base\Aimeos(); |
|
123
|
|
|
$this->inject( $this->object, 'aimeos', $aimeos ); |
|
124
|
|
|
|
|
125
|
|
|
$locale = new \Aimeos\Shop\Base\Locale(); |
|
126
|
|
|
$this->inject( $this->object, 'locale', $locale ); |
|
127
|
|
|
|
|
128
|
|
|
$view = new \Aimeos\Shop\Base\View(); |
|
129
|
|
|
$this->inject( $this->object, 'viewcontainer', $view ); |
|
130
|
|
|
|
|
131
|
|
|
$uriBuilder = $this->getMockBuilder('\TYPO3\Flow\Mvc\Routing\UriBuilder') |
|
132
|
|
|
->setMethods( array( 'uriFor' ) ) |
|
133
|
|
|
->disableOriginalConstructor() |
|
134
|
|
|
->getMock(); |
|
135
|
|
|
$this->inject( $this->object, 'uriBuilder', $uriBuilder ); |
|
136
|
|
|
|
|
137
|
|
|
$this->request->expects( $this->once() )->method( 'getArguments' ) |
|
138
|
|
|
->will( $this->returnValue( array() ) ); |
|
139
|
|
|
$this->inject( $this->object, 'request', $this->request ); |
|
140
|
|
|
|
|
141
|
|
|
$request = new \TYPO3\Flow\Http\Request( array(), array(), array(), array() ); |
|
142
|
|
|
$this->request->expects( $this->once() )->method( 'getHttpRequest' ) |
|
143
|
|
|
->will( $this->returnValue( $request ) ); |
|
144
|
|
|
|
|
145
|
|
|
|
|
146
|
|
|
$this->assertStringStartsWith( '{', $this->object->doAction() ); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @test |
|
152
|
|
|
*/ |
|
153
|
|
|
public function fileAction() |
|
154
|
|
|
{ |
|
155
|
|
|
$aimeos = new \Aimeos\Shop\Base\Aimeos(); |
|
156
|
|
|
$this->inject( $this->object, 'aimeos', $aimeos ); |
|
157
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
$response = $this->getMockBuilder( '\TYPO3\Flow\Http\Response' ) |
|
160
|
|
|
->disableOriginalConstructor() |
|
161
|
|
|
->getMock(); |
|
162
|
|
|
|
|
163
|
|
|
$this->inject( $this->object, 'response', $response ); |
|
164
|
|
|
|
|
165
|
|
|
|
|
166
|
|
|
$this->object->fileAction(); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @test |
|
172
|
|
|
*/ |
|
173
|
|
|
public function getJsonLanguages() |
|
174
|
|
|
{ |
|
175
|
|
|
$aimeos = new \Aimeos\Shop\Base\Aimeos(); |
|
176
|
|
|
$aimeos->injectSettings( array( 'flow' => array( 'extdir' => FLOW_PATH_PACKAGES . 'Extensions' ) ) ); |
|
177
|
|
|
$this->inject( $this->object, 'aimeos', $aimeos ); |
|
178
|
|
|
|
|
179
|
|
|
$class = new \ReflectionClass( '\Aimeos\Shop\Controller\ExtadmController' ); |
|
180
|
|
|
$method = $class->getMethod( 'getJsonLanguages' ); |
|
181
|
|
|
$method->setAccessible( true ); |
|
182
|
|
|
|
|
183
|
|
|
|
|
184
|
|
|
$result = json_decode( $method->invoke( $this->object ), true ); |
|
185
|
|
|
|
|
186
|
|
|
$this->assertGreaterThan( 0, count( $result ) ); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* @test |
|
192
|
|
|
*/ |
|
193
|
|
|
public function getJsonClientConfig() |
|
194
|
|
|
{ |
|
195
|
|
|
$ctx = $this->getMockBuilder( '\Aimeos\MShop\Context\Item\Standard' ) |
|
196
|
|
|
->setMethods( array( 'setEditor' ) ) |
|
197
|
|
|
->getMock(); |
|
198
|
|
|
|
|
199
|
|
|
$ctx->setConfig( new \Aimeos\MW\Config\PHPArray() ); |
|
200
|
|
|
|
|
201
|
|
|
|
|
202
|
|
|
$class = new \ReflectionClass( '\Aimeos\Shop\Controller\ExtadmController' ); |
|
203
|
|
|
$method = $class->getMethod( 'getJsonClientConfig' ); |
|
204
|
|
|
$method->setAccessible( true ); |
|
205
|
|
|
|
|
206
|
|
|
|
|
207
|
|
|
$result = json_decode( $method->invoke( $this->object, $ctx ), true ); |
|
208
|
|
|
|
|
209
|
|
|
$this->assertInternalType( 'array', $result ); |
|
210
|
|
|
$this->assertArrayHasKey( 'admin', $result ); |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* @test |
|
216
|
|
|
*/ |
|
217
|
|
|
public function getJsonClientI18n() |
|
218
|
|
|
{ |
|
219
|
|
|
$aimeos = new \Aimeos\Shop\Base\Aimeos(); |
|
220
|
|
|
$aimeos->injectSettings( array( 'flow' => array( 'extdir' => FLOW_PATH_PACKAGES . 'Extensions' ) ) ); |
|
221
|
|
|
$i18nPaths = $aimeos->get()->getI18nPaths(); |
|
222
|
|
|
|
|
223
|
|
|
$class = new \ReflectionClass( '\Aimeos\Shop\Controller\ExtadmController' ); |
|
224
|
|
|
$method = $class->getMethod( 'getJsonClientI18n' ); |
|
225
|
|
|
$method->setAccessible( true ); |
|
226
|
|
|
|
|
227
|
|
|
|
|
228
|
|
|
$result = json_decode( $method->invoke( $this->object, $i18nPaths, 'de' ), true ); |
|
229
|
|
|
|
|
230
|
|
|
$this->assertInternalType( 'array', $result ); |
|
231
|
|
|
$this->assertArrayHasKey( 'admin', $result ); |
|
232
|
|
|
$this->assertArrayHasKey( 'admin/ext', $result ); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* @test |
|
238
|
|
|
*/ |
|
239
|
|
|
public function getJsonSiteItem() |
|
240
|
|
|
{ |
|
241
|
|
|
$ctx = $this->getMockBuilder( '\Aimeos\MShop\Context\Item\Standard' )->getMock(); |
|
242
|
|
|
|
|
243
|
|
|
|
|
244
|
|
|
$siteManager = $this->getMockBuilder( '\Aimeos\MShop\Locale\Manager\Site\Standard' ) |
|
245
|
|
|
->setMethods( array( 'createSearch', 'searchItems' ) ) |
|
246
|
|
|
->disableOriginalConstructor() |
|
247
|
|
|
->getMock(); |
|
248
|
|
|
|
|
249
|
|
|
$items = array( new \Aimeos\MShop\Locale\Item\Site\Standard( array( 'id' => '1', 'label' => 'default' ) ) ); |
|
250
|
|
|
|
|
251
|
|
|
$siteManager->expects( $this->once() )->method( 'createSearch' ) |
|
252
|
|
|
->will( $this->returnValue( new \Aimeos\MW\Criteria\PHP() ) ); |
|
253
|
|
|
|
|
254
|
|
|
$siteManager->expects( $this->once() )->method( 'searchItems' ) |
|
255
|
|
|
->will( $this->returnValue( $items ) ); |
|
256
|
|
|
|
|
257
|
|
|
\Aimeos\MShop\Factory::injectManager( $ctx, 'locale/site', $siteManager ); |
|
258
|
|
|
|
|
259
|
|
|
|
|
260
|
|
|
$class = new \ReflectionClass( '\Aimeos\Shop\Controller\ExtadmController' ); |
|
261
|
|
|
$method = $class->getMethod( 'getJsonSiteItem' ); |
|
262
|
|
|
$method->setAccessible( true ); |
|
263
|
|
|
|
|
264
|
|
|
|
|
265
|
|
|
$result = json_decode( $method->invoke( $this->object, $ctx, 'default' ), true ); |
|
266
|
|
|
|
|
267
|
|
|
$this->assertInternalType( 'array', $result ); |
|
268
|
|
|
$this->assertArrayHasKey( 'locale.site.id', $result ); |
|
269
|
|
|
$this->assertArrayHasKey( 'locale.site.label', $result ); |
|
270
|
|
|
} |
|
271
|
|
|
} |