|
2 | 2 |
|
3 | 3 | use Carbon\Carbon;
|
4 | 4 | use Carbon\CarbonImmutable;
|
5 |
| -use function PHPUnit\Framework\assertEquals; |
6 |
| -use function PHPUnit\Framework\assertInstanceOf; |
7 | 5 | use Spatie\IcalendarGenerator\Components\Calendar;
|
8 | 6 | use Spatie\IcalendarGenerator\Components\Event;
|
9 | 7 | use Spatie\IcalendarGenerator\Components\Timezone;
|
10 |
| - |
11 | 8 | use Spatie\IcalendarGenerator\Tests\PayloadExpectation;
|
12 | 9 | use Spatie\IcalendarGenerator\Tests\PropertyExpectation;
|
13 | 10 |
|
| 11 | +use function PHPUnit\Framework\assertEquals; |
| 12 | +use function PHPUnit\Framework\assertInstanceOf; |
| 13 | + |
14 | 14 | test('it can create a calendar', function () {
|
15 | 15 | $payload = Calendar::create()->resolvePayload();
|
16 | 16 |
|
@@ -143,7 +143,7 @@ function (Event $event) {
|
143 | 143 | ->expectParameterValue('VALUE', 'URI');
|
144 | 144 | });
|
145 | 145 |
|
146 |
| -test('it will automatically add multiple timezone components', function () { |
| 146 | +test('it will automatically add multiple timezone components (through Carbon)', function () { |
147 | 147 | Carbon::setTestNow(new CarbonImmutable('1 august 2020'));
|
148 | 148 |
|
149 | 149 | $utcEvent = Event::create('An event with UTC timezone')
|
@@ -176,23 +176,52 @@ function (Event $event) {
|
176 | 176 | ->expectSubComponentNotInstanceOf(4, Timezone::class);
|
177 | 177 | });
|
178 | 178 |
|
179 |
| -test('it will automatically add timezone component', function () { |
180 |
| - Carbon::setTestNow(new CarbonImmutable('1 august 2020')); |
| 179 | +test('it will automatically add multiple timezone components', function () { |
| 180 | + $utcEvent = Event::create('An event with UTC timezone') |
| 181 | + ->startsAt(new DateTimeImmutable('1 january 2019')) |
| 182 | + ->endsAt(new DateTimeImmutable('1 january 2021')); |
| 183 | + |
| 184 | + $alternativeTimezoneEvent = Event::create('An event with alternative timezone') |
| 185 | + ->startsAt(new DateTimeImmutable('1 january 2020', new \DateTimeZone('Europe/Brussels'))) |
| 186 | + ->endsAt(new DateTimeImmutable('1 january 2021', new \DateTimeZone('Europe/Brussels'))); |
| 187 | + |
| 188 | + $withoutTimezoneEvent = Event::create('An event without timezone') |
| 189 | + ->withoutTimezone() |
| 190 | + ->startsAt(new DateTimeImmutable('1 january 1995', new \DateTimeZone('America/New_York'))) |
| 191 | + ->endsAt(new DateTimeImmutable('1 january 2021', new \DateTimeZone('America/New_York'))); |
| 192 | + |
| 193 | + $payload = Calendar::create()->event( |
| 194 | + [$utcEvent, $alternativeTimezoneEvent, $withoutTimezoneEvent] |
| 195 | + )->resolvePayload(); |
181 | 196 |
|
| 197 | + PayloadExpectation::create($payload) |
| 198 | + ->expectSubComponentCount(5) |
| 199 | + ->expectSubComponent(0, function (PayloadExpectation $expectation) { |
| 200 | + $expectation->expectType('VTIMEZONE')->expectPropertyValue('TZID', 'UTC'); |
| 201 | + }) |
| 202 | + ->expectSubComponent(1, function (PayloadExpectation $expectation) { |
| 203 | + $expectation->expectType('VTIMEZONE')->expectPropertyValue('TZID', 'Europe/Brussels'); |
| 204 | + }) |
| 205 | + ->expectSubComponentNotInstanceOf(2, Timezone::class) |
| 206 | + ->expectSubComponentNotInstanceOf(3, Timezone::class) |
| 207 | + ->expectSubComponentNotInstanceOf(4, Timezone::class); |
| 208 | +}); |
| 209 | + |
| 210 | +test('it will automatically add timezone component', function () { |
182 | 211 | $utcEvent = Event::create('An event with UTC timezone')
|
183 |
| - ->createdAt(new CarbonImmutable('1 january 2019')) |
184 |
| - ->startsAt(new CarbonImmutable('1 january 2019')) |
185 |
| - ->endsAt(new CarbonImmutable('1 january 2021')); |
| 212 | + ->createdAt(new DateTimeImmutable('1 january 2019')) |
| 213 | + ->startsAt(new DateTimeImmutable('1 january 2019')) |
| 214 | + ->endsAt(new DateTimeImmutable('1 january 2021')); |
186 | 215 |
|
187 | 216 | $alternativeTimezoneEvent = Event::create('An event with alternative timezone')
|
188 |
| - ->createdAt(new CarbonImmutable('1 january 2020', 'Europe/Brussels')) |
189 |
| - ->startsAt(new CarbonImmutable('1 january 2020', 'Europe/Brussels')) |
190 |
| - ->endsAt(new CarbonImmutable('1 january 2021', 'Europe/Brussels')); |
| 217 | + ->createdAt(new DateTimeImmutable('1 january 2020', new \DateTimeZone('Europe/Brussels'))) |
| 218 | + ->startsAt(new DateTimeImmutable('1 january 2020', new \DateTimeZone('Europe/Brussels'))) |
| 219 | + ->endsAt(new DateTimeImmutable('1 january 2021', new \DateTimeZone('Europe/Brussels'))); |
191 | 220 |
|
192 | 221 | $negativeOffsetTimezoneEvent = Event::create('An event with a negative timezone offset')
|
193 |
| - ->createdAt(new CarbonImmutable('1 january 2020', 'America/New_York')) |
194 |
| - ->startsAt(new CarbonImmutable('1 january 2020', 'America/New_York')) |
195 |
| - ->endsAt(new CarbonImmutable('1 january 2021', 'America/New_York')); |
| 222 | + ->createdAt(new DateTimeImmutable('1 january 2020', new \DateTimeZone('America/New_York'))) |
| 223 | + ->startsAt(new DateTimeImmutable('1 january 2020', new \DateTimeZone('America/New_York'))) |
| 224 | + ->endsAt(new DateTimeImmutable('1 january 2021', new \DateTimeZone('America/New_York'))); |
196 | 225 |
|
197 | 226 | $payload = Calendar::create()->event(
|
198 | 227 | [$utcEvent, $alternativeTimezoneEvent, $negativeOffsetTimezoneEvent]
|
|
0 commit comments