-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-7113: Add Italy States #27116
- Loading branch information
Showing
2 changed files
with
259 additions
and
0 deletions.
There are no files selected for viewing
196 changes: 196 additions & 0 deletions
196
app/code/Magento/Directory/Setup/Patch/Data/AddDataForItaly.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Directory\Setup\Patch\Data; | ||
|
||
use Magento\Directory\Setup\DataInstaller; | ||
use Magento\Directory\Setup\DataInstallerFactory; | ||
use Magento\Framework\Setup\ModuleDataSetupInterface; | ||
use Magento\Framework\Setup\Patch\DataPatchInterface; | ||
|
||
/** | ||
* Add Italy States | ||
*/ | ||
class AddDataForItaly implements DataPatchInterface | ||
{ | ||
/** | ||
* @var ModuleDataSetupInterface | ||
*/ | ||
private $moduleDataSetup; | ||
|
||
/** | ||
* @var DataInstallerFactory | ||
*/ | ||
private $dataInstallerFactory; | ||
|
||
/** | ||
* @param ModuleDataSetupInterface $moduleDataSetup | ||
* @param DataInstallerFactory $dataInstallerFactory | ||
*/ | ||
public function __construct( | ||
ModuleDataSetupInterface $moduleDataSetup, | ||
DataInstallerFactory $dataInstallerFactory | ||
) { | ||
$this->moduleDataSetup = $moduleDataSetup; | ||
$this->dataInstallerFactory = $dataInstallerFactory; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function apply() | ||
{ | ||
/** @var DataInstaller $dataInstaller */ | ||
$dataInstaller = $this->dataInstallerFactory->create(); | ||
$dataInstaller->addCountryRegions( | ||
$this->moduleDataSetup->getConnection(), | ||
$this->getDataForItaly() | ||
); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Italy states data. | ||
* | ||
* @return array | ||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) | ||
*/ | ||
private function getDataForItaly() | ||
{ | ||
return [ | ||
['IT', 'AG', 'Agrigento'], | ||
['IT', 'AL', 'Alessandria'], | ||
['IT', 'AN', 'Ancona'], | ||
['IT', 'AO', 'Aosta'], | ||
['IT', 'AQ', 'L\'Aquila'], | ||
['IT', 'AR', 'Arezzo'], | ||
['IT', 'AP', 'Ascoli-Piceno'], | ||
['IT', 'AT', 'Asti'], | ||
['IT', 'AV', 'Avellino'], | ||
['IT', 'BA', 'Bari'], | ||
['IT', 'BT', 'Barletta-Andria-Trani'], | ||
['IT', 'BL', 'Belluno'], | ||
['IT', 'BN', 'Benevento'], | ||
['IT', 'BG', 'Bergamo'], | ||
['IT', 'BI', 'Biella'], | ||
['IT', 'BO', 'Bologna'], | ||
['IT', 'BZ', 'Bolzano'], | ||
['IT', 'BS', 'Brescia'], | ||
['IT', 'BR', 'Brindisi'], | ||
['IT', 'CA', 'Cagliari'], | ||
['IT', 'CL', 'Caltanissetta'], | ||
['IT', 'CB', 'Campobasso'], | ||
['IT', 'CI', 'Carbonia Iglesias'], | ||
['IT', 'CE', 'Caserta'], | ||
['IT', 'CT', 'Catania'], | ||
['IT', 'CZ', 'Catanzaro'], | ||
['IT', 'CH', 'Chieti'], | ||
['IT', 'CO', 'Como'], | ||
['IT', 'CS', 'Cosenza'], | ||
['IT', 'CR', 'Cremona'], | ||
['IT', 'KR', 'Crotone'], | ||
['IT', 'CN', 'Cuneo'], | ||
['IT', 'EN', 'Enna'], | ||
['IT', 'FM', 'Fermo'], | ||
['IT', 'FE', 'Ferrara'], | ||
['IT', 'FI', 'Firenze'], | ||
['IT', 'FG', 'Foggia'], | ||
['IT', 'FC', 'Forli-Cesena'], | ||
['IT', 'FR', 'Frosinone'], | ||
['IT', 'GE', 'Genova'], | ||
['IT', 'GO', 'Gorizia'], | ||
['IT', 'GR', 'Grosseto'], | ||
['IT', 'IM', 'Imperia'], | ||
['IT', 'IS', 'Isernia'], | ||
['IT', 'SP', 'La-Spezia'], | ||
['IT', 'LT', 'Latina'], | ||
['IT', 'LE', 'Lecce'], | ||
['IT', 'LC', 'Lecco'], | ||
['IT', 'LI', 'Livorno'], | ||
['IT', 'LO', 'Lodi'], | ||
['IT', 'LU', 'Lucca'], | ||
['IT', 'MC', 'Macerata'], | ||
['IT', 'MN', 'Mantova'], | ||
['IT', 'MS', 'Massa-Carrara'], | ||
['IT', 'MT', 'Matera'], | ||
['IT', 'VS', 'Medio Campidano'], | ||
['IT', 'ME', 'Messina'], | ||
['IT', 'MI', 'Milano'], | ||
['IT', 'MO', 'Modena'], | ||
['IT', 'MB', 'Monza-Brianza'], | ||
['IT', 'NA', 'Napoli'], | ||
['IT', 'NO', 'Novara'], | ||
['IT', 'NU', 'Nuoro'], | ||
['IT', 'OG', 'Ogliastra'], | ||
['IT', 'OT', 'Olbia Tempio'], | ||
['IT', 'OR', 'Oristano'], | ||
['IT', 'PD', 'Padova'], | ||
['IT', 'PA', 'Palermo'], | ||
['IT', 'PR', 'Parma'], | ||
['IT', 'PV', 'Pavia'], | ||
['IT', 'PG', 'Perugia'], | ||
['IT', 'PU', 'Pesaro-Urbino'], | ||
['IT', 'PE', 'Pescara'], | ||
['IT', 'PC', 'Piacenza'], | ||
['IT', 'PI', 'Pisa'], | ||
['IT', 'PT', 'Pistoia'], | ||
['IT', 'PN', 'Pordenone'], | ||
['IT', 'PZ', 'Potenza'], | ||
['IT', 'PO', 'Prato'], | ||
['IT', 'RG', 'Ragusa'], | ||
['IT', 'RA', 'Ravenna'], | ||
['IT', 'RC', 'Reggio-Calabria'], | ||
['IT', 'RE', 'Reggio-Emilia'], | ||
['IT', 'RI', 'Rieti'], | ||
['IT', 'RN', 'Rimini'], | ||
['IT', 'RM', 'Roma'], | ||
['IT', 'RO', 'Rovigo'], | ||
['IT', 'SA', 'Salerno'], | ||
['IT', 'SS', 'Sassari'], | ||
['IT', 'SV', 'Savona'], | ||
['IT', 'SI', 'Siena'], | ||
['IT', 'SR', 'Siracusa'], | ||
['IT', 'SO', 'Sondrio'], | ||
['IT', 'TA', 'Taranto'], | ||
['IT', 'TE', 'Teramo'], | ||
['IT', 'TR', 'Terni'], | ||
['IT', 'TO', 'Torino'], | ||
['IT', 'TP', 'Trapani'], | ||
['IT', 'TN', 'Trento'], | ||
['IT', 'TV', 'Treviso'], | ||
['IT', 'TS', 'Trieste'], | ||
['IT', 'UD', 'Udine'], | ||
['IT', 'VA', 'Varese'], | ||
['IT', 'VE', 'Venezia'], | ||
['IT', 'VB', 'Verbania'], | ||
['IT', 'VC', 'Vercelli'], | ||
['IT', 'VR', 'Verona'], | ||
['IT', 'VV', 'Vibo-Valentia'], | ||
['IT', 'VI', 'Vicenza'], | ||
['IT', 'VT', 'Viterbo'], | ||
]; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public static function getDependencies() | ||
{ | ||
return [ | ||
InitializeDirectoryData::class, | ||
]; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getAliases() | ||
{ | ||
return []; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
dev/tests/integration/testsuite/Magento/Directory/Model/RegionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Directory\Model\Country\Postcode\Config; | ||
|
||
use Magento\Directory\Model\Country; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class RegionTest extends TestCase | ||
{ | ||
/** | ||
* @var Country | ||
*/ | ||
protected $country; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function setUp() | ||
{ | ||
$this->country = Bootstrap::getObjectManager()->create(Country::class); | ||
} | ||
|
||
/** | ||
* Verify country has regions. | ||
* | ||
* @var string $countryId | ||
* @dataProvider getCountryIdDataProvider | ||
*/ | ||
public function testCountryHasRegions($countryId) | ||
{ | ||
$country = $this->country->loadByCode($countryId); | ||
$region = $country->getRegions()->getItems(); | ||
|
||
$this->assertTrue(!empty($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'] | ||
]; | ||
} | ||
} |