Skip to content

Commit 92508ae

Browse files
authored
ENGCOM-7113: Add Italy States #27116
2 parents dbf9748 + 9624ae2 commit 92508ae

File tree

2 files changed

+259
-0
lines changed

2 files changed

+259
-0
lines changed
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Directory\Setup\Patch\Data;
9+
10+
use Magento\Directory\Setup\DataInstaller;
11+
use Magento\Directory\Setup\DataInstallerFactory;
12+
use Magento\Framework\Setup\ModuleDataSetupInterface;
13+
use Magento\Framework\Setup\Patch\DataPatchInterface;
14+
15+
/**
16+
* Add Italy States
17+
*/
18+
class AddDataForItaly implements DataPatchInterface
19+
{
20+
/**
21+
* @var ModuleDataSetupInterface
22+
*/
23+
private $moduleDataSetup;
24+
25+
/**
26+
* @var DataInstallerFactory
27+
*/
28+
private $dataInstallerFactory;
29+
30+
/**
31+
* @param ModuleDataSetupInterface $moduleDataSetup
32+
* @param DataInstallerFactory $dataInstallerFactory
33+
*/
34+
public function __construct(
35+
ModuleDataSetupInterface $moduleDataSetup,
36+
DataInstallerFactory $dataInstallerFactory
37+
) {
38+
$this->moduleDataSetup = $moduleDataSetup;
39+
$this->dataInstallerFactory = $dataInstallerFactory;
40+
}
41+
42+
/**
43+
* @inheritdoc
44+
*/
45+
public function apply()
46+
{
47+
/** @var DataInstaller $dataInstaller */
48+
$dataInstaller = $this->dataInstallerFactory->create();
49+
$dataInstaller->addCountryRegions(
50+
$this->moduleDataSetup->getConnection(),
51+
$this->getDataForItaly()
52+
);
53+
54+
return $this;
55+
}
56+
57+
/**
58+
* Italy states data.
59+
*
60+
* @return array
61+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
62+
*/
63+
private function getDataForItaly()
64+
{
65+
return [
66+
['IT', 'AG', 'Agrigento'],
67+
['IT', 'AL', 'Alessandria'],
68+
['IT', 'AN', 'Ancona'],
69+
['IT', 'AO', 'Aosta'],
70+
['IT', 'AQ', 'L\'Aquila'],
71+
['IT', 'AR', 'Arezzo'],
72+
['IT', 'AP', 'Ascoli-Piceno'],
73+
['IT', 'AT', 'Asti'],
74+
['IT', 'AV', 'Avellino'],
75+
['IT', 'BA', 'Bari'],
76+
['IT', 'BT', 'Barletta-Andria-Trani'],
77+
['IT', 'BL', 'Belluno'],
78+
['IT', 'BN', 'Benevento'],
79+
['IT', 'BG', 'Bergamo'],
80+
['IT', 'BI', 'Biella'],
81+
['IT', 'BO', 'Bologna'],
82+
['IT', 'BZ', 'Bolzano'],
83+
['IT', 'BS', 'Brescia'],
84+
['IT', 'BR', 'Brindisi'],
85+
['IT', 'CA', 'Cagliari'],
86+
['IT', 'CL', 'Caltanissetta'],
87+
['IT', 'CB', 'Campobasso'],
88+
['IT', 'CI', 'Carbonia Iglesias'],
89+
['IT', 'CE', 'Caserta'],
90+
['IT', 'CT', 'Catania'],
91+
['IT', 'CZ', 'Catanzaro'],
92+
['IT', 'CH', 'Chieti'],
93+
['IT', 'CO', 'Como'],
94+
['IT', 'CS', 'Cosenza'],
95+
['IT', 'CR', 'Cremona'],
96+
['IT', 'KR', 'Crotone'],
97+
['IT', 'CN', 'Cuneo'],
98+
['IT', 'EN', 'Enna'],
99+
['IT', 'FM', 'Fermo'],
100+
['IT', 'FE', 'Ferrara'],
101+
['IT', 'FI', 'Firenze'],
102+
['IT', 'FG', 'Foggia'],
103+
['IT', 'FC', 'Forli-Cesena'],
104+
['IT', 'FR', 'Frosinone'],
105+
['IT', 'GE', 'Genova'],
106+
['IT', 'GO', 'Gorizia'],
107+
['IT', 'GR', 'Grosseto'],
108+
['IT', 'IM', 'Imperia'],
109+
['IT', 'IS', 'Isernia'],
110+
['IT', 'SP', 'La-Spezia'],
111+
['IT', 'LT', 'Latina'],
112+
['IT', 'LE', 'Lecce'],
113+
['IT', 'LC', 'Lecco'],
114+
['IT', 'LI', 'Livorno'],
115+
['IT', 'LO', 'Lodi'],
116+
['IT', 'LU', 'Lucca'],
117+
['IT', 'MC', 'Macerata'],
118+
['IT', 'MN', 'Mantova'],
119+
['IT', 'MS', 'Massa-Carrara'],
120+
['IT', 'MT', 'Matera'],
121+
['IT', 'VS', 'Medio Campidano'],
122+
['IT', 'ME', 'Messina'],
123+
['IT', 'MI', 'Milano'],
124+
['IT', 'MO', 'Modena'],
125+
['IT', 'MB', 'Monza-Brianza'],
126+
['IT', 'NA', 'Napoli'],
127+
['IT', 'NO', 'Novara'],
128+
['IT', 'NU', 'Nuoro'],
129+
['IT', 'OG', 'Ogliastra'],
130+
['IT', 'OT', 'Olbia Tempio'],
131+
['IT', 'OR', 'Oristano'],
132+
['IT', 'PD', 'Padova'],
133+
['IT', 'PA', 'Palermo'],
134+
['IT', 'PR', 'Parma'],
135+
['IT', 'PV', 'Pavia'],
136+
['IT', 'PG', 'Perugia'],
137+
['IT', 'PU', 'Pesaro-Urbino'],
138+
['IT', 'PE', 'Pescara'],
139+
['IT', 'PC', 'Piacenza'],
140+
['IT', 'PI', 'Pisa'],
141+
['IT', 'PT', 'Pistoia'],
142+
['IT', 'PN', 'Pordenone'],
143+
['IT', 'PZ', 'Potenza'],
144+
['IT', 'PO', 'Prato'],
145+
['IT', 'RG', 'Ragusa'],
146+
['IT', 'RA', 'Ravenna'],
147+
['IT', 'RC', 'Reggio-Calabria'],
148+
['IT', 'RE', 'Reggio-Emilia'],
149+
['IT', 'RI', 'Rieti'],
150+
['IT', 'RN', 'Rimini'],
151+
['IT', 'RM', 'Roma'],
152+
['IT', 'RO', 'Rovigo'],
153+
['IT', 'SA', 'Salerno'],
154+
['IT', 'SS', 'Sassari'],
155+
['IT', 'SV', 'Savona'],
156+
['IT', 'SI', 'Siena'],
157+
['IT', 'SR', 'Siracusa'],
158+
['IT', 'SO', 'Sondrio'],
159+
['IT', 'TA', 'Taranto'],
160+
['IT', 'TE', 'Teramo'],
161+
['IT', 'TR', 'Terni'],
162+
['IT', 'TO', 'Torino'],
163+
['IT', 'TP', 'Trapani'],
164+
['IT', 'TN', 'Trento'],
165+
['IT', 'TV', 'Treviso'],
166+
['IT', 'TS', 'Trieste'],
167+
['IT', 'UD', 'Udine'],
168+
['IT', 'VA', 'Varese'],
169+
['IT', 'VE', 'Venezia'],
170+
['IT', 'VB', 'Verbania'],
171+
['IT', 'VC', 'Vercelli'],
172+
['IT', 'VR', 'Verona'],
173+
['IT', 'VV', 'Vibo-Valentia'],
174+
['IT', 'VI', 'Vicenza'],
175+
['IT', 'VT', 'Viterbo'],
176+
];
177+
}
178+
179+
/**
180+
* @inheritdoc
181+
*/
182+
public static function getDependencies()
183+
{
184+
return [
185+
InitializeDirectoryData::class,
186+
];
187+
}
188+
189+
/**
190+
* @inheritdoc
191+
*/
192+
public function getAliases()
193+
{
194+
return [];
195+
}
196+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Directory\Model\Country\Postcode\Config;
9+
10+
use Magento\Directory\Model\Country;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
use PHPUnit\Framework\TestCase;
13+
14+
class RegionTest extends TestCase
15+
{
16+
/**
17+
* @var Country
18+
*/
19+
protected $country;
20+
21+
/**
22+
* @inheritDoc
23+
*/
24+
public function setUp()
25+
{
26+
$this->country = Bootstrap::getObjectManager()->create(Country::class);
27+
}
28+
29+
/**
30+
* Verify country has regions.
31+
*
32+
* @var string $countryId
33+
* @dataProvider getCountryIdDataProvider
34+
*/
35+
public function testCountryHasRegions($countryId)
36+
{
37+
$country = $this->country->loadByCode($countryId);
38+
$region = $country->getRegions()->getItems();
39+
40+
$this->assertTrue(!empty($region), 'Country ' . $countryId . ' not have regions');
41+
}
42+
43+
/**
44+
* Data provider for testCountryHasRegions
45+
*
46+
* @return array
47+
*/
48+
public function getCountryIdDataProvider():array
49+
{
50+
return [
51+
['countryId' => 'US'],
52+
['countryId' => 'CA'],
53+
['countryId' => 'CN'],
54+
['countryId' => 'IN'],
55+
['countryId' => 'AU'],
56+
['countryId' => 'BE'],
57+
['countryId' => 'CO'],
58+
['countryId' => 'MX'],
59+
['countryId' => 'PL'],
60+
['countryId' => 'IT']
61+
];
62+
}
63+
}

0 commit comments

Comments
 (0)