コード例 #1
0
 /**
  * @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']);
 }
コード例 #2
0
 /**
  * Init context object
  *
  * @param array $additionalParams
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 protected function initContext(array $additionalParams = [])
 {
     $productActionMock = $this->getMock('Magento\\Catalog\\Model\\Product\\Action', [], [], '', false);
     $objectManagerMock = $this->getMockForAbstractClass('Magento\\Framework\\ObjectManagerInterface');
     $objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($productActionMock));
     $block = $this->getMockBuilder('\\Magento\\Framework\\View\\Element\\AbstractBlock')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->layout = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->setMethods(['getBlock'])->disableOriginalConstructor()->getMock();
     $this->layout->expects($this->any())->method('getBlock')->will($this->returnValue($block));
     $eventManager = $this->getMockBuilder('Magento\\Framework\\Event\\Manager')->setMethods(['dispatch'])->disableOriginalConstructor()->getMock();
     $eventManager->expects($this->any())->method('dispatch')->will($this->returnSelf());
     $title = $this->getMockBuilder('\\Magento\\Framework\\App\\Action\\Title')->setMethods(['add'])->disableOriginalConstructor()->getMock();
     $title->expects($this->any())->method('prepend')->withAnyParameters()->will($this->returnSelf());
     $requestInterfaceMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->setMethods(['getParam', 'getPost', 'getFullActionName', 'getPostValue'])->disableOriginalConstructor()->getMock();
     $responseInterfaceMock = $this->getMockBuilder('Magento\\Framework\\App\\ResponseInterface')->setMethods(['setRedirect', 'sendResponse'])->getMock();
     $managerInterfaceMock = $this->getMock('Magento\\Framework\\Message\\ManagerInterface');
     $sessionMock = $this->getMock('Magento\\Backend\\Model\\Session', ['getProductData', 'setProductData'], [], '', false);
     $actionFlagMock = $this->getMock('Magento\\Framework\\App\\ActionFlag', [], [], '', false);
     $helperDataMock = $this->getMock('Magento\\Backend\\Helper\\Data', [], [], '', false);
     $this->context = $this->getMock('Magento\\Backend\\App\\Action\\Context', ['getRequest', 'getResponse', 'getObjectManager', 'getEventManager', 'getMessageManager', 'getSession', 'getActionFlag', 'getHelper', 'getTitle', 'getView', 'getResultRedirectFactory', 'getResultFactory'], [], '', false);
     $this->context->expects($this->any())->method('getTitle')->will($this->returnValue($title));
     $this->context->expects($this->any())->method('getEventManager')->will($this->returnValue($eventManager));
     $this->context->expects($this->any())->method('getRequest')->will($this->returnValue($requestInterfaceMock));
     $this->context->expects($this->any())->method('getResponse')->will($this->returnValue($responseInterfaceMock));
     $this->context->expects($this->any())->method('getObjectManager')->will($this->returnValue($objectManagerMock));
     $this->context->expects($this->any())->method('getMessageManager')->will($this->returnValue($managerInterfaceMock));
     $this->context->expects($this->any())->method('getSession')->will($this->returnValue($sessionMock));
     $this->context->expects($this->any())->method('getActionFlag')->will($this->returnValue($actionFlagMock));
     $this->context->expects($this->any())->method('getHelper')->will($this->returnValue($helperDataMock));
     foreach ($additionalParams as $property => $object) {
         $this->context->expects($this->any())->method('get' . ucfirst($property))->willReturn($object);
     }
     $this->session = $sessionMock;
     $this->request = $requestInterfaceMock;
     return $this->context;
 }
コード例 #3
0
 /**
  * Replace the output of the block, containing ttl attribute, with ESI tag
  *
  * @param \Magento\Framework\View\Element\AbstractBlock $block
  * @param \Magento\Framework\View\Layout $layout
  * @return string
  */
 protected function _wrapEsi(\Magento\Framework\View\Element\AbstractBlock $block, \Magento\Framework\View\Layout $layout)
 {
     $url = $block->getUrl('page_cache/block/esi', ['blocks' => json_encode([$block->getNameInLayout()]), 'handles' => json_encode($layout->getUpdate()->getHandles())]);
     // Varnish does not support ESI over HTTPS must change to HTTP
     $url = substr($url, 0, 5) === 'https' ? 'http' . substr($url, 5) : $url;
     return sprintf('<esi:include src="%s" />', $url);
 }
