6
6
namespace Magento \Ui \Test \Unit \Controller \Adminhtml \Index ;
7
7
8
8
use \Magento \Ui \Controller \Adminhtml \Index \Render ;
9
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
9
10
10
11
/**
11
12
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -17,6 +18,11 @@ class RenderTest extends \PHPUnit\Framework\TestCase
17
18
*/
18
19
private $ render ;
19
20
21
+ /**
22
+ * @var ObjectManagerHelper
23
+ */
24
+ private $ objectManagerHelper ;
25
+
20
26
/**
21
27
* @var \PHPUnit_Framework_MockObject_MockObject
22
28
*/
@@ -73,6 +79,21 @@ class RenderTest extends \PHPUnit\Framework\TestCase
73
79
*/
74
80
private $ uiComponentMock ;
75
81
82
+ /**
83
+ * @var \Magento\Framework\Controller\Result\JsonFactory|\PHPUnit_Framework_MockObject_MockObject
84
+ */
85
+ private $ resultJsonFactoryMock ;
86
+
87
+ /**
88
+ * @var \Magento\Framework\Escaper|\PHPUnit_Framework_MockObject_MockObject
89
+ */
90
+ private $ escaperMock ;
91
+
92
+ /**
93
+ * @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
94
+ */
95
+ private $ loggerMock ;
96
+
76
97
protected function setUp ()
77
98
{
78
99
$ this ->requestMock = $ this ->getMockBuilder (\Magento \Framework \App \Request \Http::class)
@@ -114,6 +135,20 @@ protected function setUp()
114
135
['render ' ]
115
136
);
116
137
138
+ $ this ->resultJsonFactoryMock = $ this ->getMockBuilder (
139
+ \Magento \Framework \Controller \Result \JsonFactory::class
140
+ )
141
+ ->disableOriginalConstructor ()
142
+ ->getMock ();
143
+
144
+ $ this ->escaperMock = $ this ->getMockBuilder (
145
+ \Magento \Framework \Escaper::class
146
+ )
147
+ ->disableOriginalConstructor ()
148
+ ->getMock ();
149
+
150
+ $ this ->loggerMock = $ this ->getMockForAbstractClass (\Psr \Log \LoggerInterface::class);
151
+
117
152
$ this ->contextMock ->expects ($ this ->any ())
118
153
->method ('getRequest ' )
119
154
->willReturn ($ this ->requestMock );
@@ -136,7 +171,75 @@ protected function setUp()
136
171
->method ('getDataProvider ' )
137
172
->willReturn ($ this ->dataProviderMock );
138
173
139
- $ this ->render = new Render ($ this ->contextMock , $ this ->uiFactoryMock );
174
+ $ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
175
+
176
+ $ this ->render = $ this ->objectManagerHelper ->getObject (
177
+ \Magento \Ui \Controller \Adminhtml \Index \Render::class,
178
+ [
179
+ 'context ' => $ this ->contextMock ,
180
+ 'factory ' => $ this ->uiFactoryMock ,
181
+ 'resultJsonFactory ' => $ this ->resultJsonFactoryMock ,
182
+ 'escaper ' => $ this ->escaperMock ,
183
+ 'logger ' => $ this ->loggerMock
184
+ ]
185
+ );
186
+ }
187
+
188
+ public function testExecuteAjaxRequestException ()
189
+ {
190
+ $ name = 'test-name ' ;
191
+ $ renderedData = '<html>data</html> ' ;
192
+
193
+ $ this ->requestMock ->expects ($ this ->any ())
194
+ ->method ('getParam ' )
195
+ ->with ('namespace ' )
196
+ ->willReturn ($ name );
197
+ $ this ->requestMock ->expects ($ this ->any ())
198
+ ->method ('getParams ' )
199
+ ->willReturn ([]);
200
+ $ this ->responseMock ->expects ($ this ->once ())
201
+ ->method ('appendBody ' )
202
+ ->willThrowException (new \Exception ('exception ' ));
203
+
204
+ $ jsonResultMock = $ this ->getMockBuilder (\Magento \Framework \Controller \Result \Json::class)
205
+ ->disableOriginalConstructor ()
206
+ ->setMethods (['setData ' ])
207
+ ->getMock ();
208
+
209
+ $ this ->resultJsonFactoryMock ->expects ($ this ->once ())
210
+ ->method ('create ' )
211
+ ->willReturn ($ jsonResultMock );
212
+
213
+ $ jsonResultMock ->expects ($ this ->once ())
214
+ ->method ('setData ' )
215
+ ->willReturnSelf ();
216
+
217
+ $ this ->loggerMock ->expects ($ this ->once ())
218
+ ->method ('critical ' )
219
+ ->willReturnSelf ();
220
+
221
+ $ this ->escaperMock ->expects ($ this ->once ())
222
+ ->method ('escapeHtml ' )
223
+ ->willReturnSelf ();
224
+
225
+ $ this ->dataProviderMock ->expects ($ this ->once ())
226
+ ->method ('getConfigData ' )
227
+ ->willReturn ([]);
228
+
229
+ $ this ->uiComponentMock ->expects ($ this ->once ())
230
+ ->method ('render ' )
231
+ ->willReturn ($ renderedData );
232
+ $ this ->uiComponentMock ->expects ($ this ->once ())
233
+ ->method ('getChildComponents ' )
234
+ ->willReturn ([]);
235
+ $ this ->uiComponentMock ->expects ($ this ->once ())
236
+ ->method ('getContext ' )
237
+ ->willReturn ($ this ->uiComponentContextMock );
238
+ $ this ->uiFactoryMock ->expects ($ this ->once ())
239
+ ->method ('create ' )
240
+ ->willReturn ($ this ->uiComponentMock );
241
+
242
+ $ this ->render ->executeAjaxRequest ();
140
243
}
141
244
142
245
public function testExecuteAjaxRequest ()
0 commit comments