10
10
use Magento \Directory \Helper \Data ;
11
11
use Magento \Directory \Model \Country ;
12
12
use Magento \Directory \Model \CountryFactory ;
13
+ use Magento \Directory \Model \Currency ;
13
14
use Magento \Directory \Model \CurrencyFactory ;
14
15
use Magento \Directory \Model \RegionFactory ;
15
16
use Magento \Fedex \Model \Carrier ;
16
17
use Magento \Framework \App \Config \ScopeConfigInterface ;
18
+ use Magento \Framework \Exception \LocalizedException ;
17
19
use Magento \Framework \Module \Dir \Reader ;
18
20
use Magento \Framework \Pricing \PriceCurrencyInterface ;
19
21
use Magento \Framework \Serialize \Serializer \Json ;
@@ -100,6 +102,11 @@ class CarrierTest extends \PHPUnit\Framework\TestCase
100
102
*/
101
103
private $ logger ;
102
104
105
+ /**
106
+ * @var CurrencyFactory|MockObject
107
+ */
108
+ private $ currencyFactory ;
109
+
103
110
protected function setUp ()
104
111
{
105
112
$ this ->helper = new ObjectManager ($ this );
@@ -141,7 +148,7 @@ protected function setUp()
141
148
->disableOriginalConstructor ()
142
149
->getMock ();
143
150
144
- $ currencyFactory = $ this ->getMockBuilder (CurrencyFactory::class)
151
+ $ this -> currencyFactory = $ this ->getMockBuilder (CurrencyFactory::class)
145
152
->disableOriginalConstructor ()
146
153
->getMock ();
147
154
@@ -179,7 +186,7 @@ protected function setUp()
179
186
'trackStatusFactory ' => $ this ->statusFactory ,
180
187
'regionFactory ' => $ regionFactory ,
181
188
'countryFactory ' => $ countryFactory ,
182
- 'currencyFactory ' => $ currencyFactory ,
189
+ 'currencyFactory ' => $ this -> currencyFactory ,
183
190
'directoryData ' => $ data ,
184
191
'stockRegistry ' => $ stockRegistry ,
185
192
'storeManager ' => $ storeManager ,
@@ -240,20 +247,29 @@ public function scopeConfigGetValue(string $path)
240
247
241
248
/**
242
249
* @param float $amount
250
+ * @param string $currencyCode
251
+ * @param string $baseCurrencyCode
243
252
* @param string $rateType
244
253
* @param float $expected
245
254
* @param int $callNum
246
255
* @dataProvider collectRatesDataProvider
247
256
*/
248
- public function testCollectRatesRateAmountOriginBased ($ amount , $ rateType , $ expected , $ callNum = 1 )
249
- {
257
+ public function testCollectRatesRateAmountOriginBased (
258
+ $ amount ,
259
+ $ currencyCode ,
260
+ $ baseCurrencyCode ,
261
+ $ rateType ,
262
+ $ expected ,
263
+ $ callNum = 1
264
+ ) {
250
265
$ this ->scope ->expects ($ this ->any ())
251
266
->method ('isSetFlag ' )
252
267
->willReturn (true );
253
268
254
269
// @codingStandardsIgnoreStart
255
270
$ netAmount = new \stdClass ();
256
271
$ netAmount ->Amount = $ amount ;
272
+ $ netAmount ->Currency = $ currencyCode ;
257
273
258
274
$ totalNetCharge = new \stdClass ();
259
275
$ totalNetCharge ->TotalNetCharge = $ netAmount ;
@@ -274,9 +290,39 @@ public function testCollectRatesRateAmountOriginBased($amount, $rateType, $expec
274
290
$ this ->serializer ->method ('serialize ' )
275
291
->willReturn ('CollectRateString ' . $ amount );
276
292
293
+ $ rateCurrency = $ this ->getMockBuilder (Currency::class)
294
+ ->disableOriginalConstructor ()
295
+ ->getMock ();
296
+ $ rateCurrency ->method ('load ' )
297
+ ->willReturnSelf ();
298
+ $ rateCurrency ->method ('getAnyRate ' )
299
+ ->willReturnMap (
300
+ [
301
+ ['USD ' , 1 ],
302
+ ['EUR ' , 0.75 ],
303
+ ['UNKNOWN ' , false ]
304
+ ]
305
+ );
306
+
307
+ if ($ baseCurrencyCode === 'UNKNOWN ' ) {
308
+ $ this ->expectException (LocalizedException::class);
309
+ }
310
+
311
+ $ this ->currencyFactory ->method ('create ' )
312
+ ->willReturn ($ rateCurrency );
313
+
314
+ $ baseCurrency = $ this ->getMockBuilder (Currency::class)
315
+ ->disableOriginalConstructor ()
316
+ ->getMock ();
317
+ $ baseCurrency ->method ('getCode ' )
318
+ ->willReturn ($ baseCurrencyCode );
319
+
277
320
$ request = $ this ->getMockBuilder (RateRequest::class)
321
+ ->setMethods (['getBaseCurrency ' ])
278
322
->disableOriginalConstructor ()
279
323
->getMock ();
324
+ $ request ->method ('getBaseCurrency ' )
325
+ ->willReturn ($ baseCurrency );
280
326
281
327
$ this ->soapClient ->expects ($ this ->exactly ($ callNum ))
282
328
->method ('getRates ' )
@@ -295,22 +341,23 @@ public function testCollectRatesRateAmountOriginBased($amount, $rateType, $expec
295
341
public function collectRatesDataProvider ()
296
342
{
297
343
return [
298
- [10.0 , 'RATED_ACCOUNT_PACKAGE ' , 10 ],
299
- [10.0 , 'RATED_ACCOUNT_PACKAGE ' , 10 , 0 ],
300
- [11.50 , 'PAYOR_ACCOUNT_PACKAGE ' , 11.5 ],
301
- [11.50 , 'PAYOR_ACCOUNT_PACKAGE ' , 11.5 , 0 ],
302
- [100.01 , 'RATED_ACCOUNT_SHIPMENT ' , 100.01 ],
303
- [100.01 , 'RATED_ACCOUNT_SHIPMENT ' , 100.01 , 0 ],
304
- [32.2 , 'PAYOR_ACCOUNT_SHIPMENT ' , 32.2 ],
305
- [32.2 , 'PAYOR_ACCOUNT_SHIPMENT ' , 32.2 , 0 ],
306
- [15.0 , 'RATED_LIST_PACKAGE ' , 15 ],
307
- [15.0 , 'RATED_LIST_PACKAGE ' , 15 , 0 ],
308
- [123.25 , 'PAYOR_LIST_PACKAGE ' , 123.25 ],
309
- [123.25 , 'PAYOR_LIST_PACKAGE ' , 123.25 , 0 ],
310
- [12.12 , 'RATED_LIST_SHIPMENT ' , 12.12 ],
311
- [12.12 , 'RATED_LIST_SHIPMENT ' , 12.12 , 0 ],
312
- [38.9 , 'PAYOR_LIST_SHIPMENT ' , 38.9 ],
313
- [38.9 , 'PAYOR_LIST_SHIPMENT ' , 38.9 , 0 ],
344
+ [10.0 , 'USD ' , 'EUR ' , 'RATED_ACCOUNT_PACKAGE ' , 7.5 ],
345
+ [10.0 , 'USD ' , 'UNKNOWN ' , 'RATED_ACCOUNT_PACKAGE ' , null , 0 ],
346
+ [10.0 , 'USD ' , 'USD ' , 'RATED_ACCOUNT_PACKAGE ' , 10 , 0 ],
347
+ [11.50 , 'USD ' , 'USD ' , 'PAYOR_ACCOUNT_PACKAGE ' , 11.5 ],
348
+ [11.50 , 'USD ' , 'USD ' , 'PAYOR_ACCOUNT_PACKAGE ' , 11.5 , 0 ],
349
+ [100.01 , 'USD ' , 'USD ' , 'RATED_ACCOUNT_SHIPMENT ' , 100.01 ],
350
+ [100.01 , 'USD ' , 'USD ' , 'RATED_ACCOUNT_SHIPMENT ' , 100.01 , 0 ],
351
+ [32.2 , 'USD ' , 'USD ' , 'PAYOR_ACCOUNT_SHIPMENT ' , 32.2 ],
352
+ [32.2 , 'USD ' , 'USD ' , 'PAYOR_ACCOUNT_SHIPMENT ' , 32.2 , 0 ],
353
+ [15.0 , 'USD ' , 'USD ' , 'RATED_LIST_PACKAGE ' , 15 ],
354
+ [15.0 , 'USD ' , 'USD ' , 'RATED_LIST_PACKAGE ' , 15 , 0 ],
355
+ [123.25 , 'USD ' , 'USD ' , 'PAYOR_LIST_PACKAGE ' , 123.25 ],
356
+ [123.25 , 'USD ' , 'USD ' , 'PAYOR_LIST_PACKAGE ' , 123.25 , 0 ],
357
+ [12.12 , 'USD ' , 'USD ' , 'RATED_LIST_SHIPMENT ' , 12.12 ],
358
+ [12.12 , 'USD ' , 'USD ' , 'RATED_LIST_SHIPMENT ' , 12.12 , 0 ],
359
+ [38.9 , 'USD ' , 'USD ' , 'PAYOR_LIST_SHIPMENT ' , 38.9 ],
360
+ [38.9 , 'USD ' , 'USD ' , 'PAYOR_LIST_SHIPMENT ' , 38.9 , 0 ],
314
361
];
315
362
}
316
363
0 commit comments