コード例 #4
0
 /**
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     $this->registryMock = $this->getMockBuilder('Magento\\Framework\\Registry')->disableOriginalConstructor()->setMethods(['registry', 'register'])->getMock();
     $this->requestMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock();
     $this->viewMock = $this->getMockBuilder('Magento\\Framework\\App\\View')->disableOriginalConstructor()->setMethods(['loadLayout', 'getLayout', 'getPage', 'renderLayout'])->getMock();
     $this->layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->setMethods(['getBlock', 'createBlock', 'setChild'])->getMock();
     $this->menuBlockMock = $this->getMockBuilder('\\Magento\\Backend\\Block\\Menu')->disableOriginalConstructor()->setMethods(['setActive', 'getMenuModel', 'getParentItems'])->getMock();
     $this->breadcrumbsBlockMock = $this->getMockBuilder('\\Magento\\Backend\\Block\\Widget\\Breadcrumbs')->disableOriginalConstructor()->setMethods(['addLink'])->getMock();
     $this->editBlockMock = $this->getMockBuilder('\\Magento\\Backend\\Block\\Widget\\Breadcrumbs')->disableOriginalConstructor()->setMethods(['setEditMode'])->getMock();
     $this->resultPageMock = $this->getMockBuilder('Magento\\Framework\\View\\Result\\Page')->disableOriginalConstructor()->setMethods(['setActiveMenu', 'getConfig', 'addBreadcrumb'])->getMock();
     $this->pageConfigMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config')->disableOriginalConstructor()->getMock();
     $this->pageTitleMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Title')->disableOriginalConstructor()->getMock();
     $this->viewMock->expects($this->atLeastOnce())->method('getLayout')->willReturn($this->layoutMock);
     $this->layoutMock->expects($this->any())->method('getBlock')->willReturnMap([['menu', $this->menuBlockMock], ['breadcrumbs', $this->breadcrumbsBlockMock], ['edit', $this->editBlockMock]]);
     $this->menuBlockMock->expects($this->any())->method('getMenuModel')->will($this->returnSelf());
     $this->menuBlockMock->expects($this->any())->method('getParentItems')->will($this->returnValue([]));
     $this->viewMock->expects($this->any())->method('getPage')->willReturn($this->resultPageMock);
     $this->resultPageMock->expects($this->any())->method('getConfig')->willReturn($this->pageConfigMock);
     $this->pageConfigMock->expects($this->any())->method('getTitle')->willReturn($this->pageTitleMock);
     $this->layoutMock->expects($this->once())->method('createBlock')->with('Magento\\Email\\Block\\Adminhtml\\Template\\Edit', 'template_edit', [])->willReturn($this->editBlockMock);
     $this->editBlockMock->expects($this->once())->method('setEditMode')->willReturnSelf();
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $templateMock = $this->getMockBuilder('Magento\\Email\\Model\\Template')->disableOriginalConstructor()->getMock();
     $templateMock->expects($this->once())->method('getId')->willReturn(1);
     $templateMock->expects($this->any())->method('getTemplateCode')->willReturn('My Template');
     $objectManagerMock = $this->getMockBuilder('Magento\\Framework\\App\\ObjectManager')->disableOriginalConstructor()->getMock();
     $objectManagerMock->expects($this->once())->method('create')->with('Magento\\Email\\Model\\BackendTemplate')->willReturn($templateMock);
     $this->context = $objectManager->getObject('Magento\\Backend\\App\\Action\\Context', ['request' => $this->requestMock, 'objectManager' => $objectManagerMock, 'view' => $this->viewMock]);
     $this->editController = $objectManager->getObject('Magento\\Email\\Controller\\Adminhtml\\Email\\Template\\Edit', ['context' => $this->context, 'coreRegistry' => $this->registryMock]);
 }
コード例 #5
0
 public function testGetItemRowTotalAfterDiscountHtml()
 {
     $html = '$34.28';
     $this->layoutMock->expects($this->once())->method('getBlock')->with('item_row_total_after_discount')->will($this->returnValue($this->priceRenderBlock));
     $this->priceRenderBlock->expects($this->once())->method('setItem')->with($this->itemMock);
     $this->priceRenderBlock->expects($this->once())->method('toHtml')->will($this->returnValue($html));
     $this->assertEquals($html, $this->block->getItemRowTotalAfterDiscountHtml($this->itemMock));
 }
コード例 #6
0
 public function testGetItemPrice()
 {
     $html = '$34.28';
     $this->layoutMock->expects($this->once())->method('getBlock')->with('item_price')->will($this->returnValue($this->priceRenderBlock));
     $this->priceRenderBlock->expects($this->once())->method('setItem')->with($this->itemMock);
     $this->priceRenderBlock->expects($this->once())->method('toHtml')->will($this->returnValue($html));
     $this->assertEquals($html, $this->block->getItemPrice($this->itemMock));
 }
コード例 #7
0
 public function testAroundRenderTrue()
 {
     $attributeMock = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], [], '', false);
     $this->filterMock->expects($this->atLeastOnce())->method('getAttributeModel')->willReturn($attributeMock);
     $this->filterMock->expects($this->once())->method('hasAttributeModel')->willReturn(true);
     $this->swatchHelperMock->expects($this->once())->method('isSwatchAttribute')->with($attributeMock)->willReturn(true);
     $this->layoutMock->expects($this->once())->method('createBlock')->willReturn($this->blockMock);
     $this->blockMock->expects($this->once())->method('setSwatchFilter')->will($this->returnSelf());
     $this->plugin->aroundRender($this->filterRendererMock, $this->closureMock, $this->filterMock);
 }
コード例 #8
0
 /**
  * Categories chooser Action (Ajax request)
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $selected = $this->getRequest()->getParam('selected', '');
     $isAnchorOnly = $this->getRequest()->getParam('is_anchor_only', 0);
     /** @var \Magento\Widget\Block\Adminhtml\Widget\Catalog\Category\Chooser $chooser */
     $chooser = $this->layout->createBlock('Magento\\Widget\\Block\\Adminhtml\\Widget\\Catalog\\Category\\Chooser')->setUseMassaction(true)->setId($this->mathRandom->getUniqueHash('categories'))->setIsAnchorOnly($isAnchorOnly)->setSelectedCategories(explode(',', $selected));
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
     return $resultRaw->setContents($chooser->toHtml());
 }
