|
| 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\CatalogSearch\Test\Unit\Ui\DataProvider\Product; |
| 9 | + |
| 10 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; |
| 11 | +use Magento\CatalogSearch\Model\ResourceModel\Search\Collection as SearchCollection; |
| 12 | +use Magento\Framework\Data\Collection; |
| 13 | +use Magento\CatalogSearch\Ui\DataProvider\Product\AddFulltextFilterToCollection; |
| 14 | + |
| 15 | +class AddFulltextFilterToCollectionTest extends \PHPUnit\Framework\TestCase |
| 16 | +{ |
| 17 | + /** |
| 18 | + * @var SearchCollection|\PHPUnit_Framework_MockObject_MockObject |
| 19 | + */ |
| 20 | + private $searchCollection; |
| 21 | + |
| 22 | + /** |
| 23 | + * @var Collection|\PHPUnit_Framework_MockObject_MockObject |
| 24 | + */ |
| 25 | + private $collection; |
| 26 | + |
| 27 | + /** |
| 28 | + * @var ObjectManagerHelper |
| 29 | + */ |
| 30 | + private $objectManager; |
| 31 | + |
| 32 | + /** |
| 33 | + * @var AddFulltextFilterToCollection |
| 34 | + */ |
| 35 | + private $model; |
| 36 | + |
| 37 | + protected function setUp() |
| 38 | + { |
| 39 | + $this->objectManager = new ObjectManagerHelper($this); |
| 40 | + |
| 41 | + $this->searchCollection = $this->getMockBuilder(SearchCollection::class) |
| 42 | + ->setMethods(['addBackendSearchFilter', 'load', 'getAllIds']) |
| 43 | + ->disableOriginalConstructor() |
| 44 | + ->getMock(); |
| 45 | + $this->searchCollection->expects($this->any()) |
| 46 | + ->method('load') |
| 47 | + ->willReturnSelf(); |
| 48 | + $this->collection = $this->getMockBuilder(Collection::class) |
| 49 | + ->setMethods(['addIdFilter']) |
| 50 | + ->disableOriginalConstructor() |
| 51 | + ->getMock(); |
| 52 | + |
| 53 | + $this->model = $this->objectManager->getObject( |
| 54 | + AddFulltextFilterToCollection::class, |
| 55 | + [ |
| 56 | + 'searchCollection' => $this->searchCollection |
| 57 | + ] |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + public function testAddFilter() |
| 62 | + { |
| 63 | + $this->searchCollection->expects($this->once()) |
| 64 | + ->method('addBackendSearchFilter') |
| 65 | + ->with('test'); |
| 66 | + $this->searchCollection->expects($this->once()) |
| 67 | + ->method('getAllIds') |
| 68 | + ->willReturn([]); |
| 69 | + $this->collection->expects($this->once()) |
| 70 | + ->method('addIdFilter') |
| 71 | + ->with(-1); |
| 72 | + $this->model->addFilter($this->collection, 'test', ['fulltext' => 'test']); |
| 73 | + } |
| 74 | +} |
0 commit comments