ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Backend\Model\Search;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("unused")
|
||||
*/
|
||||
class AuthorizationMock extends \Magento\Framework\Authorization
|
||||
{
|
||||
/**
|
||||
* Check current user permission on resource and privilege
|
||||
*
|
||||
* @param string $resource
|
||||
* @param string $privilege
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAllowed($resource, $privilege = null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Backend\Model\Search;
|
||||
|
||||
use Magento\Backend\App\Area\FrontNameResolver;
|
||||
use Magento\Framework\App\Area;
|
||||
use Magento\Framework\App\AreaList;
|
||||
use Magento\Framework\App\Cache\State;
|
||||
use Magento\Framework\App\Config\FileResolver;
|
||||
use Magento\Framework\AuthorizationInterface;
|
||||
use Magento\Framework\Config\FileIteratorFactory;
|
||||
use Magento\Framework\Config\ScopeInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
* @SuppressWarnings(PHPMD.StaticAccess)
|
||||
*/
|
||||
class ConfigTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider loadDataProvider
|
||||
* @magentoConfigFixture current_store general/store_information/name Foo
|
||||
*/
|
||||
public function testLoad($query, $expectedResult)
|
||||
{
|
||||
/** @var \Magento\Backend\Model\Search\Config $configSearch */
|
||||
$configSearch = $this->getConfigSearchInstance();
|
||||
$configSearch->setQuery($query);
|
||||
$configSearch->load();
|
||||
|
||||
/** SUT Execution */
|
||||
$searchResults = $configSearch->getResults();
|
||||
|
||||
/** Ensure that search results are correct */
|
||||
$this->assertCount(count($expectedResult), $searchResults, 'Quantity of search result items is invalid.');
|
||||
foreach ($expectedResult as $itemIndex => $expectedItem) {
|
||||
/** Validate URL to item */
|
||||
$elementPathParts = explode('/', $expectedItem['id']);
|
||||
// filter empty values
|
||||
$elementPathParts = array_values(array_filter($elementPathParts));
|
||||
foreach ($elementPathParts as $elementPathPart) {
|
||||
$this->assertStringContainsString(
|
||||
$elementPathPart,
|
||||
$searchResults[$itemIndex]['url'],
|
||||
'Item URL is invalid.'
|
||||
);
|
||||
}
|
||||
unset($searchResults[$itemIndex]['url']);
|
||||
|
||||
/** Validate other item data */
|
||||
$this->assertEquals($expectedItem, $searchResults[$itemIndex], "Data of item #$itemIndex is invalid.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Magento\Backend\Model\Search\Config
|
||||
*/
|
||||
private function getConfigSearchInstance()
|
||||
{
|
||||
Bootstrap::getInstance()->reinitialize([
|
||||
State::PARAM_BAN_CACHE => true,
|
||||
]);
|
||||
Bootstrap::getObjectManager()
|
||||
->get(ScopeInterface::class)
|
||||
->setCurrentScope(FrontNameResolver::AREA_CODE);
|
||||
Bootstrap::getObjectManager()->get(AreaList::class)
|
||||
->getArea(FrontNameResolver::AREA_CODE)
|
||||
->load(Area::PART_CONFIG);
|
||||
|
||||
Bootstrap::getObjectManager()->configure([
|
||||
'preferences' => [
|
||||
AuthorizationInterface::class => \Magento\Backend\Model\Search\AuthorizationMock::class
|
||||
]
|
||||
]);
|
||||
|
||||
$fileResolverMock = $this->getMockBuilder(FileResolver::class)->disableOriginalConstructor()->getMock();
|
||||
$fileIteratorFactory = Bootstrap::getObjectManager()->get(FileIteratorFactory::class);
|
||||
$fileIterator = $fileIteratorFactory->create(
|
||||
[__DIR__ . '/_files/test_config.xml']
|
||||
);
|
||||
$fileResolverMock->expects($this->any())->method('get')->willReturn($fileIterator);
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Config\Model\Config\Structure\Reader $structureReader */
|
||||
$structureReader = $objectManager->create(
|
||||
\Magento\Config\Model\Config\Structure\Reader::class,
|
||||
['fileResolver' => $fileResolverMock]
|
||||
);
|
||||
/** @var \Magento\Config\Model\Config\Structure\Data $structureData */
|
||||
$structureData = $objectManager->create(
|
||||
\Magento\Config\Model\Config\Structure\Data::class,
|
||||
['reader' => $structureReader]
|
||||
);
|
||||
/** @var \Magento\Config\Model\Config\Structure $structure */
|
||||
$structure = $objectManager->create(
|
||||
\Magento\Config\Model\Config\Structure::class,
|
||||
['structureData' => $structureData]
|
||||
);
|
||||
|
||||
return $objectManager->create(
|
||||
\Magento\Backend\Model\Search\Config::class,
|
||||
['configStructure' => $structure]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function loadDataProvider()
|
||||
{
|
||||
return [
|
||||
'Search by field name' => [
|
||||
'Test Field',
|
||||
[
|
||||
[
|
||||
'id' => 'test_section/test_group/test_field_1',
|
||||
'type' => null,
|
||||
'name' => 'Test Field',
|
||||
'description' => ' / Test Tab / Test Section / Test Group',
|
||||
],
|
||||
[
|
||||
'id' => 'test_section/test_group/test_field_2',
|
||||
'type' => null,
|
||||
'name' => 'Test Field',
|
||||
'description' => ' / Test Tab / Test Section / Test Group',
|
||||
],
|
||||
],
|
||||
],
|
||||
'Search by group name' => [
|
||||
'Test Group',
|
||||
[
|
||||
[
|
||||
'id' => 'test_section/test_group',
|
||||
'type' => null,
|
||||
'name' => 'Test Group',
|
||||
'description' => ' / Test Tab / Test Section',
|
||||
],
|
||||
],
|
||||
],
|
||||
'Search by section name' => [
|
||||
'Test Section',
|
||||
[
|
||||
[
|
||||
'id' => '/test_section',
|
||||
'type' => null,
|
||||
'name' => 'Test Section',
|
||||
'description' => ' / Test Tab',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Backend\Model\Search;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDataFixture Magento/Customer/_files/three_customers.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_address.php
|
||||
*/
|
||||
class CustomerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider loadDataProvider
|
||||
*/
|
||||
public function testLoad($query, $limit, $start, $expectedResult)
|
||||
{
|
||||
/** Preconditions */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Backend\Model\Search\Customer $customerSearch */
|
||||
$customerSearch = $objectManager->create(\Magento\Backend\Model\Search\Customer::class);
|
||||
$customerSearch->setQuery($query);
|
||||
$customerSearch->setLimit($limit);
|
||||
$customerSearch->setStart($start);
|
||||
$customerSearch->load();
|
||||
|
||||
/** SUT Execution */
|
||||
$searchResults = $customerSearch->getResults();
|
||||
|
||||
/** Ensure that search results are correct */
|
||||
$this->assertCount(count($expectedResult), $searchResults, 'Quantity of search result items is invalid.');
|
||||
foreach ($expectedResult as $itemIndex => $expectedItem) {
|
||||
/** Validate URL to item */
|
||||
$customerId = substr($expectedItem['id'], 11); // 'customer/1/' is added to all actual customer IDs
|
||||
$this->assertStringContainsString(
|
||||
"customer/index/edit/id/$customerId",
|
||||
$searchResults[$itemIndex]['url'],
|
||||
'Item URL is invalid.'
|
||||
);
|
||||
unset($searchResults[$itemIndex]['url']);
|
||||
|
||||
/** Validate other item data */
|
||||
$this->assertEquals($expectedItem, $searchResults[$itemIndex], "Data of item #$itemIndex is invalid.");
|
||||
}
|
||||
}
|
||||
|
||||
public static function loadDataProvider()
|
||||
{
|
||||
return [
|
||||
'All items, first page' => [
|
||||
'Firstname',
|
||||
2, // Items on page
|
||||
1, // Page number
|
||||
[
|
||||
[
|
||||
'id' => 'customer/1/1',
|
||||
'type' => 'Customer',
|
||||
'name' => 'Firstname Lastname',
|
||||
'description' => 'CompanyName',
|
||||
],
|
||||
[
|
||||
'id' => 'customer/1/2',
|
||||
'type' => 'Customer',
|
||||
'name' => 'Firstname2 Lastname2',
|
||||
'description' => null
|
||||
]
|
||||
],
|
||||
],
|
||||
'All items, second page' => [
|
||||
'Firstname',
|
||||
2, // Items on page
|
||||
2, // Page number
|
||||
[
|
||||
[
|
||||
'id' => 'customer/1/3',
|
||||
'type' => 'Customer',
|
||||
'name' => 'Firstname3 Lastname3',
|
||||
'description' => null,
|
||||
]
|
||||
],
|
||||
],
|
||||
'Search by last name, second item only' => [
|
||||
'Lastname2',
|
||||
10, // Items on page
|
||||
1, // Page number
|
||||
[
|
||||
[
|
||||
'id' => 'customer/1/2',
|
||||
'type' => 'Customer',
|
||||
'name' => 'Firstname2 Lastname2',
|
||||
'description' => null,
|
||||
]
|
||||
],
|
||||
],
|
||||
'No results' => [
|
||||
'NotExistingCustomerName',
|
||||
10, // Items on page
|
||||
1, // Page number
|
||||
[],
|
||||
],
|
||||
'Search by company name, first item only' => [
|
||||
'CompanyName',
|
||||
10, // Items on page
|
||||
1, // Page number
|
||||
[
|
||||
[
|
||||
'id' => 'customer/1/1',
|
||||
'type' => 'Customer',
|
||||
'name' => 'Firstname Lastname',
|
||||
'description' => 'CompanyName',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Backend\Model\Search;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
* @magentoDataFixture Magento/Sales/_files/order_shipping_address_different_to_billing.php
|
||||
*/
|
||||
class OrderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider loadDataProvider
|
||||
*/
|
||||
public function testLoad($query, $limit, $start, $expectedResult)
|
||||
{
|
||||
/** @var $order \Magento\Sales\Model\Order */
|
||||
$order = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order::class);
|
||||
$orderIdByIncrementId = [];
|
||||
foreach (['100000001', '100000002', '100000003'] as $incrementId) {
|
||||
$orderIdByIncrementId[$incrementId] = $order->loadByIncrementId($incrementId)->getId();
|
||||
}
|
||||
|
||||
/** Preconditions */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Backend\Model\Search\Order $orderSearch */
|
||||
$orderSearch = $objectManager->create(\Magento\Backend\Model\Search\Order::class);
|
||||
$orderSearch->setQuery($query);
|
||||
$orderSearch->setLimit($limit);
|
||||
$orderSearch->setStart($start);
|
||||
$orderSearch->load();
|
||||
|
||||
/** SUT Execution */
|
||||
$searchResults = $orderSearch->getResults();
|
||||
|
||||
/** Ensure that search results are correct */
|
||||
$this->assertCount(count($expectedResult), $searchResults, 'Quantity of search result items is invalid.');
|
||||
foreach ($expectedResult as $itemIndex => $expectedItem) {
|
||||
/** Validate URL to item */
|
||||
$orderIncrementId = substr($expectedItem['id'], strlen('order/1/#'));
|
||||
$this->assertStringContainsString(
|
||||
"order/view/order_id/{$orderIdByIncrementId[$orderIncrementId]}",
|
||||
$searchResults[$itemIndex]['url'],
|
||||
'Item URL is invalid.'
|
||||
);
|
||||
$expectedItem['id'] = 'order/1/' . $orderIdByIncrementId[$orderIncrementId];
|
||||
unset($searchResults[$itemIndex]['url']);
|
||||
|
||||
/** Validate other item data */
|
||||
foreach ($expectedItem as $field => $value) {
|
||||
$this->assertEquals(
|
||||
$value,
|
||||
(string)$searchResults[$itemIndex][$field],
|
||||
"Data of item #$itemIndex is invalid."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function loadDataProvider()
|
||||
{
|
||||
return [
|
||||
'All items, first page' => [
|
||||
'10000000',
|
||||
2, // Items on page
|
||||
1, // Page number
|
||||
[
|
||||
[
|
||||
'id' => 'order/1/#100000001',
|
||||
'type' => 'Order',
|
||||
'name' => 'Order #100000001',
|
||||
'description' => 'firstname lastname',
|
||||
],
|
||||
[
|
||||
'id' => 'order/1/#100000002',
|
||||
'type' => 'Order',
|
||||
'name' => 'Order #100000002',
|
||||
'description' => 'guest guest'
|
||||
]
|
||||
],
|
||||
],
|
||||
'All items, second page' => [
|
||||
'10000000',
|
||||
2, // Items on page
|
||||
2, // Page number
|
||||
[
|
||||
[
|
||||
'id' => 'order/1/#100000003',
|
||||
'type' => 'Order',
|
||||
'name' => 'Order #100000003',
|
||||
'description' => 'guest guest',
|
||||
]
|
||||
],
|
||||
],
|
||||
'Search by first name, first item only' => [
|
||||
'First',
|
||||
10, // Items on page
|
||||
1, // Page number
|
||||
[
|
||||
[
|
||||
'id' => 'order/1/#100000001',
|
||||
'type' => 'Order',
|
||||
'name' => 'Order #100000001',
|
||||
'description' => 'firstname lastname',
|
||||
]
|
||||
],
|
||||
],
|
||||
'No results' => [
|
||||
'NotExistingOrder',
|
||||
10, // Items on page
|
||||
1, // Page number
|
||||
[],
|
||||
],
|
||||
'Search by last name, first item only' => [
|
||||
'last',
|
||||
10, // Items on page
|
||||
1, // Page number
|
||||
[
|
||||
[
|
||||
'id' => 'order/1/#100000001',
|
||||
'type' => 'Order',
|
||||
'name' => 'Order #100000001',
|
||||
'description' => 'firstname lastname',
|
||||
]
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
|
||||
<system>
|
||||
<tab id="test" translate="label" sortOrder="100">
|
||||
<label>Test Tab</label>
|
||||
</tab>
|
||||
<section id="test_section" translate="label" showInDefault="1" showInWebsite="1" showInStore="1" type="text" sortOrder="0">
|
||||
<label>Test Section</label>
|
||||
<tab>test</tab>
|
||||
<resource>Magento_Backend::test</resource>
|
||||
<group id="test_group" translate="label" showInDefault="1" showInWebsite="1" showInStore="1" type="text" sortOrder="10">
|
||||
<label>Test Group</label>
|
||||
<field id="test_field_1" translate="label" showInDefault="1" showInWebsite="1" showInStore="1" type="text" sortOrder="20">
|
||||
<label>Test Field</label>
|
||||
</field>
|
||||
<field id="test_field_2" translate="label" showInDefault="1" showInWebsite="1" showInStore="1" type="text" sortOrder="20">
|
||||
<label>Test Field</label>
|
||||
</field>
|
||||
</group>
|
||||
</section>
|
||||
</system>
|
||||
</config>
|
||||
Reference in New Issue
Block a user