11 class ViewTest extends \PHPUnit\Framework\TestCase
60 $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
61 $this->_layoutMock = $this->createMock(\
Magento\Framework\
View\Layout::class);
62 $this->_requestMock = $this->createMock(\
Magento\Framework\
App\Request\Http::class);
63 $this->_configScopeMock = $this->createMock(\
Magento\Framework\
Config\ScopeInterface::class);
64 $this->_layoutProcessor = $this->createMock(\
Magento\Framework\
View\Model\Layout\Merge::class);
65 $this->_layoutMock->expects($this->any())->method(
'getUpdate')
66 ->will($this->returnValue($this->_layoutProcessor));
67 $this->_actionFlagMock = $this->createMock(\
Magento\Framework\
App\ActionFlag::class);
68 $this->_eventManagerMock = $this->createMock(\
Magento\Framework\
Event\ManagerInterface::class);
69 $pageConfigMock = $this->getMockBuilder(
71 )->disableOriginalConstructor()->getMock();
72 $pageConfigMock->expects($this->any())
73 ->method(
'publicBuild')
76 $pageConfigRendererFactory = $this->getMockBuilder(\
Magento\Framework\
View\Page\
Config\RendererFactory::class)
77 ->disableOriginalConstructor()
78 ->setMethods([
'create'])
81 $this->resultPage = $this->getMockBuilder(\
Magento\Framework\
View\Result\Page::class)
84 'request' => $this->_requestMock,
85 'pageConfigRendererFactory' => $pageConfigRendererFactory,
86 'layout' => $this->_layoutMock
89 ->setMethods([
'renderResult',
'getConfig'])
91 $this->resultPage->expects($this->any())
93 ->will($this->returnValue($pageConfigMock));
94 $pageFactory = $this->getMockBuilder(\
Magento\Framework\
View\Result\PageFactory::class)
95 ->disableOriginalConstructor()
96 ->setMethods([
'create'])
98 $pageFactory->expects($this->once())
100 ->will($this->returnValue($this->resultPage));
104 $this->_view =
$helper->getObject(
107 'layout' => $this->_layoutMock,
108 'request' => $this->_requestMock,
109 'response' => $this->response,
110 'configScope' => $this->_configScopeMock,
111 'eventManager' => $this->_eventManagerMock,
112 'actionFlag' => $this->_actionFlagMock,
113 'pageFactory' => $pageFactory
120 $this->assertEquals($this->_layoutMock, $this->_view->getLayout());
129 $this->_view->setIsLayoutLoaded(
true);
130 $this->_view->loadLayout();
135 $this->_layoutProcessor->expects($this->at(0))->method(
'addHandle')->with(
'default');
136 $this->_requestMock->expects(
141 $this->returnValue(
'action_name')
143 $this->_view->loadLayout();
148 $this->_view->loadLayout(
'',
false,
true);
153 $this->_view->loadLayout(
'',
true,
false);
158 $this->_requestMock->expects($this->once())
159 ->method(
'getFullActionName')
160 ->will($this->returnValue(
'ExpectedValue'));
162 $this->assertEquals(
'expectedvalue', $this->_view->getDefaultLayoutHandle());
167 $this->_requestMock->expects($this->once())
168 ->method(
'getFullActionName')
169 ->will($this->returnValue(
'Full_Action_Name'));
171 $this->_layoutProcessor->expects($this->once())
172 ->method(
'addHandle')
173 ->with(
'full_action_name');
175 $this->_view->addActionLayoutHandles();
180 $pageHandles = [
'full_action_name',
'full_action_name_key_value'];
181 $this->_requestMock->expects($this->once())
182 ->method(
'getFullActionName')
183 ->will($this->returnValue(
'Full_Action_Name'));
185 $this->_layoutProcessor->expects($this->once())
186 ->method(
'addHandle')
187 ->with($pageHandles);
188 $this->_view->addPageLayoutHandles([
'key' =>
'value']);
197 $this->_actionFlagMock->expects($this->any())->method(
'get')->will($this->returnValueMap($valueMap));
198 $this->_view->generateLayoutBlocks();
207 $this->_actionFlagMock->expects($this->any())->method(
'get')->will($this->returnValueMap($valueMap));
209 $this->_eventManagerMock->expects($this->never())->method(
'dispatch');
210 $this->_view->generateLayoutBlocks();
215 $this->_actionFlagMock->expects(
223 $this->returnValue(
true)
225 $this->_eventManagerMock->expects($this->never())->method(
'dispatch');
226 $this->_view->renderLayout();
231 $this->_actionFlagMock->expects($this->once())
233 ->with(
'',
'no-renderLayout')
234 ->will($this->returnValue(
false));
235 $this->_layoutMock->expects($this->once())->method(
'addOutputElement')->with(
'output');
236 $this->resultPage->expects($this->once())->method(
'renderResult')->with($this->response);
237 $this->_view->renderLayout(
'output');
242 $this->_actionFlagMock->expects($this->once())
244 ->with(
'',
'no-renderLayout')
245 ->will($this->returnValue(
false));
247 $this->_layoutMock->expects($this->never())->method(
'addOutputElement');
248 $this->resultPage->expects($this->once())->method(
'renderResult')->with($this->response);
249 $this->_view->renderLayout();
testGenerateLayoutBlocksWhenFlagIsSet()
testLoadLayoutWhenLayoutAlreadyLoaded()
const FLAG_NO_DISPATCH_BLOCK_EVENT
testLoadLayoutWhenXmlNotGenerated()
testGenerateLayoutBlocksWhenFlagIsNotSet()
testRenderLayoutWhenOutputEmpty()
testLoadLayoutWhenBlocksNotGenerated()
testAddPageLayoutHandles()
testAddActionLayoutHandlesWhenPageLayoutHandlesExist()
testRenderLayoutWhenOutputNotEmpty()
testRenderLayoutIfActionFlagExist()
testLoadLayoutWithDefaultSetup()
testGetDefaultLayoutHandle()