Exemple #1
0
 /**
  * Run test prepare method
  *
  * @return void
  */
 public function testPrepare()
 {
     /**
      * @var \Magento\Framework\View\Element\UiComponent\ConfigInterface
      * |\PHPUnit_Framework_MockObject_MockObject $configurationMock
      */
     $configurationMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponent\\ConfigInterface', [], '', false);
     /**
      * @var \Magento\Framework\View\Element\UiComponent\ConfigStorageInterface
      * |\PHPUnit_Framework_MockObject_MockObject $configStorageMock
      */
     $configStorageMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponent\\ConfigStorageInterface', ['addComponentsData', 'getDataCollection'], '', false);
     $dataCollectionMock = $this->getMockForAbstractClass('Magento\\Framework\\Api\\CriteriaInterface', ['addOrder'], '', false);
     $this->renderContextMock->expects($this->at(0))->method('getNamespace')->will($this->returnValue('namespace'));
     $this->renderContextMock->expects($this->at(1))->method('getNamespace')->will($this->returnValue('namespace'));
     $this->configFactoryMock->expects($this->any())->method('create')->will($this->returnValue($configurationMock));
     $this->renderContextMock->expects($this->any())->method('getStorage')->will($this->returnValue($configStorageMock));
     $configStorageMock->expects($this->once())->method('addComponentsData')->with($configurationMock);
     $configurationMock->expects($this->at(0))->method('getData')->with('field')->will($this->returnValue('field'));
     $configurationMock->expects($this->at(1))->method('getData')->with('direction')->will($this->returnValue('direction'));
     $this->renderContextMock->expects($this->any())->method('getStorage')->will($this->returnValue($configStorageMock));
     $configStorageMock->expects($this->once())->method('getDataCollection')->will($this->returnValue($dataCollectionMock));
     $dataCollectionMock->expects($this->once())->method('addOrder')->with('field', 'FIELD');
     $this->renderContextMock->expects($this->any())->method('getRequestParam')->will($this->returnValue('field'));
     $this->renderContextMock->expects($this->any())->method('getRequestParam')->will($this->returnValue('direction'));
     $this->assertNull($this->view->prepare());
 }
 /**
  * @dataProvider addComponentDefinitionDataProvider
  * @param array $components
  * @param array $expected
  */
 public function testAddComponentDefinition($components, $expected)
 {
     foreach ($components as $component) {
         $this->context->addComponentDefinition($component['name'], $component['config']);
     }
     $this->assertEquals($expected, $this->context->getComponentsDefinitions());
 }
 /**
  * Create data provider
  *
  * @param string $elementName
  * @param array $data
  * @return bool|BlockInterface
  * @throws \Exception
  */
 public function create($elementName, array $data = [])
 {
     if ('text' == $elementName) {
         $elementName = 'input';
     }
     $block = $this->context->getLayout()->getBlock($elementName);
     if (!$block) {
         throw new \Exception('Can not find block of element ' . $elementName);
     }
     $newBlock = clone $block;
     $newBlock->addData($data);
     return $newBlock;
 }
