Skip to content

Commit 2d6ee05

Browse files
committed
Merge remote-tracking branch 'origin/MC-31424' into 2.4-develop-pr15
2 parents f601c40 + 56d0731 commit 2d6ee05

File tree

1 file changed

+82
-8
lines changed
  • dev/tests/integration/testsuite/Magento/CatalogSearch/Block

1 file changed

+82
-8
lines changed

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

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,94 @@
55
*/
66
namespace Magento\CatalogSearch\Block;
77

8+
use Magento\Framework\App\RequestInterface;
9+
use Magento\Framework\ObjectManagerInterface;
10+
use Magento\Framework\View\Element\Template;
11+
use Magento\Framework\View\Element\Text;
12+
use Magento\Framework\View\LayoutInterface;
13+
use Magento\Search\Model\QueryFactory;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
816
class ResultTest extends \PHPUnit\Framework\TestCase
917
{
18+
/**
19+
* @var ObjectManagerInterface
20+
*/
21+
private $objectManager;
22+
23+
/**
24+
* @var LayoutInterface
25+
*/
26+
private $layout;
27+
28+
/**
29+
* @inheritdoc
30+
*/
31+
protected function setUp()
32+
{
33+
$this->objectManager = Bootstrap::getObjectManager();
34+
$this->layout = $this->objectManager->get(LayoutInterface::class);
35+
}
36+
1037
public function testSetListOrders()
1138
{
12-
/** @var $layout \Magento\Framework\View\Layout */
13-
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
14-
\Magento\Framework\View\LayoutInterface::class
15-
);
16-
$layout->addBlock(\Magento\Framework\View\Element\Text::class, 'head');
39+
$this->layout->addBlock(Text::class, 'head');
1740
// The tested block is using head block
18-
/** @var $block \Magento\CatalogSearch\Block\Result */
19-
$block = $layout->addBlock(\Magento\CatalogSearch\Block\Result::class, 'block');
20-
$childBlock = $layout->addBlock(\Magento\Framework\View\Element\Text::class, 'search_result_list', 'block');
41+
/** @var $block Result */
42+
$block = $this->layout->addBlock(Result::class, 'block');
43+
$childBlock = $this->layout->addBlock(Text::class, 'search_result_list', 'block');
2144

2245
$this->assertSame($childBlock, $block->getListBlock());
2346
}
47+
48+
/**
49+
* Verify search value escaping process
50+
*
51+
* @magentoConfigFixture default/catalog/search/engine elasticsearch6
52+
* @dataProvider toEscapeSearchTextDataProvider
53+
* @magentoAppArea frontend
54+
* @param string $searchValue
55+
* @param string $expectedOutput
56+
* @param string $unexpectedOutput
57+
* @return void
58+
*/
59+
public function testEscapeSearchText(string $searchValue, string $expectedOutput, string $unexpectedOutput): void
60+
{
61+
/** @var Result $searchResultBlock */
62+
$searchResultBlock = $this->layout->createBlock(Result::class);
63+
/** @var Template $searchBlock */
64+
$searchBlock = $this->layout->createBlock(Template::class);
65+
$searchBlock->setTemplate('Magento_Search::form.mini.phtml');
66+
/** @var RequestInterface $request */
67+
$request = $this->objectManager->get(RequestInterface::class);
68+
69+
$request->setParam(QueryFactory::QUERY_VAR_NAME, $searchValue);
70+
$searchHtml = $searchBlock->toHtml();
71+
72+
$this->assertContains('value=' . '"' . $expectedOutput . '"', $searchHtml);
73+
$this->assertNotContains($unexpectedOutput, $searchHtml);
74+
75+
$resultTitle = $searchResultBlock->getSearchQueryText()->render();
76+
$this->assertContains("Search results for: '{$expectedOutput}'", $resultTitle);
77+
$this->assertNotContains($unexpectedOutput, $resultTitle);
78+
}
79+
80+
/**
81+
* DataProvider for testEscapeSearchText()
82+
*
83+
* @return array
84+
*/
85+
public function toEscapeSearchTextDataProvider(): array
86+
{
87+
return [
88+
'less_than_sign_escaped' => ['<', '&lt;', '&amp;lt&#x3B;'],
89+
'greater_than_sign_escaped' => ['>', '&gt;', '&amp;gt&#x3B;'],
90+
'ampersand_sign_escaped' => ['&', '&amp;', '&amp;amp&#x3B;'],
91+
'double_quote_sign_escaped' => ['"', '&quot;', '&amp;quot&#x3B;'],
92+
'single_quote_sign_escaped' => ["'", '&#039;', '&amp;&#x23;039&#x3B;'],
93+
'plus_sign_not_escaped' => ['+', '+', '&amp;+&#x3B;'],
94+
'characters_not_escaped' => ['abc', 'abc', '&amp;abc&#x3B;'],
95+
'numbers_not_escaped' => ['123', '123', '&amp;123&#x3B;'],
96+
];
97+
}
2498
}

0 commit comments

Comments
 (0)