Skip to content

Commit 759950a

Browse files
MC-33168: Default State dropdown is not filled with correct data
1 parent 2b4cfab commit 759950a

File tree

1 file changed

+40
-26
lines changed

1 file changed

+40
-26
lines changed

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

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,64 +7,78 @@
77

88
use Magento\Directory\Helper\Data;
99
use Magento\Directory\Model\AllowedCountries;
10+
use Magento\Directory\Model\CurrencyFactory;
11+
use Magento\Directory\Model\ResourceModel\Country\Collection as CountryCollection;
12+
use Magento\Directory\Model\ResourceModel\Region\Collection as RegionCollection;
13+
use Magento\Directory\Model\ResourceModel\Region\CollectionFactory;
14+
use Magento\Framework\App\Cache\Type\Config;
1015
use Magento\Framework\App\Config\ScopeConfigInterface;
16+
use Magento\Framework\App\Helper\Context;
1117
use Magento\Framework\App\RequestInterface;
18+
use Magento\Framework\DataObject;
19+
use Magento\Framework\Json\Helper\Data as JsonDataHelper;
20+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1221
use Magento\Store\Model\ScopeInterface;
22+
use Magento\Store\Model\Store;
23+
use Magento\Store\Model\StoreManagerInterface;
24+
use PHPUnit\Framework\Constraint\IsIdentical;
25+
use PHPUnit\Framework\MockObject\MockObject;
26+
use PHPUnit\Framework\TestCase;
1327

1428
/**
1529
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1630
*/
17-
class DataTest extends \PHPUnit\Framework\TestCase
31+
class DataTest extends TestCase
1832
{
1933
/**
20-
* @var \Magento\Directory\Model\ResourceModel\Country\Collection|\PHPUnit_Framework_MockObject_MockObject
34+
* @var CountryCollection|MockObject
2135
*/
2236
protected $_countryCollection;
2337

2438
/**
25-
* @var \Magento\Directory\Model\ResourceModel\Region\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
39+
* @var CollectionFactory|MockObject
2640
*/
2741
protected $_regionCollection;
2842

2943
/**
30-
* @var \Magento\Framework\Json\Helper\Data|\PHPUnit_Framework_MockObject_MockObject
44+
* @var JsonDataHelper|MockObject
3145
*/
3246
protected $jsonHelperMock;
3347

3448
/**
35-
* @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject
49+
* @var Store|MockObject
3650
*/
3751
protected $_store;
3852

3953
/**
40-
* @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
54+
* @var ScopeConfigInterface|MockObject
4155
*/
4256
protected $scopeConfigMock;
4357

4458
/**
45-
* @var \Magento\Directory\Helper\Data
59+
* @var Data
4660
*/
4761
protected $_object;
4862

4963
protected function setUp()
5064
{
51-
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
52-
$this->scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
65+
$objectManager = new ObjectManager($this);
66+
$this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class);
5367
$this->scopeConfigMock->expects($this->any())->method('isSetFlag')->willReturn(false);
5468
$requestMock = $this->createMock(RequestInterface::class);
55-
$context = $this->createMock(\Magento\Framework\App\Helper\Context::class);
69+
$context = $this->createMock(Context::class);
5670
$context->method('getRequest')
5771
->willReturn($requestMock);
5872
$context->expects($this->any())
5973
->method('getScopeConfig')
6074
->willReturn($this->scopeConfigMock);
61-
$configCacheType = $this->createMock(\Magento\Framework\App\Cache\Type\Config::class);
75+
$configCacheType = $this->createMock(Config::class);
6276

63-
$this->_countryCollection = $this->createMock(\Magento\Directory\Model\ResourceModel\Country\Collection::class);
77+
$this->_countryCollection = $this->createMock(CountryCollection::class);
6478

65-
$this->_regionCollection = $this->createMock(\Magento\Directory\Model\ResourceModel\Region\Collection::class);
79+
$this->_regionCollection = $this->createMock(RegionCollection::class);
6680
$regCollectionFactory = $this->createPartialMock(
67-
\Magento\Directory\Model\ResourceModel\Region\CollectionFactory::class,
81+
CollectionFactory::class,
6882
['create']
6983
);
7084
$regCollectionFactory->expects(
@@ -75,13 +89,13 @@ protected function setUp()
7589
$this->returnValue($this->_regionCollection)
7690
);
7791

78-
$this->jsonHelperMock = $this->createMock(\Magento\Framework\Json\Helper\Data::class);
92+
$this->jsonHelperMock = $this->createMock(JsonDataHelper::class);
7993

80-
$this->_store = $this->createMock(\Magento\Store\Model\Store::class);
81-
$storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
94+
$this->_store = $this->createMock(Store::class);
95+
$storeManager = $this->createMock(StoreManagerInterface::class);
8296
$storeManager->expects($this->any())->method('getStore')->will($this->returnValue($this->_store));
8397

84-
$currencyFactory = $this->createMock(\Magento\Directory\Model\CurrencyFactory::class);
98+
$currencyFactory = $this->createMock(CurrencyFactory::class);
8599

86100
$arguments = [
87101
'context' => $context,
@@ -92,7 +106,7 @@ protected function setUp()
92106
'storeManager' => $storeManager,
93107
'currencyFactory' => $currencyFactory,
94108
];
95-
$this->_object = $objectManager->getObject(\Magento\Directory\Helper\Data::class, $arguments);
109+
$this->_object = $objectManager->getObject(Data::class, $arguments);
96110
}
97111

