/**
  * @param bool $cacheState
  * @param bool $varnishIsEnabled
  * @param bool $scopeIsPrivate
  * @param int|null $blockTtl
  * @param string $expectedOutput
  * @dataProvider processLayoutRenderDataProvider
  */
 public function testExecute($cacheState, $varnishIsEnabled, $scopeIsPrivate, $blockTtl, $expectedOutput)
 {
     $eventMock = $this->getMock('Magento\\Framework\\Event', ['getLayout', 'getElementName', 'getTransport'], [], '', false);
     $this->_observerMock->expects($this->once())->method('getEvent')->will($this->returnValue($eventMock));
     $eventMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->_layoutMock));
     $this->_configMock->expects($this->any())->method('isEnabled')->will($this->returnValue($cacheState));
     if ($cacheState) {
         $eventMock->expects($this->once())->method('getElementName')->will($this->returnValue('blockName'));
         $eventMock->expects($this->once())->method('getTransport')->will($this->returnValue($this->_transport));
         $this->_layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(true));
         $this->_layoutMock->expects($this->any())->method('getUpdate')->will($this->returnSelf());
         $this->_layoutMock->expects($this->any())->method('getHandles')->will($this->returnValue([]));
         $this->_layoutMock->expects($this->once())->method('getBlock')->will($this->returnValue($this->_blockMock));
         if ($varnishIsEnabled) {
             $this->_blockMock->expects($this->once())->method('getData')->with('ttl')->will($this->returnValue($blockTtl));
             $this->_blockMock->expects($this->any())->method('getUrl')->will($this->returnValue('page_cache/block/wrapesi/with/handles/and/other/stuff'));
         }
         if ($scopeIsPrivate) {
             $this->_blockMock->expects($this->once())->method('getNameInLayout')->will($this->returnValue('testBlockName'));
             $this->_blockMock->expects($this->once())->method('isScopePrivate')->will($this->returnValue($scopeIsPrivate));
         }
         $this->_configMock->expects($this->any())->method('getType')->will($this->returnValue($varnishIsEnabled));
     }
     $this->_model->execute($this->_observerMock);
     $this->assertEquals($expectedOutput, $this->_transport['output']);
 }
 public function testGetRenderer()
 {
     $this->blockMock->expects($this->any())->method('setRenderedBlock')->will($this->returnValue($this->blockMock));
     $this->blockMock->expects($this->any())->method('getTemplate')->will($this->returnValue('template'));
     $this->blockMock->expects($this->any())->method('setTemplate')->will($this->returnValue($this->blockMock));
     $this->layoutMock->expects($this->any())->method('getChildName')->will($this->returnValue(true));
     /** During the first call cache will be generated */
     $this->assertInstanceOf('\\Magento\\Framework\\View\\Element\\BlockInterface', $this->renderList->getRenderer('type', null, null));
     /** Cached value should be returned during second call */
     $this->assertInstanceOf('\\Magento\\Framework\\View\\Element\\BlockInterface', $this->renderList->getRenderer('type', null, 'renderer_template'));
 }
Ejemplo n.º 3
0
 /**
  * Set up test
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     $this->contextMock = $this->getMock('Magento\\Backend\\App\\Action\\Context', ['getAuthorization', 'getSession', 'getActionFlag', 'getAuth', 'getView', 'getHelper', 'getBackendUrl', 'getFormKeyValidator', 'getLocaleResolver', 'getCanUseBaseUrl', 'getRequest', 'getResponse', 'getObjectManager', 'getMessageManager'], [], '', false);
     $this->response = $this->getMock('Magento\\Framework\\App\\ResponseInterface', ['setRedirect', 'sendResponse'], [], '', false);
     $this->request = $this->getMockForAbstractClass('\\Magento\\Framework\\App\\RequestInterface', ['getParam', 'getRequest'], '', false);
     $this->view = $this->getMock('\\Magento\\Framework\\App\\ViewInterface', ['loadLayout', 'getPage', 'getConfig', 'getTitle', 'loadLayoutUpdates', 'renderLayout', 'getDefaultLayoutHandle', 'generateLayoutXml', 'addPageLayoutHandles', 'generateLayoutBlocks', 'getLayout', 'addActionLayoutHandles', 'setIsLayoutLoaded', 'isLayoutLoaded'], [], '', false);
     $this->block = $this->getMock('\\Magento\\Framework\\View\\Element\\AbstractBlock', ['setActive', 'getMenuModel'], [], '', false);
     $this->layout = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\LayoutInterface', ['getBlock'], '', false);
     $this->menu = $this->getMock('\\Magento\\Backend\\Model\\Menu', ['getParentItems'], [], '', false);
     $this->items = $this->getMock('\\Magento\\Backend\\Model\\Menu\\Item', ['getParentItems'], [], '', false);
     $this->contextMock->expects($this->any())->method("getRequest")->willReturn($this->request);
     $this->contextMock->expects($this->any())->method("getResponse")->willReturn($this->response);
     $this->contextMock->expects($this->any())->method('getView')->will($this->returnValue($this->view));
     $this->page = $this->getMock('\\Magento\\Framework\\View\\Result\\Page', ['getConfig'], [], '', false);
     $this->config = $this->getMock('\\Magento\\Framework\\View\\Result\\Page', ['getTitle'], [], '', false);
     $this->title = $this->getMock('\\Title', ['prepend'], [], '', false);
     $this->block->expects($this->any())->method('setActive')->will($this->returnValue(1));
     $this->view->expects($this->any())->method('getLayout')->will($this->returnValue($this->layout));
     $this->layout->expects($this->any())->method('getBlock')->with('menu')->will($this->returnValue($this->block));
     $this->block->expects($this->any())->method('getMenuModel')->will($this->returnValue($this->menu));
     $this->menu->expects($this->any())->method('getParentItems')->will($this->returnValue($this->items));
     $this->object = new \Magento\Indexer\Controller\Adminhtml\Indexer\ListAction($this->contextMock);
 }