コード例 #9
0
ファイル: IndexTest.php プロジェクト: nblair/magescotch
 /**
  * test setup
  */
 public function setUp()
 {
     $this->pageConfig = $this->getMockBuilder('\\Magento\\Framework\\View\\Page\\Config')->disableOriginalConstructor()->setMethods(['set', 'getTitle'])->getMock();
     $this->resultPageFactory = $this->getMockBuilder('\\Magento\\Framework\\View\\Result\\PageFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->resultPage = $this->getMockBuilder('\\Magento\\Framework\\View\\Result\\Page')->disableOriginalConstructor()->getMock();
     $this->block = $this->getMockBuilder('\\Magento\\Framework\\View\\Element\\AbstractBlock')->disableOriginalConstructor()->getMock();
     $this->pageLayout = $this->getMockBuilder('\\Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->getMock();
     $this->resultPageFactory->expects($this->once())->method('create')->willReturn($this->resultPage);
     $this->resultPage->expects($this->any())->method('getLayout')->willReturn($this->pageLayout);
     $this->pageLayout->expects($this->any())->method('getBlock')->willReturn($this->block);
     $this->pageConfig->expects($this->once())->method('getTitle')->willReturnSelf();
     $this->resultPage->expects($this->any())->method('getConfig')->willReturn($this->pageConfig);
 }
コード例 #10
0
 /**
  * Executes the controller action and asserts non exception logic
  */
 public function testExecute()
 {
     $objectManager = new ObjectManagerHelper($this);
     $this->vault->expects($this->once())->method('storedCard')->willReturn(true);
     $this->request->expects($this->any())->method('getParam')->willReturn('token');
     $this->resultRedirectFactory->expects($this->never())->method('create')->willReturn($this->resultRedirect);
     $this->resultPageFactory->expects($this->once())->method('create')->willReturn($this->resultPage);
     $this->resultPage->expects($this->any())->method('getLayout')->willReturn($this->pageLayout);
     $this->pageLayout->expects($this->any())->method('getBlock')->willReturn($this->block);
     $this->pageConfig->expects($this->once())->method('getTitle')->willReturnSelf();
     $this->resultPage->expects($this->any())->method('getConfig')->willReturn($this->pageConfig);
     $notification = $objectManager->getObject('Magento\\Braintree\\Controller\\Creditcard\\Delete', ['request' => $this->request, 'resultPageFactory' => $this->resultPageFactory, 'vault' => $this->vault]);
     $this->assertSame($this->resultPage, $notification->execute());
 }
コード例 #11
0
ファイル: IndexTest.php プロジェクト: nblair/magescotch
 public function testExecute()
 {
     $this->menuMock->expects($this->once())->method('getParentItems')->willReturn([$this->menuItemMock]);
     $this->titleMock->expects($this->atLeastOnce())->method('prepend');
     $this->pageConfigMock->expects($this->atLeastOnce())->method('getTitle')->willReturn($this->titleMock);
     $this->pageMock->expects($this->atLeastOnce())->method('getConfig')->willReturn($this->pageConfigMock);
     $this->blockMock->expects($this->atLeastOnce())->method('addLink');
     $this->blockMock->expects($this->once())->method('setActive');
     $this->blockMock->expects($this->once())->method('getMenuModel')->willReturn($this->menuMock);
     $this->layoutMock->expects($this->atLeastOnce())->method('getBlock')->willReturn($this->blockMock);
     $this->viewMock->expects($this->once())->method('loadLayout')->willReturnSelf();
     $this->viewMock->expects($this->atLeastOnce())->method('getLayout')->willReturn($this->layoutMock);
     $this->viewMock->expects($this->atLeastOnce())->method('getPage')->willReturn($this->pageMock);
     $this->action->executeInternal();
 }
コード例 #12
0
 /**
  * @covers \Magento\Email\Controller\Adminhtml\Email\Template\Index::execute
  */
 public function testExecute()
 {
     $this->prepareExecute();
     $this->viewMock->expects($this->atLeastOnce())->method('getLayout')->willReturn($this->layoutMock);
     $this->layoutMock->expects($this->at(0))->method('getBlock')->with('menu')->will($this->returnValue($this->menuBlockMock));
     $this->menuBlockMock->expects($this->any())->method('getMenuModel')->will($this->returnSelf());
     $this->menuBlockMock->expects($this->any())->method('getParentItems')->will($this->returnValue([]));
     $this->viewMock->expects($this->once())->method('getPage')->willReturn($this->resultPageMock);
     $this->resultPageMock->expects($this->once())->method('getConfig')->willReturn($this->pageConfigMock);
     $this->pageConfigMock->expects($this->once())->method('getTitle')->willReturn($this->pageTitleMock);
     $this->pageTitleMock->expects($this->once())->method('prepend')->with('Email Templates');
     $this->layoutMock->expects($this->at(1))->method('getBlock')->with('breadcrumbs')->will($this->returnValue($this->breadcrumbsBlockMock));
     $this->breadcrumbsBlockMock->expects($this->any())->method('addLink')->willReturnSelf();
     $this->assertNull($this->indexController->execute());
 }
コード例 #13
0
 /**
  * Set X-Cache-Tags header with all the Magento Cache Tags so
  * they can be purged by the CloudFlare API
  *
  * @param \Magento\Framework\View\Layout $subject
  * @param $result
  * @return mixed
  */
 public function afterGetOutput(\Magento\Framework\View\Layout $subject, $result)
 {
     if (!$subject->isCacheable() || !$this->config->isEnabled()) {
         return $result;
     }
     $tags = [];
     foreach ($subject->getAllBlocks() as $block) {
         if ($block->getIdentities() !== null) {
             $tags = array_merge($tags, $block->getIdentities());
         }
     }
     $tags = array_unique($tags);
     $this->cacheTagsUtil->setCloudFlareCacheTagsResponseHeader($this->response, $tags);
     return $result;
 }
コード例 #14
0
ファイル: LayoutTest.php プロジェクト: nja78/magento2
    public function testGenerateElementsWithCache()
    {
        $layoutCacheId = 'layout_cache_id';
        /** @var \Magento\Framework\View\Layout\Element $xml */
        $xml = simplexml_load_string('<layout/>', 'Magento\Framework\View\Layout\Element');
        $this->model->setXml($xml);

        $themeMock = $this->getMockForAbstractClass('Magento\Framework\View\Design\ThemeInterface');
        $this->themeResolverMock->expects($this->once())
            ->method('get')
            ->willReturn($themeMock);
        $this->processorFactoryMock->expects($this->once())
            ->method('create')
            ->with(['theme' => $themeMock])
            ->willReturn($this->processorMock);

        $this->processorMock->expects($this->once())
            ->method('getCacheId')
            ->willReturn($layoutCacheId);

        $readerContextMock = $this->getMockBuilder('Magento\Framework\View\Layout\Reader\Context')
            ->disableOriginalConstructor()
            ->getMock();

        $this->cacheMock->expects($this->once())
            ->method('load')
            ->with('structure_' . $layoutCacheId)
            ->willReturn(serialize($readerContextMock));

        $this->readerPoolMock->expects($this->never())
            ->method('interpret');
        $this->cacheMock->expects($this->never())
            ->method('save');

        $generatorContextMock = $this->getMockBuilder('Magento\Framework\View\Layout\Generator\Context')
            ->disableOriginalConstructor()
            ->getMock();
        $this->generatorContextFactoryMock->expects($this->once())
            ->method('create')
            ->with(['structure' => $this->structureMock, 'layout' => $this->model])
            ->willReturn($generatorContextMock);

        $this->generatorPoolMock->expects($this->once())
            ->method('process')
            ->with($readerContextMock, $generatorContextMock)
            ->willReturn(true);

        $elements = [
            'name_1' => ['type' => '', 'parent' => null],
            'name_2' => ['type' => \Magento\Framework\View\Layout\Element::TYPE_CONTAINER, 'parent' => null],
            'name_3' => ['type' => '', 'parent' => 'parent'],
            'name_4' => ['type' => \Magento\Framework\View\Layout\Element::TYPE_CONTAINER, 'parent' => 'parent'],
        ];

        $this->structureMock->expects($this->once())
            ->method('exportElements')
            ->willReturn($elements);

        $this->model->generateElements();
    }
コード例 #15
0
 protected function _buildEntries(&$entries, $block, $alias, $level)
 {
     $blocks = $this->_layout->getAllBlocks();
     $extras = array();
     $extras[] = count($block->getChild()) ? count($block->getChild()) : "-";
     $extras[] = $block->getType();
     if ($block->getType() === 'cms/block') {
         $extras[] = $block->getBlockId();
     } elseif ($block->getType() == 'cms/page') {
         $extras[] = $block->getPage()->getIdentifier();
     } elseif ($template = $block->getTemplate()) {
         $extras[] = $template;
     } else {
         $extras[] = '-';
     }
     $extras[] = get_class($block);
     // sprintf("$offset%s %s\n", $alias, $this->_colorize($extraString, self::COLOR_DARK_GRAY))
     $name = $block->getNameInLayout();
     $entry = array('name' => $name, 'alias' => $alias, 'level' => $level, 'extras' => $extras);
     $profileName = "BLOCK: {$name}";
     if (isset($this->timers[$profileName])) {
         $entry['time'] = $this->timers[$profileName]['sum'] * 1000;
     }
     $entries[] = $entry;
     foreach ($block->getChild() as $alias => $childBlock) {
         $this->_buildEntries($entries, $childBlock, $alias, $level + 1);
     }
 }
コード例 #16
0
ファイル: AccordionTest.php プロジェクト: aiesh/magento2
 /**
  * @magentoConfigFixture customer/account_share/scope 1
  */
 public function testToHtmlEmptyWebsiteShareNewCustomer()
 {
     $block = $this->layout->createBlock('Magento\\Customer\\Block\\Adminhtml\\Edit\\Tab\\View\\Accordion');
     $html = $block->toHtml();
     $this->assertContains('Wishlist - 0 item(s)', $html);
     $this->assertContains('Shopping Cart - 0 item(s)', $html);
 }
コード例 #17
0
 protected function buildEntries(MagentoLayout $layout, &$structure, $name = 'root', $alias = '', $level = 0)
 {
     if (!isset($structure[$name])) {
         return [];
     }
     $instance = $layout->getBlock($name);
     $block = $structure[$name];
     $entries = [];
     $entries[] = ['level' => $level, 'name' => $name, 'alias' => $alias, 'type' => $block['type'], 'label' => isset($block['label']) ? $block['label'] : '', 'extra' => array_filter(['htmlTag' => isset($block['htmlTag']) ? $block['htmlTag'] : '', 'htmlId' => isset($block['htmlId']) ? $block['htmlId'] : '', 'htmlClass' => isset($block['htmlClass']) ? $block['htmlClass'] : '', 'template' => $instance ? $instance->getTemplate() : ''])];
     if (isset($block['children'])) {
         foreach ($block['children'] as $child => $alias) {
             $entries = array_merge($entries, $this->buildEntries($layout, $structure, $child, $alias, $level + 1));
         }
     }
     return $entries;
 }
コード例 #18
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();
 }
コード例 #19
0
ファイル: ViewTest.php プロジェクト: Atlis/docker-magento2
 public function setUp()
 {
     $this->request = $this->getMock('Magento\\Framework\\App\\RequestInterface');
     $this->response = $this->getMock('Magento\\Framework\\App\\ResponseInterface');
     $this->categoryHelper = $this->getMock('Magento\\Catalog\\Helper\\Category', [], [], '', false);
     $this->objectManager = $this->getMock('Magento\\Framework\\ObjectManager', [], [], '', false);
     $this->eventManager = $this->getMock('Magento\\Framework\\Event\\ManagerInterface');
     $this->update = $this->getMock('Magento\\Framework\\View\\Layout\\ProcessorInterface');
     $this->layout = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false);
     $this->layout->expects($this->any())->method('getUpdate')->will($this->returnValue($this->update));
     $this->view = $this->getMock('Magento\\Framework\\App\\ViewInterface');
     $this->view->expects($this->any())->method('getLayout')->will($this->returnValue($this->layout));
     $this->context = $this->getMock('Magento\\Backend\\App\\Action\\Context', [], [], '', false);
     $this->context->expects($this->any())->method('getRequest')->will($this->returnValue($this->request));
     $this->context->expects($this->any())->method('getResponse')->will($this->returnValue($this->response));
     $this->context->expects($this->any())->method('getObjectManager')->will($this->returnValue($this->objectManager));
     $this->context->expects($this->any())->method('getEventManager')->will($this->returnValue($this->eventManager));
     $this->context->expects($this->any())->method('getView')->will($this->returnValue($this->view));
     $this->category = $this->getMock('Magento\\Catalog\\Model\\Category', [], [], '', false);
     $this->categoryFactory = $this->getMock('Magento\\Catalog\\Model\\CategoryFactory', ['create'], [], '', false);
     $this->store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $this->storeManager = $this->getMock('Magento\\Store\\Model\\StoreManagerInterface');
     $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($this->store));
     $this->catalogDesign = $this->getMock('Magento\\Catalog\\Model\\Design', [], [], '', false);
     $this->layoutHelper = $this->getMock('Magento\\Theme\\Helper\\Layout', [], [], '', false);
     $this->action = (new ObjectManager($this))->getObject('Magento\\Catalog\\Controller\\Category\\View', ['context' => $this->context, 'catalogDesign' => $this->catalogDesign, 'categoryFactory' => $this->categoryFactory, 'storeManager' => $this->storeManager]);
 }
