예제 #1
0
 /**
  * @param \Magento\Framework\View\Layout\Element $elementCurrent
  * @param string $containerName
  * @param array $structureElement
  * @param array $expectedData
  *
  * @dataProvider processDataProvider
  */
 public function testProcess($elementCurrent, $containerName, $structureElement, $expectedData)
 {
     /** @var ScheduledStructure|\PHPUnit_Framework_MockObject_MockObject $scheduledStructureMock */
     $scheduledStructureMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\ScheduledStructure')->disableOriginalConstructor()->getMock();
     $scheduledStructureMock->expects($this->once())->method('getStructureElementData')->with($containerName)->willReturn($structureElement);
     $scheduledStructureMock->expects($this->once())->method('setStructureElementData')->with($containerName, $expectedData)->willReturnSelf();
     /** @var Context|\PHPUnit_Framework_MockObject_MockObject $contextMock */
     $contextMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Reader\\Context')->disableOriginalConstructor()->getMock();
     $contextMock->expects($this->any())->method('getScheduledStructure')->willReturn($scheduledStructureMock);
     $this->helperMock->method('scheduleStructure')->with($scheduledStructureMock, $elementCurrent);
     $this->readerPoolMock->expects($this->once())->method('interpret')->with($contextMock, $elementCurrent)->willReturnSelf();
     $this->container->interpret($contextMock, $elementCurrent);
 }
예제 #2
0
 public function testRead()
 {
     $data = 'test_string';
     $xml = '<body>
                 <attribute name="body_attribute_name" value="body_attribute_value" />
             </body>';
     $this->processorInterface->expects($this->any())->method('load')->with($data)->will($this->returnValue($this->processorInterface));
     $this->themeResolver->expects($this->atLeastOnce())->method('get')->will($this->returnValue($this->themeInterface));
     $createData = ['theme' => $this->themeInterface, 'fileSource' => $this->pageLayoutFileSource, 'cacheSuffix' => 'page_layout'];
     $this->processorFactory->expects($this->once())->method('create')->with($createData)->will($this->returnValue($this->processorInterface));
     $element = new \Magento\Framework\View\Layout\Element($xml);
     $this->processorInterface->expects($this->once())->method('asSimplexml')->will($this->returnValue($element));
     $this->readerPool->expects($this->once())->method('interpret')->with($this->readerContext, $element);
     $this->model->read($this->readerContext, $data);
 }
예제 #3
0
    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();
    }
예제 #4
0
 /**
  * Prepare reader pool
  *
  * @param string $xml
  * @param string $elementType
  */
 protected function prepareReaderPool($xml, $elementType)
 {
     $this->currentElement = $this->getElement($xml, $elementType);
     $this->readerPool->expects($this->once())->method('interpret')->with($this->context, $this->currentElement);
 }