protected function setUp()
 {
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->scheduledStructureMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\ScheduledStructure')->disableOriginalConstructor()->getMock();
     $this->structureMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Data\\Structure')->disableOriginalConstructor()->getMock();
     $this->generatorContextMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Generator\\Context')->disableOriginalConstructor()->getMock();
     $this->generatorContextMock->expects($this->any())->method('getStructure')->willReturn($this->structureMock);
     $this->readerContextMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Reader\\Context')->disableOriginalConstructor()->getMock();
     $this->readerContextMock->expects($this->any())->method('getScheduledStructure')->willReturn($this->scheduledStructureMock);
     $this->container = $this->objectManagerHelper->getObject('Magento\\Framework\\View\\Layout\\Generator\\Container');
 }
Beispiel #2
0
 /**
  * Process container elements
  *
  * @param \Magento\Framework\View\Layout\Reader\Context $readerContext
  * @param Context $generatorContext
  * @return $this
  */
 public function process(Layout\Reader\Context $readerContext, Layout\Generator\Context $generatorContext)
 {
     $structure = $generatorContext->getStructure();
     $scheduledStructure = $readerContext->getScheduledStructure();
     foreach ($scheduledStructure->getElements() as $elementName => $element) {
         list($type, $data) = $element;
         if ($type === self::TYPE) {
             $this->generateContainer($structure, $elementName, $data['attributes']);
             $scheduledStructure->unsetElement($elementName);
         }
     }
     return $this;
 }
 /**
  * @return void
  */
 protected function setUp()
 {
     // ScheduledStructure
     $this->readerContextMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Reader\\Context')->disableOriginalConstructor()->getMock();
     $this->scheduledStructure = new ScheduledStructure();
     $this->readerContextMock->expects($this->any())->method('getScheduledStructure')->willReturn($this->scheduledStructure);
     // DataStructure
     $this->generatorContextMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Generator\\Context')->disableOriginalConstructor()->getMock();
     $this->structureMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Data\\Structure')->disableOriginalConstructor()->setMethods(['reorderChildElement'])->getMock();
     $this->generatorContextMock->expects($this->any())->method('getStructure')->willReturn($this->structureMock);
     $this->helperMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\ScheduledStructure\\Helper')->disableOriginalConstructor()->getMock();
     $helperObjectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->model = $helperObjectManager->getObject('Magento\\Framework\\View\\Layout\\GeneratorPool', ['helper' => $this->helperMock, 'generators' => $this->getGeneratorsMocks()]);
 }
Beispiel #4
0
 /**
  * Creates UI Component object based on scheduled data and add it to the layout
  *
  * @param ReaderContext $readerContext
  * @param GeneratorContext $generatorContext
  * @return $this
  */
 public function process(ReaderContext $readerContext, GeneratorContext $generatorContext)
 {
     $scheduledStructure = $readerContext->getScheduledStructure();
     $scheduledElements = $scheduledStructure->getElements();
     if (!$scheduledElements) {
         return $this;
     }
     $structure = $generatorContext->getStructure();
     $layout = $generatorContext->getLayout();
     // Instantiate blocks and collect all actions data
     /** @var $blocks \Magento\Framework\View\Element\AbstractBlock[] */
     $blocks = [];
     foreach ($scheduledElements as $elementName => $element) {
         list(, $data) = $element;
         $block = $this->generateComponent($structure, $elementName, $data, $layout);
         $blocks[$elementName] = $block;
         $layout->setBlock($elementName, $block);
         $scheduledStructure->unsetElement($elementName);
     }
     return $this;
 }
Beispiel #5
0
 /**
  * Creates block object based on data and add it to the layout
  *
  * @param Layout\Reader\Context $readerContext
  * @param Context $generatorContext
  * @return $this
  */
 public function process(Layout\Reader\Context $readerContext, Layout\Generator\Context $generatorContext)
 {
     $scheduledStructure = $readerContext->getScheduledStructure();
     $layout = $generatorContext->getLayout();
     $structure = $generatorContext->getStructure();
     /** @var $blocks \Magento\Framework\View\Element\AbstractBlock[] */
     $blocks = [];
     $blockActions = [];
     // Instantiate blocks and collect all actions data
     foreach ($scheduledStructure->getElements() as $elementName => $element) {
         list($type, $data) = $element;
         if ($type === self::TYPE) {
             $block = $this->generateBlock($scheduledStructure, $structure, $elementName);
             $blocks[$elementName] = $block;
             $layout->setBlock($elementName, $block);
             if (!empty($data['actions'])) {
                 $blockActions[$elementName] = $data['actions'];
             }
         }
     }
     // Set layout instance to all generated block (trigger _prepareLayout method)
     foreach ($blocks as $elementName => $block) {
         $block->setLayout($layout);
         $this->eventManager->dispatch('core_layout_block_create_after', ['block' => $block]);
         $scheduledStructure->unsetElement($elementName);
     }
     // Run all actions after layout initialization
     foreach ($blockActions as $elementName => $actions) {
         foreach ($actions as $action) {
             list($methodName, $actionArguments, $configPath, $scopeType) = $action;
             if (empty($configPath) || $this->scopeConfig->isSetFlag($configPath, $scopeType, $this->scopeResolver->getScope())) {
                 $this->generateAction($blocks[$elementName], $methodName, $actionArguments);
             }
         }
     }
     return $this;
 }