ltsecurityinc安防产品在线商城代码
This commit is contained in:
+61
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Directory\Model\Country\Postcode\Config;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ReaderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Reader
|
||||
*/
|
||||
private $reader;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->reader = Bootstrap::getObjectManager()
|
||||
->create(Reader::class);
|
||||
}
|
||||
|
||||
public function testRead()
|
||||
{
|
||||
$result = $this->reader->read();
|
||||
|
||||
$this->assertArrayHasKey('NL', $result);
|
||||
$this->assertArrayHasKey('pattern_1', $result['NL']);
|
||||
$this->assertArrayHasKey('pattern_2', $result['NL']);
|
||||
|
||||
$this->assertEquals('test1', $result['NL']['pattern_1']['example']);
|
||||
$this->assertEquals('^[0-9]{4}\s[a-zA-Z]{2}$', $result['NL']['pattern_1']['pattern']);
|
||||
|
||||
$this->assertEquals('test2', $result['NL']['pattern_2']['example']);
|
||||
$this->assertEquals('^[0-5]{4}[a-z]{2}$', $result['NL']['pattern_2']['pattern']);
|
||||
|
||||
$this->assertArrayHasKey('NL_NEW', $result);
|
||||
$this->assertArrayHasKey('pattern_1', $result['NL_NEW']);
|
||||
|
||||
$this->assertEquals('test1', $result['NL_NEW']['pattern_1']['example']);
|
||||
$this->assertEquals('^[0-2]{4}[A-Z]{2}$', $result['NL_NEW']['pattern_1']['pattern']);
|
||||
|
||||
$this->assertArrayHasKey('AR', $result);
|
||||
$this->assertArrayHasKey('pattern_1', $result['AR']);
|
||||
$this->assertArrayHasKey('pattern_2', $result['AR']);
|
||||
$this->assertEquals('1234', $result['AR']['pattern_1']['example']);
|
||||
$this->assertEquals('^[0-9]{4}$', $result['AR']['pattern_1']['pattern']);
|
||||
$this->assertEquals('A1234BCD', $result['AR']['pattern_2']['example']);
|
||||
$this->assertEquals('^[a-zA-z]{1}[0-9]{4}[a-zA-z]{3}$', $result['AR']['pattern_2']['pattern']);
|
||||
|
||||
$this->assertArrayHasKey('KR', $result);
|
||||
$this->assertArrayHasKey('pattern_1', $result['KR']);
|
||||
$this->assertArrayHasKey('pattern_2', $result['KR']);
|
||||
$this->assertEquals('123-456', $result['KR']['pattern_1']['example']);
|
||||
$this->assertEquals('^[0-9]{3}-[0-9]{3}$', $result['KR']['pattern_1']['pattern']);
|
||||
$this->assertEquals('12345', $result['KR']['pattern_2']['example']);
|
||||
$this->assertEquals('^[0-9]{5}$', $result['KR']['pattern_2']['pattern']);
|
||||
}
|
||||
}
|
||||
+276
@@ -0,0 +1,276 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Directory\Model\Country\Postcode;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
class ValidatorTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Directory\Model\Country\Postcode\ValidatorInterface
|
||||
*/
|
||||
protected $validator;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->validator = $objectManager->create(\Magento\Directory\Model\Country\Postcode\ValidatorInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPostcodesDataProvider
|
||||
*/
|
||||
public function testPostCodes($countryId, $validPostcode)
|
||||
{
|
||||
try {
|
||||
$this->assertTrue($this->validator->validate($validPostcode, $countryId));
|
||||
$this->assertFalse($this->validator->validate('INVALID-100', $countryId));
|
||||
} catch (\InvalidArgumentException $ex) {
|
||||
//skip validation test for none existing countryId
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testPostCodesThrowsExceptionIfCountryDoesNotExist()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Provided countryId does not exist.');
|
||||
|
||||
$this->validator->validate('12345', 'INVALID-CODE');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getCanadaInvalidPostCodes
|
||||
*/
|
||||
public function testInvalidCanadaZipCode($countryId, $invalidPostCode)
|
||||
{
|
||||
$this->assertFalse($this->validator->validate($invalidPostCode, $countryId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getCanadaValidPostCodes
|
||||
*/
|
||||
public function testValidCanadaZipCode($countryId, $validPostCode)
|
||||
{
|
||||
$this->assertTrue($this->validator->validate($validPostCode, $countryId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCanadaInvalidPostCodes()
|
||||
{
|
||||
return [
|
||||
['countryId' => 'CA', 'postcode' => '12345'],
|
||||
['countryId' => 'CA', 'postcode' => 'A1B2C3D'],
|
||||
['countryId' => 'CA', 'postcode' => 'A1B2C'],
|
||||
['countryId' => 'CA', 'postcode' => 'A1B 2C3'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCanadaValidPostCodes()
|
||||
{
|
||||
return [
|
||||
['countryId' => 'CA', 'postcode' => 'A1B2C3'],
|
||||
['countryId' => 'CA', 'postcode' => 'A1B 2C3'],
|
||||
['countryId' => 'CA', 'postcode' => 'A1B'],
|
||||
['countryId' => 'CA', 'postcode' => 'Z9Y 8X7'],
|
||||
['countryId' => 'CA', 'postcode' => 'Z9Y8X7'],
|
||||
['countryId' => 'CA', 'postcode' => 'Z9Y'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function getPostcodesDataProvider()
|
||||
{
|
||||
return [
|
||||
['countryId' => 'AD', 'postcode' => 'AD100'],
|
||||
['countryId' => 'AM', 'postcode' => '123456'],
|
||||
['countryId' => 'AR', 'postcode' => '1234'],
|
||||
['countryId' => 'AS', 'postcode' => '12345'],
|
||||
['countryId' => 'AT', 'postcode' => '1234'],
|
||||
['countryId' => 'AU', 'postcode' => '1234'],
|
||||
['countryId' => 'AX', 'postcode' => '22101'],
|
||||
['countryId' => 'AZ', 'postcode' => '1234'],
|
||||
['countryId' => 'AZ', 'postcode' => '123456'],
|
||||
['countryId' => 'BA', 'postcode' => '12345'],
|
||||
['countryId' => 'BB', 'postcode' => 'BB10900'],
|
||||
['countryId' => 'BD', 'postcode' => '1234'],
|
||||
['countryId' => 'BE', 'postcode' => '1234'],
|
||||
['countryId' => 'BG', 'postcode' => '1234'],
|
||||
['countryId' => 'BH', 'postcode' => '323'],
|
||||
['countryId' => 'BH', 'postcode' => '1209'],
|
||||
['countryId' => 'BM', 'postcode' => 'MA 02'],
|
||||
['countryId' => 'BN', 'postcode' => 'PS1234'],
|
||||
['countryId' => 'BR', 'postcode' => '12345678'],
|
||||
['countryId' => 'BR', 'postcode' => '12345-678'],
|
||||
['countryId' => 'BY', 'postcode' => '123456'],
|
||||
['countryId' => 'CA', 'postcode' => 'P9M 3T6'],
|
||||
['countryId' => 'CC', 'postcode' => '6799'],
|
||||
['countryId' => 'CH', 'postcode' => '1234'],
|
||||
['countryId' => 'CK', 'postcode' => '1234'],
|
||||
['countryId' => 'CL', 'postcode' => '1234567'],
|
||||
['countryId' => 'CN', 'postcode' => '123456'],
|
||||
['countryId' => 'CR', 'postcode' => '12345'],
|
||||
['countryId' => 'CS', 'postcode' => '12345'],
|
||||
['countryId' => 'CU', 'postcode' => '12345'],
|
||||
['countryId' => 'CV', 'postcode' => '1234'],
|
||||
['countryId' => 'CX', 'postcode' => '6798'],
|
||||
['countryId' => 'CY', 'postcode' => '1234'],
|
||||
['countryId' => 'CZ', 'postcode' => '123 45'],
|
||||
['countryId' => 'DE', 'postcode' => '12345'],
|
||||
['countryId' => 'DK', 'postcode' => '1234'],
|
||||
['countryId' => 'DO', 'postcode' => '12345'],
|
||||
['countryId' => 'DZ', 'postcode' => '12345'],
|
||||
['countryId' => 'EC', 'postcode' => 'A1234B'],
|
||||
['countryId' => 'EC', 'postcode' => 'AB123456'],
|
||||
['countryId' => 'EC', 'postcode' => '123456'],
|
||||
['countryId' => 'EE', 'postcode' => '12345'],
|
||||
['countryId' => 'EG', 'postcode' => '12345'],
|
||||
['countryId' => 'ES', 'postcode' => '12345'],
|
||||
['countryId' => 'ET', 'postcode' => '1234'],
|
||||
['countryId' => 'FI', 'postcode' => '12345'],
|
||||
['countryId' => 'FK', 'postcode' => 'FIQQ 1ZZ'],
|
||||
['countryId' => 'FM', 'postcode' => '96941'],
|
||||
['countryId' => 'FO', 'postcode' => '123'],
|
||||
['countryId' => 'FR', 'postcode' => '12345'],
|
||||
['countryId' => 'GB', 'postcode' => 'PL12 3RT'],
|
||||
['countryId' => 'GB', 'postcode' => 'P1L 2RT'],
|
||||
['countryId' => 'GB', 'postcode' => 'QW1 2RT'],
|
||||
['countryId' => 'GB', 'postcode' => 'QW1R 2TG'],
|
||||
['countryId' => 'GB', 'postcode' => 'L12 3PL'],
|
||||
['countryId' => 'GB', 'postcode' => 'Q1 2PL'],
|
||||
['countryId' => 'GE', 'postcode' => '1234'],
|
||||
['countryId' => 'GF', 'postcode' => '12345'],
|
||||
['countryId' => 'GG', 'postcode' => 'GY10 2AB'],
|
||||
['countryId' => 'GL', 'postcode' => '1234'],
|
||||
['countryId' => 'GH', 'postcode' => 'GA18400'],
|
||||
['countryId' => 'GN', 'postcode' => '123'],
|
||||
['countryId' => 'GP', 'postcode' => '12345'],
|
||||
['countryId' => 'GR', 'postcode' => '123 45'],
|
||||
['countryId' => 'GS', 'postcode' => 'SIQQ 1ZZ'],
|
||||
['countryId' => 'GT', 'postcode' => '12345'],
|
||||
['countryId' => 'GU', 'postcode' => '12345'],
|
||||
['countryId' => 'GW', 'postcode' => '1234'],
|
||||
['countryId' => 'HM', 'postcode' => '1234'],
|
||||
['countryId' => 'HN', 'postcode' => '12345'],
|
||||
['countryId' => 'HR', 'postcode' => '12345'],
|
||||
['countryId' => 'HT', 'postcode' => '1234'],
|
||||
['countryId' => 'HU', 'postcode' => '1234'],
|
||||
['countryId' => 'IC', 'postcode' => '12345'],
|
||||
['countryId' => 'ID', 'postcode' => '12345'],
|
||||
['countryId' => 'IL', 'postcode' => '1234567'],
|
||||
['countryId' => 'IM', 'postcode' => 'IM1 1AD'],
|
||||
['countryId' => 'IN', 'postcode' => '123456'],
|
||||
['countryId' => 'IS', 'postcode' => '123'],
|
||||
['countryId' => 'IT', 'postcode' => '12345'],
|
||||
['countryId' => 'JE', 'postcode' => 'JE2 4PJ'],
|
||||
['countryId' => 'JO', 'postcode' => '12345'],
|
||||
['countryId' => 'JP', 'postcode' => '123-4567'],
|
||||
['countryId' => 'JP', 'postcode' => '1234567'],
|
||||
['countryId' => 'KE', 'postcode' => '12345'],
|
||||
['countryId' => 'KG', 'postcode' => '123456'],
|
||||
['countryId' => 'KH', 'postcode' => '12345'],
|
||||
['countryId' => 'KR', 'postcode' => '123-456'],
|
||||
['countryId' => 'KW', 'postcode' => '12345'],
|
||||
['countryId' => 'KZ', 'postcode' => '123456'],
|
||||
['countryId' => 'LA', 'postcode' => '12345'],
|
||||
['countryId' => 'LB', 'postcode' => '1234 5678'],
|
||||
['countryId' => 'LI', 'postcode' => '1234'],
|
||||
['countryId' => 'LK', 'postcode' => '12345'],
|
||||
['countryId' => 'LT', 'postcode' => '12345'],
|
||||
['countryId' => 'LU', 'postcode' => '1234'],
|
||||
['countryId' => 'LV', 'postcode' => '1234'],
|
||||
['countryId' => 'MA', 'postcode' => '12345'],
|
||||
['countryId' => 'MC', 'postcode' => '12345'],
|
||||
['countryId' => 'ME', 'postcode' => '81101'],
|
||||
['countryId' => 'MD', 'postcode' => '1234'],
|
||||
['countryId' => 'MG', 'postcode' => '123'],
|
||||
['countryId' => 'MH', 'postcode' => '12345'],
|
||||
['countryId' => 'MK', 'postcode' => '1234'],
|
||||
['countryId' => 'MN', 'postcode' => '123456'],
|
||||
['countryId' => 'MP', 'postcode' => '12345'],
|
||||
['countryId' => 'MQ', 'postcode' => '12345'],
|
||||
['countryId' => 'MS', 'postcode' => 'MSR1250'],
|
||||
['countryId' => 'MT', 'postcode' => 'WRT 123'],
|
||||
['countryId' => 'MT', 'postcode' => 'WRT 45'],
|
||||
['countryId' => 'MU', 'postcode' => 'A1201'],
|
||||
['countryId' => 'MU', 'postcode' => '80110'],
|
||||
['countryId' => 'MV', 'postcode' => '12345'],
|
||||
['countryId' => 'MV', 'postcode' => '1234'],
|
||||
['countryId' => 'MX', 'postcode' => '12345'],
|
||||
['countryId' => 'MY', 'postcode' => '12345'],
|
||||
['countryId' => 'NC', 'postcode' => '98800'],
|
||||
['countryId' => 'NE', 'postcode' => '1234'],
|
||||
['countryId' => 'NF', 'postcode' => '2899'],
|
||||
['countryId' => 'NG', 'postcode' => '123456'],
|
||||
['countryId' => 'NI', 'postcode' => '22500'],
|
||||
['countryId' => 'NL', 'postcode' => '1234 TR'],
|
||||
['countryId' => 'NO', 'postcode' => '1234'],
|
||||
['countryId' => 'NP', 'postcode' => '12345'],
|
||||
['countryId' => 'NZ', 'postcode' => '1234'],
|
||||
['countryId' => 'OM', 'postcode' => 'PC 123'],
|
||||
['countryId' => 'PA', 'postcode' => '1234'],
|
||||
['countryId' => 'PF', 'postcode' => '98701'],
|
||||
['countryId' => 'PG', 'postcode' => '123'],
|
||||
['countryId' => 'PH', 'postcode' => '1234'],
|
||||
['countryId' => 'PK', 'postcode' => '12345'],
|
||||
['countryId' => 'PL', 'postcode' => '12-345'],
|
||||
['countryId' => 'PM', 'postcode' => '97500'],
|
||||
['countryId' => 'PN', 'postcode' => 'PCRN 1ZZ'],
|
||||
['countryId' => 'PR', 'postcode' => '12345'],
|
||||
['countryId' => 'PT', 'postcode' => '1234'],
|
||||
['countryId' => 'PT', 'postcode' => '1234-567'],
|
||||
['countryId' => 'PW', 'postcode' => '96939'],
|
||||
['countryId' => 'PW', 'postcode' => '96940'],
|
||||
['countryId' => 'PY', 'postcode' => '1234'],
|
||||
['countryId' => 'RE', 'postcode' => '12345'],
|
||||
['countryId' => 'RO', 'postcode' => '123456'],
|
||||
['countryId' => 'RU', 'postcode' => '123456'],
|
||||
['countryId' => 'SA', 'postcode' => '12345'],
|
||||
['countryId' => 'SE', 'postcode' => '123 45'],
|
||||
['countryId' => 'SG', 'postcode' => '123456'],
|
||||
['countryId' => 'SH', 'postcode' => 'ASCN 1ZZ'],
|
||||
['countryId' => 'SI', 'postcode' => '1234'],
|
||||
['countryId' => 'SJ', 'postcode' => '1234'],
|
||||
['countryId' => 'SK', 'postcode' => '123 45'],
|
||||
['countryId' => 'SM', 'postcode' => '47890'],
|
||||
['countryId' => 'SN', 'postcode' => '12345'],
|
||||
['countryId' => 'SO', 'postcode' => '12345'],
|
||||
['countryId' => 'SZ', 'postcode' => 'R123'],
|
||||
['countryId' => 'TC', 'postcode' => 'TKCA 1ZZ'],
|
||||
['countryId' => 'TH', 'postcode' => '12345'],
|
||||
['countryId' => 'TJ', 'postcode' => '123456'],
|
||||
['countryId' => 'TM', 'postcode' => '123456'],
|
||||
['countryId' => 'TN', 'postcode' => '1234'],
|
||||
['countryId' => 'TR', 'postcode' => '12345'],
|
||||
['countryId' => 'TT', 'postcode' => '120110'],
|
||||
['countryId' => 'TW', 'postcode' => '123'],
|
||||
['countryId' => 'TW', 'postcode' => '12345'],
|
||||
['countryId' => 'UA', 'postcode' => '02232'],
|
||||
['countryId' => 'US', 'postcode' => '12345-6789'],
|
||||
['countryId' => 'US', 'postcode' => '12345'],
|
||||
['countryId' => 'UY', 'postcode' => '12345'],
|
||||
['countryId' => 'UZ', 'postcode' => '123456'],
|
||||
['countryId' => 'VA', 'postcode' => '00120'],
|
||||
['countryId' => 'VE', 'postcode' => '1234'],
|
||||
['countryId' => 'VI', 'postcode' => '12345'],
|
||||
['countryId' => 'WF', 'postcode' => '98601'],
|
||||
['countryId' => 'XK', 'postcode' => '12345'],
|
||||
['countryId' => 'XY', 'postcode' => '12345'],
|
||||
['countryId' => 'YT', 'postcode' => '97601'],
|
||||
['countryId' => 'ZA', 'postcode' => '1234'],
|
||||
['countryId' => 'ZM', 'postcode' => '12345'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Directory\Model;
|
||||
|
||||
use Magento\Directory\Model\Currency as CurrencyModel;
|
||||
use Magento\Framework\App\Area;
|
||||
use Magento\Framework\App\Config\ConfigResource\ConfigInterface;
|
||||
use Magento\Framework\App\Config\ReinitableConfigInterface;
|
||||
use Magento\Store\Model\Store;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\App\State;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Provide tests for CurrencyConfig model.
|
||||
*/
|
||||
class CurrencyConfigTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $baseCurrencyPath = 'currency/options/base';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $defaultCurrencyPath = 'currency/options/default';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $allowedCurrenciesPath = 'currency/options/allow';
|
||||
|
||||
/**
|
||||
* @var ConfigInterface
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var CurrencyModel
|
||||
*/
|
||||
private $currency;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->currency = Bootstrap::getObjectManager()->get(CurrencyModel::class);
|
||||
$this->config = Bootstrap::getObjectManager()->get(ConfigInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get currency config for admin, crontab and storefront areas.
|
||||
*
|
||||
* @dataProvider getConfigCurrenciesDataProvider
|
||||
* @magentoDataFixture Magento/Store/_files/store.php
|
||||
* @magentoDbIsolation disabled
|
||||
* @param string $areaCode
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetConfigCurrencies(string $areaCode, array $expected)
|
||||
{
|
||||
/** @var State $appState */
|
||||
$appState = Bootstrap::getObjectManager()->get(State::class);
|
||||
$appState->setAreaCode($areaCode);
|
||||
$store = Bootstrap::getObjectManager()->get(Store::class);
|
||||
$store->load('test', 'code');
|
||||
$this->clearCurrencyConfig();
|
||||
$this->setStoreConfig($store->getId());
|
||||
$storeManager = Bootstrap::getObjectManager()->get(StoreManagerInterface::class);
|
||||
$storeManager->setCurrentStore($store->getId());
|
||||
|
||||
if (in_array($areaCode, [Area::AREA_ADMINHTML, Area::AREA_CRONTAB])) {
|
||||
self::assertEquals($expected['allowed'], $this->currency->getConfigAllowCurrencies());
|
||||
self::assertEquals($expected['base'], $this->currency->getConfigBaseCurrencies());
|
||||
self::assertEquals($expected['default'], $this->currency->getConfigDefaultCurrencies());
|
||||
} else {
|
||||
/** @var StoreManagerInterface $storeManager */
|
||||
$storeManager = Bootstrap::getObjectManager()->get(StoreManagerInterface::class);
|
||||
foreach ($storeManager->getStores() as $store) {
|
||||
$storeManager->setCurrentStore($store->getId());
|
||||
self::assertEquals(
|
||||
$expected[$store->getCode()]['allowed'],
|
||||
$this->currency->getConfigAllowCurrencies()
|
||||
);
|
||||
self::assertEquals(
|
||||
$expected[$store->getCode()]['base'],
|
||||
$this->currency->getConfigBaseCurrencies()
|
||||
);
|
||||
self::assertEquals(
|
||||
$expected[$store->getCode()]['default'],
|
||||
$this->currency->getConfigDefaultCurrencies()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide test data for getConfigCurrencies test.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getConfigCurrenciesDataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'areaCode' => Area::AREA_ADMINHTML,
|
||||
'expected' => [
|
||||
'allowed' => ['BDT', 'BNS', 'BTD', 'EUR', 'USD'],
|
||||
'base' => ['BDT', 'USD'],
|
||||
'default' => ['BDT', 'USD'],
|
||||
],
|
||||
],
|
||||
[
|
||||
'areaCode' => Area::AREA_CRONTAB,
|
||||
'expected' => [
|
||||
'allowed' => ['BDT', 'BNS', 'BTD', 'EUR', 'USD'],
|
||||
'base' => ['BDT', 'USD'],
|
||||
'default' => ['BDT', 'USD'],
|
||||
],
|
||||
],
|
||||
[
|
||||
'areaCode' => Area::AREA_FRONTEND,
|
||||
'expected' => [
|
||||
'default' => [
|
||||
'allowed' => ['EUR', 'USD'],
|
||||
'base' => ['USD'],
|
||||
'default' => ['USD'],
|
||||
],
|
||||
'test' => [
|
||||
'allowed' => ['BDT', 'BNS', 'BTD', 'USD'],
|
||||
'base' => ['BDT'],
|
||||
'default' => ['BDT'],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove currency config form Db.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function clearCurrencyConfig()
|
||||
{
|
||||
$storeManager = Bootstrap::getObjectManager()->get(StoreManagerInterface::class);
|
||||
foreach ($storeManager->getStores() as $store) {
|
||||
$this->config->deleteConfig(
|
||||
$this->allowedCurrenciesPath,
|
||||
'stores',
|
||||
$store->getId()
|
||||
);
|
||||
$this->config->deleteConfig(
|
||||
$this->baseCurrencyPath,
|
||||
'stores',
|
||||
$store->getId()
|
||||
);
|
||||
$this->config->deleteConfig(
|
||||
$this->defaultCurrencyPath,
|
||||
'stores',
|
||||
$store->getId()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set allowed, base and default currency config values for given store.
|
||||
*
|
||||
* @param string $storeId
|
||||
* @return void
|
||||
*/
|
||||
private function setStoreConfig(string $storeId)
|
||||
{
|
||||
$allowedCurrencies = 'BDT,BNS,BTD';
|
||||
$baseCurrency = 'BDT';
|
||||
$this->config->saveConfig(
|
||||
$this->baseCurrencyPath,
|
||||
$baseCurrency,
|
||||
'stores',
|
||||
$storeId
|
||||
);
|
||||
$this->config->saveConfig(
|
||||
$this->defaultCurrencyPath,
|
||||
$baseCurrency,
|
||||
'stores',
|
||||
$storeId
|
||||
);
|
||||
$this->config->saveConfig(
|
||||
$this->allowedCurrenciesPath,
|
||||
$allowedCurrencies,
|
||||
'stores',
|
||||
$storeId
|
||||
);
|
||||
Bootstrap::getObjectManager()->get(ReinitableConfigInterface::class)->reinit();
|
||||
Bootstrap::getObjectManager()->create(StoreManagerInterface::class)->reinitStores();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->clearCurrencyConfig();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Directory\Model;
|
||||
|
||||
use Magento\Directory\Model\ResourceModel\Region\CollectionFactory as RegionCollectionFactory;
|
||||
use Magento\Directory\Setup\Patch\Data\UpdateRegionNamesForSwitzerland as SwitzerlandRegionData;
|
||||
use Magento\Framework\AppInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use SebastianBergmann\RecursionContext\InvalidArgumentException;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
|
||||
class RegionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Country
|
||||
*/
|
||||
private $country;
|
||||
|
||||
/**
|
||||
* @var RegionCollectionFactory
|
||||
*/
|
||||
private $regionCollectionFactory;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->country = Bootstrap::getObjectManager()->create(Country::class);
|
||||
$this->regionCollectionFactory = Bootstrap::getObjectManager()->create(RegionCollectionFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify country has regions.
|
||||
*
|
||||
* @param string $countryId
|
||||
* @dataProvider getCountryIdDataProvider
|
||||
*
|
||||
* @throws ExpectationFailedException
|
||||
* @throws InvalidArgumentException
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function testCountryHasRegions(string $countryId): void
|
||||
{
|
||||
$country = $this->country->loadByCode($countryId);
|
||||
$region = $country->getRegions()->getItems();
|
||||
|
||||
$this->assertNotEmpty($region, 'Country ' . $countryId . ' not have regions');
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testCountryHasRegions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCountryIdDataProvider(): array
|
||||
{
|
||||
return [
|
||||
['countryId' => 'US'],
|
||||
['countryId' => 'CA'],
|
||||
['countryId' => 'CN'],
|
||||
['countryId' => 'IN'],
|
||||
['countryId' => 'AU'],
|
||||
['countryId' => 'BE'],
|
||||
['countryId' => 'CO'],
|
||||
['countryId' => 'MX'],
|
||||
['countryId' => 'PL'],
|
||||
['countryId' => 'IT'],
|
||||
['countryId' => 'BG'],
|
||||
['countryId' => 'AR'],
|
||||
['countryId' => 'BO'],
|
||||
['countryId' => 'CL'],
|
||||
['countryId' => 'EC'],
|
||||
['countryId' => 'GY'],
|
||||
['countryId' => 'PY'],
|
||||
['countryId' => 'PE'],
|
||||
['countryId' => 'SR'],
|
||||
['countryId' => 'VE'],
|
||||
['countryId' => 'PT'],
|
||||
['countryId' => 'IS'],
|
||||
['countryId' => 'SE'],
|
||||
['countryId' => 'GR'],
|
||||
['countryId' => 'DK'],
|
||||
['countryId' => 'AL'],
|
||||
['countryId' => 'BY'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify updated Switzerland regions
|
||||
*
|
||||
* @throws ExpectationFailedException
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function testUpdatedSwitzerlandRegions(): void
|
||||
{
|
||||
$regionCollection = $this->regionCollectionFactory->create();
|
||||
$regionCollection->addCountryFilter(SwitzerlandRegionData::SWITZERLAND_COUNTRY_CODE);
|
||||
$regionCollection->addRegionCodeFilter(
|
||||
array_keys(SwitzerlandRegionData::SWITZERLAND_COUNTRY_REGION_DATA_TO_UPDATE)
|
||||
);
|
||||
$regionCollection->addBindParam(':region_locale', AppInterface::DISTRO_LOCALE_CODE);
|
||||
foreach ($regionCollection->getItems() as $regionItem) {
|
||||
$code = $regionItem->getData('code');
|
||||
$expectRegionName = SwitzerlandRegionData::SWITZERLAND_COUNTRY_REGION_DATA_TO_UPDATE[$code] ?? null;
|
||||
$this->assertEquals($expectRegionName, $regionItem->getData('default_name'));
|
||||
$this->assertEquals($expectRegionName, $regionItem->getData('name'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user