12 use \Magento\Framework\View\Context;
41 $this->markTestSkipped(
'Testcase needs to be refactored.');
42 $this->appState = $this->getMockBuilder(\
Magento\Framework\
App\State::class)
43 ->disableOriginalConstructor()
46 $this->request = $this->getMockBuilder(\
Magento\Framework\
App\Request\Http::class)
47 ->disableOriginalConstructor()
50 $this->design = $this->getMockBuilder(\
Magento\Framework\View\DesignInterface::class)
51 ->disableOriginalConstructor()
54 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
56 \
Magento\Framework\View\Context::class,
58 'appState' => $this->appState,
59 'request' => $this->request,
60 'design' => $this->design
67 $this->assertInstanceOf(\
Magento\Framework\
App\CacheInterface::class, $this->context->getCache());
72 $this->assertInstanceOf(\
Magento\Framework\View\DesignInterface::class, $this->context->getDesignPackage());
77 $this->assertInstanceOf(\
Magento\Framework\
Event\ManagerInterface::class, $this->context->getEventManager());
82 $this->assertInstanceOf(
83 \
Magento\Framework\
App\FrontControllerInterface::class,
84 $this->context->getFrontController()
90 $this->assertInstanceOf(\
Magento\Framework\View\LayoutInterface::class, $this->context->getLayout());
95 $this->assertInstanceOf(\
Magento\Framework\
App\Request\Http::class, $this->context->getRequest());
100 $this->assertInstanceOf(
101 \
Magento\Framework\Session\SessionManagerInterface::class,
102 $this->context->getSession()
108 $this->assertInstanceOf(
110 $this->context->getScopeConfig()
116 $this->assertInstanceOf(\
Magento\Framework\TranslateInterface::class, $this->context->getTranslator());
121 $this->assertInstanceOf(\
Magento\Framework\UrlInterface::class, $this->context->getUrlBuilder());
126 $this->assertInstanceOf(\
Magento\Framework\View\ConfigInterface::class, $this->context->getViewConfig());
131 $this->assertInstanceOf(\
Magento\Framework\
App\Cache\StateInterface::class, $this->context->getCacheState());
136 $this->assertInstanceOf(\Psr\Log\LoggerInterface::class, $this->context->getLogger());
141 $this->assertInstanceOf(\
Magento\Framework\
App\State::class, $this->context->getAppState());
146 $area =
'frontendArea';
148 $this->appState->expects($this->once())
149 ->method(
'getAreaCode')
150 ->will($this->returnValue($area));
152 $this->assertEquals($area, $this->context->getArea());
157 $moduleName =
'testModuleName';
159 $this->request->expects($this->once())
160 ->method(
'getModuleName')
161 ->will($this->returnValue($moduleName));
163 $this->assertEquals($moduleName, $this->context->getModuleName());
168 $frontName =
'testFrontName';
170 $this->request->expects($this->once())
171 ->method(
'getModuleName')
172 ->will($this->returnValue($frontName));
174 $this->assertEquals($frontName, $this->context->getFrontName());
179 $controllerName =
'testControllerName';
181 $this->request->expects($this->once())
182 ->method(
'getControllerName')
183 ->will($this->returnValue($controllerName));
185 $this->assertEquals($controllerName, $this->context->getControllerName());
190 $actionName =
'testActionName';
192 $this->request->expects($this->once())
193 ->method(
'getActionName')
194 ->will($this->returnValue($actionName));
196 $this->assertEquals($actionName, $this->context->getActionName());
201 $frontName =
'testFrontName';
202 $controllerName =
'testControllerName';
203 $actionName =
'testActionName';
204 $fullActionName =
'testfrontname_testcontrollername_testactionname';
206 $this->request->expects($this->once())
207 ->method(
'getModuleName')
208 ->will($this->returnValue($frontName));
210 $this->request->expects($this->once())
211 ->method(
'getControllerName')
212 ->will($this->returnValue($controllerName));
214 $this->request->expects($this->once())
215 ->method(
'getActionName')
216 ->will($this->returnValue($actionName));
218 $this->assertEquals($fullActionName, $this->context->getFullActionName());
229 $this->request->expects($this->once())
230 ->method(
'getHeader')
232 ->will($this->returnValue($headerAccept));
234 $this->assertEquals($acceptType, $this->context->getAcceptType());
244 [
'testjson',
'json'],
246 [
'testsoap',
'soap'],
247 [
'text/html',
'html'],
248 [
'testtext/html',
'html'],
256 $key =
'getParamName';
257 $default =
'defaultGetParamValue';
258 $postValue =
'someGetParamValue';
260 $this->request->expects($this->once())
262 ->with($key, $default)
263 ->will($this->returnValue($postValue));
265 $this->assertEquals($postValue, $this->context->getPost($key, $default));
270 $key =
'getParamName';
271 $default =
'defaultGetParamValue';
272 $queryValue =
'someGetParamValue';
274 $this->request->expects($this->once())
276 ->with($key, $default)
277 ->will($this->returnValue($queryValue));
279 $this->assertEquals($queryValue, $this->context->getQuery($key, $default));
285 $default =
'defaultParamValue';
286 $paramValue =
'someParamValue';
288 $this->request->expects($this->once())
290 ->with($key, $default)
291 ->will($this->returnValue($paramValue));
293 $this->assertEquals($paramValue, $this->context->getParam($key, $default));
298 $params = [
'paramName' =>
'value'];
300 $this->request->expects($this->once())
301 ->method(
'getParams')
302 ->will($this->returnValue(
$params));
304 $this->assertEquals(
$params, $this->context->getParams());
309 $headerName =
'headerName';
310 $headerValue =
'headerValue';
312 $this->request->expects($this->once())
313 ->method(
'getHeader')
315 ->will($this->returnValue($headerValue));
317 $this->assertEquals($headerValue, $this->context->getHeader($headerName));
324 $this->request->expects($this->once())
325 ->method(
'getContent')
326 ->will($this->returnValue(
$content));
328 $this->assertEquals(
$content, $this->context->getContent());
getAcceptTypeDataProvider()
testGetAcceptType($headerAccept, $acceptType)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]