|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the eluceo/iCal package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2019 Markus Poerschke <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Eluceo\iCal\Test\Unit\Presentation\Factory; |
|
13
|
|
|
|
|
14
|
|
|
use DateTimeImmutable; |
|
15
|
|
|
use DateTimeZone; |
|
16
|
|
|
use Eluceo\iCal\Domain\Entity\Calendar; |
|
17
|
|
|
use Eluceo\iCal\Domain\Entity\Event; |
|
18
|
|
|
use Eluceo\iCal\Domain\ValueObject\Timestamp; |
|
19
|
|
|
use Eluceo\iCal\Domain\ValueObject\UniqueIdentifier; |
|
20
|
|
|
use Eluceo\iCal\Presentation\Component; |
|
21
|
|
|
use Eluceo\iCal\Presentation\Factory\CalendarFactory; |
|
22
|
|
|
use PHPUnit\Framework\TestCase; |
|
23
|
|
|
|
|
24
|
|
|
class CalendarFactoryTest extends TestCase |
|
25
|
|
|
{ |
|
26
|
|
|
public function testRenderEmptyCalendar() |
|
27
|
|
|
{ |
|
28
|
|
|
$calendar = Calendar::create(); |
|
29
|
|
|
$expected = implode(Component::LINE_SEPARATOR, [ |
|
30
|
|
|
'BEGIN:VCALENDAR', |
|
31
|
|
|
'PRODID:' . $calendar->getProductIdentifier(), |
|
32
|
|
|
'VERSION:2.0', |
|
33
|
|
|
'END:VCALENDAR', |
|
34
|
|
|
]); |
|
35
|
|
|
|
|
36
|
|
|
self::assertSame($expected, (string) (new CalendarFactory())->createCalendar($calendar)); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testRenderWithEvents() |
|
40
|
|
|
{ |
|
41
|
|
|
$currentTime = Timestamp::fromDateTimeInterface( |
|
42
|
|
|
DateTimeImmutable::createFromFormat( |
|
43
|
|
|
'Y-m-d H:i:s', |
|
44
|
|
|
'2019-11-10 11:22:33', |
|
45
|
|
|
new DateTimeZone('UTC') |
|
46
|
|
|
) |
|
47
|
|
|
); |
|
48
|
|
|
$calendar = Calendar::create( |
|
49
|
|
|
[ |
|
50
|
|
|
Event::create(UniqueIdentifier::fromString('event1'))->touch($currentTime), |
|
51
|
|
|
Event::create(UniqueIdentifier::fromString('event2'))->touch($currentTime), |
|
52
|
|
|
] |
|
53
|
|
|
); |
|
54
|
|
|
|
|
55
|
|
|
$expected = implode(Component::LINE_SEPARATOR, [ |
|
56
|
|
|
'BEGIN:VCALENDAR', |
|
57
|
|
|
'PRODID:' . $calendar->getProductIdentifier(), |
|
58
|
|
|
'VERSION:2.0', |
|
59
|
|
|
'BEGIN:VEVENT', |
|
60
|
|
|
'UID:event1', |
|
61
|
|
|
'DTSTAMP:20191110T112233Z', |
|
62
|
|
|
'END:VEVENT', |
|
63
|
|
|
'BEGIN:VEVENT', |
|
64
|
|
|
'UID:event2', |
|
65
|
|
|
'DTSTAMP:20191110T112233Z', |
|
66
|
|
|
'END:VEVENT', |
|
67
|
|
|
'END:VCALENDAR', |
|
68
|
|
|
]); |
|
69
|
|
|
|
|
70
|
|
|
self::assertSame($expected, (string) (new CalendarFactory())->createCalendar($calendar)); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|