コード例 #20
0
 /**
  * @param $cacheState
  * @param $layoutIsCacheable
  * @param $expectedTags
  * @param $configCacheType
  * @param $ttl
  * @dataProvider afterGetOutputDataProvider
  */
 public function testAfterGetOutput($cacheState, $layoutIsCacheable, $expectedTags, $configCacheType, $ttl)
 {
     $html = 'html';
     $this->configMock->expects($this->any())->method('isEnabled')->will($this->returnValue($cacheState));
     $blockStub = $this->getMock('Magento\\PageCache\\Test\\Unit\\Block\\Controller\\StubBlock', null, [], '', false);
     $blockStub->setTtl($ttl);
     $this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue($layoutIsCacheable));
     $this->layoutMock->expects($this->any())->method('getAllBlocks')->will($this->returnValue([$blockStub]));
     $this->configMock->expects($this->any())->method('getType')->will($this->returnValue($configCacheType));
     if ($layoutIsCacheable && $cacheState) {
         $this->responseMock->expects($this->once())->method('setHeader')->with('X-Magento-Tags', $expectedTags);
     } else {
         $this->responseMock->expects($this->never())->method('setHeader');
     }
     $output = $this->model->afterGetOutput($this->layoutMock, $html);
     $this->assertSame($output, $html);
 }
