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