Skip to content

Commit 41363bc

Browse files
committed
ACP2E-3340: added unit test and translations
1 parent 81ab477 commit 41363bc

File tree

2 files changed

+85
-12
lines changed

2 files changed

+85
-12
lines changed

app/code/Magento/Fedex/Test/Unit/Model/CarrierTest.php

Lines changed: 80 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,6 @@ protected function setUp(): void
143143
->disableOriginalConstructor()
144144
->getMockForAbstractClass();
145145

146-
$this->scope->expects($this->any())
147-
->method('getValue')
148-
->willReturnCallback([$this, 'scopeConfigGetValue']);
149-
150146
$countryFactory = $this->getCountryFactory();
151147
$rateFactory = $this->getRateFactory();
152148
$storeManager = $this->getStoreManager();
@@ -293,6 +289,11 @@ public function testRequestToShipmentSuccess(): void
293289
];
294290
$storeId = 1;
295291
$phoneNumber = '1234567890';
292+
293+
$this->scope->expects($this->any())
294+
->method('getValue')
295+
->willReturnCallback([$this, 'scopeConfigGetValue']);
296+
296297
$request->expects($this->once())->method('getPackages')->willReturn($packages);
297298
$request->expects($this->exactly(3))->method('getStoreId')->willReturn($storeId);
298299
$request->expects($this->once())->method('setPackageId');
@@ -355,6 +356,10 @@ public function testRequestToShipmentSuccess(): void
355356