98112
public function testGetRegionJson()
@@ -110,13 +124,13 @@ public function testGetRegionJson()
110124
]
111125
);
112126
$regions = [
113-
new \Magento\Framework\DataObject(
127+
new DataObject(
114128
['country_id' => 'Country1', 'region_id' => 'r1', 'code' => 'r1-code', 'name' => 'r1-name']
115129
),
116-
new \Magento\Framework\DataObject(
130+
new DataObject(
117131
['country_id' => 'Country1', 'region_id' => 'r2', 'code' => 'r2-code', 'name' => 'r2-name']
118132
),
119-
new \Magento\Framework\DataObject(
133+
new DataObject(
120134
['country_id' => 'Country2', 'region_id' => 'r3', 'code' => 'r3-code', 'name' => 'r3-name']
121135
)
122136
];
@@ -153,7 +167,7 @@ public function testGetRegionJson()
153167
)->method(
154168
'jsonEncode'
155169
)->with(
156-
new \PHPUnit\Framework\Constraint\IsIdentical($expectedDataToEncode)
170+
new IsIdentical($expectedDataToEncode)
157171
)->will(
158172
$this->returnValue('encoded_json')
159173
);
@@ -225,7 +239,7 @@ public function testGetDefaultCountry()
225239
->method('getValue')
226240
->with(
227241
Data::XML_PATH_DEFAULT_COUNTRY,
228-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
242+
ScopeInterface::SCOPE_STORE,
229243
$storeId
230244
)->will($this->returnValue($country));
231245

@@ -242,7 +256,7 @@ public function testGetCountryCollection()
242256
$this->returnValue(0)
243257
);
244258

245-
$store = $this->createMock(\Magento\Store\Model\Store::class);
259+
$store = $this->createMock(Store::class);
246260
$this->_countryCollection->expects(
247261
$this->once()
248262
)->method(
@@ -262,7 +276,7 @@ public function testGetCountryCollection()
262276
public function testGetTopCountryCodesReturnsParsedConfigurationValue($topCountriesValue, $expectedResult)
263277
{
264278
$this->scopeConfigMock->expects($this->once())
265-
->method('getValue')->with(\Magento\Directory\Helper\Data::XML_PATH_TOP_COUNTRIES)
279+
->method('getValue')->with(Data::XML_PATH_TOP_COUNTRIES)
266280
->willReturn($topCountriesValue);
267281

268282
$this->assertEquals($expectedResult, $this->_object->getTopCountryCodes());

0 commit comments

Comments
 (0)