Пример #1
0
 public function testCreate()
 {
     $filterName = 'created_at';
     $config = ['data' => ['config' => ['dataScope' => $filterName, 'label' => __('Label'), 'options' => [['value' => 'Value', 'label' => 'Label']], 'caption' => __('Select...')]], 'context' => $this->context];
     $attributeData = ['attribute_code' => $filterName, 'frontend_input' => 'frontend-input', 'frontend_label' => 'Label', 'backend_type' => 'backend-type', 'options' => [['label' => 'Label', 'value' => 'Value']], 'is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => true, 'is_searchable_in_grid' => true];
     $this->componentFactory->expects($this->once())->method('create')->with($filterName, 'filterInput', $config)->willReturn($this->filter);
     $this->assertSame($this->filter, $this->filterFactory->create($attributeData, $this->context));
 }
Пример #2
0
 /**
  * Run test for prepare method
  *
  * @param array $data
  * @return void
  *
  * @dataProvider prepareDataProvider
  */
 public function testPrepare(array $data)
 {
     $this->uiComponentFactoryMock->expects($this->exactly($data['config']['size']))->method('create')->with($this->stringContains(self::NAME . '_'), Field::NAME, $this->logicalNot($this->isEmpty()))->willReturn($this->getComponentMock($data['config']['size']));
     $this->multiline->setData($data);
     $this->multiline->prepare();
     $result = $this->multiline->getData();
     $this->assertEquals($data, $result);
 }
 public function testCreate()
 {
     $columnName = 'created_at';
     $config = ['data' => ['js_config' => ['component' => 'Magento_Ui/js/grid/columns/column'], 'config' => ['label' => __('Label'), 'dataType' => 'text', 'align' => 'left', 'visible' => true, 'options' => [['label' => 'Label', 'value' => 'Value']], 'component' => 'Magento_Ui/js/grid/columns/column']], 'context' => $this->context];
     $attributeData = ['attribute_code' => 'billing_attribute_code', 'frontend_input' => 'text', 'frontend_label' => 'Label', 'backend_type' => 'backend-type', 'options' => [['label' => 'Label', 'value' => 'Value']], 'is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => true, 'is_searchable_in_grid' => true, 'entity_type_code' => 'customer', 'validation_rules' => [], 'required' => false];
     $this->inlineEditUpdater->expects($this->once())->method('applyEditing')->with($this->column, 'text', []);
     $this->componentFactory->expects($this->once())->method('create')->with($columnName, 'column', $config)->willReturn($this->column);
     $this->assertSame($this->column, $this->columnFactory->create($attributeData, $columnName, $this->context));
 }
Пример #4
0
 /**
  * Run test prepare method
  *
  * @param array $data
  * @param array $filterData
  * @param array|null $expectedCondition
  * @dataProvider getPrepareDataProvider
  * @return void
  */
 public function testPrepare($data, $filterData, $expectedCondition)
 {
     $name = $data['name'];
     /** @var UiComponentInterface $uiComponent */
     $uiComponent = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponentInterface', [], '', false);
     $uiComponent->expects($this->any())->method('getContext')->willReturn($this->contextMock);
     $this->contextMock->expects($this->any())->method('getNamespace')->willReturn(Select::NAME);
     $this->contextMock->expects($this->any())->method('addComponentDefinition')->with(Select::NAME, ['extends' => Select::NAME]);
     $this->contextMock->expects($this->any())->method('getFiltersParams')->willReturn($filterData);
     /** @var DataProviderInterface $dataProvider */
     $dataProvider = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponent\\DataProvider\\DataProviderInterface', ['addFilter'], '', false);
     $this->contextMock->expects($this->any())->method('getDataProvider')->willReturn($dataProvider);
     if ($expectedCondition !== null) {
         $filterMock = $this->getMock('Magento\\Framework\\Api\\Filter');
         $this->filterBuilderMock->expects($this->any())->method('setConditionType')->with($expectedCondition)->willReturnSelf();
         $this->filterBuilderMock->expects($this->any())->method('setField')->with($name)->willReturnSelf();
         $this->filterBuilderMock->expects($this->any())->method('setValue')->willReturnSelf();
         $this->filterBuilderMock->expects($this->any())->method('create')->willReturn($filterMock);
         $dataProvider->expects($this->any())->method('addFilter')->with($filterMock);
     }
     /** @var \Magento\Framework\Data\OptionSourceInterface $selectOptions */
     $selectOptions = $this->getMockForAbstractClass('Magento\\Framework\\Data\\OptionSourceInterface', [], '', false);
     $this->uiComponentFactory->expects($this->any())->method('create')->with($name, Select::COMPONENT, ['context' => $this->contextMock, 'options' => $selectOptions])->willReturn($uiComponent);
     $date = new Select($this->contextMock, $this->uiComponentFactory, $this->filterBuilderMock, $this->filterModifierMock, $selectOptions, [], $data);
     $date->prepare();
 }
Пример #5
0
 /**
  * Run test prepare method
  *
  * @param string $name
  * @param array $filterData
  * @param array|null $expectedCondition
  * @dataProvider getPrepareDataProvider
  * @return void
  */
 public function testPrepare($name, $filterData, $expectedCondition)
 {
     /** @var UiComponentInterface $uiComponent */
     $uiComponent = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponentInterface', [], '', false);
     $uiComponent->expects($this->any())->method('getContext')->willReturn($this->contextMock);
     $this->contextMock->expects($this->any())->method('getNamespace')->willReturn(Input::NAME);
     $this->contextMock->expects($this->any())->method('addComponentDefinition')->with(Input::NAME, ['extends' => Input::NAME]);
     $this->contextMock->expects($this->any())->method('getRequestParam')->with(UiContext::FILTER_VAR)->willReturn($filterData);
     $dataProvider = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponent\\DataProvider\\DataProviderInterface', [], '', false);
     $this->contextMock->expects($this->any())->method('getDataProvider')->willReturn($dataProvider);
     if ($expectedCondition !== null) {
         $dataProvider->expects($this->any())->method('addFilter')->with($expectedCondition, $name);
     }
     $this->uiComponentFactory->expects($this->any())->method('create')->with($name, Input::COMPONENT, ['context' => $this->contextMock])->willReturn($uiComponent);
     $date = new Input($this->contextMock, $this->uiComponentFactory, $this->filterBuilderMock, $this->filterModifierMock, [], ['name' => $name]);
     $date->prepare();
 }
Пример #6
0
 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();
     $blockMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\AbstractBlock')->disableOriginalConstructor()->getMock();
     $this->uiComponentFactoryMock->expects($this->any())->method('createUiComponent')->with('component_name', UiComponent::TYPE, ['attribute_1' => 'value_1', 'attribute_2' => 'value_2'])->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);
 }