コード例 #21
0
 /**
  * @param mixed $displayValue
  * @dataProvider renderElementDoNotDisplayDataProvider
  */
 public function testRenderElementDoNotDisplay($displayValue)
 {
     $displayValue = 'false';
     $name = 'test_container';
     $blockHtml = '';
     $this->structureMock->expects($this->atLeastOnce())->method('getAttribute')->willReturnMap([[$name, 'display', $displayValue]]);
     $this->assertEquals($blockHtml, $this->model->renderElement($name, false));
 }
コード例 #22
0
ファイル: LayoutTest.php プロジェクト: Atlis/docker-magento2
 public function testGetUpdate()
 {
     $themeMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Design\\ThemeInterface');
     $this->themeResolverMock->expects($this->once())->method('get')->will($this->returnValue($themeMock));
     $this->processorFactoryMock->expects($this->once())->method('create')->with(array('theme' => $themeMock))->will($this->returnValue($this->processorMock));
     $this->assertEquals($this->processorMock, $this->_model->getUpdate());
     $this->assertEquals($this->processorMock, $this->_model->getUpdate());
 }
コード例 #23
0
 public function testAddDefaultHandle()
 {
     $processor = $this->getMock('Magento\\Framework\\View\\Layout\\ProcessorInterface', [], [], '', false);
     $processor->expects($this->once())->method('addHandle')->with('module_controller_action');
     $this->layout->expects($this->once())->method('getUpdate')->will($this->returnValue($processor));
     $this->request->expects($this->once())->method('getFullActionName')->will($this->returnValue('Module_Controller_Action'));
     $this->assertSame($this->resultLayout, $this->resultLayout->addDefaultHandle());
 }
