1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\AdvancedSearch\Test\Unit\Block;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
class SearchDataTest extends \PHPUnit\Framework\TestCase
{
/** @var \Magento\Framework\View\Element\Template\Context|MockObject */
private $context;
/**
* @var \Magento\Search\Model\QueryFactoryInterface|MockObject
*/
private $queryFactory;
/**
* @var \Magento\Search\Model\Query|MockObject
*/
private $searchQuery;
/**
* @var \Magento\AdvancedSearch\Model\SuggestedQueriesInterface|MockObject
*/
private $dataProvider;
/**
* @var \Magento\AdvancedSearch\Block\SearchData
*/
private $block;
protected function setUp()
{
$this->dataProvider = $this->getMockBuilder(\Magento\AdvancedSearch\Model\SuggestedQueriesInterface::class)
->disableOriginalConstructor()
->setMethods(['getItems', 'isResultsCountEnabled'])
->getMockForAbstractClass();
$this->searchQuery = $this->getMockBuilder(\Magento\Search\Model\QueryInterface::class)
->disableOriginalConstructor()
->setMethods(['getQueryText'])
->getMockForAbstractClass();
$this->queryFactory = $this->getMockBuilder(\Magento\Search\Model\QueryFactoryInterface::class)
->disableOriginalConstructor()
->setMethods(['get'])
->getMockForAbstractClass();
$this->queryFactory->expects($this->once())
->method('get')
->will($this->returnValue($this->searchQuery));
$this->context = $this->getMockBuilder(\Magento\Framework\View\Element\Template\Context::class)
->disableOriginalConstructor()
->getMock();
$this->block = $this->getMockBuilder(\Magento\AdvancedSearch\Block\SearchData::class)->setConstructorArgs(
[
$this->context,
$this->dataProvider,
$this->queryFactory,
'Test Title',
[],
]
)
->setMethods(['getUrl'])
->getMockForAbstractClass();
}
public function testGetSuggestions()
{
$value = [1, 2, 3, 100500];
$this->dataProvider->expects($this->once())
->method('getItems')
->with($this->searchQuery)
->will($this->returnValue($value));
$actualValue = $this->block->getItems();
$this->assertEquals($value, $actualValue);
}
public function testGetLink()
{
$searchQuery = 'Some test search query';
$expectedResult = '?q=Some+test+search+query';
$actualResult = $this->block->getLink($searchQuery);
$this->assertEquals($expectedResult, $actualResult);
}
public function testIsShowResultsCount()
{
$value = 'qwertyasdfzxcv';
$this->dataProvider->expects($this->once())
->method('isResultsCountEnabled')
->will($this->returnValue($value));
$this->assertEquals($value, $this->block->isShowResultsCount());
}
}