Skip to content

Commit cd14221

Browse files
author
Valeriy Nayda
committed
Merge remote-tracking branch 'origin/MAGETWO-53826' into PR-8
2 parents 8fcee06 + 63cc19e commit cd14221

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

app/code/Magento/CatalogSearch/Controller/Result/Index.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ public function execute()
7979
} else {
8080
$query->saveIncrementalPopularity();
8181

82-
if ($query->getRedirect()) {
83-
$this->getResponse()->setRedirect($query->getRedirect());
82+
$redirect = $query->getRedirect();
83+
if ($redirect && $this->_url->getCurrentUrl() !== $redirect) {
84+
$this->getResponse()->setRedirect($redirect);
8485
return;
8586
}
8687
}

dev/tests/integration/testsuite/Magento/CatalogSearch/Controller/ResultTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,26 @@ public function testIndexActionXSSQueryVerification()
3737
$this->assertNotContains($data, $responseBody);
3838
$this->assertContains(htmlspecialchars($data, ENT_COMPAT, 'UTF-8', false), $responseBody);
3939
}
40+
41+
/**
42+
* @magentoDataFixture Magento/CatalogSearch/_files/query_redirect.php
43+
*/
44+
public function testRedirect()
45+
{
46+
$this->dispatch('/catalogsearch/result/?q=query_text');
47+
$responseBody = $this->getResponse();
48+
49+
$this->assertTrue($responseBody->isRedirect());
50+
}
51+
52+
/**
53+
* @magentoDataFixture Magento/CatalogSearch/_files/query_redirect.php
54+
*/
55+
public function testNoRedirectIfCurrentUrlAndRedirectTermAreSame()
56+
{
57+
$this->dispatch('/catalogsearch/result/?q=query_text&cat=41');
58+
$responseBody = $this->getResponse();
59+
60+
$this->assertFalse($responseBody->isRedirect());
61+
}
4062
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Framework\UrlInterface;
8+
use Magento\TestFramework\Helper\Bootstrap;
9+
10+
include 'query.php';
11+
12+
$objectManager = Bootstrap::getObjectManager();
13+
/** @var UrlInterface $url */
14+
$url = $objectManager->get(UrlInterface::class);
15+
16+
$query->setRedirect($url->getCurrentUrl() . 'catalogsearch/result/?q=query_text&cat=41')
17+
->save();

0 commit comments

Comments
 (0)