Skip to content

Commit

Permalink
⏫ Forwardport of #11722 to 2.3-develop branch
Browse files Browse the repository at this point in the history
Applied pull request patch https://github.com/magento/magento2/pull/11722.patch (created by @nmalevanec) based on commit(s):
  1. 751143b

Fixed GitHub Issues in 2.3-develop branch:
  - #6802: Magento\Search\Helper\getSuggestUrl() not used in search template (reported by @schmengler)
  • Loading branch information
magento-engcom-team committed Jan 23, 2018
1 parent 8e77e2f commit 1a11319
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
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

0 comments on commit 1a11319

Please sign in to comment.