コード例 #1
0
ファイル: ParserTest.php プロジェクト: Doability/magento2dev
 public function testProcessResponseBodyStringProcessingAttributesCorrectly()
 {
     $testContent = file_get_contents(__DIR__ . '/_files/datatranslate_fixture.html');
     $processedAttributes = ["data-translate=\"[{'shown':'* Required Fields','translated':'* Required Fields'," . "'original':'* Required Fields','location':'Tag attribute (ALT, TITLE, etc.)'}]\"", "data-translate=\"[{'shown':'Email','translated':'Email','original':'Email'," . "'location':'Tag attribute (ALT, TITLE, etc.)'}]\"", "data-translate=\"[{'shown':'Password','translated':'Password','original':'Password'," . "'location':'Tag attribute (ALT, TITLE, etc.)'}]\""];
     $this->translateInlineMock->expects($this->any())->method('getAdditionalHtmlAttribute')->willReturn(null);
     $processedContent = $this->model->processResponseBodyString($testContent);
     foreach ($processedAttributes as $attribute) {
         $this->assertContains($attribute, $processedContent, "data-translate attribute not processed correctly");
     }
 }
コード例 #2
0
 public function testExecute()
 {
     $blocks = ['block1', 'block2'];
     $handles = ['handle1', 'handle2'];
     $originalRequest = '{"route":"route","controller":"controller","action":"action","uri":"uri"}';
     $expectedData = ['block1' => 'data1', 'block2' => 'data2'];
     $blockInstance1 = $this->getMock('Magento\\PageCache\\Test\\Unit\\Block\\Controller\\StubBlock', ['toHtml'], [], '', false);
     $blockInstance1->expects($this->once())->method('toHtml')->will($this->returnValue($expectedData['block1']));
     $blockInstance2 = $this->getMock('Magento\\PageCache\\Test\\Unit\\Block\\Controller\\StubBlock', ['toHtml'], [], '', false);
     $blockInstance2->expects($this->once())->method('toHtml')->will($this->returnValue($expectedData['block2']));
     $this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(true));
     $this->requestMock->expects($this->at(1))->method('getRouteName')->will($this->returnValue('magento_pagecache'));
     $this->requestMock->expects($this->at(2))->method('getControllerName')->will($this->returnValue('block'));
     $this->requestMock->expects($this->at(3))->method('getActionName')->will($this->returnValue('render'));
     $this->requestMock->expects($this->at(4))->method('getRequestUri')->will($this->returnValue('uri'));
     $this->requestMock->expects($this->at(5))->method('getParam')->with($this->equalTo('originalRequest'))->will($this->returnValue($originalRequest));
     $this->requestMock->expects($this->at(10))->method('getParam')->with($this->equalTo('blocks'), $this->equalTo(''))->will($this->returnValue(json_encode($blocks)));
     $this->requestMock->expects($this->at(11))->method('getParam')->with($this->equalTo('handles'), $this->equalTo(''))->will($this->returnValue(json_encode($handles)));
     $this->viewMock->expects($this->once())->method('loadLayout')->with($this->equalTo($handles));
     $this->viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($this->layoutMock));
     $this->layoutMock->expects($this->at(0))->method('getBlock')->with($this->equalTo($blocks[0]))->will($this->returnValue($blockInstance1));
     $this->layoutMock->expects($this->at(1))->method('getBlock')->with($this->equalTo($blocks[1]))->will($this->returnValue($blockInstance2));
     $this->translateInline->expects($this->once())->method('processResponseBody')->with($expectedData)->willReturnSelf();
     $this->responseMock->expects($this->once())->method('appendBody')->with($this->equalTo(json_encode($expectedData)));
     $this->action->execute();
 }
