Skip to content

Commit 916a0c4

Browse files
committed
Integration tests
Signed-off-by: Christopher Ng <[email protected]>
1 parent 358b029 commit 916a0c4

13 files changed

+504
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright 2022 Christopher Ng <[email protected]>
7+
*
8+
* @author Christopher Ng <[email protected]>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OCA\DAV\Tests\integration\UserMigration;
28+
29+
use function Safe\scandir;
30+
use function Safe\sort;
31+
use OCA\DAV\AppInfo\Application;
32+
use OCA\DAV\UserMigration\CalendarMigrator;
33+
use OCP\AppFramework\App;
34+
use OCP\IUserManager;
35+
use Sabre\VObject\Component\VCalendar;
36+
use Sabre\VObject\Reader as VObjectReader;
37+
use Sabre\VObject\UUIDUtil;
38+
use Test\TestCase;
39+
40+
/**
41+
* @group DB
42+
*/
43+
class CalendarMigratorTest extends TestCase {
44+
45+
private IUserManager $userManager;
46+
47+
private CalendarMigrator $migrator;
48+
49+
private const ASSETS_DIR = __DIR__ . '/assets/';
50+
51+
protected function setUp(): void {
52+
$app = new App(Application::APP_ID);
53+
$container = $app->getContainer();
54+
55+
$this->userManager = $container->get(IUserManager::class);
56+
$this->migrator = $container->get(CalendarMigrator::class);
57+
}
58+
59+
public function dataAssets() {
60+
return array_map(
61+
function (string $filename) {
62+
/** @var VCalendar $vCalendar */
63+
$vCalendar = VObjectReader::read(
64+
fopen(self::ASSETS_DIR . $filename, 'r'),
65+
VObjectReader::OPTION_FORGIVING,
66+
);
67+
[$initialCalendarUri, $ext] = explode('.', $filename, 2);
68+
return [UUIDUtil::getUUID(), $filename, $initialCalendarUri, $vCalendar];
69+
},
70+
// Get asset files excluding current and parent directories
71+
array_diff(
72+
scandir(self::ASSETS_DIR),
73+
['.', '..'],
74+
),
75+
);
76+
}
77+
78+
/**
79+
* @dataProvider dataAssets
80+
*/
81+
public function testImportExportAssets(string $userId, string $filename, string $initialCalendarUri, VCalendar $importCalendar) {
82+
$user = $this->userManager->createUser($userId, 'topsecretpassword');
83+
84+
$problems = $importCalendar->validate();
85+
$this->assertEmpty($problems);
86+
87+
$this->migrator->importCalendar($user, $filename, $initialCalendarUri, $importCalendar);
88+
89+
$calendarExports = $this->migrator->getCalendarExports($user);
90+
/**
91+
* @var string $name
92+
* @var VCalendar $exportedCalendar
93+
*/
94+
['name' => $name, 'vCalendar' => $exportedCalendar] = reset($calendarExports);
95+
96+
// Remove default properties added on import
97+
$exportedCalendar->remove('X-WR-CALNAME');
98+
$exportedCalendar->remove('X-APPLE-CALENDAR-COLOR');
99+
100+
// TODO compare each serialized component instead of using this hack
101+
$importedArray = explode("\n", $importCalendar->serialize());
102+
$exportedArray = explode("\n", $exportedCalendar->serialize());
103+
sort($importedArray);
104+
sort($exportedArray);
105+
$importedSorted = implode("\n", $importedArray);
106+
$exportedSorted = implode("\n", $exportedArray);
107+
108+
$this->assertEquals(
109+
$importedSorted,
110+
$exportedSorted,
111+
);
112+
113+
// TODO test removal of RSVP on import
114+
}
115+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
BEGIN:VCALENDAR
2+
VERSION:2.0
3+
PRODID:-//SabreDAV//SabreDAV//EN
4+
CALSCALE:GREGORIAN
5+
BEGIN:VTIMEZONE
6+
TZID:Europe/Berlin
7+
BEGIN:DAYLIGHT
8+
TZOFFSETFROM:+0100
9+
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
10+
DTSTART:19810329T020000
11+
TZNAME:GMT+2
12+
TZOFFSETTO:+0200
13+
END:DAYLIGHT
14+
BEGIN:STANDARD
15+
TZOFFSETFROM:+0200
16+
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
17+
DTSTART:19961027T030000
18+
TZNAME:GMT+1
19+
TZOFFSETTO:+0100
20+
END:STANDARD
21+
END:VTIMEZONE
22+
BEGIN:VEVENT
23+
CREATED:20160809T163629Z
24+
UID:0AD16F58-01B3-463B-A215-FD09FC729A02
25+
DTEND;TZID=Europe/Berlin:20160816T100000
26+
TRANSP:OPAQUE
27+
SUMMARY:Test Europe Berlin
28+
DTSTART;TZID=Europe/Berlin:20160816T090000
29+
DTSTAMP:20160809T163632Z
30+
SEQUENCE:0
31+
BEGIN:VALARM
32+
ACTION:DISPLAY
33+
TRIGGER;RELATED=START:P1DT9H
34+
END:VALARM
35+
BEGIN:VALARM
36+
ACTION:DISPLAY
37+
TRIGGER;VALUE=DATE-TIME:20200306T083000Z
38+
END:VALARM
39+
END:VEVENT
40+
END:VCALENDAR
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
BEGIN:VCALENDAR
2+
VERSION:2.0
3+
PRODID:-//SabreDAV//SabreDAV//EN
4+
CALSCALE:GREGORIAN
5+
BEGIN:VEVENT
6+
CREATED:20161004T144433Z
7+
UID:85560E76-1B0D-47E1-A735-21625767FCA4
8+
DTEND;VALUE=DATE:20161008
9+
TRANSP:TRANSPARENT
10+
DTSTART;VALUE=DATE:20161005
11+
DTSTAMP:20161004T144437Z
12+
SUMMARY:allday event
13+
SEQUENCE:0
14+
END:VEVENT
15+
END:VCALENDAR
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
BEGIN:VCALENDAR
2+
VERSION:2.0
3+
PRODID:-//SabreDAV//SabreDAV//EN
4+
CALSCALE:GREGORIAN
5+
BEGIN:VTIMEZONE
6+
TZID:Europe/Berlin
7+
BEGIN:DAYLIGHT
8+
TZOFFSETFROM:+0100
9+
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
10+
DTSTART:19810329T020000
11+
TZNAME:GMT+2
12+
TZOFFSETTO:+0200
13+
END:DAYLIGHT
14+
BEGIN:STANDARD
15+
TZOFFSETFROM:+0200
16+
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
17+
DTSTART:19961027T030000
18+
TZNAME:GMT+1
19+
TZOFFSETTO:+0100
20+
END:STANDARD
21+
END:VTIMEZONE
22+
BEGIN:VEVENT
23+
CREATED:20160809T163629Z
24+
UID:0AD16F58-01B3-463B-A215-FD09FC729A02
25+
DTEND;TZID=Europe/Berlin:20160816T100000
26+
TRANSP:OPAQUE
27+
SUMMARY:Test Europe Berlin
28+
DTSTART;TZID=Europe/Berlin:20160816T090000
29+
DTSTAMP:20160809T163632Z
30+
SEQUENCE:0
31+
ORGANIZER;CN=John Smith:mailto:[email protected]
32+
ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT:mailto:[email protected]
33+
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=TENTATIVE;CN=Henry Cabot:mailto:[email protected]
34+
ATTENDEE;ROLE=REQ-PARTICIPANT;DELEGATED-FROM="mailto:[email protected]";PARTSTAT=ACCEPTED;CN=Jane Doe:mailto:[email protected]
35+
ATTENDEE;ROLE=NON-PARTICIPANT;PARTSTAT=DELEGATED;DELEGATED-TO="mailto:[email protected]";CN=The Big Cheese:mailto:[email protected]
36+
END:VEVENT
37+
END:VCALENDAR
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
BEGIN:VCALENDAR
2+
VERSION:2.0
3+
PRODID:-//SabreDAV//SabreDAV//EN
4+
CALSCALE:GREGORIAN
5+
BEGIN:VTIMEZONE
6+
TZID:Europe/Berlin
7+
BEGIN:DAYLIGHT
8+
TZOFFSETFROM:+0100
9+
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
10+
DTSTART:19810329T020000
11+
TZNAME:GMT+2
12+
TZOFFSETTO:+0200
13+
END:DAYLIGHT
14+
BEGIN:STANDARD
15+
TZOFFSETFROM:+0200
16+
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
17+
DTSTART:19961027T030000
18+
TZNAME:GMT+1
19+
TZOFFSETTO:+0100
20+
END:STANDARD
21+
END:VTIMEZONE
22+
BEGIN:VEVENT
23+
CREATED:20160809T163629Z
24+
UID:0AD16F58-01B3-463B-A215-FD09FC729A02
25+
DTEND;TZID=Europe/Berlin:20160816T100000
26+
TRANSP:OPAQUE
27+
SUMMARY:Test Europe Berlin
28+
DTSTART;TZID=Europe/Berlin:20160816T090000
29+
DTSTAMP:20160809T163632Z
30+
SEQUENCE:0
31+
CATEGORIES:BUSINESS,HUMAN RESOURCES
32+
END:VEVENT
33+
END:VCALENDAR
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
BEGIN:VCALENDAR
2+
VERSION:2.0
3+
PRODID:-//SabreDAV//SabreDAV//EN
4+
CALSCALE:GREGORIAN
5+
BEGIN:VTIMEZONE
6+
TZID:Europe/Berlin
7+
BEGIN:DAYLIGHT
8+
TZOFFSETFROM:+0100
9+
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
10+
DTSTART:19810329T020000
11+
TZNAME:GMT+2
12+
TZOFFSETTO:+0200
13+
END:DAYLIGHT
14+
BEGIN:STANDARD
15+
TZOFFSETFROM:+0200
16+
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
17+
DTSTART:19961027T030000
18+
TZNAME:GMT+1
19+
TZOFFSETTO:+0100
20+
END:STANDARD
21+
END:VTIMEZONE
22+
BEGIN:VEVENT
23+
CREATED:20160809T163629Z
24+
UID:0AD16F58-01B3-463B-A215-FD09FC729A02
25+
DTEND;TZID=Europe/Berlin:20160816T100000
26+
TRANSP:OPAQUE
27+
SUMMARY:Test Europe Berlin
28+
DTSTART;TZID=Europe/Berlin:20160816T090000
29+
DTSTAMP:20160809T163632Z
30+
SEQUENCE:0
31+
COLOR:turquoise
32+
END:VEVENT
33+
END:VCALENDAR
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
BEGIN:VCALENDAR
2+
VERSION:2.0
3+
PRODID:-//SabreDAV//SabreDAV//EN
4+
CALSCALE:GREGORIAN
5+
BEGIN:VTIMEZONE
6+
TZID:Europe/Berlin
7+
BEGIN:DAYLIGHT
8+
TZOFFSETFROM:+0100
9+
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
10+
DTSTART:19810329T020000
11+
TZNAME:GMT+2
12+
TZOFFSETTO:+0200
13+
END:DAYLIGHT
14+
BEGIN:STANDARD
15+
TZOFFSETFROM:+0200
16+
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
17+
DTSTART:19961027T030000
18+
TZNAME:GMT+1
19+
TZOFFSETTO:+0100
20+
END:STANDARD
21+
END:VTIMEZONE
22+
BEGIN:VEVENT
23+
CREATED:20160809T163629Z
24+
UID:0AD16F58-01B3-463B-A215-FD09FC729A02
25+
DTEND;TZID=Europe/Berlin:20160816T100000
26+
TRANSP:OPAQUE
27+
SUMMARY:Test Europe Berlin
28+
DTSTART;TZID=Europe/Berlin:20160816T090000
29+
DTSTAMP:20160809T163632Z
30+
SEQUENCE:0
31+
END:VEVENT
32+
END:VCALENDAR
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
BEGIN:VCALENDAR
2+
PRODID:-//SabreDAV//SabreDAV//EN
3+
CALSCALE:GREGORIAN
4+
VERSION:2.0
5+
BEGIN:VEVENT
6+
CREATED:20200401T142357Z
7+
DTSTAMP:20200401T142406Z
8+
LAST-MODIFIED:20200401T142406Z
9+
SEQUENCE:2
10+
UID:4f7a5e63-6ae5-43da-b949-7bad490882c5
11+
DTSTART;VALUE=DATE:20200401
12+
DTEND;VALUE=DATE:20200402
13+
RRULE:FREQ=WEEKLY;BYDAY=WE
14+
SUMMARY:Weekly test
15+
END:VEVENT
16+
END:VCALENDAR

0 commit comments

Comments
 (0)