ltsecurityinc安防产品在线商城代码

This commit is contained in:
2026-09-14 17:47:10 +08:00
parent 57d8444c15
commit 6a3c9c5bd8
14539 changed files with 1775310 additions and 0 deletions
@@ -0,0 +1,115 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\CatalogSearch\Controller\Advanced;
use Magento\TestFramework\TestCase\AbstractController;
use Laminas\Stdlib\Parameters;
/**
* Test cases for catalog advanced index using params.
*
* @magentoDbIsolation disabled
* @magentoAppIsolation enabled
*/
class IndexTest extends AbstractController
{
/**
* Advanced index test by params with the array in params.
*
* @magentoAppArea frontend
* @dataProvider fromParamsInArrayDataProvider
*
* @param array $searchParams
* @return void
*/
public function testExecuteWithArrayInParams(array $searchParams): void
{
$this->getRequest()->setQuery(
$this->_objectManager->create(
Parameters::class,
[
'values' => $searchParams
]
)
);
$this->dispatch('catalogsearch/advanced/index');
$this->assertEquals(200, $this->getResponse()->getStatusCode());
$this->getResponse()->getBody();
}
/**
* Data provider with array in param values.
*
* @return array
*/
public function fromParamsInArrayDataProvider(): array
{
return [
'from_data_with_from_param_is_array' => [
[
'name' => '',
'sku' => '',
'description' => '',
'short_description' => '',
'price' => [
'from' => [],
'to' => 1,
]
]
],
'from_data_with_to_param_is_array' => [
[
'name' => '',
'sku' => '',
'description' => '',
'short_description' => '',
'price' => [
'from' => 0,
'to' => [],
]
]
],
'from_data_with_params_in_array' => [
[
'name' => '',
'sku' => '',
'description' => '',
'short_description' => '',
'price' => [
'from' => ['0' => 1],
'to' => [1],
]
]
],
'from_data_with_params_in_array_in_array' => [
[
'name' => '',
'sku' => '',
'description' => '',
'short_description' => '',
'price' => [
'from' => ['0' => ['0' => 1]],
'to' => 1,
]
]
],
'from_data_with_name_param_is_array' => [
[
'name' => [],
'sku' => '',
'description' => '',
'short_description' => '',
'price' => [
'from' => 0,
'to' => 20,
]
]
]
];
}
}
@@ -0,0 +1,342 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\CatalogSearch\Controller\Advanced;
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
use Magento\TestFramework\TestCase\AbstractController;
use Laminas\Stdlib\Parameters;
/**
* Test cases for catalog advanced search using search engine.
*
* @magentoDbIsolation disabled
* @magentoAppIsolation enabled
*/
class ResultTest extends AbstractController
{
/**
* @var ProductAttributeRepositoryInterface
*/
private $productAttributeRepository;
/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();
$this->productAttributeRepository = $this->_objectManager->create(ProductAttributeRepositoryInterface::class);
}
/**
* Advanced search test by difference product attributes.
*
* @magentoAppArea frontend
* @magentoDataFixture Magento/CatalogSearch/_files/product_for_search.php
* @magentoDataFixture Magento/CatalogSearch/_files/full_reindex.php
* @dataProvider searchStringDataProvider
*
* @param array $searchParams
* @return void
*/
public function testExecute(array $searchParams): void
{
if ('' !== $searchParams['test_searchable_attribute']) {
$searchParams['test_searchable_attribute'] = $this->getAttributeOptionValueByOptionLabel(
'test_searchable_attribute',
$searchParams['test_searchable_attribute']
);
}
$this->getRequest()->setQuery(
$this->_objectManager->create(
Parameters::class,
[
'values' => $searchParams
]
)
);
$this->dispatch('catalogsearch/advanced/result');
$responseBody = $this->getResponse()->getBody();
$this->assertStringContainsString('Simple product name', $responseBody);
$this->assertStringNotContainsString('Not visible simple product', $responseBody);
}
/**
* Advanced search test by difference product attributes.
*
* @magentoAppArea frontend
* @magentoDataFixture Magento/CatalogSearch/_files/product_for_search_with_hyphen_in_sku.php
* @magentoDataFixture Magento/CatalogSearch/_files/full_reindex.php
*
* @return void
*/
public function testExecuteSkuWithHyphen(): void
{
$this->getRequest()->setQuery(
$this->_objectManager->create(
Parameters::class,
[
'values' => [
'name' => '',
'sku' => '24-mb01',
'description' => '',
'short_description' => '',
'price' => [
'from' => '',
'to' => '',
],
'test_searchable_attribute' => '',
]
]
)
);
$this->dispatch('catalogsearch/advanced/result');
$responseBody = $this->getResponse()->getBody();
$this->assertStringContainsString('Simple product name', $responseBody);
}
/**
* Advanced search with an underscore in product attributes.
*
* @magentoAppArea frontend
* @magentoDataFixture Magento/CatalogSearch/_files/product_for_search_with_underscore.php
* @magentoDataFixture Magento/CatalogSearch/_files/full_reindex.php
*
* @return void
*/
public function testExecuteWithUnderscore(): void
{
$this->getRequest()->setQuery(
$this->_objectManager->create(
Parameters::class,
[
'values' => [
'name' => 'name',
'sku' => 'sku',
'description' => 'description',
'short_description' => 'short',
'price' => [
'from' => '',
'to' => '',
],
],
]
)
);
$this->dispatch('catalogsearch/advanced/result');
$responseBody = $this->getResponse()->getBody();
$this->assertStringContainsString('name_simple_product', $responseBody);
}
/**
* Advanced search with array in price parameters
*
* @magentoAppArea frontend
* @magentoDataFixture Magento/CatalogSearch/_files/product_for_search.php
* @magentoDataFixture Magento/CatalogSearch/_files/full_reindex.php
* @dataProvider searchParamsInArrayDataProvider
*
* @param array $searchParams
* @return void
*/
public function testExecuteWithArrayInParam(array $searchParams): void
{
$this->getRequest()->setQuery(
$this->_objectManager->create(
Parameters::class,
[
'values' => $searchParams
]
)
);
$this->dispatch('catalogsearch/advanced/result');
$this->assertEquals(200, $this->getResponse()->getStatusCode());
$responseBody = $this->getResponse()->getBody();
$this->assertStringContainsString(
'We can&#039;t find any items matching these search criteria.',
$responseBody
);
}
/**
* Data provider with array in params values
*
* @return array
*/
public function searchParamsInArrayDataProvider(): array
{
return [
'search_with_from_param_is_array' => [
[
'name' => '',
'sku' => '',
'description' => '',
'short_description' => '',
'price' => [
'from' => [],
'to' => 1,
]
]
],
'search_with_to_param_is_array' => [
[
'name' => '',
'sku' => '',
'description' => '',
'short_description' => '',
'price' => [
'from' => 0,
'to' => [],
]
]
],
'search_with_params_in_array' => [
[
'name' => '',
'sku' => '',
'description' => '',
'short_description' => '',
'price' => [
'from' => ['0' => 1],
'to' => [1],
]
]
],
'search_with_params_in_array_in_array' => [
[
'name' => '',
'sku' => '',
'description' => '',
'short_description' => '',
'price' => [
'from' => ['0' => ['0' => 1]],
'to' => 1,
]
]
],
'search_with_name_param_is_array' => [
[
'name' => [],
'sku' => '',
'description' => '',
'short_description' => '',
'price' => [
'from' => 0,
'to' => 20,
]
]
]
];
}
/**
* Data provider with strings for quick search.
*
* @return array
*/
public function searchStringDataProvider(): array
{
return [
'search_product_by_name' => [
[
'name' => 'Simple product name',
'sku' => '',
'description' => '',
'short_description' => '',
'price' => [
'from' => '',
'to' => '',
],
'test_searchable_attribute' => '',
],
],
'search_product_by_sku' => [
[
'name' => '',
'sku' => 'simple_for_search',
'description' => '',
'short_description' => '',
'price' => [
'from' => '',
'to' => '',
],
'test_searchable_attribute' => '',
],
],
'search_product_by_description' => [
[
'name' => '',
'sku' => '',
'description' => 'Product description',
'short_description' => '',
'price' => [
'from' => '',
'to' => '',
],
'test_searchable_attribute' => '',
],
],
'search_product_by_short_description' => [
[
'name' => '',
'sku' => '',
'description' => '',
'short_description' => 'Product short description',
'price' => [
'from' => '',
'to' => '',
],
'test_searchable_attribute' => '',
],
],
'search_product_by_price_range' => [
[
'name' => '',
'sku' => '',
'description' => '',
'short_description' => '',
'price' => [
'from' => 50,
'to' => 150,
],
'test_searchable_attribute' => '',
],
],
'search_product_by_custom_attribute' => [
[
'name' => '',
'sku' => '',
'description' => '',
'short_description' => '',
'price' => [
'from' => '',
'to' => '',
],
'test_searchable_attribute' => 'Option 1',
],
],
];
}
/**
* Return attribute option value by option label.
*
* @param string $attributeCode
* @param string $optionLabel
* @return null|string
*/
private function getAttributeOptionValueByOptionLabel(string $attributeCode, string $optionLabel): ?string
{
/** @var Attribute $attribute */
$attribute = $this->productAttributeRepository->get($attributeCode);
return $attribute->getSource()->getOptionId($optionLabel);
}
}
@@ -0,0 +1,19 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogSearch\Controller;
class AjaxTest extends \Magento\TestFramework\TestCase\AbstractController
{
/**
* @magentoDataFixture Magento/CatalogSearch/_files/query.php
*/
public function testSuggestAction()
{
$this->getRequest()->setParam('q', 'query_text');
$this->dispatch('catalogsearch/ajax/suggest');
$this->assertStringContainsString('query_text', $this->getResponse()->getBody());
}
}
@@ -0,0 +1,54 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\CatalogSearch\Controller\Result;
use Magento\TestFramework\TestCase\AbstractController;
/**
* Test cases for catalog quick search using search engine.
*
* @magentoDbIsolation disabled
* @magentoAppIsolation enabled
*/
class IndexTest extends AbstractController
{
/**
* Quick search test by difference product attributes.
*
* @magentoAppArea frontend
* @magentoDataFixture Magento/CatalogSearch/_files/product_for_search.php
* @magentoDataFixture Magento/CatalogSearch/_files/full_reindex.php
* @dataProvider searchStringDataProvider
*
* @param string $searchString
* @return void
*/
public function testExecute(string $searchString): void
{
$this->getRequest()->setParam('q', $searchString);
$this->dispatch('catalogsearch/result');
$responseBody = $this->getResponse()->getBody();
$this->assertStringContainsString('Simple product name', $responseBody);
}
/**
* Data provider with strings for quick search.
*
* @return array
*/
public function searchStringDataProvider(): array
{
return [
'search_product_by_name' => ['Simple product name'],
'search_product_by_sku' => ['simple_for_search'],
'search_product_by_description' => ['Product description'],
'search_product_by_short_description' => ['Product short description'],
'search_product_by_custom_attribute' => ['Option 1'],
];
}
}
@@ -0,0 +1,186 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogSearch\Controller;
/**
* @magentoDbIsolation enabled
* @magentoAppIsolation enabled
* @magentoDataFixture Magento/CatalogSearch/_files/full_reindex.php
*/
class ResultTest extends \Magento\TestFramework\TestCase\AbstractController
{
/**
* @magentoDataFixture Magento/CatalogSearch/_files/query.php
*/
public function testIndexActionTranslation()
{
$this->markTestSkipped('MAGETWO-44910');
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$objectManager->get(\Magento\Framework\Locale\ResolverInterface::class)->setLocale('de_DE');
$this->getRequest()->setParam('q', 'query_text');
$this->dispatch('catalogsearch/result');
$responseBody = $this->getResponse()->getBody();
$this->assertStringNotContainsString('for="search">Search', $responseBody);
$this->assertStringMatchesFormat('%aSuche%S%a', $responseBody);
$this->assertStringNotContainsString('Search entire store here...', $responseBody);
$this->assertStringContainsString('Den gesamten Shop durchsuchen...', $responseBody);
}
/**
* @magentoDbIsolation disabled
*/
public function testIndexActionXSSQueryVerification()
{
$escaper = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->get(\Magento\Framework\Escaper::class);
$this->getRequest()->setParam('q', '<script>alert(1)</script>');
$this->dispatch('catalogsearch/result');
$responseBody = $this->getResponse()->getBody();
$data = '<script>alert(1)</script>';
$this->assertStringNotContainsString($data, $responseBody);
$this->assertStringContainsString($escaper->escapeHtml($data), $responseBody);
}
/**
* @magentoDataFixture Magento/CatalogSearch/_files/query_redirect.php
*/
public function testRedirect()
{
$this->dispatch('/catalogsearch/result/?q=query_text');
$responseBody = $this->getResponse();
$this->assertTrue($responseBody->isRedirect());
}
/**
* @magentoDataFixture Magento/CatalogSearch/_files/query_redirect.php
*/
public function testNoRedirectIfCurrentUrlAndRedirectTermAreSame()
{
$this->dispatch('/catalogsearch/result/?q=query_text&cat=41');
$responseBody = $this->getResponse();
$this->assertFalse($responseBody->isRedirect());
}
/**
* @magentoDataFixture Magento/CatalogSearch/_files/query.php
*/
public function testPopularity()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var $query \Magento\Search\Model\Query */
$query = $objectManager->create(\Magento\Search\Model\Query::class);
$query->loadByQueryText('query_text');
$this->assertEquals(1, $query->getPopularity());
$this->dispatch('catalogsearch/searchTermsLog/save?q=query_text');
$responseBody = $this->getResponse()->getBody();
$data = '"success":true';
$this->assertStringContainsString($data, $responseBody);
$query->loadByQueryText('query_text');
$this->assertEquals(2, $query->getPopularity());
}
/**
* @magentoDataFixture Magento/CatalogSearch/_files/popular_query.php
* @magentoDataFixture Magento/CatalogSearch/_files/query.php
*/
public function testPopularSearch()
{
$this->cacheAndPopularitySetup();
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var $query \Magento\Search\Model\Query */
$query = $objectManager->create(\Magento\Search\Model\Query::class);
$query->loadByQueryText('popular_query_text');
$this->assertEquals(100, $query->getPopularity());
$this->dispatch('/catalogsearch/result/?q=popular_query_text');
$responseBody = $this->getResponse()->getBody();
$this->assertStringContainsString('Search results for: &#039;popular_query_text&#039;', $responseBody);
$this->assertStringContainsString('/catalogsearch/searchTermsLog/save/', $responseBody);
$query->loadByQueryText('popular_query_text');
$this->assertEquals(100, $query->getPopularity());
}
/**
* @magentoDataFixture Magento/CatalogSearch/_files/popular_query.php
* @magentoDataFixture Magento/CatalogSearch/_files/query.php
*/
public function testPopularSearchWithAdditionalRequestParameters()
{
$this->cacheAndPopularitySetup();
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var $query \Magento\Search\Model\Query */
$query = $objectManager->create(\Magento\Search\Model\Query::class);
$query->loadByQueryText('popular_query_text');
$this->assertEquals(100, $query->getPopularity());
$this->dispatch('/catalogsearch/result/?q=popular_query_text&additional_parameters=some');
$responseBody = $this->getResponse()->getBody();
$this->assertStringContainsString('Search results for: &#039;popular_query_text&#039;', $responseBody);
$this->assertStringNotContainsString('/catalogsearch/searchTermsLog/save/', $responseBody);
$query->loadByQueryText('popular_query_text');
$this->assertEquals(101, $query->getPopularity());
}
/**
* @magentoDataFixture Magento/CatalogSearch/_files/popular_query.php
* @magentoDataFixture Magento/CatalogSearch/_files/query.php
*/
public function testNotPopularSearch()
{
$this->cacheAndPopularitySetup();
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var $query \Magento\Search\Model\Query */
$query = $objectManager->create(\Magento\Search\Model\Query::class);
$query->loadByQueryText('query_text');
$this->assertEquals(1, $query->getPopularity());
$this->dispatch('/catalogsearch/result/?q=query_text');
$responseBody = $this->getResponse()->getBody();
$this->assertStringContainsString('Search results for: &#039;query_text&#039;', $responseBody);
$this->assertStringNotContainsString('/catalogsearch/searchTermsLog/save/', $responseBody);
$query->loadByQueryText('query_text');
$this->assertEquals(2, $query->getPopularity());
}
private function cacheAndPopularitySetup()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var $scopeConfig \Magento\Framework\App\MutableScopeConfig */
$scopeConfig = $objectManager->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class);
$scopeConfig->setValue(
\Magento\Search\Model\PopularSearchTerms::XML_PATH_MAX_COUNT_CACHEABLE_SEARCH_TERMS,
1,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
/** @var $cacheState \Magento\Framework\App\Cache\StateInterface */
$cacheState = $objectManager->get(\Magento\Framework\App\Cache\StateInterface::class);
$cacheState->setEnabled(\Magento\PageCache\Model\Cache\Type::TYPE_IDENTIFIER, true);
/** @var $fpc \Magento\PageCache\Model\Cache\Type */
$fpc = $objectManager->get(\Magento\PageCache\Model\Cache\Type::class);
$fpc->clean();
}
}