123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Framework\View\Test\Unit\Result;
- use Magento\Framework\View\Page\Config as PageConfig;
- use Magento\Framework\View\EntitySpecificHandlesList;
- /**
- * Result Page Test
- *
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
- class PageTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var \Magento\Framework\View\Result\Page
- */
- private $page;
- /**
- * @var \Magento\Framework\View\Element\Template\Context|\PHPUnit_Framework_MockObject_MockObject
- */
- private $context;
- /**
- * @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject
- */
- private $request;
- /**
- * @var \Magento\Framework\View\Layout|\PHPUnit_Framework_MockObject_MockObject
- */
- private $layout;
- /**
- * @var \Magento\Framework\View\Model\Layout\Merge|\PHPUnit_Framework_MockObject_MockObject
- */
- private $layoutMerge;
- /**
- * @var \Magento\Framework\View\Page\Config|\PHPUnit_Framework_MockObject_MockObject
- */
- private $pageConfig;
- /**
- * @var \Magento\Framework\Translate\InlineInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- private $translateInline;
- /**
- * @var \Magento\Framework\View\Page\Config\Renderer|\PHPUnit_Framework_MockObject_MockObject
- */
- private $pageConfigRenderer;
- /**
- * @var \Magento\Framework\View\FileSystem|\PHPUnit_Framework_MockObject_MockObject
- */
- private $viewFileSystem;
- /**
- * @var \Magento\Framework\View\LayoutFactory|\PHPUnit_Framework_MockObject_MockObject
- */
- private $layoutFactory;
- /** @var \PHPUnit_Framework_MockObject_MockObject|EntitySpecificHandlesList */
- private $entitySpecificHandlesListMock;
- protected function setUp()
- {
- $this->layout = $this->getMockBuilder(\Magento\Framework\View\Layout::class)
- ->setMethods(['addHandle', 'getUpdate', 'isLayoutDefined'])
- ->disableOriginalConstructor()
- ->getMock();
- $this->layoutFactory = $this->getMockBuilder(\Magento\Framework\View\LayoutFactory::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->layoutFactory->expects($this->any())->method('create')->will($this->returnValue($this->layout));
- $this->layoutMerge = $this->getMockBuilder(\Magento\Framework\View\Model\Layout\Merge::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->layout->expects($this->any())
- ->method('getUpdate')
- ->will($this->returnValue($this->layoutMerge));
- $this->request = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->pageConfig = $this->getMockBuilder(\Magento\Framework\View\Page\Config::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->viewFileSystem = $this->getMockBuilder(\Magento\Framework\View\FileSystem::class)
- ->disableOriginalConstructor()
- ->getMock();
- $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
- $this->context = $objectManagerHelper->getObject(
- \Magento\Framework\View\Element\Template\Context::class,
- [
- 'layout' => $this->layout,
- 'request' => $this->request,
- 'viewFileSystem' => $this->viewFileSystem,
- 'pageConfig' => $this->pageConfig
- ]
- );
- $this->translateInline = $this->createMock(\Magento\Framework\Translate\InlineInterface::class);
- $this->pageConfigRenderer = $this->getMockBuilder(\Magento\Framework\View\Page\Config\Renderer::class)
- ->disableOriginalConstructor()
- ->getMock();
- $pageConfigRendererFactory = $this->getMockBuilder(\Magento\Framework\View\Page\Config\RendererFactory::class)
- ->disableOriginalConstructor()
- ->setMethods(['create'])
- ->getMock();
- $pageConfigRendererFactory->expects($this->once())
- ->method('create')
- ->with(['pageConfig' => $this->pageConfig])
- ->willReturn($this->pageConfigRenderer);
- $this->entitySpecificHandlesListMock = $this->createMock(EntitySpecificHandlesList::class);
- $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
- $this->page = $objectManagerHelper->getObject(
- \Magento\Framework\View\Result\Page::class,
- [
- 'isIsolated' => true,
- 'layoutFactory' => $this->layoutFactory,
- 'context' => $this->context,
- 'translateInline' => $this->translateInline,
- 'pageConfigRendererFactory' => $pageConfigRendererFactory,
- 'entitySpecificHandlesList' => $this->entitySpecificHandlesListMock
- ]
- );
- }
- public function testInitLayout()
- {
- $handleDefault = 'default';
- $fullActionName = 'full_action_name';
- $this->request->expects($this->any())
- ->method('getFullActionName')
- ->will($this->returnValue($fullActionName));
- $this->layoutMerge->expects($this->at(0))
- ->method('addHandle')
- ->with($handleDefault)
- ->willReturnSelf();
- $this->layoutMerge->expects($this->at(1))
- ->method('addHandle')
- ->with($fullActionName)
- ->willReturnSelf();
- $this->layoutMerge->expects($this->at(2))
- ->method('isLayoutDefined')
- ->willReturn(false);
- $this->assertEquals($this->page, $this->page->initLayout());
- }
- public function testInitLayoutLayoutDefined()
- {
- $handleDefault = 'default';
- $fullActionName = 'full_action_name';
- $this->request->expects($this->any())
- ->method('getFullActionName')
- ->will($this->returnValue($fullActionName));
- $this->layoutMerge->expects($this->at(0))
- ->method('addHandle')
- ->with($handleDefault)
- ->willReturnSelf();
- $this->layoutMerge->expects($this->at(1))
- ->method('addHandle')
- ->with($fullActionName)
- ->willReturnSelf();
- $this->layoutMerge->expects($this->at(2))
- ->method('isLayoutDefined')
- ->willReturn(true);
- $this->layoutMerge->expects($this->at(3))
- ->method('removeHandle')
- ->with($handleDefault)
- ->willReturnSelf();
- $this->assertEquals($this->page, $this->page->initLayout());
- }
- public function testGetConfig()
- {
- $this->assertEquals($this->pageConfig, $this->page->getConfig());
- }
- public function testGetDefaultLayoutHandle()
- {
- $fullActionName = 'Full_Action_Name';
- $expectedFullActionName = 'full_action_name';
- $this->request->expects($this->any())
- ->method('getFullActionName')
- ->will($this->returnValue($fullActionName));
- $this->assertEquals($expectedFullActionName, $this->page->getDefaultLayoutHandle());
- }
- public function testAddPageLayoutHandles()
- {
- $fullActionName = 'Full_Action_Name';
- $defaultHandle = null;
- $parameters = [
- 'key_one' => 'val_one',
- 'key_two' => 'val_two',
- ];
- $expected = [
- 'full_action_name',
- 'full_action_name_key_one_val_one',
- 'full_action_name_key_two_val_two',
- ];
- $this->request->expects($this->any())
- ->method('getFullActionName')
- ->will($this->returnValue($fullActionName));
- $this->layoutMerge->expects($this->any())
- ->method('addHandle')
- ->with($expected)
- ->willReturnSelf();
- $this->entitySpecificHandlesListMock->expects($this->at(0))
- ->method('addHandle')->with('full_action_name_key_one_val_one');
- $this->entitySpecificHandlesListMock->expects($this->at(1))
- ->method('addHandle')->with('full_action_name_key_two_val_two');
- $this->page->addPageLayoutHandles($parameters, $defaultHandle);
- }
- public function testAddPageLayoutHandlesNotEntitySpecific()
- {
- $fullActionName = 'Full_Action_Name';
- $defaultHandle = null;
- $parameters = [
- 'key_one' => 'val_one',
- 'key_two' => 'val_two',
- ];
- $expected = [
- 'full_action_name',
- 'full_action_name_key_one_val_one',
- 'full_action_name_key_two_val_two',
- ];
- $this->request->expects($this->any())
- ->method('getFullActionName')
- ->will($this->returnValue($fullActionName));
- $this->layoutMerge->expects($this->any())
- ->method('addHandle')
- ->with($expected)
- ->willReturnSelf();
- $this->entitySpecificHandlesListMock->expects($this->never())->method('addHandle');
- $this->page->addPageLayoutHandles($parameters, $defaultHandle, false);
- }
- public function testAddPageLayoutHandlesWithDefaultHandle()
- {
- $defaultHandle = 'default_handle';
- $parameters = [
- 'key_one' => 'val_one',
- 'key_two' => 'val_two',
- ];
- $expected = [
- 'default_handle',
- 'default_handle_key_one_val_one',
- 'default_handle_key_two_val_two',
- ];
- $this->request->expects($this->never())
- ->method('getFullActionName');
- $this->layoutMerge->expects($this->any())
- ->method('addHandle')
- ->with($expected)
- ->willReturnSelf();
- $this->page->addPageLayoutHandles($parameters, $defaultHandle);
- }
- }
|