/** * @dataProvider processDataProvider */ public function testProcess($xml) { $this->element = new \Magento\Framework\View\Layout\Element($xml); $this->context->expects($this->any())->method('getScheduledStructure')->will($this->returnValue($this->scheduledStructure)); $this->scheduledStructure->expects($this->once())->method('setElementToRemoveList')->with('header'); $this->model->interpret($this->context, $this->element, $this->element); }
/** * @param string $literal * @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $getCondition * @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $setCondition * @dataProvider processReferenceDataProvider */ public function testProcessReference($literal, $getCondition, $setCondition) { $this->context->expects($this->once())->method('getScheduledStructure')->will($this->returnValue($this->scheduledStructure)); $this->scheduledStructure->expects($getCondition)->method('getStructureElementData')->with($literal, [])->willReturn(['actions' => [['someMethod', [], 'action_config_path', 'scope']]]); $this->scheduledStructure->expects($setCondition)->method('setStructureElementData')->with($literal, ['actions' => [['someMethod', [], 'action_config_path', 'scope']], 'arguments' => []]); $this->prepareReaderPool('<' . $literal . ' name="' . $literal . '">' . '<action method="someMethod" ifconfig="action_config_path" />' . '</' . $literal . '>', $literal); /** @var \Magento\Framework\View\Layout\Reader\Block $block */ $block = $this->getBlock(['readerPool' => $this->readerPool, 'scopeType' => 'scope']); $block->interpret($this->context, $this->currentElement); }
/** * @covers Magento\Framework\View\Layout\Reader\Block::interpret() */ public function testProcessReference() { $testName = 'test_value'; $literal = 'referenceBlock'; $this->context->expects($this->once())->method('getScheduledStructure')->will($this->returnValue($this->scheduledStructure)); $this->scheduledStructure->expects($this->once())->method('getStructureElementData')->with($testName, [])->will($this->returnValue([])); $this->scheduledStructure->expects($this->once())->method('setStructureElementData')->with($testName, ['actions' => [], 'arguments' => []]); $this->prepareReaderPool('<' . $literal . ' name="' . $testName . '"/>'); /** @var \Magento\Framework\View\Layout\Reader\Block $block */ $block = $this->getBlock(['readerPool' => $this->readerPool]); $block->interpret($this->context, $this->currentElement); }
/** * @param bool $hasParent * @param int $setAsChild * @param int $toRemoveList * @param string $siblingName * @param bool $isAfter * @param int $toSortList * @return void * * @dataProvider scheduleElementDataProvider */ public function testScheduleElement($hasParent, $setAsChild, $toRemoveList, $siblingName, $isAfter, $toSortList) { $key = 'key'; $parentName = 'parent'; $alias = 'alias'; $block = 'block'; $data = ['data']; $this->scheduledStructureMock->expects($this->any())->method('getStructureElement')->willReturnMap([[$key, null, [Layout\ScheduledStructure\Helper::SCHEDULED_STRUCTURE_INDEX_TYPE => $block, Layout\ScheduledStructure\Helper::SCHEDULED_STRUCTURE_INDEX_ALIAS => $alias, Layout\ScheduledStructure\Helper::SCHEDULED_STRUCTURE_INDEX_PARENT_NAME => $parentName, Layout\ScheduledStructure\Helper::SCHEDULED_STRUCTURE_INDEX_SIBLING_NAME => $siblingName, Layout\ScheduledStructure\Helper::SCHEDULED_STRUCTURE_INDEX_IS_AFTER => $isAfter]], [$parentName, null, []]]); $this->scheduledStructureMock->expects($this->any())->method('getStructureElementData')->willReturnMap([[$key, null, $data], [$parentName, null, $data]]); $this->scheduledStructureMock->expects($this->any())->method('hasStructureElement')->willReturn(true); $this->scheduledStructureMock->expects($this->once())->method('setElement')->with($key, [$block, $data]); $this->dataStructureMock->expects($this->once())->method('createElement')->with($key, ['type' => $block]); $this->dataStructureMock->expects($this->once())->method('hasElement')->with($parentName)->willReturn($hasParent); $this->dataStructureMock->expects($this->exactly($setAsChild))->method('setAsChild')->with($key, $parentName, $alias)->willReturn(true); $this->scheduledStructureMock->expects($this->exactly($toRemoveList))->method('setElementToBrokenParentList')->with($key); $this->scheduledStructureMock->expects($this->exactly($toSortList))->method('setElementToSortList')->with($parentName, $key, $siblingName, $isAfter); $this->helper->scheduleElement($this->scheduledStructureMock, $this->dataStructureMock, $key); }
/** * @param string $name */ protected function prepareGenerateBlock($name) { $blockClass = 'Magento\\Framework\\View\\Element\\Template'; $template = 'file.phtml'; $ttl = 100; $xmlString = '<?xml version="1.0"?><block class="' . $blockClass . '" template="' . $template . '" ttl="' . $ttl . '"></block>'; $xml = simplexml_load_string($xmlString, 'Magento\\Framework\\View\\Layout\\Element'); $elementData = [\Magento\Framework\View\Layout\Element::TYPE_BLOCK, $xml, [], []]; $this->schStructureMock->expects($this->once())->method('getElement')->with($this->equalTo($name))->will($this->returnValue($elementData)); $this->schStructureMock->expects($this->once())->method('unsetElement')->with($this->equalTo($name))->will($this->returnSelf()); $blockMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\Template')->setMethods(['setType', 'setNameInLayout', 'addData', 'setLayout', 'setTemplate', 'setTtl'])->disableOriginalConstructor()->getMock(); $blockMock->expects($this->once())->method('setTemplate')->with($this->equalTo($template))->will($this->returnSelf()); $blockMock->expects($this->once())->method('setTtl')->with($this->equalTo($ttl))->will($this->returnSelf()); $blockMock->expects($this->once())->method('setType')->with($this->equalTo(get_class($blockMock)))->will($this->returnSelf()); $blockMock->expects($this->once())->method('setNameInLayout')->with($this->equalTo($name))->will($this->returnSelf()); $blockMock->expects($this->once())->method('addData')->with($this->equalTo([]))->will($this->returnSelf()); $blockMock->expects($this->once())->method('setLayout')->with($this->equalTo($this->model))->will($this->returnSelf()); $this->blockFactoryMock->expects($this->once())->method('createBlock')->with($this->equalTo('Magento\\Framework\\View\\Element\\Template'), $this->equalTo(['data' => []]))->will($this->returnValue($blockMock)); $this->eventManagerMock->expects($this->once())->method('dispatch')->with($this->equalTo('core_layout_block_create_after'), $this->equalTo(['block' => $blockMock]))->will($this->returnSelf()); }
protected function prepareScheduledStructure() { $this->scheduledStructureMock->expects($this->any())->method('getElements')->willReturn([UiComponent::TYPE => [UiComponent::TYPE, ['attributes' => ['group' => 'new_group', 'component' => 'component_name'], 'arguments' => ['attribute_1' => ['key_1' => 'value_1'], 'attribute_2' => ['key_2' => 'value_2']]]]]); }
/** * @param array $structureElements * * @dataProvider processWithExceptionDataProvider * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testProcessWithException($structureElements) { $this->scheduledStructureMock->expects($this->once())->method('getElements')->willReturn($structureElements); $this->structureMock->expects($this->once())->method('setAttribute')->willReturnSelf(); $this->container->process($this->readerContextMock, $this->generatorContextMock); }
/** * @param \Magento\Framework\View\Layout\Element $currentElement * @param string $destination * @param string $siblingName * @param bool $isAfter * @param string $alias * @param \Magento\Framework\View\Layout\Element $parentElement * * @dataProvider processDataProvider */ public function testProcess($currentElement, $destination, $siblingName, $isAfter, $alias, $parentElement) { $this->scheduledStructureMock->expects($this->any())->method('setElementToMove')->with((string) $currentElement->getAttribute('element'), [$destination, $siblingName, $isAfter, $alias]); $this->move->interpret($this->contextMock, $currentElement, $parentElement); }