コード例 #24
0
 /**
  * {@inheritdoc}
  */
 public function getOutput()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getOutput');
     if (!$pluginInfo) {
         return parent::getOutput();
     } else {
         return $this->___callPlugins('getOutput', func_get_args(), $pluginInfo);
     }
 }
コード例 #25
0
 protected function setUp()
 {
     $this->layout = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->setMethods(['addHandle', 'getUpdate', 'isLayoutDefined'])->disableOriginalConstructor()->getMock();
     $this->layoutFactory = $this->getMockBuilder('Magento\\Framework\\View\\LayoutFactory')->disableOriginalConstructor()->getMock();
     $this->layoutFactory->expects($this->any())->method('create')->will($this->returnValue($this->layout));
     $this->layoutMerge = $this->getMockBuilder('Magento\\Framework\\View\\Model\\Layout\\Merge')->disableOriginalConstructor()->getMock();
     $this->layout->expects($this->any())->method('getUpdate')->will($this->returnValue($this->layoutMerge));
     $this->request = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock();
     $this->pageConfig = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config')->disableOriginalConstructor()->getMock();
     $this->viewFileSystem = $this->getMockBuilder('Magento\\Framework\\View\\FileSystem')->disableOriginalConstructor()->getMock();
     $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->context = $objectManagerHelper->getObject('Magento\\Framework\\View\\Element\\Template\\Context', ['layout' => $this->layout, 'request' => $this->request, 'viewFileSystem' => $this->viewFileSystem, 'pageConfig' => $this->pageConfig]);
     $this->translateInline = $this->getMock('Magento\\Framework\\Translate\\InlineInterface');
     $this->pageConfigRenderer = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config\\Renderer')->disableOriginalConstructor()->getMock();
     $pageConfigRendererFactory = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config\\RendererFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $pageConfigRendererFactory->expects($this->once())->method('create')->with(['pageConfig' => $this->pageConfig])->willReturn($this->pageConfigRenderer);
     $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->page = $objectManagerHelper->getObject('Magento\\Framework\\View\\Result\\Page', ['isIsolated' => true, 'layoutFactory' => $this->layoutFactory, 'context' => $this->context, 'translateInline' => $this->translateInline, 'pageConfigRendererFactory' => $pageConfigRendererFactory]);
 }
