Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/code/Magento/Search/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function getSuggestUrl()
{
return $this->_getUrl(
'search/ajax/suggest',
['_secure' => $this->storeManager->getStore()->isCurrentlySecure()]
['_secure' => $this->_getRequest()->isSecure()]
);
}

Expand Down
46 changes: 46 additions & 0 deletions app/code/Magento/Search/Test/Unit/Helper/DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Search\Test\Unit\Helper;

/**
Expand Down Expand Up @@ -43,6 +44,11 @@ class DataTest extends \PHPUnit\Framework\TestCase
*/
protected $storeManagerMock;

/**
* @var \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $urlBuilderMock;

protected function setUp()
{
$this->stringMock = $this->createMock(\Magento\Framework\Stdlib\StringUtils::class);
Expand All @@ -53,9 +59,14 @@ protected function setUp()
->disableOriginalConstructor()
->setMethods([])
->getMock();
$this->urlBuilderMock = $this->getMockBuilder(\Magento\Framework\UrlInterface::class)
->setMethods(['getUrl'])
->disableOriginalConstructor()
->getMockForAbstractClass();
$this->contextMock = $this->createMock(\Magento\Framework\App\Helper\Context::class);
$this->contextMock->expects($this->any())->method('getScopeConfig')->willReturn($this->scopeConfigMock);
$this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->requestMock);
$this->contextMock->expects($this->any())->method('getUrlBuilder')->willReturn($this->urlBuilderMock);

$this->model = new \Magento\Search\Helper\Data(
$this->contextMock,
Expand Down Expand Up @@ -126,4 +137,39 @@ public function queryTextDataProvider()
['testtest', 7, 'testtes'],
];
}

/**
* Test getSuggestUrl() take into consideration type of request(secure, non-secure).
*
* @dataProvider getSuggestUrlDataProvider
* @param bool $isSecure
* @return void
*/
public function testGetSuggestUrl(bool $isSecure)
{
$this->requestMock->expects(self::once())
->method('isSecure')
->willReturn($isSecure);
$this->urlBuilderMock->expects(self::once())
->method('getUrl')
->with(self::identicalTo('search/ajax/suggest'), self::identicalTo(['_secure' => $isSecure]));
$this->model->getSuggestUrl();
}

/**
* Provide test data for testGetSuggestUrl() test.
*
* @return array
*/
public function getSuggestUrlDataProvider()
{
return [
'non-secure' => [
'isSecure' => false,
],
'secure' => [
'secure' => true,
],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<?php
/** @var $block \Magento\Framework\View\Element\Template */
/** @var $helper \Magento\Search\Helper\Data */
$helper = $this->helper('Magento\Search\Helper\Data');
$helper = $this->helper(\Magento\Search\Helper\Data::class);
?>
<div class="block block-search">
<div class="block block-title"><strong><?= /* @escapeNotVerified */ __('Search') ?></strong></div>
Expand All @@ -23,7 +23,7 @@ $helper = $this->helper('Magento\Search\Helper\Data');
<input id="search"
data-mage-init='{"quickSearch":{
"formSelector":"#search_mini_form",
"url":"<?= /* @escapeNotVerified */ $block->getUrl('search/ajax/suggest', ['_secure' => $block->getRequest()->isSecure()]) ?>",
"url":"<?= /* @escapeNotVerified */ $helper->getSuggestUrl()?>",
"destinationSelector":"#search_autocomplete"}
}'
type="text"
Expand Down