Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FulltextFilterTest.php
Go to the documentation of this file.
1 <?php
11 
12 use Magento\Framework\Data\Collection\AbstractDb as CollectionAbstractDb;
15 use Psr\Log\LoggerInterface;
22 use Magento\Framework\Model\ResourceModel\Db\AbstractDb as ResourceModelAbstractDb;
23 use Magento\Framework\Mview\View\Collection as MviewCollection;
24 
29 class FulltextFilterTest extends \PHPUnit\Framework\TestCase
30 {
34  protected $fulltextFilter;
35 
39  protected $entityFactoryMock;
40 
44  protected $loggerMock;
45 
49  protected $fetchStrategyMock;
50 
54  private $connectionMock;
55 
59  protected $selectMock;
60 
65 
70 
71  protected function setUp()
72  {
73  $this->entityFactoryMock = $this->createMock(EntityFactory::class);
74  $this->loggerMock = $this->createMock(LoggerInterface::class);
75  $this->fetchStrategyMock = $this->createMock(FetchStrategyInterface::class);
76  $this->resourceModelAbstractDb = $this->createMock(FetchStrategyInterface::class);
77  $this->connectionMock = $this->createPartialMock(Mysql::class, ['select', 'getIndexList']);
78  $this->selectMock = $this->createPartialMock(Select::class, ['getPart', 'where']);
79 
80  $this->resourceModelAbstractDb = $this->getMockBuilder(ResourceModelAbstractDb::class)
81  ->disableOriginalConstructor()
82  ->getMockForAbstractClass();
83 
84  $this->collectionAbstractDbMock = $this->getMockBuilder(CollectionAbstractDb::class)
85  ->setMethods(['getConnection', 'getSelect', 'getMainTable'])
86  ->disableOriginalConstructor()
87  ->getMockForAbstractClass();
88 
89  $this->fulltextFilter = new FulltextFilter();
90  }
91 
92  public function testApply()
93  {
94  $filter = new Filter();
95  $filter->setValue('test');
96 
97  $this->collectionAbstractDbMock->expects($this->any())
98  ->method('getMainTable')
99  ->willReturn('testTable');
100 
101  $this->collectionAbstractDbMock->expects($this->once())
102  ->method('getConnection')
103  ->willReturn($this->connectionMock);
104 
105  $this->connectionMock->expects($this->any())
106  ->method('select')
107  ->willReturn($this->selectMock);
108  $this->connectionMock->expects($this->once())
109  ->method('getIndexList')
110  ->willReturn([['INDEX_TYPE' => 'FULLTEXT', 'COLUMNS_LIST' => ['col1', 'col2']]]);
111 
112  $this->selectMock->expects($this->once())
113  ->method('getPart')
114  ->willReturn([]);
115  $this->selectMock->expects($this->once())
116  ->method('where')
117  ->willReturn(null);
118 
119  $this->collectionAbstractDbMock->expects($this->exactly(2))
120  ->method('getSelect')
121  ->willReturn($this->selectMock);
122 
123  $this->fulltextFilter->apply($this->collectionAbstractDbMock, $filter);
124  }
125 
129  public function testApplyWrongCollectionType()
130  {
132  $mviewCollection = $this->getMockBuilder(MviewCollection::class)
133  ->setMethods([])
134  ->disableOriginalConstructor()
135  ->getMock();
136 
137  $this->fulltextFilter->apply($mviewCollection, new Filter());
138  }
139 }