Exemple #4
0
 public function testPrepare()
 {
     $paramsSize = 20;
     $paramsPage = 1;
     $nameSpace = 'namespace';
     $configurationMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponent\\ConfigInterface', ['getData'], '', false);
     $this->renderContextMock->expects($this->any())->method('getNamespace')->willReturn($nameSpace);
     $this->configFactoryMock->expects($this->once())->method('create')->willReturn($configurationMock);
     $storageMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponent\\ConfigStorageInterface');
     $dataCollectionMock = $this->getMockForAbstractClass('\\Magento\\Framework\\Data\\CollectionDataSourceInterface', [], '', false, true, true, ['setLimit']);
     $this->renderContextMock->expects($this->any())->method('getStorage')->willReturn($storageMock);
     $storageMock->expects($this->once())->method('getDataCollection')->willReturn($dataCollectionMock);
     $configurationMock->expects($this->at(0))->method('getData')->with('current')->willReturn($paramsPage);
     $configurationMock->expects($this->at(1))->method('getData')->with('pageSize')->willReturn($paramsSize);
     $this->renderContextMock->expects($this->atLeastOnce())->method('getRequestParam')->willReturnMap([['page', $paramsPage, $paramsPage], ['limit', $paramsSize, $paramsSize]]);
     $dataCollectionMock->expects($this->any())->method('setLimit')->with($paramsPage, $paramsSize)->willReturnSelf();
     $this->assertNull($this->view->prepare());
 }
 /**
  * Create data provider
  *
  * @return void
  */
 protected function createDataProviders()
 {
     if ($this->hasData('data_provider_pool')) {
         foreach ($this->getData('data_provider_pool') as $name => $config) {
             $arguments = empty($config['arguments']) ? [] : $config['arguments'];
             $arguments['params'] = $this->renderContext->getRequestParams();
             $dataProvider = $this->dataProviderFactory->create($config['class'], $arguments);
             $this->renderContext->getStorage()->addDataProvider($name, $dataProvider);
         }
     }
 }
 /**
  * Create Ui Component instance
  *
  * @param string $componentName
  * @param string $handleName
  * @param array $arguments
  * @return UiComponentInterface
  */
 public function createUiComponent($componentName, $handleName, array $arguments = [])
 {
     if (!$this->layout) {
         $this->renderContext->setNamespace($handleName);
         $this->layout = $this->layoutFactory->create();
         $this->renderContext->setLayout($this->layout);
         $this->layout->getUpdate()->addHandle('ui_components');
         $this->layout->getUpdate()->addHandle($handleName);
         $this->loadLayout();
         $this->layoutLoaded = true;
     }
     $view = $this->getUiElementView($componentName);
     $view->update($arguments);
     if ($this->layoutLoaded) {
         $this->prepare($view);
     }
     return $view;
 }
 /**
  * Run test getActiveFilters method
  *
  * @return void
  */
 public function _testGetActiveFilters()
 {
     $result = ['field-1' => ['title' => 'title-1', 'current_display_value' => 'value-1'], 'field-2' => ['title' => 'title-2', 'current_display_value' => 'value-2'], 'field-3' => ['title' => 'title-3', 'current_display_value' => 'value-3'], 'field-4' => ['title' => 'title-4', 'current_display_value' => 'value-4']];
     $meta = ['fields' => ['field-1' => ['filter_type' => true, 'title' => 'title-1'], 'field-2' => ['filter_type' => true, 'title' => 'title-2'], 'field-3' => ['filter_type' => true, 'title' => 'title-3'], 'field-4' => ['filter_type' => true, 'title' => 'title-4']]];
     $filters = ['field-1' => 'value-1', 'field-2' => 'value-2', 'field-3' => 'value-3', 'field-4' => 'value-4'];
     /**
      * @var \Magento\Framework\View\Element\UiComponent\ConfigInterface
      * |\PHPUnit_Framework_MockObject_MockObject $configurationMock
      */
     $configMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponent\\ConfigInterface', [], '', false);
     /**
      * @var \Magento\Framework\View\Element\UiComponent\ConfigStorageInterface
      * |\PHPUnit_Framework_MockObject_MockObject $configStorageMock
      */
     $configStorageMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponent\\ConfigStorageInterface', ['addComponentsData', 'getDataCollection', 'getMeta'], '', false);
     $this->filterPool->setConfig($configMock);
     $this->renderContextMock->expects($this->any())->method('getStorage')->will($this->returnValue($configStorageMock));
     $configStorageMock->expects($this->any())->method('getMeta')->will($this->returnValue($meta));
     $this->dataHelperMock->expects($this->once())->method('prepareFilterString')->will($this->returnValue($filters));
     $this->renderContextMock->expects($this->once())->method('getRequestParam')->with(static::FILTER_VAR);
     $this->assertEquals($result, $this->filterPool->getActiveFilters());
 }
 /**
  * Create button container
  *
  * @param string $key
  * @param UiComponentInterface $view
  * @return Container
  */
 protected function createContainer($key, UiComponentInterface $view)
 {
     $container = $this->context->getPageLayout()->createBlock('Magento\\Ui\\Component\\Control\\Container', 'container-' . $view->getName() . '-' . $key, ['data' => ['button_item' => $this->items[$key], 'context' => $view]]);
     return $container;
 }
Exemple #9
0
 /**
  * Generate url by route and parameters
  *
  * @param string $route
  * @param array $params
  * @return string
  */
 public function getUrl($route = '', $params = [])
 {
     return $this->context->getUrl($route, $params);
 }
Exemple #10
0
 public function testGetUrl()
 {
     $this->contextMock->expects($this->once())->method('getUrl')->willReturn('http://example.com');
     $this->assertSame('http://example.com', $this->getModel()->getUrl());
 }