コード例 #26
0
 /**
  * Retrieve all identities from blocks for further cache invalidation
  *
  * @param \Magento\Framework\View\Layout $subject
  * @param mixed $result
  * @return mixed
  */
 public function afterGetOutput(\Magento\Framework\View\Layout $subject, $result)
 {
     if ($subject->isCacheable() && $this->config->isEnabled()) {
         $tags = [];
         foreach ($subject->getAllBlocks() as $block) {
             if ($block instanceof \Magento\Framework\DataObject\IdentityInterface) {
                 $isEsiBlock = $block->getTtl() > 0;
                 $isVarnish = $this->config->getType() == \Magento\PageCache\Model\Config::VARNISH;
                 if ($isVarnish && $isEsiBlock) {
                     continue;
                 }
                 $tags = array_merge($tags, $block->getIdentities());
             }
         }
         $tags = array_unique($tags);
         $this->response->setHeader('X-Magento-Tags', implode(',', $tags));
     }
     return $result;
 }
コード例 #27
0
 /**
  * Test afterGenerateXml method with enabled module PageCache and request is Ajax and Layout is not cacheable
  */
 public function testAfterGenerateXmlLayoutIsNotCacheable()
 {
     $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', array(), array(), '', false);
     $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(true));
     $this->cacheConfigMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
     $this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(false));
     $this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(false));
     $this->visitorMock->expects($this->never())->method('setSkipRequestLogging');
     $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult);
     $this->assertSame($expectedResult, $actualResult);
 }
