1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SRF\Tests\iCalendar; |
4
|
|
|
|
5
|
|
|
use SMW\Tests\TestEnvironment; |
6
|
|
|
use SRF\iCalendar\IcalFormatter; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @covers \SRF\iCalendar\IcalFormatter |
10
|
|
|
* @group semantic-result-formats |
11
|
|
|
* |
12
|
|
|
* @license GNU GPL v2+ |
13
|
|
|
* @since 3.2 |
14
|
|
|
* |
15
|
|
|
* @author mwjames |
16
|
|
|
*/ |
17
|
|
|
class IcalFormatterTest extends \PHPUnit_Framework_TestCase { |
18
|
|
|
|
19
|
|
|
private $stringValidator; |
20
|
|
|
private $icalTimezoneFormatter; |
21
|
|
|
|
22
|
|
|
protected function setUp() { |
23
|
|
|
parent::setUp(); |
24
|
|
|
|
25
|
|
|
$this->icalTimezoneFormatter = $this->getMockBuilder( '\SRF\iCalendar\IcalTimezoneFormatter' ) |
26
|
|
|
->disableOriginalConstructor() |
27
|
|
|
->getMock(); |
28
|
|
|
|
29
|
|
|
$this->stringValidator = TestEnvironment::newValidatorFactory()->newStringValidator(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testCanConstruct() { |
33
|
|
|
|
34
|
|
|
$this->assertInstanceOf( |
35
|
|
|
IcalFormatter::class, |
36
|
|
|
new IcalFormatter( $this->icalTimezoneFormatter ) |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @dataProvider paramsProvider |
42
|
|
|
*/ |
43
|
|
|
public function testGetIcal( $params, $events, $expected ) { |
44
|
|
|
|
45
|
|
|
$instance = new IcalFormatter( |
46
|
|
|
$this->icalTimezoneFormatter |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
$instance->setCalendarName( $params['calendarname'] ); |
50
|
|
|
$instance->setDescription( $params['description'] ); |
51
|
|
|
|
52
|
|
|
foreach ( $events as $event ) { |
53
|
|
|
$instance->addEvent( $event ); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$this->stringValidator->assertThatStringContains( |
57
|
|
|
$expected, |
58
|
|
|
$instance->getIcal() |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function paramsProvider() { |
63
|
|
|
|
64
|
|
|
yield [ |
65
|
|
|
[ |
66
|
|
|
'calendarname' => 'FooCalendar', |
67
|
|
|
'description' => 'Calendar description' |
68
|
|
|
], |
69
|
|
|
[ |
70
|
|
|
[ |
71
|
|
|
'summary' => 'summary', |
72
|
|
|
'url' => 'http://example.org/Test_1', |
73
|
|
|
'start' => '1 Jan 2000', |
74
|
|
|
'end' => '2 Jan 2000', |
75
|
|
|
'location' => 'FooPlanet', |
76
|
|
|
'description' => 'Event description', |
77
|
|
|
'timestamp' => '1566476717', |
78
|
|
|
'sequence' => '123' |
79
|
|
|
] |
80
|
|
|
], |
81
|
|
|
"BEGIN:VCALENDAR\r\n" . |
82
|
|
|
"PRODID:-//SMW Project//Semantic Result Formats\r\n" . |
83
|
|
|
"VERSION:2.0\r\n" . |
84
|
|
|
"METHOD:PUBLISH\r\n" . |
85
|
|
|
"X-WR-CALNAME:FooCalendar\r\n" . |
86
|
|
|
"X-WR-CALDESC:Calendar description\r\n" . |
87
|
|
|
"BEGIN:VEVENT\r\n" . |
88
|
|
|
"SUMMARY:summary\r\n" . |
89
|
|
|
"URL:http://example.org/Test_1\r\n" . |
90
|
|
|
"UID:http://example.org/Test_1\r\n" . |
91
|
|
|
"DTSTART:1 Jan 2000\r\n" . |
92
|
|
|
"DTEND:2 Jan 2000\r\nLOCATION:FooPlanet\r\n" . |
93
|
|
|
"DESCRIPTION:Event description\r\n" . |
94
|
|
|
"DTSTAMP:19700101T000000\r\n" . |
95
|
|
|
"SEQUENCE:123\r\n" . |
96
|
|
|
"END:VEVENT\r\n" . |
97
|
|
|
"END:VCALENDAR" |
98
|
|
|
]; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
} |
102
|
|
|
|