Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FiltersTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
11 use \Magento\Ui\Component\Filters;
12 
16 class FiltersTest extends \PHPUnit\Framework\TestCase
17 {
19  private $filters;
20 
22  private $uiComponentInterface;
23 
25  private $uiComponentFactory;
26 
28  private $context;
29 
33  protected function setUp()
34  {
35  $objectManager = new ObjectManager($this);
36  $this->uiComponentInterface = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponentInterface::class)
37  ->disableOriginalConstructor()
38  ->getMock();
39  $this->uiComponentFactory = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponentFactory::class)
40  ->disableOriginalConstructor()
41  ->getMock();
42  $this->context = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\ContextInterface::class)
43  ->disableOriginalConstructor()
44  ->getMock();
45  $this->filters = $objectManager->getObject(
46  Filters::class,
47  [
48  'columnFilters' => ['select' => $this->uiComponentInterface],
49  'uiComponentFactory' => $this->uiComponentFactory,
50  'context' => $this->context,
51  ]
52  );
53  }
54 
55  public function testUpdate()
56  {
57  $componentName = 'component_name';
58  $componentConfig = [0, 1, 2];
59  $columnInterface = $this->getMockBuilder(\Magento\Ui\Component\Listing\Columns\ColumnInterface::class)
60  ->disableOriginalConstructor()
61  ->setMethods(['getData', 'getName', 'getConfiguration'])
62  ->getMockForAbstractClass();
63  $columnInterface->expects($this->atLeastOnce())->method('getData')->with('config/filter')->willReturn('text');
64  $columnInterface->expects($this->atLeastOnce())->method('getName')->willReturn($componentName);
65  $columnInterface->expects($this->once())->method('getConfiguration')->willReturn($componentConfig);
66  $filterComponent = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponentInterface::class)
67  ->disableOriginalConstructor()
68  ->setMethods(['setData', 'prepare'])
69  ->getMockForAbstractClass();
70  $filterComponent->expects($this->once())->method('setData')->with('config', $componentConfig)
71  ->willReturnSelf();
72  $filterComponent->expects($this->once())->method('prepare')->willReturnSelf();
73  $this->uiComponentFactory->expects($this->once())->method('create')
74  ->with($componentName, 'filterInput', ['context' => $this->context])
75  ->willReturn($filterComponent);
76 
77  $this->filters->update($columnInterface);
79  $this->filters->update($columnInterface);
80  }
81 }
$objectManager
Definition: bootstrap.php:17