Beispiel #1
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();
 }
Beispiel #2
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();
 }
 /**
  * Returns array of Select options
  *
  * @param Select $filter
  * @return array
  */
 protected function getFilterOptions(Select $filter)
 {
     $options = [];
     foreach ($filter->getData('config/options') as $option) {
         if (!is_array($option['value'])) {
             $options[$option['value']] = $option['label'];
         } else {
             $this->getComplexLabel($option['value'], $option['label'], $options);
         }
     }
     return $options;
 }