Skip to content

Commit

Permalink
Merge remote-tracking branch 'tier4/ACP2E-2738' into PR_10_JAN_2024
Browse files Browse the repository at this point in the history
  • Loading branch information
o-dubovyk committed Mar 19, 2024
2 parents 713c55e + ac031cb commit 14758b2
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PopupDeliveryDate
public function afterFormatDeliveryDateTime(Popup $subject, $result, $date, $time)
{
if ($this->getCarrier($subject) === Carrier::CODE) {
$result = $subject->formatDeliveryDate($date);
$result = $subject->formatDeliveryDate($date. ' ' . $time);
}
return $result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
*/
class PopupDeliveryDateTest extends TestCase
{
const STUB_CARRIER_CODE_NOT_FEDEX = 'not-fedex';
const STUB_DELIVERY_DATE = '2020-02-02';
const STUB_DELIVERY_TIME = '12:00';
public const STUB_CARRIER_CODE_NOT_FEDEX = 'not-fedex';
public const STUB_DELIVERY_DATE = '2020-02-02';
public const STUB_DELIVERY_TIME = '12:00';

/**
* @var MockObject|PopupDeliveryDate
Expand Down Expand Up @@ -68,6 +68,30 @@ public function testAfterFormatDeliveryDateTimeWithFedexCarrier()
$this->executeOriginalMethod();
}

/**
* Test the method with Fedex carrier with timezone impact
* @dataProvider getDates
*/
public function testAfterFormatDeliveryDateTimeWithFedexCarrierWithTimezone(
$date,
$currentTimezone,
$convertedTimezone,
$expected
) {
$this->trackingStatusMock->expects($this::once())
->method('getCarrier')
->willReturn(Carrier::CODE);

$date = new \DateTime($date, new \DateTimeZone($currentTimezone));
$date->setTimezone(new \DateTimeZone($convertedTimezone));
$this->subjectMock->expects($this->once())->method('formatDeliveryDate')
->willReturn($date->format('Y-m-d'));

$result = $this->executeOriginalMethodWithTimezone();

$this->assertEquals($expected, $result);
}

/**
* Test the method with a different carrier
*/
Expand Down Expand Up @@ -119,4 +143,40 @@ private function executeOriginalMethod()
self::STUB_DELIVERY_TIME
);
}

/**
* Run plugin's original method taking into account timezone
*/
private function executeOriginalMethodWithTimezone()
{
return $this->plugin->afterFormatDeliveryDateTime(
$this->subjectMock,
'Test Result',
self::STUB_DELIVERY_DATE,
'00:00:00'
);
}

/**
* Data provider for testAfterFormatDeliveryDateTimeWithFedexCarrierWithTimezone
*
* @return array[]
*/
public function getDates(): array
{
return [
'same day' => [
'date' => '2024-01-07 06:00:00',
'current_timezone' => 'US/Eastern',
'converted_timezone' => 'America/Chicago',
'expected' => '2024-01-07'
],
'previous day' => [
'date' => '2024-01-07 00:00:00',
'current_timezone' => 'US/Eastern',
'converted_timezone' => 'America/Chicago',
'expected' => '2024-01-06'
]
];
}
}

0 comments on commit 14758b2

Please sign in to comment.