3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \Ui \Test \Unit \Controller \Adminhtml \Index ;
7
8
9
+ use Magento \Framework \Controller \Result \Json ;
10
+ use Magento \Framework \Escaper ;
11
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
12
+ use Magento \Framework \View \Element \UiComponent \ContextInterface ;
8
13
use Magento \Ui \Controller \Adminhtml \Index \Render ;
9
14
use Magento \Ui \Model \UiComponentTypeResolver ;
10
- use Magento \ Framework \ View \ Element \ UiComponent \ ContextInterface ;
11
- use Magento \ Framework \ TestFramework \ Unit \ Helper \ ObjectManager as ObjectManagerHelper ;
15
+ use Zend \ Http \ AbstractMessage ;
16
+ use Zend \ Http \ Response ;
12
17
13
18
/**
14
19
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -97,6 +102,11 @@ class RenderTest extends \PHPUnit\Framework\TestCase
97
102
*/
98
103
private $ loggerMock ;
99
104
105
+ /**
106
+ * @var Escaper|\PHPUnit_Framework_MockObject_MockObject
107
+ */
108
+ private $ escaperMock ;
109
+
100
110
protected function setUp ()
101
111
{
102
112
$ this ->requestMock = $ this ->getMockBuilder (\Magento \Framework \App \Request \Http::class)
@@ -170,6 +180,10 @@ protected function setUp()
170
180
$ this ->uiComponentTypeResolverMock = $ this ->getMockBuilder (UiComponentTypeResolver::class)
171
181
->disableOriginalConstructor ()
172
182
->getMock ();
183
+ $ this ->escaperMock = $ this ->createMock (Escaper::class);
184
+ $ this ->escaperMock ->expects ($ this ->any ())
185
+ ->method ('escapeHtml ' )
186
+ ->willReturnArgument (0 );
173
187
174
188
$ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
175
189
@@ -181,6 +195,7 @@ protected function setUp()
181
195
'contentTypeResolver ' => $ this ->uiComponentTypeResolverMock ,
182
196
'resultJsonFactory ' => $ this ->resultJsonFactoryMock ,
183
197
'logger ' => $ this ->loggerMock ,
198
+ 'escaper ' => $ this ->escaperMock ,
184
199
]
185
200
);
186
201
}
@@ -201,7 +216,7 @@ public function testExecuteAjaxRequestException()
201
216
->method ('appendBody ' )
202
217
->willThrowException (new \Exception ('exception ' ));
203
218
204
- $ jsonResultMock = $ this ->getMockBuilder (\ Magento \ Framework \ Controller \ Result \ Json::class)
219
+ $ jsonResultMock = $ this ->getMockBuilder (Json::class)
205
220
->disableOriginalConstructor ()
206
221
->setMethods (['setData ' ])
207
222
->getMock ();
@@ -290,6 +305,34 @@ public function testExecuteAjaxRequestWithoutPermissions(array $dataProviderConf
290
305
$ name = 'test-name ' ;
291
306
$ renderedData = '<html>data</html> ' ;
292
307
308
+ if (false === $ isAllowed ) {
309
+ $ jsonResultMock = $ this ->getMockBuilder (Json::class)
310
+ ->disableOriginalConstructor ()
311
+ ->setMethods (['setStatusHeader ' , 'setData ' ])
312
+ ->getMock ();
313
+
314
+ $ jsonResultMock ->expects ($ this ->at (0 ))
315
+ ->method ('setStatusHeader ' )
316
+ ->with (
317
+ Response::STATUS_CODE_403 ,
318
+ AbstractMessage::VERSION_11 ,
319
+ 'Forbidden '
320
+ )
321
+ ->willReturnSelf ();
322
+
323
+ $ jsonResultMock ->expects ($ this ->at (1 ))
324
+ ->method ('setData ' )
325
+ ->with ([
326
+ 'error ' => 'Forbidden ' ,
327
+ 'errorcode ' => 403
328
+ ])
329
+ ->willReturnSelf ();
330
+
331
+ $ this ->resultJsonFactoryMock ->expects ($ this ->any ())
332
+ ->method ('create ' )
333
+ ->willReturn ($ jsonResultMock );
334
+ }
335
+
293
336
$ this ->requestMock ->expects ($ this ->any ())
294
337
->method ('getParam ' )
295
338
->with ('namespace ' )
0 commit comments