13 class DataTest extends \PHPUnit\Framework\TestCase
47 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
48 $this->scopeConfigMock = $this->createMock(\
Magento\Framework\
App\Config\ScopeConfigInterface::class);
49 $context = $this->createMock(\
Magento\Framework\
App\Helper\Context::class);
50 $context->expects($this->any())
51 ->method(
'getScopeConfig')
52 ->willReturn($this->scopeConfigMock);
54 $configCacheType = $this->createMock(\
Magento\Framework\
App\Cache\Type\Config::class);
56 $this->_countryCollection = $this->createMock(\
Magento\Directory\Model\
ResourceModel\Country\Collection::class);
58 $this->_regionCollection = $this->createMock(\
Magento\Directory\Model\
ResourceModel\Region\Collection::class);
59 $regCollectionFactory = $this->createPartialMock(
63 $regCollectionFactory->expects(
68 $this->returnValue($this->_regionCollection)
71 $this->jsonHelperMock = $this->createMock(\
Magento\Framework\Json\Helper\Data::class);
73 $this->_store = $this->createMock(\
Magento\Store\Model\Store::class);
75 $storeManager->expects($this->any())->method(
'getStore')->will($this->returnValue($this->_store));
77 $currencyFactory = $this->createMock(\
Magento\Directory\Model\CurrencyFactory::class);
80 'context' => $context,
81 'configCacheType' => $configCacheType,
83 'regCollectionFactory' => $regCollectionFactory,
86 'currencyFactory' => $currencyFactory,
94 new \Magento\Framework\DataObject([
'country_id' =>
'Country1']),
95 new \Magento\Framework\DataObject([
'country_id' =>
'Country2'])
97 $countryIterator = new \ArrayIterator($countries);
98 $this->_countryCollection->expects(
103 $this->returnValue($countryIterator)
107 new \Magento\Framework\DataObject(
108 [
'country_id' =>
'Country1',
'region_id' =>
'r1',
'code' =>
'r1-code',
'name' =>
'r1-name']
110 new \Magento\Framework\DataObject(
111 [
'country_id' =>
'Country1',
'region_id' =>
'r2',
'code' =>
'r2-code',
'name' =>
'r2-name']
113 new \Magento\Framework\DataObject(
114 [
'country_id' =>
'Country2',
'region_id' =>
'r3',
'code' =>
'r3-code',
'name' =>
'r3-name']
117 $regionIterator = new \ArrayIterator($regions);
119 $this->_regionCollection->expects(
124 [
'Country1',
'Country2']
128 $this->_regionCollection->expects($this->once())->method(
'load');
129 $this->_regionCollection->expects(
134 $this->returnValue($regionIterator)
137 $expectedDataToEncode = [
138 'config' => [
'show_all_regions' =>
false,
'regions_required' => []],
140 'r1' => [
'code' =>
'r1-code',
'name' =>
'r1-name'],
141 'r2' => [
'code' =>
'r2-code',
'name' =>
'r2-name']
143 'Country2' => [
'r3' => [
'code' =>
'r3-code',
'name' =>
'r3-name']]
145 $this->jsonHelperMock->expects(
150 new \PHPUnit\Framework\Constraint\IsIdentical($expectedDataToEncode)
152 $this->returnValue(
'encoded_json')
156 $result = $this->_object->getRegionJson();
157 $this->assertEquals(
'encoded_json',
$result);
167 $this->scopeConfigMock->expects(
172 'general/region/state_required' 174 $this->returnValue($configValue)
177 $result = $this->_object->getCountriesWithStatesRequired();
178 $this->assertEquals($expected,
$result);
188 $this->scopeConfigMock->expects(
193 'general/country/optional_zip_countries' 195 $this->returnValue($configValue)
198 $result = $this->_object->getCountriesWithOptionalZip();
199 $this->assertEquals($expected,
$result);
208 'empty_list' => [
'', []],
209 'normal_list' => [
'Country1,Country2', [
'Country1',
'Country2']]
216 $country =
'country';
218 $this->scopeConfigMock->expects($this->once())
222 \
Magento\Store\Model\ScopeInterface::SCOPE_STORE,
224 )->will($this->returnValue($country));
226 $this->assertEquals($country, $this->_object->getDefaultCountry(
$storeId));
231 $this->_countryCollection->expects(
236 $this->returnValue(0)
239 $store = $this->createMock(\
Magento\Store\Model\Store::class);
240 $this->_countryCollection->expects(
248 $this->_object->getCountryCollection(
$store);
258 $this->scopeConfigMock->expects($this->once())
260 ->willReturn($topCountriesValue);
262 $this->assertEquals($expectedResult, $this->_object->getTopCountryCodes());
274 [
'US,RU', [
'US',
'RU']],
topCountriesDataProvider()
static countriesCommaListDataProvider()
testGetCountryCollection()
testGetCountriesWithOptionalZip($configValue, $expected)
const XML_PATH_TOP_COUNTRIES
const XML_PATH_DEFAULT_COUNTRY
testGetCountriesWithStatesRequired($configValue, $expected)
testGetTopCountryCodesReturnsParsedConfigurationValue($topCountriesValue, $expectedResult)