356357
public function testSetRequestWithoutCity(): void
357358
{
359+
$this->scope->expects($this->any())
360+
->method('getValue')
361+
->willReturnCallback([$this, 'scopeConfigGetValue']);
362+
358363
$request = $this->getMockBuilder(RateRequest::class)
359364
->disableOriginalConstructor()
360365
->addMethods(['getDestCity'])
@@ -367,6 +372,10 @@ public function testSetRequestWithoutCity(): void
367372

368373
public function testSetRequestWithCity(): void
369374
{
375+
$this->scope->expects($this->any())
376+
->method('getValue')
377+
->willReturnCallback([$this, 'scopeConfigGetValue']);
378+
370379
$request = $this->getMockBuilder(RateRequest::class)
371380
->disableOriginalConstructor()
372381
->addMethods(['getDestCity'])
@@ -391,8 +400,31 @@ public function scopeConfigGetValue(string $path): int|string|null
391400
'carriers/fedex/debug' => 1,
392401
'carriers/fedex/api_key' => 'TestApiKey',
393402
'carriers/fedex/secret_key' => 'TestSecretKey',
403+
'carriers/fedex/enabled_tracking_api' => 0,
404+
'carriers/fedex/rest_sandbox_webservices_url' => 'https://rest.sandbox.url/',
405+
'carriers/fedex/rest_production_webservices_url' => 'https://rest.production.url/'
406+
];
407+
408+
return $pathMap[$path] ?? null;
409+
}
410+
411+
/**
412+
* @param string $path
413+
* @return int|string|null
414+
*/
415+
public function scopeConfigGetValueForTracking(string $path): int|string|null
416+
{
417+
$pathMap = [
418+
'carriers/fedex/showmethod' => 1,
419+
'carriers/fedex/allowed_methods' => 'ServiceType',
420+
'carriers/fedex/debug' => 1,
421+
'carriers/fedex/api_key' => 'TestApiKey',
422+
'carriers/fedex/secret_key' => 'TestSecretKey',
423+
'carriers/fedex/enabled_tracking_api' => 1,
424+
'carriers/fedex/tracking_api_key' => 'TestTrackingApiKey',
425+
'carriers/fedex/tracking_api_secret_key' => 'TestTrackingSecretKey',
394426
'carriers/fedex/rest_sandbox_webservices_url' => 'https://rest.sandbox.url/',
395-
'carriers/fedex/rest_production_webservices_url' => 'https://rest.production.url/',
427+
'carriers/fedex/rest_production_webservices_url' => 'https://rest.production.url/'
396428
];
397429

398430
return $pathMap[$path] ?? null;
@@ -417,6 +449,10 @@ public function testCollectRatesRateAmountOriginBased(
417449
->method('isSetFlag')
418450
->willReturn(true);
419451

452+
$this->scope->expects($this->any())
453+
->method('getValue')
454+
->willReturnCallback([$this, 'scopeConfigGetValue']);
455+
420456
$accessTokenResponse = $this->getAccessToken();
421457
$rateResponse = $this->getRateResponse($amount, $currencyCode, $rateType);
422458

@@ -503,6 +539,10 @@ public function testCollectRatesErrorMessage(): void
503539
->method('isSetFlag')
504540
->willReturn(false);
505541

542+
$this->scope->expects($this->any())
543+
->method('getValue')
544+
->willReturnCallback([$this, 'scopeConfigGetValue']);
545+
506546
$this->error->expects($this->once())
507547
->method('setCarrier')
508548
->with('fedex');
@@ -881,14 +921,25 @@ public function getAccessToken(): array
881921
* @param string $shipTimeStamp
882922
* @param string $expectedDate
883923
* @param string $expectedTime
924+
* @param bool $trackingEnabled
884925
* @dataProvider shipDateDataProvider
885926
*/
886-
public function testGetTracking($tracking, $shipTimeStamp, $expectedDate, $expectedTime): void
927+
public function testGetTracking($tracking, $shipTimeStamp, $expectedDate, $expectedTime, $trackingEnabled): void
887928
{
888929
$trackRequest = $this->getTrackRequest($tracking);
889930
$trackResponse = $this->getTrackResponse($shipTimeStamp, $expectedDate, $expectedTime);
890931
$accessTokenResponse = $this->getAccessToken();
891932

933+
if ($trackingEnabled) {
934+
$this->scope->expects($this->atLeast(1))
935+
->method('getValue')
936+
->willReturnCallback([$this, 'scopeConfigGetValueForTracking']);
937+
} else {
938+
$this->scope->expects($this->any())
939+
->method('getValue')
940+
->willReturnCallback([$this, 'scopeConfigGetValue']);
941+
}
942+
892943
$this->serializer->method('serialize')->willReturn(json_encode($trackRequest));
893944
$this->serializer->expects($this->any())
894945
->method('unserialize')
@@ -942,50 +993,67 @@ public static function shipDateDataProvider(): array
942993
'shipTimestamp' => '2020-08-15T02:06:35+03:00',
943994
'expectedDate' => '2014-01-09',
944995
'18:31:00',
945-
0,
996+
false,
997+
0
946998
],
947999
'tracking1-again' => [
9481000
'tracking1',
9491001
'shipTimestamp' => '2014-01-09T02:06:35+03:00',
9501002
'expectedDate' => '2014-01-09',
9511003
'18:31:00',
952-
0,
1004+
false,
1005+
0
9531006
],
9541007
'tracking2' => [
9551008
'tracking2',
9561009
'shipTimestamp' => '2014-01-09T02:06:35+03:00',
9571010
'expectedDate' => '2014-01-09',
9581011
'23:06:35',
1012+
false,
1013+
0
9591014
],
9601015
'tracking3' => [
9611016
'tracking3',
9621017
'shipTimestamp' => '2014-01-09T14:06:35',
9631018
'expectedDate' => '2014-01-09',
9641019
'18:31:00',
1020+
false,
1021+
0
9651022
],
9661023
'tracking4' => [
9671024
'tracking4',
9681025
'shipTimestamp' => '2016-08-05 14:06:35',
9691026
'expectedDate' => null,
970-
null,
1027+
'',
1028+
false,
9711029
],
9721030
'tracking5' => [
9731031
'tracking5',
9741032
'shipTimestamp' => '2016-08-05 14:06:35+00:00',
9751033
'expectedDate' => null,
976-
null,
1034+
'',
1035+
false,
9771036
],
9781037
'tracking6' => [
9791038
'tracking6',
9801039
'shipTimestamp' => '2016-08-05',
9811040
'expectedDate' => null,
982-
null,
1041+
'',
1042+
false,
9831043
],
9841044
'tracking7' => [
9851045
'tracking7',
9861046
'shipTimestamp' => '2016/08/05',
9871047
'expectedDate' => null,
988-
null
1048+
'',
1049+
false,
1050+
],
1051+
'tracking8' => [
1052+
'tracking8',
1053+
'shipTimestamp' => '2024-09-19T02:06:35+03:00',
1054+
'expectedDate' => '2024-09-21',
1055+
'18:31:00',
1056+
true
9891057
],
9901058
];
9911059
}

app/code/Magento/Fedex/i18n/en_US.csv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,8 @@ Debug,Debug
8888
"Package Return Program","Package Return Program"
8989
"Regular Stop","Regular Stop"
9090
"Tag","Tag"
91+
"Api Key","Api Key"
92+
"Secret Key","Secret Key"
93+
"Enable Tracking API credentials","Enable Tracking API credentials"
94+
"Tracking API Key","Tracking API Key"
95+
"Tracking API Secret Key","Tracking API Secret Key"

0 commit comments

Comments
 (0)