Skip to content

Commit 9fff19a

Browse files
committed
Merge remote-tracking branch 'origin/origin/AC-2564-fix-get-region-data' into AC-2425-update-elasticsearch-7.17
2 parents 4d3ad50 + 1a8d30d commit 9fff19a

File tree

2 files changed

+100
-33
lines changed

2 files changed

+100
-33
lines changed

app/code/Magento/Directory/Helper/Data.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,36 @@ class Data extends AbstractHelper
3333
/**
3434
* Config value that lists ISO2 country codes which have optional Zip/Postal pre-configured
3535
*/
36-
const OPTIONAL_ZIP_COUNTRIES_CONFIG_PATH = 'general/country/optional_zip_countries';
36+
public const OPTIONAL_ZIP_COUNTRIES_CONFIG_PATH = 'general/country/optional_zip_countries';
3737

3838
/*
3939
* Path to config value, which lists countries, for which state is required.
4040
*/
41-
const XML_PATH_STATES_REQUIRED = 'general/region/state_required';
41+
public const XML_PATH_STATES_REQUIRED = 'general/region/state_required';
4242

4343
/*
4444
* Path to config value, which detects whether or not display the state for the country, if it is not required
4545
*/
46-
const XML_PATH_DISPLAY_ALL_STATES = 'general/region/display_all';
46+
public const XML_PATH_DISPLAY_ALL_STATES = 'general/region/display_all';
4747

4848
/**#@+
4949
* Path to config value, which is default country
5050
*/
51-
const XML_PATH_DEFAULT_COUNTRY = 'general/country/default';
52-
const XML_PATH_DEFAULT_LOCALE = 'general/locale/code';
53-
const XML_PATH_DEFAULT_TIMEZONE = 'general/locale/timezone';
51+
public const XML_PATH_DEFAULT_COUNTRY = 'general/country/default';
52+
public const XML_PATH_DEFAULT_LOCALE = 'general/locale/code';
53+
public const XML_PATH_DEFAULT_TIMEZONE = 'general/locale/timezone';
5454
/**#@-*/
5555

5656
/**
5757
* Path to config value that contains codes of the most used countries.
5858
* Such countries can be shown on the top of the country list.
5959
*/
60-
const XML_PATH_TOP_COUNTRIES = 'general/country/destinations';
60+
public const XML_PATH_TOP_COUNTRIES = 'general/country/destinations';
6161

6262
/**
6363
* Path to config value that contains weight unit
6464
*/
65-
const XML_PATH_WEIGHT_UNIT = 'general/locale/weight_unit';
65+
public const XML_PATH_WEIGHT_UNIT = 'general/locale/weight_unit';
6666

