6
6
namespace Magento \Directory \Test \Unit \Helper ;
7
7
8
8
use Magento \Directory \Helper \Data ;
9
+ 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 ;
15
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
16
+ use Magento \Framework \App \Helper \Context ;
17
+ 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 ;
21
+ 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 ;
9
27
10
28
/**
11
29
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
12
30
*/
13
- class DataTest extends \ PHPUnit \ Framework \ TestCase
31
+ class DataTest extends TestCase
14
32
{
15
33
/**
16
- * @var \Magento\Directory\Model\ResourceModel\Country\Collection|\PHPUnit_Framework_MockObject_MockObject
34
+ * @var CountryCollection|MockObject
17
35
*/
18
36
protected $ _countryCollection ;
19
37
20
38
/**
21
- * @var \Magento\Directory\Model\ResourceModel\Region\ CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
39
+ * @var CollectionFactory|MockObject
22
40
*/
23
41
protected $ _regionCollection ;
24
42
25
43
/**
26
- * @var \Magento\Framework\Json\Helper\Data|\PHPUnit_Framework_MockObject_MockObject
44
+ * @var JsonDataHelper|MockObject
27
45
*/
28
46
protected $ jsonHelperMock ;
29
47
30
48
/**
31
- * @var \Magento\ Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject
49
+ * @var Store|MockObject
32
50
*/
33
51
protected $ _store ;
34
52
35
53
/**
36
- * @var \Magento\Framework\App\Config\ ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
54
+ * @var ScopeConfigInterface|MockObject
37
55
*/
38
56
protected $ scopeConfigMock ;
39
57
40
58
/**
41
- * @var \Magento\Directory\Helper\ Data
59
+ * @var Data
42
60
*/
43
61
protected $ _object ;
44
62
45
63
protected function setUp ()
46
64
{
47
- $ objectManager = new \ Magento \ Framework \ TestFramework \ Unit \ Helper \ ObjectManager ($ this );
48
- $ this ->scopeConfigMock = $ this ->createMock (\ Magento \ Framework \ App \ Config \ ScopeConfigInterface::class);
65
+ $ objectManager = new ObjectManager ($ this );
66
+ $ this ->scopeConfigMock = $ this ->createMock (ScopeConfigInterface::class);
49
67
$ this ->scopeConfigMock ->expects ($ this ->any ())->method ('isSetFlag ' )->willReturn (false );
50
- $ context = $ this ->createMock (\Magento \Framework \App \Helper \Context::class);
68
+ $ requestMock = $ this ->createMock (RequestInterface::class);
69
+ $ context = $ this ->createMock (Context::class);
70
+ $ context ->method ('getRequest ' )
71
+ ->willReturn ($ requestMock );
51
72
$ context ->expects ($ this ->any ())
52
73
->method ('getScopeConfig ' )
53
74
->willReturn ($ this ->scopeConfigMock );
75
+ $ configCacheType = $ this ->createMock (Config::class);
54
76
55
- $ configCacheType = $ this ->createMock (\ Magento \ Framework \ App \ Cache \ Type \Config ::class);
77
+ $ this -> _countryCollection = $ this ->createMock (CountryCollection ::class);
56
78
57
- $ this ->_countryCollection = $ this ->createMock (\Magento \Directory \Model \ResourceModel \Country \Collection::class);
58
-
59
- $ this ->_regionCollection = $ this ->createMock (\Magento \Directory \Model \ResourceModel \Region \Collection::class);
79
+ $ this ->_regionCollection = $ this ->createMock (RegionCollection::class);
60
80
$ regCollectionFactory = $ this ->createPartialMock (
61
- \ Magento \ Directory \ Model \ ResourceModel \ Region \ CollectionFactory::class,
81
+ CollectionFactory::class,
62
82
['create ' ]
63
83
);
64
84
$ regCollectionFactory ->expects (
@@ -69,13 +89,13 @@ protected function setUp()
69
89
$ this ->returnValue ($ this ->_regionCollection )
70
90
);
71
91
72
- $ this ->jsonHelperMock = $ this ->createMock (\ Magento \ Framework \ Json \ Helper \Data ::class);
92
+ $ this ->jsonHelperMock = $ this ->createMock (JsonDataHelper ::class);
73
93
74
- $ this ->_store = $ this ->createMock (\ Magento \ Store \ Model \ Store::class);
75
- $ storeManager = $ this ->createMock (\ Magento \ Store \ Model \ StoreManagerInterface::class);
94
+ $ this ->_store = $ this ->createMock (Store::class);
95
+ $ storeManager = $ this ->createMock (StoreManagerInterface::class);
76
96
$ storeManager ->expects ($ this ->any ())->method ('getStore ' )->will ($ this ->returnValue ($ this ->_store ));
77
97
78
- $ currencyFactory = $ this ->createMock (\ Magento \ Directory \ Model \ CurrencyFactory::class);
98
+ $ currencyFactory = $ this ->createMock (CurrencyFactory::class);
79
99
80
100
$ arguments = [
81
101
'context ' => $ context ,
@@ -86,32 +106,31 @@ protected function setUp()
86
106
'storeManager ' => $ storeManager ,
87
107
'currencyFactory ' => $ currencyFactory ,
88
108
];
89
- $ this ->_object = $ objectManager ->getObject (\ Magento \ Directory \ Helper \ Data::class, $ arguments );
109
+ $ this ->_object = $ objectManager ->getObject (Data::class, $ arguments );
90
110
}
91
111
92
112
public function testGetRegionJson ()
93
113
{
94
- $ countries = [
95
- new \Magento \Framework \DataObject (['country_id ' => 'Country1 ' ]),
96
- new \Magento \Framework \DataObject (['country_id ' => 'Country2 ' ])
97
- ];
98
- $ countryIterator = new \ArrayIterator ($ countries );
99
- $ this ->_countryCollection ->expects (
100
- $ this ->atLeastOnce ()
101
- )->method (
102
- 'getIterator '
103
- )->will (
104
- $ this ->returnValue ($ countryIterator )
105
- );
106
-
114
+ $ this ->scopeConfigMock ->method ('getValue ' )
115
+ ->willReturnMap (
116
+ [
117
+ [
118
+ AllowedCountries::ALLOWED_COUNTRIES_PATH ,
119
+ ScopeConfigInterface::SCOPE_TYPE_DEFAULT ,
120
+ null ,
121
+ 'Country1,Country2 '
122
+ ],
123
+ [Data::XML_PATH_STATES_REQUIRED , ScopeInterface::SCOPE_STORE , null , '' ]
124
+ ]
125
+ );
107
126
$ regions = [
108
- new \ Magento \ Framework \ DataObject (
127
+ new DataObject (
109
128
['country_id ' => 'Country1 ' , 'region_id ' => 'r1 ' , 'code ' => 'r1-code ' , 'name ' => 'r1-name ' ]
110
129
),
111
- new \ Magento \ Framework \ DataObject (
130
+ new DataObject (
112
131
['country_id ' => 'Country1 ' , 'region_id ' => 'r2 ' , 'code ' => 'r2-code ' , 'name ' => 'r2-name ' ]
113
132
),
114
- new \ Magento \ Framework \ DataObject (
133
+ new DataObject (
115
134
['country_id ' => 'Country2 ' , 'region_id ' => 'r3 ' , 'code ' => 'r3-code ' , 'name ' => 'r3-name ' ]
116
135
)
117
136
];
@@ -148,7 +167,7 @@ public function testGetRegionJson()
148
167
)->method (
149
168
'jsonEncode '
150
169
)->with (
151
- new \ PHPUnit \ Framework \ Constraint \ IsIdentical ($ expectedDataToEncode )
170
+ new IsIdentical ($ expectedDataToEncode )
152
171
)->will (
153
172
$ this ->returnValue ('encoded_json ' )
154
173
);
@@ -220,7 +239,7 @@ public function testGetDefaultCountry()
220
239
->method ('getValue ' )
221
240
->with (
222
241
Data::XML_PATH_DEFAULT_COUNTRY ,
223
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE ,
242
+ ScopeInterface::SCOPE_STORE ,
224
243
$ storeId
225
244
)->will ($ this ->returnValue ($ country ));
226
245
@@ -237,7 +256,7 @@ public function testGetCountryCollection()
237
256
$ this ->returnValue (0 )
238
257
);
239
258
240
- $ store = $ this ->createMock (\ Magento \ Store \ Model \ Store::class);
259
+ $ store = $ this ->createMock (Store::class);
241
260
$ this ->_countryCollection ->expects (
242
261
$ this ->once ()
243
262
)->method (
@@ -257,7 +276,7 @@ public function testGetCountryCollection()
257
276
public function testGetTopCountryCodesReturnsParsedConfigurationValue ($ topCountriesValue , $ expectedResult )
258
277
{
259
278
$ this ->scopeConfigMock ->expects ($ this ->once ())
260
- ->method ('getValue ' )->with (\ Magento \ Directory \ Helper \ Data::XML_PATH_TOP_COUNTRIES )
279
+ ->method ('getValue ' )->with (Data::XML_PATH_TOP_COUNTRIES )
261
280
->willReturn ($ topCountriesValue );
262
281
263
282
$ this ->assertEquals ($ expectedResult , $ this ->_object ->getTopCountryCodes ());
0 commit comments