/**
  * Create component object
  *
  * @param string $identifier
  * @param string $name
  * @param array $arguments
  * @return UiComponentInterface
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function create($identifier, $name = null, array $arguments = [])
 {
     if ($name === null) {
         $bundleComponents = $this->componentManager->prepareData($identifier)->getData($identifier);
         if (empty($bundleComponents)) {
             throw new LocalizedException(new \Magento\Framework\Phrase('You use an empty set.'));
         }
         list($className, $componentArguments) = $this->argumentsResolver($identifier, $bundleComponents[$identifier]);
         $componentArguments = array_replace_recursive($componentArguments, $arguments);
         if (!isset($componentArguments['context'])) {
             $componentArguments['context'] = $this->contextFactory->create(['namespace' => $identifier]);
         }
         $componentContext = $componentArguments['context'];
         $components = [];
         foreach ($bundleComponents[$identifier]['children'] as $childrenIdentifier => $childrenData) {
             $children = $this->createChildComponent($childrenData, $componentContext, $childrenIdentifier);
             $components[$childrenIdentifier] = $children;
         }
         $components = array_filter($components);
         $componentArguments['components'] = $components;
         /** @var \Magento\Framework\View\Element\UiComponentInterface $component */
         $component = $this->objectManager->create($className, array_replace_recursive($componentArguments, $arguments));
         return $component;
     } else {
         $defaultData = $this->componentManager->createRawComponentData($name);
         list($className, $componentArguments) = $this->argumentsResolver($identifier, $defaultData);
         /** @var \Magento\Framework\View\Element\UiComponentInterface $component */
         $component = $this->objectManager->create($className, array_replace_recursive($componentArguments, $arguments));
         return $component;
     }
 }
 public function testProcess()
 {
     $this->prepareScheduledStructure();
     $this->readerContextMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Reader\\Context')->disableOriginalConstructor()->getMock();
     $this->readerContextMock->expects($this->any())->method('getScheduledStructure')->willReturn($this->scheduledStructureMock);
     $generatorContextMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Generator\\Context')->disableOriginalConstructor()->getMock();
     $structureMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Data\\Structure')->disableOriginalConstructor()->getMock();
     $structureMock->expects($this->once())->method('addToParentGroup')->with(UiComponent::TYPE, 'new_group')->willReturnSelf();
     $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\LayoutInterface')->getMockForAbstractClass();
     $generatorContextMock->expects($this->any())->method('getStructure')->willReturn($structureMock);
     $generatorContextMock->expects($this->any())->method('getLayout')->willReturn($layoutMock);
     $this->uiComponentFactoryMock->expects($this->any())->method('setLayout')->with($layoutMock)->willReturnSelf();
     $componentMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponentInterface', [], '', false, true, true, []);
     $contextMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponent\\ContextInterface', [], '', false);
     $blockMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\BlockInterface', [], '', false);
     $this->contextFactoryMock->expects($this->once())->method('create')->with(['namespace' => 'uiComponent', 'pageLayout' => $layoutMock])->willReturn($contextMock);
     $this->uiComponentFactoryMock->expects($this->any())->method('create')->with('uiComponent', null, ['context' => $contextMock])->willReturn($componentMock);
     $this->blockFactoryMock->expects($this->once())->method('createBlock')->with(UiComponent::CONTAINER, ['component' => $componentMock])->willReturn($blockMock);
     $this->argumentInterpreterMock->expects($this->any())->method('evaluate')->will($this->returnValueMap([[['key_1' => 'value_1'], 'value_1'], [['key_2' => 'value_2'], 'value_2']]));
     $layoutMock->expects($this->any())->method('setBlock')->with(UiComponent::TYPE, $blockMock)->willReturnSelf();
     $this->uiComponent->process($this->readerContextMock, $generatorContextMock);
 }
Exemple #3
0
 /**
  * Create component object
  *
  * @param Structure $structure
  * @param string $elementName
  * @param string $data
  * @param LayoutInterface $layout
  * @return ContainerInterface
  */
 protected function generateComponent(Structure $structure, $elementName, $data, LayoutInterface $layout)
 {
     $attributes = $data['attributes'];
     if (!empty($attributes['group'])) {
         $structure->addToParentGroup($elementName, $attributes['group']);
     }
     $context = $this->contextFactory->create(['namespace' => $elementName, 'pageLayout' => $layout]);
     $component = $this->uiComponentFactory->create($elementName, null, ['context' => $context]);
     $this->prepareComponent($component);
     /** @var ContainerInterface $blockContainer */
     $blockContainer = $this->blockFactory->createBlock(static::CONTAINER, ['component' => $component]);
     return $blockContainer;
 }