1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Eluceo\iCal\Test\Unit\Presentation; |
4
|
|
|
|
5
|
|
|
use Eluceo\iCal\Presentation\Calendar; |
6
|
|
|
use Eluceo\iCal\Presentation\Component; |
7
|
|
|
use Eluceo\iCal\Presentation\Component\Property; |
8
|
|
|
use Eluceo\iCal\Presentation\Component\Property\Value\StringValue; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
class CalendarTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
public function testEmptyCalendarToString() |
14
|
|
|
{ |
15
|
|
|
$expected = implode(Component::LINE_SEPARATOR, [ |
16
|
|
|
'BEGIN:VCALENDAR', |
17
|
|
|
'END:VCALENDAR', |
18
|
|
|
]); |
19
|
|
|
|
20
|
|
|
self::assertSame($expected, (string)Calendar::createCalendar()); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testWithSingleComponentToString() |
24
|
|
|
{ |
25
|
|
|
$expected = implode(Component::LINE_SEPARATOR, [ |
26
|
|
|
'BEGIN:VCALENDAR', |
27
|
|
|
'BEGIN:VEVENT', |
28
|
|
|
'END:VEVENT', |
29
|
|
|
'END:VCALENDAR', |
30
|
|
|
]); |
31
|
|
|
|
32
|
|
|
$components = [ |
33
|
|
|
Component::create('VEVENT'), |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
$calendar = Calendar::createCalendar($components); |
37
|
|
|
|
38
|
|
|
self::assertSame($expected, (string)$calendar); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testWithMultipleComponentsToString() |
42
|
|
|
{ |
43
|
|
|
$expected = implode(Component::LINE_SEPARATOR, [ |
44
|
|
|
'BEGIN:VCALENDAR', |
45
|
|
|
'BEGIN:VEVENT', |
46
|
|
|
'UID:event1', |
47
|
|
|
'END:VEVENT', |
48
|
|
|
'BEGIN:VEVENT', |
49
|
|
|
'UID:event2', |
50
|
|
|
'END:VEVENT', |
51
|
|
|
'END:VCALENDAR', |
52
|
|
|
]); |
53
|
|
|
|
54
|
|
|
$components = [ |
55
|
|
|
Component::create( |
56
|
|
|
'VEVENT', |
57
|
|
|
[ |
58
|
|
|
Property::create('UID', StringValue::fromString('event1')), |
59
|
|
|
] |
60
|
|
|
), |
61
|
|
|
Component::create( |
62
|
|
|
'VEVENT', |
63
|
|
|
[ |
64
|
|
|
Property::create('UID', StringValue::fromString('event2')), |
65
|
|
|
] |
66
|
|
|
), |
67
|
|
|
]; |
68
|
|
|
|
69
|
|
|
$calendar = Calendar::createCalendar($components); |
70
|
|
|
|
71
|
|
|
self::assertSame($expected, (string)$calendar); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testRenderOwnPropertiesBeforeComponents() |
75
|
|
|
{ |
76
|
|
|
$expected = implode(Component::LINE_SEPARATOR, [ |
77
|
|
|
'BEGIN:VCALENDAR', |
78
|
|
|
'TEST:value', |
79
|
|
|
'TEST2:value2', |
80
|
|
|
'BEGIN:VEVENT', |
81
|
|
|
'END:VEVENT', |
82
|
|
|
'END:VCALENDAR', |
83
|
|
|
]); |
84
|
|
|
|
85
|
|
|
$properties = [ |
86
|
|
|
Property::create('TEST', StringValue::fromString('value')), |
87
|
|
|
Property::create('TEST2', StringValue::fromString('value2')), |
88
|
|
|
]; |
89
|
|
|
|
90
|
|
|
$components = [ |
91
|
|
|
Component::create('VEVENT'), |
92
|
|
|
]; |
93
|
|
|
|
94
|
|
|
$calendar = Calendar::createCalendar($components, $properties); |
95
|
|
|
|
96
|
|
|
self::assertSame($expected, (string)$calendar); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|