コード例 #28
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();
 }
コード例 #29
0
 /**
  * @dataProvider executeDataProvider
  * @param string $blockClass
  * @param bool $shouldSetHeaders
  */
 public function testExecute($blockClass, $shouldSetHeaders)
 {
     $block = 'block';
     $handles = array('handle1', 'handle2');
     $html = 'some-html';
     $mapData = array(array('blocks', '', json_encode(array($block))), array('handles', '', json_encode($handles)));
     $blockInstance1 = $this->getMock($blockClass, array('toHtml'), array(), '', 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->responseMock->expects($this->once())->method('appendBody')->with($this->equalTo($html));
     $this->action->execute();
 }
コード例 #30
0
ファイル: CategoriesTest.php プロジェクト: nblair/magescotch
    public function testExecute()
    {
        $selectedCategories = '1';
        $isAnchorOnly = true;
        $hash = '7e6baeca2d76ca0efc3a299986d31bdc9cd796fb';
        $content = 'block_content';

        $this->request->expects($this->any())->method('getParam')->willReturnMap(
            [
                ['selected', '', $selectedCategories],
                ['is_anchor_only', 0, $isAnchorOnly]
            ]
        );

        $this->mathRandom->expects($this->once())->method('getUniqueHash')->with('categories')->willReturn($hash);

        $this->chooser->expects($this->once())->method('setUseMassaction')->with()->willReturnSelf();
        $this->chooser->expects($this->once())->method('setId')->with($hash)->willReturnSelf();
        $this->chooser->expects($this->once())->method('setIsAnchorOnly')->with($isAnchorOnly)->willReturnSelf();
        $this->chooser->expects($this->once())
            ->method('setSelectedCategories')
            ->with(explode(',', $selectedCategories))
            ->willReturnSelf();
        $this->chooser->expects($this->once())->method('toHtml')->willReturn($content);

        $this->layout->expects($this->once())
            ->method('createBlock')
            ->with($this->blockClass)
            ->willReturn($this->chooser);

        $this->resultRaw->expects($this->once())->method('setContents')->with($content)->willReturnSelf();

        $this->resultFactory->expects($this->once())
            ->method('create')
            ->with(\Magento\Framework\Controller\ResultFactory::TYPE_RAW)
            ->willReturn($this->resultRaw);

        $this->context->expects($this->once())->method('getRequest')->willReturn($this->request);
        $this->context->expects($this->once())->method('getResultFactory')->willReturn($this->resultFactory);

        /** @var \Magento\Widget\Controller\Adminhtml\Widget\Instance\Categories $controller */
        $this->controller = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))
            ->getObject(
                'Magento\Widget\Controller\Adminhtml\Widget\Instance\Categories',
                [
                    'context' => $this->context,
                    'mathRandom' => $this->mathRandom,
                    'layout' => $this->layout
                ]
            );
        $this->assertSame($this->resultRaw, $this->controller->executeInternal());
    }