Пример #7
0
 /**
  * Run test prepare method
  *
  * @param string $name
  * @param array $filterData
  * @param array|null $expectedCondition
  * @dataProvider getPrepareDataProvider
  * @return void
  */
 public function testPrepare($name, $filterData, $expectedCondition)
 {
     /** @var UiComponentInterface $uiComponent */
     $uiComponent = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponentInterface', [], '', false);
     $uiComponent->expects($this->any())->method('getContext')->willReturn($this->contextMock);
     $this->contextMock->expects($this->any())->method('getNamespace')->willReturn(Select::NAME);
     $this->contextMock->expects($this->any())->method('addComponentDefinition')->with(Select::NAME, ['extends' => Select::NAME]);
     $this->contextMock->expects($this->any())->method('getRequestParam')->with(AbstractFilter::FILTER_VAR)->willReturn($filterData);
     if ($expectedCondition !== null) {
         /** @var DataProviderInterface $dataProvider */
         $dataProvider = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponent\\DataProvider\\DataProviderInterface', [], '', false);
         $dataProvider->expects($this->any())->method('addFilter')->with($expectedCondition, $name);
         $this->contextMock->expects($this->any())->method('getDataProvider')->willReturn($dataProvider);
     }
     /** @var \Magento\Framework\Data\OptionSourceInterface $selectOptions */
     $selectOptions = $this->getMockForAbstractClass('Magento\\Framework\\Data\\OptionSourceInterface', [], '', false);
     $this->uiComponentFactory->expects($this->any())->method('create')->with($name, Select::COMPONENT, ['context' => $this->contextMock, 'options' => $selectOptions])->willReturn($uiComponent);
     $date = new Select($this->contextMock, $this->uiComponentFactory, $selectOptions, [], ['name' => $name]);
     $date->prepare();
 }
Пример #8
0
 /**
  * Run test prepare method
  *
  * @param string $name
  * @param array $filterData
  * @param array|null $expectedCondition
  * @dataProvider getPrepareDataProvider
  * @return void
  */
 public function testPrepare($name, $filterData, $expectedCondition)
 {
     /** @var FormDate $uiComponent */
     $uiComponent = $this->getMock('Magento\\Ui\\Component\\Form\\Element\\DataType\\Date', [], [], '', false);
     $uiComponent->expects($this->any())->method('getContext')->willReturn($this->contextMock);
     $this->contextMock->expects($this->any())->method('getNamespace')->willReturn(DateRange::NAME);
     $this->contextMock->expects($this->any())->method('addComponentDefinition')->with(DateRange::NAME, ['extends' => DateRange::NAME]);
     $this->contextMock->expects($this->any())->method('getRequestParam')->with(AbstractFilter::FILTER_VAR)->willReturn($filterData);
     if ($expectedCondition !== null) {
         /** @var DataProviderInterface $dataProvider */
         $dataProvider = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponent\\DataProvider\\DataProviderInterface', [], '', false);
         $dataProvider->expects($this->any())->method('addFilter')->with($name, $expectedCondition);
         $this->contextMock->expects($this->any())->method('getDataProvider')->willReturn($dataProvider);
         $uiComponent->expects($this->any())->method('getLocale')->willReturn($expectedCondition['locale']);
         $uiComponent->expects($this->any())->method('convertDate')->willReturnArgument(0);
     }
     $this->uiComponentFactory->expects($this->any())->method('create')->with($name, DateRange::COMPONENT, ['context' => $this->contextMock])->willReturn($uiComponent);
     $dateRange = new DateRange($this->contextMock, $this->uiComponentFactory, [], ['name' => $name]);
     $dateRange->prepare();
 }
Пример #9
0
 /**
  * Run test prepare method (Exception)
  *
  * @return void
  *
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @expectedExceptionMessage The configuration parameter "formElement" is a required for "test-name" field.
  */
 public function testPrepareException()
 {
     $this->uiComponentFactoryMock->expects($this->never())->method('create');
     $this->field->setData(['name' => self::NAME]);
     $this->field->prepare();
 }