init
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\CatalogSearch\Block\Advanced;
|
||||
|
||||
class ResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\View\LayoutInterface
|
||||
*/
|
||||
protected $_layout;
|
||||
|
||||
/**
|
||||
* @var \Magento\CatalogSearch\Block\Advanced\Result
|
||||
*/
|
||||
protected $_block;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
);
|
||||
$this->_block = $this->_layout->createBlock(\Magento\CatalogSearch\Block\Advanced\Result::class, 'block');
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testSetListOrders()
|
||||
{
|
||||
$sortOptions = [
|
||||
'option1' => 'Label Option 1',
|
||||
'position' => 'Label Position',
|
||||
'option3' => 'Label Option 2',
|
||||
];
|
||||
/** @var \Magento\Catalog\Model\Category $category */
|
||||
$category = $this->createPartialMock(\Magento\Catalog\Model\Category::class, ['getAvailableSortByOptions']);
|
||||
$category->expects($this->atLeastOnce())
|
||||
->method('getAvailableSortByOptions')
|
||||
->willReturn($sortOptions);
|
||||
$category->setId(100500); // Any id - just for layer navigation
|
||||
/** @var \Magento\Catalog\Model\Layer\Resolver $resolver */
|
||||
$resolver = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Catalog\Model\Layer\Resolver::class);
|
||||
$resolver->get()->setCurrentCategory($category);
|
||||
|
||||
$childBlock = $this->_layout->addBlock(
|
||||
\Magento\Framework\View\Element\Text::class,
|
||||
'search_result_list',
|
||||
'block'
|
||||
);
|
||||
|
||||
$expectedOptions = ['option1' => 'Label Option 1', 'option3' => 'Label Option 2'];
|
||||
$this->assertNotEquals($expectedOptions, $childBlock->getAvailableOrders());
|
||||
$this->_block->setListOrders();
|
||||
$this->assertEquals($expectedOptions, $childBlock->getAvailableOrders());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testSetListModes()
|
||||
{
|
||||
/** @var $childBlock \Magento\Framework\View\Element\Text */
|
||||
$childBlock = $this->_layout->addBlock(
|
||||
\Magento\Framework\View\Element\Text::class,
|
||||
'search_result_list',
|
||||
'block'
|
||||
);
|
||||
$this->assertEmpty($childBlock->getModes());
|
||||
$this->_block->setListModes();
|
||||
$this->assertNotEmpty($childBlock->getModes());
|
||||
}
|
||||
|
||||
public function testSetListCollection()
|
||||
{
|
||||
/** @var $childBlock \Magento\Framework\View\Element\Text */
|
||||
$childBlock = $this->_layout->addBlock(
|
||||
\Magento\Framework\View\Element\Text::class,
|
||||
'search_result_list',
|
||||
'block'
|
||||
);
|
||||
$this->assertEmpty($childBlock->getCollection());
|
||||
$this->_block->setListCollection();
|
||||
$this->assertInstanceOf(
|
||||
\Magento\CatalogSearch\Model\ResourceModel\Advanced\Collection::class,
|
||||
$childBlock->getCollection()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\CatalogSearch\Block;
|
||||
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\View\Element\Template;
|
||||
use Magento\Framework\View\Element\Text;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\Search\Model\QueryFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Search\ViewModel\ConfigProvider;
|
||||
|
||||
class ResultTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var LayoutInterface
|
||||
*/
|
||||
private $layout;
|
||||
|
||||
/**
|
||||
* @var ConfigProvider
|
||||
*/
|
||||
private $configProvider;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->layout = $this->objectManager->get(LayoutInterface::class);
|
||||
$this->configProvider = $this->objectManager->get(ConfigProvider::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set list orders test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetListOrders(): void
|
||||
{
|
||||
$this->layout->addBlock(Text::class, 'head');
|
||||
// The tested block is using head block
|
||||
/** @var $block Result */
|
||||
$block = $this->layout->addBlock(Result::class, 'block');
|
||||
$childBlock = $this->layout->addBlock(Text::class, 'search_result_list', 'block');
|
||||
|
||||
$this->assertSame($childBlock, $block->getListBlock());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify search value escaping process
|
||||
*
|
||||
* @dataProvider toEscapeSearchTextDataProvider
|
||||
* @magentoAppArea frontend
|
||||
* @param string $searchValue
|
||||
* @param string $expectedOutput
|
||||
* @param string $unexpectedOutput
|
||||
* @return void
|
||||
*/
|
||||
public function testEscapeSearchText(string $searchValue, string $expectedOutput, string $unexpectedOutput): void
|
||||
{
|
||||
/** @var Result $searchResultBlock */
|
||||
$searchResultBlock = $this->layout->createBlock(Result::class);
|
||||
/** @var Template $searchBlock */
|
||||
$searchQueryParams = $this->getMockBuilder(\Magento\Search\ViewModel\AdditionalSearchFormData::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['getFormData'])
|
||||
->getMock();
|
||||
$searchQueryParams->expects($this->any())
|
||||
->method('getFormData')
|
||||
->willReturn([]);
|
||||
$searchBlock = $this->layout->createBlock(Template::class);
|
||||
$searchBlock->setData([
|
||||
'configProvider' => $this->configProvider,
|
||||
'additionalSearchFormData' => $searchQueryParams,
|
||||
]);
|
||||
$searchBlock->setTemplate('Magento_Search::form.mini.phtml');
|
||||
/** @var RequestInterface $request */
|
||||
$request = $this->objectManager->get(RequestInterface::class);
|
||||
|
||||
$request->setParam(QueryFactory::QUERY_VAR_NAME, $searchValue);
|
||||
$searchHtml = $searchBlock->toHtml();
|
||||
|
||||
$this->assertStringContainsString('value=' . '"' . $expectedOutput . '"', $searchHtml);
|
||||
$this->assertStringNotContainsString($unexpectedOutput, $searchHtml);
|
||||
|
||||
$resultTitle = $searchResultBlock->getSearchQueryText()->render();
|
||||
$this->assertStringContainsString("Search results for: '{$expectedOutput}'", $resultTitle);
|
||||
$this->assertStringNotContainsString($unexpectedOutput, $resultTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
* DataProvider for testEscapeSearchText()
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toEscapeSearchTextDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'less_than_sign_escaped' => ['<', '<', '&lt;'],
|
||||
'greater_than_sign_escaped' => ['>', '>', '&gt;'],
|
||||
'ampersand_sign_escaped' => ['&', '&', '&amp;'],
|
||||
'double_quote_sign_escaped' => ['"', '"', '&quot;'],
|
||||
'single_quote_sign_escaped' => ["'", ''', '&#039;'],
|
||||
'plus_sign_not_escaped' => ['+', '+', '&+;'],
|
||||
'characters_not_escaped' => ['abc', 'abc', '&abc;'],
|
||||
'numbers_not_escaped' => ['123', '123', '&123;'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\CatalogSearch\Block;
|
||||
|
||||
class TermTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Search\Block\Term
|
||||
*/
|
||||
protected $_block;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Search\Block\Term::class
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetSearchUrl()
|
||||
{
|
||||
$query = uniqid();
|
||||
$obj = new \Magento\Framework\DataObject(['query_text' => $query]);
|
||||
$this->assertStringEndsWith("/catalogsearch/result/?q={$query}", $this->_block->getSearchUrl($obj));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user