6767
/**
6868
* @var Collection
@@ -348,7 +348,7 @@ public function getRegionData()
348348
AllowedCountries::ALLOWED_COUNTRIES_PATH,
349349
$scope['type'],
350350
$scope['value']
351-
);
351+
) ?? '';
352352
$countryIds = explode(',', $allowedCountries);
353353
$collection = $this->_regCollectionFactory->create();
354354
$collection->addCountryFilter($countryIds)->load();

app/code/Magento/Directory/Test/Unit/Helper/DataTest.php

Lines changed: 91 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Framework\App\Helper\Context;
1919
use Magento\Framework\App\RequestInterface;
2020
use Magento\Framework\DataObject;
21+
use Magento\Framework\Exception\NoSuchEntityException;
2122
use Magento\Framework\Json\Helper\Data as JsonDataHelper;
2223
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
2324
use Magento\Store\Model\ScopeInterface;
@@ -111,39 +112,45 @@ protected function setUp(): void
111112
$this->_object = $objectManager->getObject(Data::class, $arguments);
112113
}
113114

114-
public function testGetRegionJson()
115-
{
115+
/**
116+
* @param string|null $configValue
117+
* @param array $countryIds
118+
* @param array $regionList
119+
* @param array $expectedDataToEncode
120+
*
121+
* @throws NoSuchEntityException
122+
* @dataProvider getRegionJsonDataProvider
123+
*/
124+
public function testGetRegionJson(
125+
?string $configValue,
126+
array $countryIds,
127+
array $regionList,
128+
array $expectedDataToEncode
129+
) {
116130
$this->scopeConfigMock->method('getValue')
117131
->willReturnMap(
118132
[
119133
[
120134
AllowedCountries::ALLOWED_COUNTRIES_PATH,
121135
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
122136
null,
123-
'Country1,Country2'
137+
$configValue
124138
],
125139
[Data::XML_PATH_STATES_REQUIRED, ScopeInterface::SCOPE_STORE, null, '']
126140
]
127141
);
128-
$regions = [
129-
new DataObject(
130-
['country_id' => 'Country1', 'region_id' => 'r1', 'code' => 'r1-code', 'name' => 'r1-name']
131-
),
132-
new DataObject(
133-
['country_id' => 'Country1', 'region_id' => 'r2', 'code' => 'r2-code', 'name' => 'r2-name']
134-
),
135-
new DataObject(
136-
['country_id' => 'Country2', 'region_id' => 'r3', 'code' => 'r3-code', 'name' => 'r3-name']
137-
)
138-
];
142+
$regions = [];
143+
foreach ($regionList as $region) {
144+
$regions[] = new DataObject($region);
145+
}
139146
$regionIterator = new \ArrayIterator($regions);
140147

141148
$this->_regionCollection->expects(
142149
$this->once()
143150
)->method(
144151
'addCountryFilter'
145152
)->with(
146-
['Country1', 'Country2']
153+
$countryIds
147154
)->willReturnSelf();
148155
$this->_regionCollection->expects($this->once())->method('load');
149156
$this->_regionCollection->expects(
@@ -153,15 +160,6 @@ public function testGetRegionJson()
153160
)->willReturn(
154161
$regionIterator
155162
);
156-
157-
$expectedDataToEncode = [
158-
'config' => ['show_all_regions' => false, 'regions_required' => []],
159-
'Country1' => [
160-
'r1' => ['code' => 'r1-code', 'name' => 'r1-name'],
161-
'r2' => ['code' => 'r2-code', 'name' => 'r2-name']
162-
],
163-
'Country2' => ['r3' => ['code' => 'r3-code', 'name' => 'r3-name']]
164-
];
165163
$this->jsonHelperMock->expects(
166164
$this->once()
167165
)->method(
@@ -177,6 +175,75 @@ public function testGetRegionJson()
177175
$this->assertEquals('encoded_json', $result);
178176
}
179177

178+
/**
179+
* @return array
180+
*/
181+
public function getRegionJsonDataProvider(): array
182+
{
183+
return [
184+
[
185+
'Country1,Country2',
186+
[
187+
'Country1',
188+
'Country2',
189+
],
190+
[
191+
[
192+
'country_id' => 'Country1',
193+
'region_id' => 'r1',
194+
'code' => 'r1-code',
195+
'name' => 'r1-name',
196+
],
197+
[
198+
'country_id' => 'Country1',
199+
'region_id' => 'r2',
200+
'code' => 'r2-code',
201+
'name' => 'r2-name',
202+
],
203+
[
204+
'country_id' => 'Country2',
205+
'region_id' => 'r3',
206+
'code' => 'r3-code',
207+
'name' => 'r3-name',
208+
],
209+
],
210+
[
211+
'config' => [
212+
'show_all_regions' => false,
213+
'regions_required' => [],
214+
],
215+
'Country1' => [
216+
'r1' => [
217+
'code' => 'r1-code',
218+
'name' => 'r1-name',
219+
],
220+
'r2' => [
221+
'code' => 'r2-code',
222+
'name' => 'r2-name',
223+
],
224+
],
225+
'Country2' => [
226+
'r3' => [
227+
'code' => 'r3-code',
228+
'name' => 'r3-name',
229+
]
230+
],
231+
],
232+
],
233+
[
234+
null,
235+
[''],
236+
[],
237+
[
238+
'config' => [
239+
'show_all_regions' => false,
240+
'regions_required' => [],
241+
],
242+
],
243+
],
244+
];
245+
}
246+
180247
/**
181248
* @param string $configValue
182249
* @param mixed $expected

0 commit comments

Comments
 (0)