|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Ui\Test\Unit\Component; |
| 9 | + |
| 10 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
| 11 | +use \Magento\Ui\Component\Filters; |
| 12 | + |
| 13 | +/** |
| 14 | + * Unit tests for \Magento\Ui\Component\Filters class |
| 15 | + */ |
| 16 | +class FiltersTest extends \PHPUnit\Framework\TestCase |
| 17 | +{ |
| 18 | + /** @var Filters|\PHPUnit_Framework_MockObject_MockObject */ |
| 19 | + private $filters; |
| 20 | + |
| 21 | + /** @var \Magento\Framework\View\Element\UiComponentInterface|\PHPUnit_Framework_MockObject_MockObject */ |
| 22 | + private $uiComponentInterface; |
| 23 | + |
| 24 | + /** @var \Magento\Framework\View\Element\UiComponentFactory|\PHPUnit_Framework_MockObject_MockObject */ |
| 25 | + private $uiComponentFactory; |
| 26 | + |
| 27 | + /** @var \Magento\Framework\View\Element\UiComponent\ContextInterface|\PHPUnit_Framework_MockObject_MockObject */ |
| 28 | + private $context; |
| 29 | + |
| 30 | + /** |
| 31 | + * @inheritdoc |
| 32 | + */ |
| 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); |
| 78 | + /** Verify that filter is already set and it wouldn't be set again */ |
| 79 | + $this->filters->update($columnInterface); |
| 80 | + } |
| 81 | +} |
0 commit comments