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(); }
public function testExecuteBlockNotExists() { $handles = json_encode(['handle1', 'handle2']); $mapData = [['blocks', '', null], ['handles', '', $handles]]; $this->requestMock->expects($this->any())->method('getParam')->will($this->returnValueMap($mapData)); $this->viewMock->expects($this->never())->method('getLayout')->will($this->returnValue($this->layoutMock)); $this->action->execute(); }
public function testExecute() { $blocks = array('block1', 'block2'); $handles = array('handle1', 'handle2'); $expectedData = array('block1' => 'data1', 'block2' => 'data2'); $blockInstance1 = $this->getMock('Magento\\PageCache\\Block\\Controller\\StubBlock', array('toHtml'), array(), '', false); $blockInstance1->expects($this->once())->method('toHtml')->will($this->returnValue($expectedData['block1'])); $blockInstance2 = $this->getMock('Magento\\PageCache\\Block\\Controller\\StubBlock', array('toHtml'), array(), '', 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->responseMock->expects($this->once())->method('appendBody')->with($this->equalTo(json_encode($expectedData))); $this->action->execute(); }