Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PopularSearchTermsTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
14 
18 class PopularSearchTermsTest extends \PHPUnit\Framework\TestCase
19 {
25  private $popularSearchTerms;
26 
30  private $scopeConfigMock;
31 
35  private $queryCollectionMock;
36 
42  protected function setUp()
43  {
44  $this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class);
45  $this->queryCollectionMock = $this->createMock(Collection::class);
46  $this->popularSearchTerms = new PopularSearchTerms($this->scopeConfigMock, $this->queryCollectionMock);
47  }
48 
60  public function testIsCacheable($term, $terms, $expected)
61  {
62  $storeId = 7;
63  $pageSize = 25;
64 
65  $this->scopeConfigMock->expects($this->once())->method('getValue')
66  ->with(
69  $storeId
70  )->willReturn($pageSize);
71  $this->queryCollectionMock->expects($this->once())->method('setPopularQueryFilter')->with($storeId)
72  ->willReturnSelf();
73  $this->queryCollectionMock->expects($this->once())->method('setPageSize')->with($pageSize)
74  ->willReturnSelf();
75  $this->queryCollectionMock->expects($this->once())->method('load')->willReturnSelf();
76  $this->queryCollectionMock->expects($this->once())->method('getColumnValues')->with('query_text')
77  ->willReturn($terms);
78 
79  $actual = $this->popularSearchTerms->isCacheable($term, $storeId);
80  self::assertEquals($expected, $actual);
81  }
82 
86  public function isCacheableDataProvider()
87  {
88  return [
89  ['test01', [], false],
90  ['test02', ['test01', 'test02'], true],
91  ['test03', ['test01', 'test02'], false],
92  ['test04', ['test04'], true],
93  ];
94  }
95 }