ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Ui\Component;
|
||||
|
||||
use Magento\Backend\Model\Locale\Resolver;
|
||||
use Magento\Framework\Api\Filter;
|
||||
use Magento\Framework\Locale\ResolverInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class to test Data Provider for customer listing
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class DataProviderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ResolverInterface|MockObject
|
||||
*/
|
||||
private $localeResolverMock;
|
||||
|
||||
/**
|
||||
* @var DataProvider
|
||||
*/
|
||||
private $dataProvider;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->initLocaleResolverMock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to filter by region name in custom locale
|
||||
*
|
||||
* @param array $filterData
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_address.php
|
||||
* @magentoDataFixture Magento/Directory/_files/region_name_jp.php
|
||||
* @dataProvider getDataByRegionDataProvider
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testGetDataByRegion(array $filterData)
|
||||
{
|
||||
$locale = 'JA_jp';
|
||||
$this->localeResolverMock->method('getLocale')->willReturn($locale);
|
||||
$this->dataProvider = Bootstrap::getObjectManager()->create(
|
||||
DataProvider::class,
|
||||
[
|
||||
'name' => 'customer_listing_data_source',
|
||||
'requestFieldName' => 'id',
|
||||
'primaryFieldName' => 'entity_id',
|
||||
]
|
||||
);
|
||||
|
||||
$filter = Bootstrap::getObjectManager()->create(
|
||||
Filter::class,
|
||||
['data' => $filterData]
|
||||
);
|
||||
$this->dataProvider->addFilter($filter);
|
||||
$data = $this->dataProvider->getData();
|
||||
$this->assertEquals(1, $data['totalRecords']);
|
||||
$this->assertCount(1, $data['items']);
|
||||
$this->assertEquals($filterData['value'], $data['items'][0]['billing_region']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getDataByRegionDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[['condition_type' => 'fulltext', 'field' => 'fulltext', 'value' => 'アラバマ']],
|
||||
[['condition_type' => 'regular', 'field' => 'billing_region', 'value' => 'アラバマ']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock locale resolver
|
||||
*/
|
||||
private function initLocaleResolverMock(): void
|
||||
{
|
||||
$this->localeResolverMock = $this->createMock(ResolverInterface::class);
|
||||
Bootstrap::getObjectManager()->removeSharedInstance(ResolverInterface::class);
|
||||
Bootstrap::getObjectManager()->removeSharedInstance(Resolver::class);
|
||||
Bootstrap::getObjectManager()->addSharedInstance($this->localeResolverMock, ResolverInterface::class);
|
||||
Bootstrap::getObjectManager()->addSharedInstance($this->localeResolverMock, Resolver::class);
|
||||
}
|
||||
}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Ui\Component\Listing\Address;
|
||||
|
||||
use Magento\Backend\Model\Locale\Resolver;
|
||||
use Magento\Framework\Api\Filter;
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\Locale\ResolverInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class to test Data Provider for customer address listing
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class DataProviderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ResolverInterface|MockObject
|
||||
*/
|
||||
private $localeResolverMock;
|
||||
|
||||
/**
|
||||
* @var RequestInterface|MockObject
|
||||
*/
|
||||
private $requestMock;
|
||||
|
||||
/**
|
||||
* @var DataProvider
|
||||
*/
|
||||
private $dataProvider;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->requestMock = $this->createMock(RequestInterface::class);
|
||||
$this->dataProvider = Bootstrap::getObjectManager()->create(
|
||||
DataProvider::class,
|
||||
[
|
||||
'name' => 'customer_address_listing_data_source',
|
||||
'requestFieldName' => 'id',
|
||||
'primaryFieldName' => 'entity_id',
|
||||
'request' => $this->requestMock,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to filter by region name in custom locale
|
||||
*
|
||||
* @param array $filterData
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_address.php
|
||||
* @magentoDataFixture Magento/Directory/_files/region_name_jp.php
|
||||
* @dataProvider getDataByRegionDataProvider
|
||||
*/
|
||||
public function testGetDataByRegion(array $filterData)
|
||||
{
|
||||
$customerId = 1;
|
||||
$locale = 'JA_jp';
|
||||
$this->initLocaleResolverMock();
|
||||
$this->localeResolverMock->method('getLocale')->willReturn($locale);
|
||||
|
||||
$this->requestMock->method('getParam')->with('parent_id')->willReturn($customerId);
|
||||
$this->dataProvider = Bootstrap::getObjectManager()->create(
|
||||
DataProvider::class,
|
||||
[
|
||||
'name' => 'customer_address_listing_data_source',
|
||||
'requestFieldName' => 'id',
|
||||
'primaryFieldName' => 'entity_id',
|
||||
'request' => $this->requestMock,
|
||||
]
|
||||
);
|
||||
|
||||
$filter = Bootstrap::getObjectManager()->create(
|
||||
Filter::class,
|
||||
['data' => $filterData]
|
||||
);
|
||||
$this->dataProvider->addFilter($filter);
|
||||
$data = $this->dataProvider->getData();
|
||||
$this->assertEquals(1, $data['totalRecords']);
|
||||
$this->assertCount(1, $data['items']);
|
||||
$this->assertEquals($filterData['value'], $data['items'][0]['region']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getDataByRegionDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[['condition_type' => 'fulltext', 'field' => 'fulltext', 'value' => 'アラバマ']],
|
||||
[['condition_type' => 'regular', 'field' => 'region', 'value' => 'アラバマ']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock locale resolver
|
||||
*/
|
||||
private function initLocaleResolverMock()
|
||||
{
|
||||
$this->localeResolverMock = $this->createMock(ResolverInterface::class);
|
||||
Bootstrap::getObjectManager()->addSharedInstance($this->localeResolverMock, ResolverInterface::class);
|
||||
Bootstrap::getObjectManager()->addSharedInstance($this->localeResolverMock, Resolver::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Bootstrap::getObjectManager()->removeSharedInstance(ResolverInterface::class);
|
||||
Bootstrap::getObjectManager()->removeSharedInstance(Resolver::class);
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Ui\Component\Listing;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test for \Magento\Customer\Ui\Component\Listing\AttributeRepository.
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class AttributeRepositoryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var AttributeRepository
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->model = Bootstrap::getObjectManager()->create(AttributeRepository::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for get store_id option array
|
||||
*
|
||||
* @magentoDataFixture Magento/Store/_files/core_fixturestore.php
|
||||
* @return void
|
||||
*/
|
||||
public function testGetOptionArray(): void
|
||||
{
|
||||
$result = $this->model->getMetadataByCode('store_id');
|
||||
|
||||
$this->assertTrue(isset($result['options']['1']['value']));
|
||||
$this->assertEquals(
|
||||
['Default Store View', 'Fixture Store'],
|
||||
$this->getStoreViewLabels($result['options'][1]['value'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns prepared store view labels
|
||||
*
|
||||
* @param array $storeViewsData
|
||||
* @return array
|
||||
*/
|
||||
private function getStoreViewLabels(array $storeViewsData): array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($storeViewsData as $storeView) {
|
||||
$result[] = str_replace("\xc2\xa0", '', $storeView['label']);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Ui\Component\Listing\Column;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests for \Magento\Customer\Ui\Component\Listing\Column\Confirmation.
|
||||
*/
|
||||
class ConfirmationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test subject.
|
||||
*
|
||||
* @var Confirmation
|
||||
*/
|
||||
private $confirmation;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->confirmation = Bootstrap::getObjectManager()->create(
|
||||
Confirmation::class,
|
||||
[
|
||||
'components' => [],
|
||||
'data' => ['name' => 'confirmation'],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify Confirmation::prepareDataSource() won't throw exception in case requested website doesn't exist.
|
||||
*
|
||||
* @param array $customerDataSource
|
||||
* @param array $expectedResult
|
||||
* @magentoConfigFixture base_website customer/create_account/confirm 1
|
||||
* @dataProvider customersDataProvider
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPrepareDataSource(array $customerDataSource, array $expectedResult): void
|
||||
{
|
||||
$result = $this->confirmation->prepareDataSource($customerDataSource);
|
||||
|
||||
self::assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* CustomerDataSource data provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function customersDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'customerDataSource' => [
|
||||
'data' => [
|
||||
'items' => [
|
||||
[
|
||||
'id_field_name' => 'entity_id',
|
||||
'entity_id' => '1',
|
||||
'name' => 'John Doe',
|
||||
'email' => 'john.doe@example.com',
|
||||
'group_id' => ['1'],
|
||||
'created_at' => '2020-12-28 07:05:50',
|
||||
'website_id' => ['1'],
|
||||
'confirmation' => false,
|
||||
'created_in' => 'Default Store View',
|
||||
],
|
||||
[
|
||||
'id_field_name' => 'entity_id',
|
||||
'entity_id' => '2',
|
||||
'name' => 'Jane Doe',
|
||||
'email' => 'jane.doe@example.com',
|
||||
'group_id' => ['1'],
|
||||
'created_at' => '2020-12-28 07:06:17',
|
||||
'website_id' => ['999999999'],
|
||||
'confirmation' => null,
|
||||
'created_in' => 'CustomStoreViewWhichDoesNotExistAnymore',
|
||||
],
|
||||
],
|
||||
'totalRecords' => 2,
|
||||
],
|
||||
],
|
||||
'expectedResult' => [
|
||||
'data' => [
|
||||
'items' => [
|
||||
[
|
||||
'id_field_name' => 'entity_id',
|
||||
'entity_id' => '1',
|
||||
'name' => 'John Doe',
|
||||
'email' => 'john.doe@example.com',
|
||||
'group_id' => ['1'],
|
||||
'created_at' => '2020-12-28 07:05:50',
|
||||
'website_id' => ['1'],
|
||||
'confirmation' => __('Confirmation Required'),
|
||||
'created_in' => 'Default Store View',
|
||||
],
|
||||
[
|
||||
'id_field_name' => 'entity_id',
|
||||
'entity_id' => '2',
|
||||
'name' => 'Jane Doe',
|
||||
'email' => 'jane.doe@example.com',
|
||||
'group_id' => ['1'],
|
||||
'created_at' => '2020-12-28 07:06:17',
|
||||
'website_id' => ['999999999'],
|
||||
'confirmation' => __('Confirmed'),
|
||||
'created_in' => 'CustomStoreViewWhichDoesNotExistAnymore',
|
||||
],
|
||||
],
|
||||
'totalRecords' => 2,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user