35 $this->_request = $this->createMock(\
Magento\Framework\
App\Request\Http::class);
37 $this->_objectManager = $this->createMock(\
Magento\Framework\ObjectManagerInterface::class);
42 $this->_request =
null;
43 $this->_response =
null;
44 $this->_objectManager =
null;
47 public function testTunnelAction()
50 $this->_request->expects($this->at(0))
53 ->will($this->returnValue(urlencode(base64_encode(json_encode([1])))));
54 $this->_request->expects($this->at(1))->method(
'getParam')->with(
'h')->will($this->returnValue($fixture));
56 $httpClient = $this->createPartialMock(
57 \
Magento\Framework\HTTP\ZendClient::class,
58 [
'setUri',
'setParameterGet',
'setConfig',
'request',
'getHeaders']
61 $helper = $this->createPartialMock(\
Magento\Backend\Helper\Dashboard\Data::class, [
'getChartDataHash']);
62 $helper->expects($this->any())->method(
'getChartDataHash')->will($this->returnValue($fixture));
64 $this->_objectManager->expects($this->at(0))
66 ->with(\
Magento\Backend\Helper\Dashboard\Data::class)
67 ->will($this->returnValue(
$helper));
68 $this->_objectManager->expects($this->at(1))
70 ->with(\
Magento\Framework\HTTP\ZendClient::class)
71 ->will($this->returnValue($httpClient));
72 $httpClient->expects($this->once())->method(
'setUri')->will($this->returnValue($httpClient));
73 $httpClient->expects($this->once())->method(
'setParameterGet')->will($this->returnValue($httpClient));
74 $httpClient->expects($this->once())->method(
'setConfig')->will($this->returnValue($httpClient));
75 $httpClient->expects($this->once())->method(
'request')->with(
'GET')->will($this->returnValue($tunnelResponse));
76 $tunnelResponse->expects($this->any())->method(
'getHeaders')
77 ->will($this->returnValue([
'Content-type' =>
'test_header']));
78 $tunnelResponse->expects($this->any())->method(
'getBody')->will($this->returnValue(
'success_msg'));
79 $this->_response->expects($this->any())->method(
'getBody')->will($this->returnValue(
'success_msg'));
81 $controller = $this->_factory($this->_request, $this->_response);
82 $this->resultRaw->expects($this->once())
84 ->with(
'Content-type',
'test_header')
86 $this->resultRaw->expects($this->once())
87 ->method(
'setContents')
92 $this->assertEquals(
'success_msg',
$controller->getResponse()->getBody());
97 $controller = $this->_factory($this->_request, $this->_response);
99 $this->resultRaw->expects($this->once())
100 ->method(
'setHeader')
102 $this->resultRaw->expects($this->once())
103 ->method(
'setHttpResponseCode')
106 $this->resultRaw->expects($this->once())
107 ->method(
'setContents')
108 ->with(
'Service unavailable: invalid request')
114 public function testTunnelAction503()
117 $this->_request->expects($this->at(0))
120 ->will($this->returnValue(urlencode(base64_encode(json_encode([1])))));
121 $this->_request->expects($this->at(1))->method(
'getParam')->with(
'h')->will($this->returnValue($fixture));
123 $helper = $this->createPartialMock(\
Magento\Backend\Helper\Dashboard\Data::class, [
'getChartDataHash']);
124 $helper->expects($this->any())->method(
'getChartDataHash')->will($this->returnValue($fixture));
126 $this->_objectManager->expects($this->at(0))
128 ->with(\
Magento\Backend\Helper\Dashboard\Data::class)
129 ->will($this->returnValue(
$helper));
130 $exceptionMock = new \Exception();
131 $this->_objectManager->expects($this->at(1))
133 ->with(\
Magento\Framework\HTTP\ZendClient::class)
134 ->will($this->throwException($exceptionMock));
135 $loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
136 $loggerMock->expects($this->once())->method(
'critical')->with($exceptionMock);
137 $this->_objectManager->expects($this->at(2))
139 ->with(\Psr\Log\LoggerInterface::class)
140 ->will($this->returnValue($loggerMock));
142 $controller = $this->_factory($this->_request, $this->_response);
144 $this->resultRaw->expects($this->once())
145 ->method(
'setHeader')
147 $this->resultRaw->expects($this->once())
148 ->method(
'setHttpResponseCode')
151 $this->resultRaw->expects($this->once())
152 ->method(
'setContents')
153 ->with(
'Service unavailable: see error log for details')
171 $response->headersSentThrowsException =
false;
173 $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
174 $varienFront =
$helper->getObject(\
Magento\Framework\
App\FrontController::class);
180 'frontController' => $varienFront,
182 $this->resultRaw = $this->getMockBuilder(\
Magento\Framework\Controller\Result\Raw::class)
183 ->disableOriginalConstructor()
186 $resultRawFactory = $this->getMockBuilder(\
Magento\Framework\Controller\Result\RawFactory::class)
187 ->disableOriginalConstructor()
188 ->setMethods([
'create'])
190 $resultRawFactory->expects($this->atLeastOnce())
192 ->willReturn($this->resultRaw);
194 return new \Magento\Backend\Controller\Adminhtml\Dashboard\Tunnel($context, $resultRawFactory);