/** * @param array $schedule * @param array $expectedSchedule * @return void * @dataProvider processDataProvider */ public function testProcess($schedule, $expectedSchedule) { foreach ($schedule['structure'] as $structureElement) { $this->scheduledStructure->setStructureElement($structureElement, []); } $reorderMap = []; foreach ($schedule['sort'] as $elementName => $sort) { list($parentName, $sibling, $isAfter) = $sort; $this->scheduledStructure->setElementToSortList($parentName, $elementName, $sibling, $isAfter); $reorderMap[] = [$parentName, $elementName, $sibling, $isAfter]; } foreach ($schedule['move'] as $elementName => $move) { $this->scheduledStructure->setElementToMove($elementName, $move); list($destination, $sibling, $isAfter) = $move; $reorderMap[] = [$destination, $elementName, $sibling, $isAfter]; } $invocation = $this->structureMock->expects($this->any())->method('reorderChildElement'); call_user_func_array([$invocation, 'withConsecutive'], $reorderMap); foreach ($schedule['remove'] as $remove) { $this->scheduledStructure->setElementToRemoveList($remove); } $this->helperMock->expects($this->atLeastOnce())->method('scheduleElement')->with($this->scheduledStructure, $this->structureMock, $this->anything())->willReturnCallback(function ($scheduledStructure, $structure, $elementName) use($schedule) { /** * @var $scheduledStructure ScheduledStructure * @var $structure DataStructure */ $this->assertContains($elementName, $schedule['structure']); $scheduledStructure->unsetStructureElement($elementName); $scheduledStructure->setElement($elementName, []); $structure->createStructuralElement($elementName, 'block', 'someClass'); }); $this->model->process($this->readerContextMock, $this->generatorContextMock); $this->assertEquals($expectedSchedule, $this->scheduledStructure->getElements()); }
/** * Create structure of elements from the loaded XML configuration * * @return void */ public function generateElements() { \Magento\Framework\Profiler::start(__CLASS__ . '::' . __METHOD__); $cacheId = 'structure_' . $this->getUpdate()->getCacheId(); $result = $this->cache->load($cacheId); if ($result) { $this->readerContext = unserialize($result); } else { \Magento\Framework\Profiler::start('build_structure'); $this->readerPool->interpret($this->getReaderContext(), $this->getNode()); \Magento\Framework\Profiler::stop('build_structure'); $this->cache->save(serialize($this->getReaderContext()), $cacheId, $this->getUpdate()->getHandles()); } $generatorContext = $this->generatorContextFactory->create(['structure' => $this->structure, 'layout' => $this]); \Magento\Framework\Profiler::start('generate_elements'); $this->generatorPool->process($this->getReaderContext(), $generatorContext); \Magento\Framework\Profiler::stop('generate_elements'); $this->addToOutputRootContainers(); \Magento\Framework\Profiler::stop(__CLASS__ . '::' . __METHOD__); }