コード例 #3
0
ファイル: EsiTest.php プロジェクト: pradeep-wagento/magento2
 /**
  * @dataProvider executeDataProvider
  * @param string $blockClass
  * @param bool $shouldSetHeaders
  */
 public function testExecute($blockClass, $shouldSetHeaders)
 {
     $block = 'block';
     $handles = ['handle1', 'handle2'];
     $html = 'some-html';
     $mapData = [['blocks', '', json_encode([$block])], ['handles', '', json_encode($handles)]];
     $blockInstance1 = $this->getMock($blockClass, ['toHtml'], [], '', false);
     $blockInstance1->expects($this->once())->method('toHtml')->will($this->returnValue($html));
     $blockInstance1->setTtl(360);
     $this->requestMock->expects($this->any())->method('getParam')->will($this->returnValueMap($mapData));
     $this->viewMock->expects($this->once())->method('loadLayout')->with($this->equalTo($handles));
     $this->viewMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->layoutMock));
     $this->layoutMock->expects($this->once())->method('getBlock')->with($this->equalTo($block))->will($this->returnValue($blockInstance1));
     if ($shouldSetHeaders) {
         $this->responseMock->expects($this->once())->method('setHeader')->with('X-Magento-Tags', implode(',', $blockInstance1->getIdentities()));
     } else {
         $this->responseMock->expects($this->never())->method('setHeader');
     }
     $this->translateInline->expects($this->once())->method('processResponseBody')->with($html)->willReturnSelf();
     $this->responseMock->expects($this->once())->method('appendBody')->with($this->equalTo($html));
     $this->action->execute();
 }
コード例 #4
0
 /**
  * @param int|string $httpCode
  * @param string $headerName
  * @param string $headerValue
  * @param bool $replaceHeader
  * @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $setHttpResponseCodeCount
  * @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $setHeaderCount
  * @dataProvider renderResultDataProvider
  */
 public function testRenderResult($httpCode, $headerName, $headerValue, $replaceHeader, $setHttpResponseCodeCount, $setHeaderCount)
 {
     $layoutOutput = 'output';
     $this->layout->expects($this->once())->method('getOutput')->will($this->returnValue($layoutOutput));
     $this->request->expects($this->once())->method('getFullActionName')->will($this->returnValue('Module_Controller_Action'));
     $this->eventManager->expects($this->exactly(2))->method('dispatch')->withConsecutive(['layout_render_before'], ['layout_render_before_Module_Controller_Action']);
     $this->translateInline->expects($this->once())->method('processResponseBody')->with($layoutOutput)->willReturnSelf();
     /** @var \Magento\Framework\App\Response\Http|\PHPUnit_Framework_MockObject_MockObject $response */
     $response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false);
     $response->expects($setHttpResponseCodeCount)->method('setHttpResponseCode')->with($httpCode);
     $response->expects($setHeaderCount)->method('setHeader')->with($headerName, $headerValue, $replaceHeader);
     $response->expects($this->once())->method('appendBody')->with($layoutOutput);
     $this->resultLayout->setHttpResponseCode($httpCode);
     if ($headerName && $headerValue) {
         $this->resultLayout->setHeader($headerName, $headerValue, $replaceHeader);
     }
     $this->resultLayout->renderResult($response);
 }
コード例 #5
0
 public function testExecute()
 {
     $blocks = ['block1', 'block2'];
     $handles = ['handle1', 'handle2'];
     $expectedData = ['block1' => 'data1', 'block2' => 'data2'];
     $blockInstance1 = $this->getMock('Magento\\PageCache\\Block\\Controller\\StubBlock', ['toHtml'], [], '', false);
     $blockInstance1->expects($this->once())->method('toHtml')->will($this->returnValue($expectedData['block1']));
     $blockInstance2 = $this->getMock('Magento\\PageCache\\Block\\Controller\\StubBlock', ['toHtml'], [], '', false);
     $blockInstance2->expects($this->once())->method('toHtml')->will($this->returnValue($expectedData['block2']));
     $this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(true));
     $this->requestMock->expects($this->at(1))->method('getParam')->with($this->equalTo('blocks'), $this->equalTo(''))->will($this->returnValue(json_encode($blocks)));
     $this->requestMock->expects($this->at(2))->method('getParam')->with($this->equalTo('handles'), $this->equalTo(''))->will($this->returnValue(json_encode($handles)));
     $this->viewMock->expects($this->once())->method('loadLayout')->with($this->equalTo($handles));
     $this->viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($this->layoutMock));
     $this->layoutMock->expects($this->at(0))->method('getBlock')->with($this->equalTo($blocks[0]))->will($this->returnValue($blockInstance1));
     $this->layoutMock->expects($this->at(1))->method('getBlock')->with($this->equalTo($blocks[1]))->will($this->returnValue($blockInstance2));
     $this->translateInline->expects($this->once())->method('processResponseBody')->with($expectedData)->willReturnSelf();
     $this->responseMock->expects($this->once())->method('appendBody')->with($this->equalTo(json_encode($expectedData)));
     $this->action->execute();
 }