Skip to content

Commit 14758b2

Browse files
committed
Merge remote-tracking branch 'tier4/ACP2E-2738' into PR_10_JAN_2024
2 parents 713c55e + ac031cb commit 14758b2

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

app/code/Magento/Fedex/Plugin/Block/Tracking/PopupDeliveryDate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class PopupDeliveryDate
2828
public function afterFormatDeliveryDateTime(Popup $subject, $result, $date, $time)
2929
{
3030
if ($this->getCarrier($subject) === Carrier::CODE) {
31-
$result = $subject->formatDeliveryDate($date);
31+
$result = $subject->formatDeliveryDate($date. ' ' . $time);
3232
}
3333
return $result;
3434
}

app/code/Magento/Fedex/Test/Unit/Plugin/Block/Tracking/PopupDeliveryDateTest.php

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
*/
2222
class PopupDeliveryDateTest extends TestCase
2323
{
24-
const STUB_CARRIER_CODE_NOT_FEDEX = 'not-fedex';
25-
const STUB_DELIVERY_DATE = '2020-02-02';
26-
const STUB_DELIVERY_TIME = '12:00';
24+
public const STUB_CARRIER_CODE_NOT_FEDEX = 'not-fedex';
25+
public const STUB_DELIVERY_DATE = '2020-02-02';
26+
public const STUB_DELIVERY_TIME = '12:00';
2727

2828
/**
2929
* @var MockObject|PopupDeliveryDate
@@ -68,6 +68,30 @@ public function testAfterFormatDeliveryDateTimeWithFedexCarrier()
6868
$this->executeOriginalMethod();
6969
}
7070

71+
/**
72+
* Test the method with Fedex carrier with timezone impact
73+
* @dataProvider getDates
74+
*/
75+
public function testAfterFormatDeliveryDateTimeWithFedexCarrierWithTimezone(
76+
$date,
77+
$currentTimezone,
78+
$convertedTimezone,
79+
$expected
80+
) {
81+
$this->trackingStatusMock->expects($this::once())
82+
->method('getCarrier')
83+
->willReturn(Carrier::CODE);
84+
85+
$date = new \DateTime($date, new \DateTimeZone($currentTimezone));
86+
$date->setTimezone(new \DateTimeZone($convertedTimezone));
87+
$this->subjectMock->expects($this->once())->method('formatDeliveryDate')
88+
->willReturn($date->format('Y-m-d'));
89+
90+
$result = $this->executeOriginalMethodWithTimezone();
91+
92+
$this->assertEquals($expected, $result);
93+
}
94+
7195
/**
7296
* Test the method with a different carrier
7397
*/
@@ -119,4 +143,40 @@ private function executeOriginalMethod()
119143
self::STUB_DELIVERY_TIME
120144
);
121145
}
146+
147+
/**
148+
* Run plugin's original method taking into account timezone
149+
*/
150+
private function executeOriginalMethodWithTimezone()
151+
{
152+
return $this->plugin->afterFormatDeliveryDateTime(
153+
$this->subjectMock,
154+
'Test Result',
155+
self::STUB_DELIVERY_DATE,
156+
'00:00:00'
157+
);
158+
}
159+
160+
/**
161+
* Data provider for testAfterFormatDeliveryDateTimeWithFedexCarrierWithTimezone
162+
*
163+
* @return array[]
164+
*/
165+
public function getDates(): array
166+
{
167+
return [
168+
'same day' => [
169+
'date' => '2024-01-07 06:00:00',
170+
'current_timezone' => 'US/Eastern',
171+
'converted_timezone' => 'America/Chicago',
172+
'expected' => '2024-01-07'
173+
],
174+
'previous day' => [
175+
'date' => '2024-01-07 00:00:00',
176+
'current_timezone' => 'US/Eastern',
177+
'converted_timezone' => 'America/Chicago',
178+
'expected' => '2024-01-06'
179+
]
180+
];
181+
}
122182
}

0 commit comments

Comments
 (0)