|
21 | 21 | */
|
22 | 22 | class PopupDeliveryDateTest extends TestCase
|
23 | 23 | {
|
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'; |
27 | 27 |
|
28 | 28 | /**
|
29 | 29 | * @var MockObject|PopupDeliveryDate
|
@@ -68,6 +68,30 @@ public function testAfterFormatDeliveryDateTimeWithFedexCarrier()
|
68 | 68 | $this->executeOriginalMethod();
|
69 | 69 | }
|
70 | 70 |
|
| 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 | + |
71 | 95 | /**
|
72 | 96 | * Test the method with a different carrier
|
73 | 97 | */
|
@@ -119,4 +143,40 @@ private function executeOriginalMethod()
|
119 | 143 | self::STUB_DELIVERY_TIME
|
120 | 144 | );
|
121 | 145 | }
|
| 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 | + } |
122 | 182 | }
|
0 commit comments