Skip to content

Commit e454edf

Browse files
MAGETWO-82904: MAGETWO-6802: Magento\Search\Helper\getSuggestUrl() not used in search template. #11722
2 parents dd5b5e3 + 02f5b21 commit e454edf

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

app/code/Magento/Search/Helper/Data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function getSuggestUrl()
124124
{
125125
return $this->_getUrl(
126126
'search/ajax/suggest',
127-
['_secure' => $this->storeManager->getStore()->isCurrentlySecure()]
127+
['_secure' => $this->_getRequest()->isSecure()]
128128
);
129129
}
130130

app/code/Magento/Search/Test/Unit/Helper/DataTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Search\Test\Unit\Helper;
78

89
/**
@@ -43,6 +44,11 @@ class DataTest extends \PHPUnit\Framework\TestCase
4344
*/
4445
protected $storeManagerMock;
4546

47+
/**
48+
* @var \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject
49+
*/
50+
private $urlBuilderMock;
51+
4652
protected function setUp()
4753
{
4854
$this->stringMock = $this->createMock(\Magento\Framework\Stdlib\StringUtils::class);
@@ -53,9 +59,14 @@ protected function setUp()
5359
->disableOriginalConstructor()
5460
->setMethods([])
5561
->getMock();
62+
$this->urlBuilderMock = $this->getMockBuilder(\Magento\Framework\UrlInterface::class)
63+
->setMethods(['getUrl'])
64+
->disableOriginalConstructor()
65+
->getMockForAbstractClass();
5666
$this->contextMock = $this->createMock(\Magento\Framework\App\Helper\Context::class);
5767
$this->contextMock->expects($this->any())->method('getScopeConfig')->willReturn($this->scopeConfigMock);
5868
$this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->requestMock);
69+
$this->contextMock->expects($this->any())->method('getUrlBuilder')->willReturn($this->urlBuilderMock);
5970

6071
$this->model = new \Magento\Search\Helper\Data(
6172
$this->contextMock,
@@ -126,4 +137,39 @@ public function queryTextDataProvider()
126137
['testtest', 7, 'testtes'],
127138
];
128139
}
140+
141+
/**
142+
* Test getSuggestUrl() take into consideration type of request(secure, non-secure).
143+
*
144+
* @dataProvider getSuggestUrlDataProvider
145+
* @param bool $isSecure
146+
* @return void
147+
*/
148+
public function testGetSuggestUrl(bool $isSecure)
149+
{
150+
$this->requestMock->expects(self::once())
151+
->method('isSecure')
152+
->willReturn($isSecure);
153+
$this->urlBuilderMock->expects(self::once())
154+
->method('getUrl')
155+
->with(self::identicalTo('search/ajax/suggest'), self::identicalTo(['_secure' => $isSecure]));
156+
$this->model->getSuggestUrl();
157+
}
158+
159+
/**
160+
* Provide test data for testGetSuggestUrl() test.
161+
*
162+
* @return array
163+
*/
164+
public function getSuggestUrlDataProvider()
165+
{
166+
return [
167+
'non-secure' => [
168+
'isSecure' => false,
169+
],
170+
'secure' => [
171+
'secure' => true,
172+
],
173+
];
174+
}
129175
}

app/code/Magento/Search/view/frontend/templates/form.mini.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<?php
1010
/** @var $block \Magento\Framework\View\Element\Template */
1111
/** @var $helper \Magento\Search\Helper\Data */
12-
$helper = $this->helper('Magento\Search\Helper\Data');
12+
$helper = $this->helper(\Magento\Search\Helper\Data::class);
1313
?>
1414
<div class="block block-search">
1515
<div class="block block-title"><strong><?= /* @escapeNotVerified */ __('Search') ?></strong></div>
@@ -23,7 +23,7 @@ $helper = $this->helper('Magento\Search\Helper\Data');
2323
<input id="search"
2424
data-mage-init='{"quickSearch":{
2525
"formSelector":"#search_mini_form",
26-
"url":"<?= /* @escapeNotVerified */ $block->getUrl('search/ajax/suggest', ['_secure' => $block->getRequest()->isSecure()]) ?>",
26+
"url":"<?= /* @escapeNotVerified */ $helper->getSuggestUrl()?>",
2727
"destinationSelector":"#search_autocomplete"}
2828
}'
2929
type="text"

0 commit comments

Comments
 (0)