Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SearchDataTest.php
Go to the documentation of this file.
1 <?php
8 
9 use PHPUnit_Framework_MockObject_MockObject as MockObject;
10 
11 class SearchDataTest extends \PHPUnit\Framework\TestCase
12 {
14  private $context;
15 
19  private $queryFactory;
20 
24  private $searchQuery;
25 
29  private $dataProvider;
30 
34  private $block;
35 
36  protected function setUp()
37  {
38  $this->dataProvider = $this->getMockBuilder(\Magento\AdvancedSearch\Model\SuggestedQueriesInterface::class)
39  ->disableOriginalConstructor()
40  ->setMethods(['getItems', 'isResultsCountEnabled'])
41  ->getMockForAbstractClass();
42 
43  $this->searchQuery = $this->getMockBuilder(\Magento\Search\Model\QueryInterface::class)
44  ->disableOriginalConstructor()
45  ->setMethods(['getQueryText'])
46  ->getMockForAbstractClass();
47  $this->queryFactory = $this->getMockBuilder(\Magento\Search\Model\QueryFactoryInterface::class)
48  ->disableOriginalConstructor()
49  ->setMethods(['get'])
50  ->getMockForAbstractClass();
51  $this->queryFactory->expects($this->once())
52  ->method('get')
53  ->will($this->returnValue($this->searchQuery));
54  $this->context = $this->getMockBuilder(\Magento\Framework\View\Element\Template\Context::class)
55  ->disableOriginalConstructor()
56  ->getMock();
57  $this->block = $this->getMockBuilder(\Magento\AdvancedSearch\Block\SearchData::class)->setConstructorArgs(
58  [
59  $this->context,
60  $this->dataProvider,
61  $this->queryFactory,
62  'Test Title',
63  [],
64  ]
65  )
66  ->setMethods(['getUrl'])
67  ->getMockForAbstractClass();
68  }
69 
70  public function testGetSuggestions()
71  {
72  $value = [1, 2, 3, 100500];
73 
74  $this->dataProvider->expects($this->once())
75  ->method('getItems')
76  ->with($this->searchQuery)
77  ->will($this->returnValue($value));
78  $actualValue = $this->block->getItems();
79  $this->assertEquals($value, $actualValue);
80  }
81 
82  public function testGetLink()
83  {
84  $searchQuery = 'Some test search query';
85  $expectedResult = '?q=Some+test+search+query';
86  $actualResult = $this->block->getLink($searchQuery);
87  $this->assertEquals($expectedResult, $actualResult);
88  }
89 
90  public function testIsShowResultsCount()
91  {
92  $value = 'qwertyasdfzxcv';
93  $this->dataProvider->expects($this->once())
94  ->method('isResultsCountEnabled')
95  ->will($this->returnValue($value));
96  $this->assertEquals($value, $this->block->isShowResultsCount());
97  }
98 }
$value
Definition: gender.phtml:16