@@ -18,102 +18,102 @@ |
||
18 | 18 | use Test\TestCase; |
19 | 19 | |
20 | 20 | class RefreshWebcalJobRegistrarTest extends TestCase { |
21 | - private IDBConnection&MockObject $db; |
|
22 | - private IJobList&MockObject $jobList; |
|
23 | - private RefreshWebcalJobRegistrar $migration; |
|
24 | - |
|
25 | - protected function setUp(): void { |
|
26 | - parent::setUp(); |
|
27 | - |
|
28 | - $this->db = $this->createMock(IDBConnection::class); |
|
29 | - $this->jobList = $this->createMock(IJobList::class); |
|
30 | - |
|
31 | - $this->migration = new RefreshWebcalJobRegistrar($this->db, $this->jobList); |
|
32 | - } |
|
33 | - |
|
34 | - public function testGetName(): void { |
|
35 | - $this->assertEquals($this->migration->getName(), 'Registering background jobs to update cache for webcal calendars'); |
|
36 | - } |
|
37 | - |
|
38 | - public function testRun(): void { |
|
39 | - $output = $this->createMock(IOutput::class); |
|
40 | - |
|
41 | - $queryBuilder = $this->createMock(IQueryBuilder::class); |
|
42 | - $statement = $this->createMock(IResult::class); |
|
43 | - |
|
44 | - $this->db->expects($this->once()) |
|
45 | - ->method('getQueryBuilder') |
|
46 | - ->willReturn($queryBuilder); |
|
47 | - |
|
48 | - $queryBuilder->expects($this->once()) |
|
49 | - ->method('select') |
|
50 | - ->with(['principaluri', 'uri']) |
|
51 | - ->willReturn($queryBuilder); |
|
52 | - $queryBuilder->expects($this->once()) |
|
53 | - ->method('from') |
|
54 | - ->with('calendarsubscriptions') |
|
55 | - ->willReturn($queryBuilder); |
|
56 | - $queryBuilder->expects($this->once()) |
|
57 | - ->method('execute') |
|
58 | - ->willReturn($statement); |
|
59 | - |
|
60 | - $statement->expects($this->exactly(4)) |
|
61 | - ->method('fetch') |
|
62 | - ->with(\PDO::FETCH_ASSOC) |
|
63 | - ->willReturnOnConsecutiveCalls( |
|
64 | - [ |
|
65 | - 'principaluri' => 'foo1', |
|
66 | - 'uri' => 'bar1', |
|
67 | - ], |
|
68 | - [ |
|
69 | - 'principaluri' => 'foo2', |
|
70 | - 'uri' => 'bar2', |
|
71 | - ], |
|
72 | - [ |
|
73 | - 'principaluri' => 'foo3', |
|
74 | - 'uri' => 'bar3', |
|
75 | - ], |
|
76 | - null |
|
77 | - ); |
|
78 | - |
|
79 | - $this->jobList->expects($this->exactly(3)) |
|
80 | - ->method('has') |
|
81 | - ->willReturnMap([ |
|
82 | - [RefreshWebcalJob::class, [ |
|
83 | - 'principaluri' => 'foo1', |
|
84 | - 'uri' => 'bar1', |
|
85 | - ], false], |
|
86 | - [RefreshWebcalJob::class, [ |
|
87 | - 'principaluri' => 'foo2', |
|
88 | - 'uri' => 'bar2', |
|
89 | - ], true ], |
|
90 | - [RefreshWebcalJob::class, [ |
|
91 | - 'principaluri' => 'foo3', |
|
92 | - 'uri' => 'bar3', |
|
93 | - ], false], |
|
94 | - ]); |
|
95 | - |
|
96 | - $calls = [ |
|
97 | - [RefreshWebcalJob::class, [ |
|
98 | - 'principaluri' => 'foo1', |
|
99 | - 'uri' => 'bar1', |
|
100 | - ]], |
|
101 | - [RefreshWebcalJob::class, [ |
|
102 | - 'principaluri' => 'foo3', |
|
103 | - 'uri' => 'bar3', |
|
104 | - ]] |
|
105 | - ]; |
|
106 | - $this->jobList->expects($this->exactly(2)) |
|
107 | - ->method('add') |
|
108 | - ->willReturnCallback(function () use (&$calls) { |
|
109 | - $expected = array_shift($calls); |
|
110 | - $this->assertEquals($expected, func_get_args()); |
|
111 | - }); |
|
112 | - |
|
113 | - $output->expects($this->once()) |
|
114 | - ->method('info') |
|
115 | - ->with('Added 2 background jobs to update webcal calendars'); |
|
116 | - |
|
117 | - $this->migration->run($output); |
|
118 | - } |
|
21 | + private IDBConnection&MockObject $db; |
|
22 | + private IJobList&MockObject $jobList; |
|
23 | + private RefreshWebcalJobRegistrar $migration; |
|
24 | + |
|
25 | + protected function setUp(): void { |
|
26 | + parent::setUp(); |
|
27 | + |
|
28 | + $this->db = $this->createMock(IDBConnection::class); |
|
29 | + $this->jobList = $this->createMock(IJobList::class); |
|
30 | + |
|
31 | + $this->migration = new RefreshWebcalJobRegistrar($this->db, $this->jobList); |
|
32 | + } |
|
33 | + |
|
34 | + public function testGetName(): void { |
|
35 | + $this->assertEquals($this->migration->getName(), 'Registering background jobs to update cache for webcal calendars'); |
|
36 | + } |
|
37 | + |
|
38 | + public function testRun(): void { |
|
39 | + $output = $this->createMock(IOutput::class); |
|
40 | + |
|
41 | + $queryBuilder = $this->createMock(IQueryBuilder::class); |
|
42 | + $statement = $this->createMock(IResult::class); |
|
43 | + |
|
44 | + $this->db->expects($this->once()) |
|
45 | + ->method('getQueryBuilder') |
|
46 | + ->willReturn($queryBuilder); |
|
47 | + |
|
48 | + $queryBuilder->expects($this->once()) |
|
49 | + ->method('select') |
|
50 | + ->with(['principaluri', 'uri']) |
|
51 | + ->willReturn($queryBuilder); |
|
52 | + $queryBuilder->expects($this->once()) |
|
53 | + ->method('from') |
|
54 | + ->with('calendarsubscriptions') |
|
55 | + ->willReturn($queryBuilder); |
|
56 | + $queryBuilder->expects($this->once()) |
|
57 | + ->method('execute') |
|
58 | + ->willReturn($statement); |
|
59 | + |
|
60 | + $statement->expects($this->exactly(4)) |
|
61 | + ->method('fetch') |
|
62 | + ->with(\PDO::FETCH_ASSOC) |
|
63 | + ->willReturnOnConsecutiveCalls( |
|
64 | + [ |
|
65 | + 'principaluri' => 'foo1', |
|
66 | + 'uri' => 'bar1', |
|
67 | + ], |
|
68 | + [ |
|
69 | + 'principaluri' => 'foo2', |
|
70 | + 'uri' => 'bar2', |
|
71 | + ], |
|
72 | + [ |
|
73 | + 'principaluri' => 'foo3', |
|
74 | + 'uri' => 'bar3', |
|
75 | + ], |
|
76 | + null |
|
77 | + ); |
|
78 | + |
|
79 | + $this->jobList->expects($this->exactly(3)) |
|
80 | + ->method('has') |
|
81 | + ->willReturnMap([ |
|
82 | + [RefreshWebcalJob::class, [ |
|
83 | + 'principaluri' => 'foo1', |
|
84 | + 'uri' => 'bar1', |
|
85 | + ], false], |
|
86 | + [RefreshWebcalJob::class, [ |
|
87 | + 'principaluri' => 'foo2', |
|
88 | + 'uri' => 'bar2', |
|
89 | + ], true ], |
|
90 | + [RefreshWebcalJob::class, [ |
|
91 | + 'principaluri' => 'foo3', |
|
92 | + 'uri' => 'bar3', |
|
93 | + ], false], |
|
94 | + ]); |
|
95 | + |
|
96 | + $calls = [ |
|
97 | + [RefreshWebcalJob::class, [ |
|
98 | + 'principaluri' => 'foo1', |
|
99 | + 'uri' => 'bar1', |
|
100 | + ]], |
|
101 | + [RefreshWebcalJob::class, [ |
|
102 | + 'principaluri' => 'foo3', |
|
103 | + 'uri' => 'bar3', |
|
104 | + ]] |
|
105 | + ]; |
|
106 | + $this->jobList->expects($this->exactly(2)) |
|
107 | + ->method('add') |
|
108 | + ->willReturnCallback(function () use (&$calls) { |
|
109 | + $expected = array_shift($calls); |
|
110 | + $this->assertEquals($expected, func_get_args()); |
|
111 | + }); |
|
112 | + |
|
113 | + $output->expects($this->once()) |
|
114 | + ->method('info') |
|
115 | + ->with('Added 2 background jobs to update webcal calendars'); |
|
116 | + |
|
117 | + $this->migration->run($output); |
|
118 | + } |
|
119 | 119 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | [RefreshWebcalJob::class, [ |
87 | 87 | 'principaluri' => 'foo2', |
88 | 88 | 'uri' => 'bar2', |
89 | - ], true ], |
|
89 | + ], true], |
|
90 | 90 | [RefreshWebcalJob::class, [ |
91 | 91 | 'principaluri' => 'foo3', |
92 | 92 | 'uri' => 'bar3', |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | ]; |
106 | 106 | $this->jobList->expects($this->exactly(2)) |
107 | 107 | ->method('add') |
108 | - ->willReturnCallback(function () use (&$calls) { |
|
108 | + ->willReturnCallback(function() use (&$calls) { |
|
109 | 109 | $expected = array_shift($calls); |
110 | 110 | $this->assertEquals($expected, func_get_args()); |
111 | 111 | }); |
@@ -16,63 +16,63 @@ |
||
16 | 16 | use Test\TestCase; |
17 | 17 | |
18 | 18 | class RegenerateBirthdayCalendarsTest extends TestCase { |
19 | - private IJobList&MockObject $jobList; |
|
20 | - private IConfig&MockObject $config; |
|
21 | - private RegenerateBirthdayCalendars $migration; |
|
22 | - |
|
23 | - protected function setUp(): void { |
|
24 | - parent::setUp(); |
|
25 | - |
|
26 | - $this->jobList = $this->createMock(IJobList::class); |
|
27 | - $this->config = $this->createMock(IConfig::class); |
|
28 | - |
|
29 | - $this->migration = new RegenerateBirthdayCalendars($this->jobList, |
|
30 | - $this->config); |
|
31 | - } |
|
32 | - |
|
33 | - public function testGetName(): void { |
|
34 | - $this->assertEquals( |
|
35 | - 'Regenerating birthday calendars to use new icons and fix old birthday events without year', |
|
36 | - $this->migration->getName() |
|
37 | - ); |
|
38 | - } |
|
39 | - |
|
40 | - public function testRun(): void { |
|
41 | - $this->config->expects($this->once()) |
|
42 | - ->method('getAppValue') |
|
43 | - ->with('dav', 'regeneratedBirthdayCalendarsForYearFix') |
|
44 | - ->willReturn(null); |
|
45 | - |
|
46 | - $output = $this->createMock(IOutput::class); |
|
47 | - $output->expects($this->once()) |
|
48 | - ->method('info') |
|
49 | - ->with('Adding background jobs to regenerate birthday calendar'); |
|
50 | - |
|
51 | - $this->jobList->expects($this->once()) |
|
52 | - ->method('add') |
|
53 | - ->with(RegisterRegenerateBirthdayCalendars::class); |
|
54 | - |
|
55 | - $this->config->expects($this->once()) |
|
56 | - ->method('setAppValue') |
|
57 | - ->with('dav', 'regeneratedBirthdayCalendarsForYearFix', 'yes'); |
|
58 | - |
|
59 | - $this->migration->run($output); |
|
60 | - } |
|
61 | - |
|
62 | - public function testRunSecondTime(): void { |
|
63 | - $this->config->expects($this->once()) |
|
64 | - ->method('getAppValue') |
|
65 | - ->with('dav', 'regeneratedBirthdayCalendarsForYearFix') |
|
66 | - ->willReturn('yes'); |
|
67 | - |
|
68 | - $output = $this->createMock(IOutput::class); |
|
69 | - $output->expects($this->once()) |
|
70 | - ->method('info') |
|
71 | - ->with('Repair step already executed'); |
|
72 | - |
|
73 | - $this->jobList->expects($this->never()) |
|
74 | - ->method('add'); |
|
75 | - |
|
76 | - $this->migration->run($output); |
|
77 | - } |
|
19 | + private IJobList&MockObject $jobList; |
|
20 | + private IConfig&MockObject $config; |
|
21 | + private RegenerateBirthdayCalendars $migration; |
|
22 | + |
|
23 | + protected function setUp(): void { |
|
24 | + parent::setUp(); |
|
25 | + |
|
26 | + $this->jobList = $this->createMock(IJobList::class); |
|
27 | + $this->config = $this->createMock(IConfig::class); |
|
28 | + |
|
29 | + $this->migration = new RegenerateBirthdayCalendars($this->jobList, |
|
30 | + $this->config); |
|
31 | + } |
|
32 | + |
|
33 | + public function testGetName(): void { |
|
34 | + $this->assertEquals( |
|
35 | + 'Regenerating birthday calendars to use new icons and fix old birthday events without year', |
|
36 | + $this->migration->getName() |
|
37 | + ); |
|
38 | + } |
|
39 | + |
|
40 | + public function testRun(): void { |
|
41 | + $this->config->expects($this->once()) |
|
42 | + ->method('getAppValue') |
|
43 | + ->with('dav', 'regeneratedBirthdayCalendarsForYearFix') |
|
44 | + ->willReturn(null); |
|
45 | + |
|
46 | + $output = $this->createMock(IOutput::class); |
|
47 | + $output->expects($this->once()) |
|
48 | + ->method('info') |
|
49 | + ->with('Adding background jobs to regenerate birthday calendar'); |
|
50 | + |
|
51 | + $this->jobList->expects($this->once()) |
|
52 | + ->method('add') |
|
53 | + ->with(RegisterRegenerateBirthdayCalendars::class); |
|
54 | + |
|
55 | + $this->config->expects($this->once()) |
|
56 | + ->method('setAppValue') |
|
57 | + ->with('dav', 'regeneratedBirthdayCalendarsForYearFix', 'yes'); |
|
58 | + |
|
59 | + $this->migration->run($output); |
|
60 | + } |
|
61 | + |
|
62 | + public function testRunSecondTime(): void { |
|
63 | + $this->config->expects($this->once()) |
|
64 | + ->method('getAppValue') |
|
65 | + ->with('dav', 'regeneratedBirthdayCalendarsForYearFix') |
|
66 | + ->willReturn('yes'); |
|
67 | + |
|
68 | + $output = $this->createMock(IOutput::class); |
|
69 | + $output->expects($this->once()) |
|
70 | + ->method('info') |
|
71 | + ->with('Repair step already executed'); |
|
72 | + |
|
73 | + $this->jobList->expects($this->never()) |
|
74 | + ->method('add'); |
|
75 | + |
|
76 | + $this->migration->run($output); |
|
77 | + } |
|
78 | 78 | } |
@@ -17,31 +17,31 @@ |
||
17 | 17 | |
18 | 18 | class CreateSystemAddressBookStepTest extends TestCase { |
19 | 19 | |
20 | - private SyncService&MockObject $syncService; |
|
21 | - private CreateSystemAddressBookStep $step; |
|
20 | + private SyncService&MockObject $syncService; |
|
21 | + private CreateSystemAddressBookStep $step; |
|
22 | 22 | |
23 | - protected function setUp(): void { |
|
24 | - parent::setUp(); |
|
23 | + protected function setUp(): void { |
|
24 | + parent::setUp(); |
|
25 | 25 | |
26 | - $this->syncService = $this->createMock(SyncService::class); |
|
26 | + $this->syncService = $this->createMock(SyncService::class); |
|
27 | 27 | |
28 | - $this->step = new CreateSystemAddressBookStep( |
|
29 | - $this->syncService, |
|
30 | - ); |
|
31 | - } |
|
28 | + $this->step = new CreateSystemAddressBookStep( |
|
29 | + $this->syncService, |
|
30 | + ); |
|
31 | + } |
|
32 | 32 | |
33 | - public function testGetName(): void { |
|
34 | - $name = $this->step->getName(); |
|
33 | + public function testGetName(): void { |
|
34 | + $name = $this->step->getName(); |
|
35 | 35 | |
36 | - self::assertEquals('Create system address book', $name); |
|
37 | - } |
|
36 | + self::assertEquals('Create system address book', $name); |
|
37 | + } |
|
38 | 38 | |
39 | - public function testRun(): void { |
|
40 | - $output = $this->createMock(IOutput::class); |
|
39 | + public function testRun(): void { |
|
40 | + $output = $this->createMock(IOutput::class); |
|
41 | 41 | |
42 | - $this->step->run($output); |
|
42 | + $this->step->run($output); |
|
43 | 43 | |
44 | - $this->addToAssertionCount(1); |
|
45 | - } |
|
44 | + $this->addToAssertionCount(1); |
|
45 | + } |
|
46 | 46 | |
47 | 47 | } |
@@ -22,121 +22,121 @@ |
||
22 | 22 | use Test\TestCase; |
23 | 23 | |
24 | 24 | class RemoveDeletedUsersCalendarSubscriptionsTest extends TestCase { |
25 | - private IDBConnection&MockObject $dbConnection; |
|
26 | - private IUserManager&MockObject $userManager; |
|
27 | - private IOutput&MockObject $output; |
|
28 | - private RemoveDeletedUsersCalendarSubscriptions $migration; |
|
25 | + private IDBConnection&MockObject $dbConnection; |
|
26 | + private IUserManager&MockObject $userManager; |
|
27 | + private IOutput&MockObject $output; |
|
28 | + private RemoveDeletedUsersCalendarSubscriptions $migration; |
|
29 | 29 | |
30 | 30 | |
31 | - protected function setUp(): void { |
|
32 | - parent::setUp(); |
|
33 | - |
|
34 | - $this->dbConnection = $this->createMock(IDBConnection::class); |
|
35 | - $this->userManager = $this->createMock(IUserManager::class); |
|
36 | - $this->output = $this->createMock(IOutput::class); |
|
37 | - |
|
38 | - $this->migration = new RemoveDeletedUsersCalendarSubscriptions($this->dbConnection, $this->userManager); |
|
39 | - } |
|
40 | - |
|
41 | - public function testGetName(): void { |
|
42 | - $this->assertEquals( |
|
43 | - 'Clean up old calendar subscriptions from deleted users that were not cleaned-up', |
|
44 | - $this->migration->getName() |
|
45 | - ); |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * @dataProvider dataTestRun |
|
50 | - */ |
|
51 | - public function testRun(array $subscriptions, array $userExists, int $deletions): void { |
|
52 | - $qb = $this->createMock(IQueryBuilder::class); |
|
53 | - |
|
54 | - $qb->method('select')->willReturn($qb); |
|
55 | - |
|
56 | - $functionBuilder = $this->createMock(IFunctionBuilder::class); |
|
57 | - |
|
58 | - $qb->method('func')->willReturn($functionBuilder); |
|
59 | - $functionBuilder->method('count')->willReturn($this->createMock(IQueryFunction::class)); |
|
60 | - |
|
61 | - $qb->method('selectDistinct') |
|
62 | - ->with(['id', 'principaluri']) |
|
63 | - ->willReturn($qb); |
|
64 | - |
|
65 | - $qb->method('from') |
|
66 | - ->with('calendarsubscriptions') |
|
67 | - ->willReturn($qb); |
|
68 | - |
|
69 | - $qb->method('setMaxResults') |
|
70 | - ->willReturn($qb); |
|
71 | - |
|
72 | - $qb->method('setFirstResult') |
|
73 | - ->willReturn($qb); |
|
74 | - |
|
75 | - $result = $this->createMock(IResult::class); |
|
76 | - |
|
77 | - $qb->method('execute') |
|
78 | - ->willReturn($result); |
|
79 | - |
|
80 | - $result->expects($this->once()) |
|
81 | - ->method('fetchOne') |
|
82 | - ->willReturn(count($subscriptions)); |
|
83 | - |
|
84 | - $result |
|
85 | - ->method('fetch') |
|
86 | - ->willReturnOnConsecutiveCalls(...$subscriptions); |
|
87 | - |
|
88 | - $qb->method('delete') |
|
89 | - ->with('calendarsubscriptions') |
|
90 | - ->willReturn($qb); |
|
91 | - |
|
92 | - $expr = $this->createMock(IExpressionBuilder::class); |
|
93 | - |
|
94 | - $qb->method('expr')->willReturn($expr); |
|
95 | - $qb->method('createNamedParameter')->willReturn($this->createMock(IParameter::class)); |
|
96 | - $qb->method('where')->willReturn($qb); |
|
97 | - // Only when user exists |
|
98 | - $qb->expects($this->exactly($deletions))->method('executeStatement'); |
|
99 | - |
|
100 | - $this->dbConnection->method('getQueryBuilder')->willReturn($qb); |
|
101 | - |
|
102 | - |
|
103 | - $this->output->expects($this->once())->method('startProgress'); |
|
104 | - |
|
105 | - $this->output->expects($subscriptions === [] ? $this->never(): $this->once())->method('advance'); |
|
106 | - if (count($subscriptions)) { |
|
107 | - $this->userManager->method('userExists') |
|
108 | - ->willReturnCallback(function (string $username) use ($userExists) { |
|
109 | - return $userExists[$username]; |
|
110 | - }); |
|
111 | - } |
|
112 | - $this->output->expects($this->once())->method('finishProgress'); |
|
113 | - $this->output->expects($this->once())->method('info')->with(sprintf('%d calendar subscriptions without an user have been cleaned up', $deletions)); |
|
114 | - |
|
115 | - $this->migration->run($this->output); |
|
116 | - } |
|
117 | - |
|
118 | - public static function dataTestRun(): array { |
|
119 | - return [ |
|
120 | - [[], [], 0], |
|
121 | - [ |
|
122 | - [ |
|
123 | - [ |
|
124 | - 'id' => 1, |
|
125 | - 'principaluri' => 'users/principals/foo1', |
|
126 | - ], |
|
127 | - [ |
|
128 | - 'id' => 2, |
|
129 | - 'principaluri' => 'users/principals/bar1', |
|
130 | - ], |
|
131 | - [ |
|
132 | - 'id' => 3, |
|
133 | - 'principaluri' => 'users/principals/bar1', |
|
134 | - ], |
|
135 | - [], |
|
136 | - ], |
|
137 | - ['foo1' => true, 'bar1' => false], |
|
138 | - 2 |
|
139 | - ], |
|
140 | - ]; |
|
141 | - } |
|
31 | + protected function setUp(): void { |
|
32 | + parent::setUp(); |
|
33 | + |
|
34 | + $this->dbConnection = $this->createMock(IDBConnection::class); |
|
35 | + $this->userManager = $this->createMock(IUserManager::class); |
|
36 | + $this->output = $this->createMock(IOutput::class); |
|
37 | + |
|
38 | + $this->migration = new RemoveDeletedUsersCalendarSubscriptions($this->dbConnection, $this->userManager); |
|
39 | + } |
|
40 | + |
|
41 | + public function testGetName(): void { |
|
42 | + $this->assertEquals( |
|
43 | + 'Clean up old calendar subscriptions from deleted users that were not cleaned-up', |
|
44 | + $this->migration->getName() |
|
45 | + ); |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * @dataProvider dataTestRun |
|
50 | + */ |
|
51 | + public function testRun(array $subscriptions, array $userExists, int $deletions): void { |
|
52 | + $qb = $this->createMock(IQueryBuilder::class); |
|
53 | + |
|
54 | + $qb->method('select')->willReturn($qb); |
|
55 | + |
|
56 | + $functionBuilder = $this->createMock(IFunctionBuilder::class); |
|
57 | + |
|
58 | + $qb->method('func')->willReturn($functionBuilder); |
|
59 | + $functionBuilder->method('count')->willReturn($this->createMock(IQueryFunction::class)); |
|
60 | + |
|
61 | + $qb->method('selectDistinct') |
|
62 | + ->with(['id', 'principaluri']) |
|
63 | + ->willReturn($qb); |
|
64 | + |
|
65 | + $qb->method('from') |
|
66 | + ->with('calendarsubscriptions') |
|
67 | + ->willReturn($qb); |
|
68 | + |
|
69 | + $qb->method('setMaxResults') |
|
70 | + ->willReturn($qb); |
|
71 | + |
|
72 | + $qb->method('setFirstResult') |
|
73 | + ->willReturn($qb); |
|
74 | + |
|
75 | + $result = $this->createMock(IResult::class); |
|
76 | + |
|
77 | + $qb->method('execute') |
|
78 | + ->willReturn($result); |
|
79 | + |
|
80 | + $result->expects($this->once()) |
|
81 | + ->method('fetchOne') |
|
82 | + ->willReturn(count($subscriptions)); |
|
83 | + |
|
84 | + $result |
|
85 | + ->method('fetch') |
|
86 | + ->willReturnOnConsecutiveCalls(...$subscriptions); |
|
87 | + |
|
88 | + $qb->method('delete') |
|
89 | + ->with('calendarsubscriptions') |
|
90 | + ->willReturn($qb); |
|
91 | + |
|
92 | + $expr = $this->createMock(IExpressionBuilder::class); |
|
93 | + |
|
94 | + $qb->method('expr')->willReturn($expr); |
|
95 | + $qb->method('createNamedParameter')->willReturn($this->createMock(IParameter::class)); |
|
96 | + $qb->method('where')->willReturn($qb); |
|
97 | + // Only when user exists |
|
98 | + $qb->expects($this->exactly($deletions))->method('executeStatement'); |
|
99 | + |
|
100 | + $this->dbConnection->method('getQueryBuilder')->willReturn($qb); |
|
101 | + |
|
102 | + |
|
103 | + $this->output->expects($this->once())->method('startProgress'); |
|
104 | + |
|
105 | + $this->output->expects($subscriptions === [] ? $this->never(): $this->once())->method('advance'); |
|
106 | + if (count($subscriptions)) { |
|
107 | + $this->userManager->method('userExists') |
|
108 | + ->willReturnCallback(function (string $username) use ($userExists) { |
|
109 | + return $userExists[$username]; |
|
110 | + }); |
|
111 | + } |
|
112 | + $this->output->expects($this->once())->method('finishProgress'); |
|
113 | + $this->output->expects($this->once())->method('info')->with(sprintf('%d calendar subscriptions without an user have been cleaned up', $deletions)); |
|
114 | + |
|
115 | + $this->migration->run($this->output); |
|
116 | + } |
|
117 | + |
|
118 | + public static function dataTestRun(): array { |
|
119 | + return [ |
|
120 | + [[], [], 0], |
|
121 | + [ |
|
122 | + [ |
|
123 | + [ |
|
124 | + 'id' => 1, |
|
125 | + 'principaluri' => 'users/principals/foo1', |
|
126 | + ], |
|
127 | + [ |
|
128 | + 'id' => 2, |
|
129 | + 'principaluri' => 'users/principals/bar1', |
|
130 | + ], |
|
131 | + [ |
|
132 | + 'id' => 3, |
|
133 | + 'principaluri' => 'users/principals/bar1', |
|
134 | + ], |
|
135 | + [], |
|
136 | + ], |
|
137 | + ['foo1' => true, 'bar1' => false], |
|
138 | + 2 |
|
139 | + ], |
|
140 | + ]; |
|
141 | + } |
|
142 | 142 | } |
@@ -20,65 +20,65 @@ |
||
20 | 20 | |
21 | 21 | class ActivityUpdaterListenerTest extends TestCase { |
22 | 22 | |
23 | - private ActivityBackend&MockObject $activityBackend; |
|
24 | - private LoggerInterface&MockObject $logger; |
|
25 | - private ActivityUpdaterListener $listener; |
|
23 | + private ActivityBackend&MockObject $activityBackend; |
|
24 | + private LoggerInterface&MockObject $logger; |
|
25 | + private ActivityUpdaterListener $listener; |
|
26 | 26 | |
27 | - protected function setUp(): void { |
|
28 | - parent::setUp(); |
|
27 | + protected function setUp(): void { |
|
28 | + parent::setUp(); |
|
29 | 29 | |
30 | - $this->activityBackend = $this->createMock(ActivityBackend::class); |
|
31 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
30 | + $this->activityBackend = $this->createMock(ActivityBackend::class); |
|
31 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
32 | 32 | |
33 | - $this->listener = new ActivityUpdaterListener( |
|
34 | - $this->activityBackend, |
|
35 | - $this->logger |
|
36 | - ); |
|
37 | - } |
|
33 | + $this->listener = new ActivityUpdaterListener( |
|
34 | + $this->activityBackend, |
|
35 | + $this->logger |
|
36 | + ); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @dataProvider dataForTestHandleCalendarObjectDeletedEvent |
|
41 | - */ |
|
42 | - public function testHandleCalendarObjectDeletedEvent(int $calendarId, array $calendarData, array $shares, array $objectData, bool $createsActivity): void { |
|
43 | - $event = new CalendarObjectDeletedEvent($calendarId, $calendarData, $shares, $objectData); |
|
44 | - $this->logger->expects($this->once())->method('debug')->with( |
|
45 | - $createsActivity ? "Activity generated for deleted calendar object in calendar $calendarId" : "Calendar object in calendar $calendarId was already in trashbin, skipping deletion activity" |
|
46 | - ); |
|
47 | - $this->activityBackend->expects($createsActivity ? $this->once() : $this->never())->method('onTouchCalendarObject')->with( |
|
48 | - Event::SUBJECT_OBJECT_DELETE, |
|
49 | - $calendarData, |
|
50 | - $shares, |
|
51 | - $objectData |
|
52 | - ); |
|
53 | - $this->listener->handle($event); |
|
54 | - } |
|
39 | + /** |
|
40 | + * @dataProvider dataForTestHandleCalendarObjectDeletedEvent |
|
41 | + */ |
|
42 | + public function testHandleCalendarObjectDeletedEvent(int $calendarId, array $calendarData, array $shares, array $objectData, bool $createsActivity): void { |
|
43 | + $event = new CalendarObjectDeletedEvent($calendarId, $calendarData, $shares, $objectData); |
|
44 | + $this->logger->expects($this->once())->method('debug')->with( |
|
45 | + $createsActivity ? "Activity generated for deleted calendar object in calendar $calendarId" : "Calendar object in calendar $calendarId was already in trashbin, skipping deletion activity" |
|
46 | + ); |
|
47 | + $this->activityBackend->expects($createsActivity ? $this->once() : $this->never())->method('onTouchCalendarObject')->with( |
|
48 | + Event::SUBJECT_OBJECT_DELETE, |
|
49 | + $calendarData, |
|
50 | + $shares, |
|
51 | + $objectData |
|
52 | + ); |
|
53 | + $this->listener->handle($event); |
|
54 | + } |
|
55 | 55 | |
56 | - public static function dataForTestHandleCalendarObjectDeletedEvent(): array { |
|
57 | - return [ |
|
58 | - [1, [], [], [], true], |
|
59 | - [1, [], [], ['{' . SharingPlugin::NS_NEXTCLOUD . '}deleted-at' => 120], false], |
|
60 | - ]; |
|
61 | - } |
|
56 | + public static function dataForTestHandleCalendarObjectDeletedEvent(): array { |
|
57 | + return [ |
|
58 | + [1, [], [], [], true], |
|
59 | + [1, [], [], ['{' . SharingPlugin::NS_NEXTCLOUD . '}deleted-at' => 120], false], |
|
60 | + ]; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @dataProvider dataForTestHandleCalendarDeletedEvent |
|
65 | - */ |
|
66 | - public function testHandleCalendarDeletedEvent(int $calendarId, array $calendarData, array $shares, bool $createsActivity): void { |
|
67 | - $event = new CalendarDeletedEvent($calendarId, $calendarData, $shares); |
|
68 | - $this->logger->expects($this->once())->method('debug')->with( |
|
69 | - $createsActivity ? "Activity generated for deleted calendar $calendarId" : "Calendar $calendarId was already in trashbin, skipping deletion activity" |
|
70 | - ); |
|
71 | - $this->activityBackend->expects($createsActivity ? $this->once() : $this->never())->method('onCalendarDelete')->with( |
|
72 | - $calendarData, |
|
73 | - $shares |
|
74 | - ); |
|
75 | - $this->listener->handle($event); |
|
76 | - } |
|
63 | + /** |
|
64 | + * @dataProvider dataForTestHandleCalendarDeletedEvent |
|
65 | + */ |
|
66 | + public function testHandleCalendarDeletedEvent(int $calendarId, array $calendarData, array $shares, bool $createsActivity): void { |
|
67 | + $event = new CalendarDeletedEvent($calendarId, $calendarData, $shares); |
|
68 | + $this->logger->expects($this->once())->method('debug')->with( |
|
69 | + $createsActivity ? "Activity generated for deleted calendar $calendarId" : "Calendar $calendarId was already in trashbin, skipping deletion activity" |
|
70 | + ); |
|
71 | + $this->activityBackend->expects($createsActivity ? $this->once() : $this->never())->method('onCalendarDelete')->with( |
|
72 | + $calendarData, |
|
73 | + $shares |
|
74 | + ); |
|
75 | + $this->listener->handle($event); |
|
76 | + } |
|
77 | 77 | |
78 | - public static function dataForTestHandleCalendarDeletedEvent(): array { |
|
79 | - return [ |
|
80 | - [1, [], [], true], |
|
81 | - [1, ['{' . SharingPlugin::NS_NEXTCLOUD . '}deleted-at' => 120], [], false], |
|
82 | - ]; |
|
83 | - } |
|
78 | + public static function dataForTestHandleCalendarDeletedEvent(): array { |
|
79 | + return [ |
|
80 | + [1, [], [], true], |
|
81 | + [1, ['{' . SharingPlugin::NS_NEXTCLOUD . '}deleted-at' => 120], [], false], |
|
82 | + ]; |
|
83 | + } |
|
84 | 84 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | public static function dataForTestHandleCalendarObjectDeletedEvent(): array { |
57 | 57 | return [ |
58 | 58 | [1, [], [], [], true], |
59 | - [1, [], [], ['{' . SharingPlugin::NS_NEXTCLOUD . '}deleted-at' => 120], false], |
|
59 | + [1, [], [], ['{'.SharingPlugin::NS_NEXTCLOUD.'}deleted-at' => 120], false], |
|
60 | 60 | ]; |
61 | 61 | } |
62 | 62 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | public static function dataForTestHandleCalendarDeletedEvent(): array { |
79 | 79 | return [ |
80 | 80 | [1, [], [], true], |
81 | - [1, ['{' . SharingPlugin::NS_NEXTCLOUD . '}deleted-at' => 120], [], false], |
|
81 | + [1, ['{'.SharingPlugin::NS_NEXTCLOUD.'}deleted-at' => 120], [], false], |
|
82 | 82 | ]; |
83 | 83 | } |
84 | 84 | } |
@@ -23,59 +23,59 @@ discard block |
||
23 | 23 | use Test\TestCase; |
24 | 24 | |
25 | 25 | class CalendarContactInteractionListenerTest extends TestCase { |
26 | - private IEventDispatcher&MockObject $eventDispatcher; |
|
27 | - private IUserSession&MockObject $userSession; |
|
28 | - private Principal&MockObject $principalConnector; |
|
29 | - private LoggerInterface&MockObject $logger; |
|
30 | - private IMailer&MockObject $mailer; |
|
31 | - private CalendarContactInteractionListener $listener; |
|
32 | - |
|
33 | - protected function setUp(): void { |
|
34 | - parent::setUp(); |
|
35 | - |
|
36 | - $this->eventDispatcher = $this->createMock(IEventDispatcher::class); |
|
37 | - $this->userSession = $this->createMock(IUserSession::class); |
|
38 | - $this->principalConnector = $this->createMock(Principal::class); |
|
39 | - $this->mailer = $this->createMock(IMailer::class); |
|
40 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
41 | - |
|
42 | - $this->listener = new CalendarContactInteractionListener( |
|
43 | - $this->eventDispatcher, |
|
44 | - $this->userSession, |
|
45 | - $this->principalConnector, |
|
46 | - $this->mailer, |
|
47 | - $this->logger |
|
48 | - ); |
|
49 | - } |
|
50 | - |
|
51 | - public function testParseUnrelated(): void { |
|
52 | - $event = new Event(); |
|
53 | - $this->eventDispatcher->expects(self::never())->method('dispatchTyped'); |
|
54 | - |
|
55 | - $this->listener->handle($event); |
|
56 | - } |
|
57 | - |
|
58 | - public function testHandleWithoutAnythingInteresting(): void { |
|
59 | - $event = new CalendarShareUpdatedEvent(123, [], [], [], []); |
|
60 | - $user = $this->createMock(IUser::class); |
|
61 | - $this->userSession->expects(self::once())->method('getUser')->willReturn($user); |
|
62 | - $this->eventDispatcher->expects(self::never())->method('dispatchTyped'); |
|
63 | - |
|
64 | - $this->listener->handle($event); |
|
65 | - } |
|
66 | - |
|
67 | - public function testParseInvalidData(): void { |
|
68 | - $event = new CalendarObjectCreatedEvent(123, [], [], ['calendardata' => 'BEGIN:FOO']); |
|
69 | - $user = $this->createMock(IUser::class); |
|
70 | - $this->userSession->expects(self::once())->method('getUser')->willReturn($user); |
|
71 | - $this->eventDispatcher->expects(self::never())->method('dispatchTyped'); |
|
72 | - $this->logger->expects(self::once())->method('warning'); |
|
73 | - |
|
74 | - $this->listener->handle($event); |
|
75 | - } |
|
76 | - |
|
77 | - public function testParseCalendarEventWithInvalidEmail(): void { |
|
78 | - $event = new CalendarObjectCreatedEvent(123, [], [], ['calendardata' => <<<EVENT |
|
26 | + private IEventDispatcher&MockObject $eventDispatcher; |
|
27 | + private IUserSession&MockObject $userSession; |
|
28 | + private Principal&MockObject $principalConnector; |
|
29 | + private LoggerInterface&MockObject $logger; |
|
30 | + private IMailer&MockObject $mailer; |
|
31 | + private CalendarContactInteractionListener $listener; |
|
32 | + |
|
33 | + protected function setUp(): void { |
|
34 | + parent::setUp(); |
|
35 | + |
|
36 | + $this->eventDispatcher = $this->createMock(IEventDispatcher::class); |
|
37 | + $this->userSession = $this->createMock(IUserSession::class); |
|
38 | + $this->principalConnector = $this->createMock(Principal::class); |
|
39 | + $this->mailer = $this->createMock(IMailer::class); |
|
40 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
41 | + |
|
42 | + $this->listener = new CalendarContactInteractionListener( |
|
43 | + $this->eventDispatcher, |
|
44 | + $this->userSession, |
|
45 | + $this->principalConnector, |
|
46 | + $this->mailer, |
|
47 | + $this->logger |
|
48 | + ); |
|
49 | + } |
|
50 | + |
|
51 | + public function testParseUnrelated(): void { |
|
52 | + $event = new Event(); |
|
53 | + $this->eventDispatcher->expects(self::never())->method('dispatchTyped'); |
|
54 | + |
|
55 | + $this->listener->handle($event); |
|
56 | + } |
|
57 | + |
|
58 | + public function testHandleWithoutAnythingInteresting(): void { |
|
59 | + $event = new CalendarShareUpdatedEvent(123, [], [], [], []); |
|
60 | + $user = $this->createMock(IUser::class); |
|
61 | + $this->userSession->expects(self::once())->method('getUser')->willReturn($user); |
|
62 | + $this->eventDispatcher->expects(self::never())->method('dispatchTyped'); |
|
63 | + |
|
64 | + $this->listener->handle($event); |
|
65 | + } |
|
66 | + |
|
67 | + public function testParseInvalidData(): void { |
|
68 | + $event = new CalendarObjectCreatedEvent(123, [], [], ['calendardata' => 'BEGIN:FOO']); |
|
69 | + $user = $this->createMock(IUser::class); |
|
70 | + $this->userSession->expects(self::once())->method('getUser')->willReturn($user); |
|
71 | + $this->eventDispatcher->expects(self::never())->method('dispatchTyped'); |
|
72 | + $this->logger->expects(self::once())->method('warning'); |
|
73 | + |
|
74 | + $this->listener->handle($event); |
|
75 | + } |
|
76 | + |
|
77 | + public function testParseCalendarEventWithInvalidEmail(): void { |
|
78 | + $event = new CalendarObjectCreatedEvent(123, [], [], ['calendardata' => <<<EVENT |
|
79 | 79 | BEGIN:VCALENDAR |
80 | 80 | VERSION:2.0 |
81 | 81 | CALSCALE:GREGORIAN |
@@ -113,16 +113,16 @@ discard block |
||
113 | 113 | END:VEVENT |
114 | 114 | END:VCALENDAR |
115 | 115 | EVENT]); |
116 | - $user = $this->createMock(IUser::class); |
|
117 | - $this->userSession->expects(self::once())->method('getUser')->willReturn($user); |
|
118 | - $this->eventDispatcher->expects(self::never())->method('dispatchTyped'); |
|
119 | - $this->logger->expects(self::never())->method('warning'); |
|
116 | + $user = $this->createMock(IUser::class); |
|
117 | + $this->userSession->expects(self::once())->method('getUser')->willReturn($user); |
|
118 | + $this->eventDispatcher->expects(self::never())->method('dispatchTyped'); |
|
119 | + $this->logger->expects(self::never())->method('warning'); |
|
120 | 120 | |
121 | - $this->listener->handle($event); |
|
122 | - } |
|
121 | + $this->listener->handle($event); |
|
122 | + } |
|
123 | 123 | |
124 | - public function testParseCalendarEvent(): void { |
|
125 | - $event = new CalendarObjectCreatedEvent(123, [], [], ['calendardata' => <<<EVENT |
|
124 | + public function testParseCalendarEvent(): void { |
|
125 | + $event = new CalendarObjectCreatedEvent(123, [], [], ['calendardata' => <<<EVENT |
|
126 | 126 | BEGIN:VCALENDAR |
127 | 127 | VERSION:2.0 |
128 | 128 | CALSCALE:GREGORIAN |
@@ -160,14 +160,14 @@ discard block |
||
160 | 160 | END:VEVENT |
161 | 161 | END:VCALENDAR |
162 | 162 | EVENT]); |
163 | - $user = $this->createMock(IUser::class); |
|
164 | - $this->userSession->expects(self::once())->method('getUser')->willReturn($user); |
|
165 | - $this->mailer->expects(self::once())->method('validateMailAddress')->willReturn(true); |
|
166 | - $this->eventDispatcher->expects(self::once()) |
|
167 | - ->method('dispatchTyped') |
|
168 | - ->with(self::equalTo((new ContactInteractedWithEvent($user))->setEmail('[email protected]'))); |
|
169 | - $this->logger->expects(self::never())->method('warning'); |
|
170 | - |
|
171 | - $this->listener->handle($event); |
|
172 | - } |
|
163 | + $user = $this->createMock(IUser::class); |
|
164 | + $this->userSession->expects(self::once())->method('getUser')->willReturn($user); |
|
165 | + $this->mailer->expects(self::once())->method('validateMailAddress')->willReturn(true); |
|
166 | + $this->eventDispatcher->expects(self::once()) |
|
167 | + ->method('dispatchTyped') |
|
168 | + ->with(self::equalTo((new ContactInteractedWithEvent($user))->setEmail('[email protected]'))); |
|
169 | + $this->logger->expects(self::never())->method('warning'); |
|
170 | + |
|
171 | + $this->listener->handle($event); |
|
172 | + } |
|
173 | 173 | } |
@@ -41,566 +41,566 @@ |
||
41 | 41 | */ |
42 | 42 | class OutOfOfficeListenerTest extends TestCase { |
43 | 43 | |
44 | - private ServerFactory&MockObject $serverFactory; |
|
45 | - private IConfig&MockObject $appConfig; |
|
46 | - private LoggerInterface&MockObject $loggerInterface; |
|
47 | - private TimezoneService&MockObject $timezoneService; |
|
48 | - private OutOfOfficeListener $listener; |
|
49 | - |
|
50 | - protected function setUp(): void { |
|
51 | - parent::setUp(); |
|
52 | - |
|
53 | - $this->serverFactory = $this->createMock(ServerFactory::class); |
|
54 | - $this->appConfig = $this->createMock(IConfig::class); |
|
55 | - $this->timezoneService = $this->createMock(TimezoneService::class); |
|
56 | - $this->loggerInterface = $this->createMock(LoggerInterface::class); |
|
57 | - |
|
58 | - $this->listener = new OutOfOfficeListener( |
|
59 | - $this->serverFactory, |
|
60 | - $this->appConfig, |
|
61 | - $this->timezoneService, |
|
62 | - $this->loggerInterface, |
|
63 | - ); |
|
64 | - } |
|
65 | - |
|
66 | - public function testHandleUnrelated(): void { |
|
67 | - $event = new Event(); |
|
68 | - |
|
69 | - $this->listener->handle($event); |
|
70 | - |
|
71 | - $this->addToAssertionCount(1); |
|
72 | - } |
|
73 | - |
|
74 | - public function testHandleSchedulingNoCalendarHome(): void { |
|
75 | - $user = $this->createMock(IUser::class); |
|
76 | - $user->method('getUID')->willReturn('user123'); |
|
77 | - $data = $this->createMock(IOutOfOfficeData::class); |
|
78 | - $data->method('getUser')->willReturn($user); |
|
79 | - $davServer = $this->createMock(Server::class); |
|
80 | - $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
81 | - $invitationServer->method('getServer')->willReturn($davServer); |
|
82 | - $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
83 | - $caldavPlugin = $this->createMock(Plugin::class); |
|
84 | - $davServer->expects(self::once()) |
|
85 | - ->method('getPlugin') |
|
86 | - ->with('caldav') |
|
87 | - ->willReturn($caldavPlugin); |
|
88 | - $event = new OutOfOfficeScheduledEvent($data); |
|
89 | - |
|
90 | - $this->listener->handle($event); |
|
91 | - } |
|
92 | - |
|
93 | - public function testHandleSchedulingNoCalendarHomeNode(): void { |
|
94 | - $user = $this->createMock(IUser::class); |
|
95 | - $user->method('getUID')->willReturn('user123'); |
|
96 | - $data = $this->createMock(IOutOfOfficeData::class); |
|
97 | - $data->method('getUser')->willReturn($user); |
|
98 | - $davServer = $this->createMock(Server::class); |
|
99 | - $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
100 | - $invitationServer->method('getServer')->willReturn($davServer); |
|
101 | - $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
102 | - $caldavPlugin = $this->createMock(Plugin::class); |
|
103 | - $davServer->expects(self::once()) |
|
104 | - ->method('getPlugin') |
|
105 | - ->with('caldav') |
|
106 | - ->willReturn($caldavPlugin); |
|
107 | - $caldavPlugin->expects(self::once()) |
|
108 | - ->method('getCalendarHomeForPrincipal') |
|
109 | - ->willReturn('/home/calendar'); |
|
110 | - $tree = $this->createMock(Tree::class); |
|
111 | - $davServer->tree = $tree; |
|
112 | - $tree->expects(self::once()) |
|
113 | - ->method('getNodeForPath') |
|
114 | - ->with('/home/calendar') |
|
115 | - ->willThrowException(new NotFound('nope')); |
|
116 | - $event = new OutOfOfficeScheduledEvent($data); |
|
117 | - |
|
118 | - $this->listener->handle($event); |
|
119 | - } |
|
120 | - |
|
121 | - public function testHandleSchedulingPersonalCalendarNotFound(): void { |
|
122 | - $user = $this->createMock(IUser::class); |
|
123 | - $user->method('getUID')->willReturn('user123'); |
|
124 | - $data = $this->createMock(IOutOfOfficeData::class); |
|
125 | - $data->method('getUser')->willReturn($user); |
|
126 | - $davServer = $this->createMock(Server::class); |
|
127 | - $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
128 | - $invitationServer->method('getServer')->willReturn($davServer); |
|
129 | - $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
130 | - $caldavPlugin = $this->createMock(Plugin::class); |
|
131 | - $davServer->expects(self::once()) |
|
132 | - ->method('getPlugin') |
|
133 | - ->with('caldav') |
|
134 | - ->willReturn($caldavPlugin); |
|
135 | - $caldavPlugin->expects(self::once()) |
|
136 | - ->method('getCalendarHomeForPrincipal') |
|
137 | - ->willReturn('/home/calendar'); |
|
138 | - $tree = $this->createMock(Tree::class); |
|
139 | - $davServer->tree = $tree; |
|
140 | - $calendarHome = $this->createMock(CalendarHome::class); |
|
141 | - $tree->expects(self::once()) |
|
142 | - ->method('getNodeForPath') |
|
143 | - ->with('/home/calendar') |
|
144 | - ->willReturn($calendarHome); |
|
145 | - $this->appConfig->expects(self::once()) |
|
146 | - ->method('getUserValue') |
|
147 | - ->with('user123', 'dav', 'defaultCalendar', 'personal') |
|
148 | - ->willReturn('personal-1'); |
|
149 | - $calendarHome->expects(self::once()) |
|
150 | - ->method('getChild') |
|
151 | - ->with('personal-1') |
|
152 | - ->willThrowException(new NotFound('nope')); |
|
153 | - $event = new OutOfOfficeScheduledEvent($data); |
|
154 | - |
|
155 | - $this->listener->handle($event); |
|
156 | - } |
|
157 | - |
|
158 | - public function testHandleSchedulingWithDefaultTimezone(): void { |
|
159 | - $user = $this->createMock(IUser::class); |
|
160 | - $user->method('getUID')->willReturn('user123'); |
|
161 | - $data = $this->createMock(IOutOfOfficeData::class); |
|
162 | - $data->method('getUser')->willReturn($user); |
|
163 | - $data->method('getStartDate') |
|
164 | - ->willReturn((new DateTimeImmutable('2023-12-12T00:00:00Z'))->getTimestamp()); |
|
165 | - $data->method('getEndDate') |
|
166 | - ->willReturn((new DateTimeImmutable('2023-12-13T00:00:00Z'))->getTimestamp()); |
|
167 | - $davServer = $this->createMock(Server::class); |
|
168 | - $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
169 | - $invitationServer->method('getServer')->willReturn($davServer); |
|
170 | - $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
171 | - $caldavPlugin = $this->createMock(Plugin::class); |
|
172 | - $davServer->expects(self::once()) |
|
173 | - ->method('getPlugin') |
|
174 | - ->with('caldav') |
|
175 | - ->willReturn($caldavPlugin); |
|
176 | - $caldavPlugin->expects(self::once()) |
|
177 | - ->method('getCalendarHomeForPrincipal') |
|
178 | - ->willReturn('/home/calendar'); |
|
179 | - $tree = $this->createMock(Tree::class); |
|
180 | - $davServer->tree = $tree; |
|
181 | - $calendarHome = $this->createMock(CalendarHome::class); |
|
182 | - $tree->expects(self::once()) |
|
183 | - ->method('getNodeForPath') |
|
184 | - ->with('/home/calendar') |
|
185 | - ->willReturn($calendarHome); |
|
186 | - $this->appConfig->expects(self::once()) |
|
187 | - ->method('getUserValue') |
|
188 | - ->with('user123', 'dav', 'defaultCalendar', 'personal') |
|
189 | - ->willReturn('personal-1'); |
|
190 | - $calendar = $this->createMock(Calendar::class); |
|
191 | - $this->timezoneService->expects(self::once()) |
|
192 | - ->method('getUserTimezone') |
|
193 | - ->with('user123') |
|
194 | - ->willReturn('Europe/Prague'); |
|
195 | - $calendarHome->expects(self::once()) |
|
196 | - ->method('getChild') |
|
197 | - ->with('personal-1') |
|
198 | - ->willReturn($calendar); |
|
199 | - $calendar->expects(self::once()) |
|
200 | - ->method('createFile') |
|
201 | - ->willReturnCallback(function ($name, $data): void { |
|
202 | - $vcalendar = Reader::read($data); |
|
203 | - if (!($vcalendar instanceof VCalendar)) { |
|
204 | - throw new InvalidArgumentException('Calendar data should be a VCALENDAR'); |
|
205 | - } |
|
206 | - $vevent = $vcalendar->VEVENT; |
|
207 | - if ($vevent === null || !($vevent instanceof VEvent)) { |
|
208 | - throw new InvalidArgumentException('Calendar data should contain a VEVENT'); |
|
209 | - } |
|
210 | - self::assertSame('Europe/Prague', $vevent->DTSTART['TZID']?->getValue()); |
|
211 | - self::assertSame('Europe/Prague', $vevent->DTEND['TZID']?->getValue()); |
|
212 | - }); |
|
213 | - $event = new OutOfOfficeScheduledEvent($data); |
|
214 | - |
|
215 | - $this->listener->handle($event); |
|
216 | - } |
|
217 | - |
|
218 | - public function testHandleChangeNoCalendarHome(): void { |
|
219 | - $user = $this->createMock(IUser::class); |
|
220 | - $user->method('getUID')->willReturn('user123'); |
|
221 | - $data = $this->createMock(IOutOfOfficeData::class); |
|
222 | - $data->method('getUser')->willReturn($user); |
|
223 | - $davServer = $this->createMock(Server::class); |
|
224 | - $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
225 | - $invitationServer->method('getServer')->willReturn($davServer); |
|
226 | - $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
227 | - $caldavPlugin = $this->createMock(Plugin::class); |
|
228 | - $davServer->expects(self::once()) |
|
229 | - ->method('getPlugin') |
|
230 | - ->with('caldav') |
|
231 | - ->willReturn($caldavPlugin); |
|
232 | - $event = new OutOfOfficeChangedEvent($data); |
|
233 | - |
|
234 | - $this->listener->handle($event); |
|
235 | - } |
|
236 | - |
|
237 | - public function testHandleChangeNoCalendarHomeNode(): void { |
|
238 | - $user = $this->createMock(IUser::class); |
|
239 | - $user->method('getUID')->willReturn('user123'); |
|
240 | - $data = $this->createMock(IOutOfOfficeData::class); |
|
241 | - $data->method('getUser')->willReturn($user); |
|
242 | - $davServer = $this->createMock(Server::class); |
|
243 | - $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
244 | - $invitationServer->method('getServer')->willReturn($davServer); |
|
245 | - $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
246 | - $caldavPlugin = $this->createMock(Plugin::class); |
|
247 | - $davServer->expects(self::once()) |
|
248 | - ->method('getPlugin') |
|
249 | - ->with('caldav') |
|
250 | - ->willReturn($caldavPlugin); |
|
251 | - $caldavPlugin->expects(self::once()) |
|
252 | - ->method('getCalendarHomeForPrincipal') |
|
253 | - ->willReturn('/home/calendar'); |
|
254 | - $tree = $this->createMock(Tree::class); |
|
255 | - $davServer->tree = $tree; |
|
256 | - $tree->expects(self::once()) |
|
257 | - ->method('getNodeForPath') |
|
258 | - ->with('/home/calendar') |
|
259 | - ->willThrowException(new NotFound('nope')); |
|
260 | - $event = new OutOfOfficeChangedEvent($data); |
|
261 | - |
|
262 | - $this->listener->handle($event); |
|
263 | - } |
|
264 | - |
|
265 | - public function testHandleChangePersonalCalendarNotFound(): void { |
|
266 | - $user = $this->createMock(IUser::class); |
|
267 | - $user->method('getUID')->willReturn('user123'); |
|
268 | - $data = $this->createMock(IOutOfOfficeData::class); |
|
269 | - $data->method('getUser')->willReturn($user); |
|
270 | - $davServer = $this->createMock(Server::class); |
|
271 | - $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
272 | - $invitationServer->method('getServer')->willReturn($davServer); |
|
273 | - $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
274 | - $caldavPlugin = $this->createMock(Plugin::class); |
|
275 | - $davServer->expects(self::once()) |
|
276 | - ->method('getPlugin') |
|
277 | - ->with('caldav') |
|
278 | - ->willReturn($caldavPlugin); |
|
279 | - $caldavPlugin->expects(self::once()) |
|
280 | - ->method('getCalendarHomeForPrincipal') |
|
281 | - ->willReturn('/home/calendar'); |
|
282 | - $tree = $this->createMock(Tree::class); |
|
283 | - $davServer->tree = $tree; |
|
284 | - $calendarHome = $this->createMock(CalendarHome::class); |
|
285 | - $tree->expects(self::once()) |
|
286 | - ->method('getNodeForPath') |
|
287 | - ->with('/home/calendar') |
|
288 | - ->willReturn($calendarHome); |
|
289 | - $this->appConfig->expects(self::once()) |
|
290 | - ->method('getUserValue') |
|
291 | - ->with('user123', 'dav', 'defaultCalendar', 'personal') |
|
292 | - ->willReturn('personal-1'); |
|
293 | - $calendarHome->expects(self::once()) |
|
294 | - ->method('getChild') |
|
295 | - ->with('personal-1') |
|
296 | - ->willThrowException(new NotFound('nope')); |
|
297 | - $event = new OutOfOfficeChangedEvent($data); |
|
298 | - |
|
299 | - $this->listener->handle($event); |
|
300 | - } |
|
301 | - |
|
302 | - public function testHandleChangeRecreate(): void { |
|
303 | - $user = $this->createMock(IUser::class); |
|
304 | - $user->method('getUID')->willReturn('user123'); |
|
305 | - $data = $this->createMock(IOutOfOfficeData::class); |
|
306 | - $data->method('getUser')->willReturn($user); |
|
307 | - $data->method('getStartDate') |
|
308 | - ->willReturn((new DateTimeImmutable('2023-12-12T00:00:00Z'))->getTimestamp()); |
|
309 | - $data->method('getEndDate') |
|
310 | - ->willReturn((new DateTimeImmutable('2023-12-14T00:00:00Z'))->getTimestamp()); |
|
311 | - $davServer = $this->createMock(Server::class); |
|
312 | - $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
313 | - $invitationServer->method('getServer')->willReturn($davServer); |
|
314 | - $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
315 | - $caldavPlugin = $this->createMock(Plugin::class); |
|
316 | - $davServer->expects(self::once()) |
|
317 | - ->method('getPlugin') |
|
318 | - ->with('caldav') |
|
319 | - ->willReturn($caldavPlugin); |
|
320 | - $caldavPlugin->expects(self::once()) |
|
321 | - ->method('getCalendarHomeForPrincipal') |
|
322 | - ->willReturn('/home/calendar'); |
|
323 | - $tree = $this->createMock(Tree::class); |
|
324 | - $davServer->tree = $tree; |
|
325 | - $calendarHome = $this->createMock(CalendarHome::class); |
|
326 | - $tree->expects(self::once()) |
|
327 | - ->method('getNodeForPath') |
|
328 | - ->with('/home/calendar') |
|
329 | - ->willReturn($calendarHome); |
|
330 | - $this->appConfig->expects(self::once()) |
|
331 | - ->method('getUserValue') |
|
332 | - ->with('user123', 'dav', 'defaultCalendar', 'personal') |
|
333 | - ->willReturn('personal-1'); |
|
334 | - $calendar = $this->createMock(Calendar::class); |
|
335 | - $this->timezoneService->expects(self::once()) |
|
336 | - ->method('getUserTimezone') |
|
337 | - ->with('user123') |
|
338 | - ->willReturn(null); |
|
339 | - $this->timezoneService->expects(self::once()) |
|
340 | - ->method('getDefaultTimezone') |
|
341 | - ->willReturn('Europe/Berlin'); |
|
342 | - $calendarHome->expects(self::once()) |
|
343 | - ->method('getChild') |
|
344 | - ->with('personal-1') |
|
345 | - ->willReturn($calendar); |
|
346 | - $calendar->expects(self::once()) |
|
347 | - ->method('getChild') |
|
348 | - ->willThrowException(new NotFound()); |
|
349 | - $calendar->expects(self::once()) |
|
350 | - ->method('createFile') |
|
351 | - ->willReturnCallback(function ($name, $data): void { |
|
352 | - $vcalendar = Reader::read($data); |
|
353 | - if (!($vcalendar instanceof VCalendar)) { |
|
354 | - throw new InvalidArgumentException('Calendar data should be a VCALENDAR'); |
|
355 | - } |
|
356 | - $vevent = $vcalendar->VEVENT; |
|
357 | - if ($vevent === null || !($vevent instanceof VEvent)) { |
|
358 | - throw new InvalidArgumentException('Calendar data should contain a VEVENT'); |
|
359 | - } |
|
360 | - self::assertSame('Europe/Berlin', $vevent->DTSTART['TZID']?->getValue()); |
|
361 | - self::assertSame('Europe/Berlin', $vevent->DTEND['TZID']?->getValue()); |
|
362 | - }); |
|
363 | - $event = new OutOfOfficeChangedEvent($data); |
|
364 | - |
|
365 | - $this->listener->handle($event); |
|
366 | - } |
|
367 | - |
|
368 | - public function testHandleChangeWithoutTimezone(): void { |
|
369 | - $user = $this->createMock(IUser::class); |
|
370 | - $user->method('getUID')->willReturn('user123'); |
|
371 | - $data = $this->createMock(IOutOfOfficeData::class); |
|
372 | - $data->method('getUser')->willReturn($user); |
|
373 | - $data->method('getStartDate') |
|
374 | - ->willReturn((new DateTimeImmutable('2023-01-12T00:00:00Z'))->getTimestamp()); |
|
375 | - $data->method('getEndDate') |
|
376 | - ->willReturn((new DateTimeImmutable('2023-12-14T00:00:00Z'))->getTimestamp()); |
|
377 | - $davServer = $this->createMock(Server::class); |
|
378 | - $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
379 | - $invitationServer->method('getServer')->willReturn($davServer); |
|
380 | - $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
381 | - $caldavPlugin = $this->createMock(Plugin::class); |
|
382 | - $davServer->expects(self::once()) |
|
383 | - ->method('getPlugin') |
|
384 | - ->with('caldav') |
|
385 | - ->willReturn($caldavPlugin); |
|
386 | - $caldavPlugin->expects(self::once()) |
|
387 | - ->method('getCalendarHomeForPrincipal') |
|
388 | - ->willReturn('/home/calendar'); |
|
389 | - $tree = $this->createMock(Tree::class); |
|
390 | - $davServer->tree = $tree; |
|
391 | - $calendarHome = $this->createMock(CalendarHome::class); |
|
392 | - $tree->expects(self::once()) |
|
393 | - ->method('getNodeForPath') |
|
394 | - ->with('/home/calendar') |
|
395 | - ->willReturn($calendarHome); |
|
396 | - $this->appConfig->expects(self::once()) |
|
397 | - ->method('getUserValue') |
|
398 | - ->with('user123', 'dav', 'defaultCalendar', 'personal') |
|
399 | - ->willReturn('personal-1'); |
|
400 | - $calendar = $this->createMock(Calendar::class); |
|
401 | - $calendarHome->expects(self::once()) |
|
402 | - ->method('getChild') |
|
403 | - ->with('personal-1') |
|
404 | - ->willReturn($calendar); |
|
405 | - $eventNode = $this->createMock(CalendarObject::class); |
|
406 | - $this->timezoneService->expects(self::once()) |
|
407 | - ->method('getUserTimezone') |
|
408 | - ->with('user123') |
|
409 | - ->willReturn(null); |
|
410 | - $this->timezoneService->expects(self::once()) |
|
411 | - ->method('getDefaultTimezone') |
|
412 | - ->willReturn('UTC'); |
|
413 | - $calendar->expects(self::once()) |
|
414 | - ->method('getChild') |
|
415 | - ->willReturn($eventNode); |
|
416 | - $eventNode->expects(self::once()) |
|
417 | - ->method('put') |
|
418 | - ->willReturnCallback(function ($data): void { |
|
419 | - $vcalendar = Reader::read($data); |
|
420 | - if (!($vcalendar instanceof VCalendar)) { |
|
421 | - throw new InvalidArgumentException('Calendar data should be a VCALENDAR'); |
|
422 | - } |
|
423 | - $vevent = $vcalendar->VEVENT; |
|
424 | - if ($vevent === null || !($vevent instanceof VEvent)) { |
|
425 | - throw new InvalidArgumentException('Calendar data should contain a VEVENT'); |
|
426 | - } |
|
427 | - // UTC datetimes are stored without a TZID |
|
428 | - self::assertSame(null, $vevent->DTSTART['TZID']?->getValue()); |
|
429 | - self::assertSame(null, $vevent->DTEND['TZID']?->getValue()); |
|
430 | - }); |
|
431 | - $calendar->expects(self::never()) |
|
432 | - ->method('createFile'); |
|
433 | - $event = new OutOfOfficeChangedEvent($data); |
|
434 | - |
|
435 | - $this->listener->handle($event); |
|
436 | - } |
|
437 | - |
|
438 | - public function testHandleClearNoCalendarHome(): void { |
|
439 | - $user = $this->createMock(IUser::class); |
|
440 | - $user->method('getUID')->willReturn('user123'); |
|
441 | - $data = $this->createMock(IOutOfOfficeData::class); |
|
442 | - $data->method('getUser')->willReturn($user); |
|
443 | - $davServer = $this->createMock(Server::class); |
|
444 | - $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
445 | - $invitationServer->method('getServer')->willReturn($davServer); |
|
446 | - $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
447 | - $caldavPlugin = $this->createMock(Plugin::class); |
|
448 | - $davServer->expects(self::once()) |
|
449 | - ->method('getPlugin') |
|
450 | - ->with('caldav') |
|
451 | - ->willReturn($caldavPlugin); |
|
452 | - $event = new OutOfOfficeClearedEvent($data); |
|
453 | - |
|
454 | - $this->listener->handle($event); |
|
455 | - } |
|
456 | - |
|
457 | - public function testHandleClearNoCalendarHomeNode(): void { |
|
458 | - $user = $this->createMock(IUser::class); |
|
459 | - $user->method('getUID')->willReturn('user123'); |
|
460 | - $data = $this->createMock(IOutOfOfficeData::class); |
|
461 | - $data->method('getUser')->willReturn($user); |
|
462 | - $davServer = $this->createMock(Server::class); |
|
463 | - $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
464 | - $invitationServer->method('getServer')->willReturn($davServer); |
|
465 | - $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
466 | - $caldavPlugin = $this->createMock(Plugin::class); |
|
467 | - $davServer->expects(self::once()) |
|
468 | - ->method('getPlugin') |
|
469 | - ->with('caldav') |
|
470 | - ->willReturn($caldavPlugin); |
|
471 | - $caldavPlugin->expects(self::once()) |
|
472 | - ->method('getCalendarHomeForPrincipal') |
|
473 | - ->willReturn('/home/calendar'); |
|
474 | - $tree = $this->createMock(Tree::class); |
|
475 | - $davServer->tree = $tree; |
|
476 | - $tree->expects(self::once()) |
|
477 | - ->method('getNodeForPath') |
|
478 | - ->with('/home/calendar') |
|
479 | - ->willThrowException(new NotFound('nope')); |
|
480 | - $event = new OutOfOfficeClearedEvent($data); |
|
481 | - |
|
482 | - $this->listener->handle($event); |
|
483 | - } |
|
484 | - |
|
485 | - public function testHandleClearPersonalCalendarNotFound(): void { |
|
486 | - $user = $this->createMock(IUser::class); |
|
487 | - $user->method('getUID')->willReturn('user123'); |
|
488 | - $data = $this->createMock(IOutOfOfficeData::class); |
|
489 | - $data->method('getUser')->willReturn($user); |
|
490 | - $davServer = $this->createMock(Server::class); |
|
491 | - $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
492 | - $invitationServer->method('getServer')->willReturn($davServer); |
|
493 | - $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
494 | - $caldavPlugin = $this->createMock(Plugin::class); |
|
495 | - $davServer->expects(self::once()) |
|
496 | - ->method('getPlugin') |
|
497 | - ->with('caldav') |
|
498 | - ->willReturn($caldavPlugin); |
|
499 | - $caldavPlugin->expects(self::once()) |
|
500 | - ->method('getCalendarHomeForPrincipal') |
|
501 | - ->willReturn('/home/calendar'); |
|
502 | - $tree = $this->createMock(Tree::class); |
|
503 | - $davServer->tree = $tree; |
|
504 | - $calendarHome = $this->createMock(CalendarHome::class); |
|
505 | - $tree->expects(self::once()) |
|
506 | - ->method('getNodeForPath') |
|
507 | - ->with('/home/calendar') |
|
508 | - ->willReturn($calendarHome); |
|
509 | - $this->appConfig->expects(self::once()) |
|
510 | - ->method('getUserValue') |
|
511 | - ->with('user123', 'dav', 'defaultCalendar', 'personal') |
|
512 | - ->willReturn('personal-1'); |
|
513 | - $calendarHome->expects(self::once()) |
|
514 | - ->method('getChild') |
|
515 | - ->with('personal-1') |
|
516 | - ->willThrowException(new NotFound('nope')); |
|
517 | - $event = new OutOfOfficeClearedEvent($data); |
|
518 | - |
|
519 | - $this->listener->handle($event); |
|
520 | - } |
|
521 | - |
|
522 | - public function testHandleClearRecreate(): void { |
|
523 | - $user = $this->createMock(IUser::class); |
|
524 | - $user->method('getUID')->willReturn('user123'); |
|
525 | - $data = $this->createMock(IOutOfOfficeData::class); |
|
526 | - $data->method('getUser')->willReturn($user); |
|
527 | - $davServer = $this->createMock(Server::class); |
|
528 | - $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
529 | - $invitationServer->method('getServer')->willReturn($davServer); |
|
530 | - $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
531 | - $caldavPlugin = $this->createMock(Plugin::class); |
|
532 | - $davServer->expects(self::once()) |
|
533 | - ->method('getPlugin') |
|
534 | - ->with('caldav') |
|
535 | - ->willReturn($caldavPlugin); |
|
536 | - $caldavPlugin->expects(self::once()) |
|
537 | - ->method('getCalendarHomeForPrincipal') |
|
538 | - ->willReturn('/home/calendar'); |
|
539 | - $tree = $this->createMock(Tree::class); |
|
540 | - $davServer->tree = $tree; |
|
541 | - $calendarHome = $this->createMock(CalendarHome::class); |
|
542 | - $tree->expects(self::once()) |
|
543 | - ->method('getNodeForPath') |
|
544 | - ->with('/home/calendar') |
|
545 | - ->willReturn($calendarHome); |
|
546 | - $this->appConfig->expects(self::once()) |
|
547 | - ->method('getUserValue') |
|
548 | - ->with('user123', 'dav', 'defaultCalendar', 'personal') |
|
549 | - ->willReturn('personal-1'); |
|
550 | - $calendar = $this->createMock(Calendar::class); |
|
551 | - $calendarHome->expects(self::once()) |
|
552 | - ->method('getChild') |
|
553 | - ->with('personal-1') |
|
554 | - ->willReturn($calendar); |
|
555 | - $calendar->expects(self::once()) |
|
556 | - ->method('getChild') |
|
557 | - ->willThrowException(new NotFound()); |
|
558 | - $event = new OutOfOfficeClearedEvent($data); |
|
559 | - |
|
560 | - $this->listener->handle($event); |
|
561 | - } |
|
562 | - |
|
563 | - public function testHandleClear(): void { |
|
564 | - $user = $this->createMock(IUser::class); |
|
565 | - $user->method('getUID')->willReturn('user123'); |
|
566 | - $data = $this->createMock(IOutOfOfficeData::class); |
|
567 | - $data->method('getUser')->willReturn($user); |
|
568 | - $davServer = $this->createMock(Server::class); |
|
569 | - $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
570 | - $invitationServer->method('getServer')->willReturn($davServer); |
|
571 | - $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
572 | - $caldavPlugin = $this->createMock(Plugin::class); |
|
573 | - $davServer->expects(self::once()) |
|
574 | - ->method('getPlugin') |
|
575 | - ->with('caldav') |
|
576 | - ->willReturn($caldavPlugin); |
|
577 | - $caldavPlugin->expects(self::once()) |
|
578 | - ->method('getCalendarHomeForPrincipal') |
|
579 | - ->willReturn('/home/calendar'); |
|
580 | - $tree = $this->createMock(Tree::class); |
|
581 | - $davServer->tree = $tree; |
|
582 | - $calendarHome = $this->createMock(CalendarHome::class); |
|
583 | - $tree->expects(self::once()) |
|
584 | - ->method('getNodeForPath') |
|
585 | - ->with('/home/calendar') |
|
586 | - ->willReturn($calendarHome); |
|
587 | - $this->appConfig->expects(self::once()) |
|
588 | - ->method('getUserValue') |
|
589 | - ->with('user123', 'dav', 'defaultCalendar', 'personal') |
|
590 | - ->willReturn('personal-1'); |
|
591 | - $calendar = $this->createMock(Calendar::class); |
|
592 | - $calendarHome->expects(self::once()) |
|
593 | - ->method('getChild') |
|
594 | - ->with('personal-1') |
|
595 | - ->willReturn($calendar); |
|
596 | - $eventNode = $this->createMock(CalendarObject::class); |
|
597 | - $calendar->expects(self::once()) |
|
598 | - ->method('getChild') |
|
599 | - ->willReturn($eventNode); |
|
600 | - $eventNode->expects(self::once()) |
|
601 | - ->method('delete'); |
|
602 | - $event = new OutOfOfficeClearedEvent($data); |
|
603 | - |
|
604 | - $this->listener->handle($event); |
|
605 | - } |
|
44 | + private ServerFactory&MockObject $serverFactory; |
|
45 | + private IConfig&MockObject $appConfig; |
|
46 | + private LoggerInterface&MockObject $loggerInterface; |
|
47 | + private TimezoneService&MockObject $timezoneService; |
|
48 | + private OutOfOfficeListener $listener; |
|
49 | + |
|
50 | + protected function setUp(): void { |
|
51 | + parent::setUp(); |
|
52 | + |
|
53 | + $this->serverFactory = $this->createMock(ServerFactory::class); |
|
54 | + $this->appConfig = $this->createMock(IConfig::class); |
|
55 | + $this->timezoneService = $this->createMock(TimezoneService::class); |
|
56 | + $this->loggerInterface = $this->createMock(LoggerInterface::class); |
|
57 | + |
|
58 | + $this->listener = new OutOfOfficeListener( |
|
59 | + $this->serverFactory, |
|
60 | + $this->appConfig, |
|
61 | + $this->timezoneService, |
|
62 | + $this->loggerInterface, |
|
63 | + ); |
|
64 | + } |
|
65 | + |
|
66 | + public function testHandleUnrelated(): void { |
|
67 | + $event = new Event(); |
|
68 | + |
|
69 | + $this->listener->handle($event); |
|
70 | + |
|
71 | + $this->addToAssertionCount(1); |
|
72 | + } |
|
73 | + |
|
74 | + public function testHandleSchedulingNoCalendarHome(): void { |
|
75 | + $user = $this->createMock(IUser::class); |
|
76 | + $user->method('getUID')->willReturn('user123'); |
|
77 | + $data = $this->createMock(IOutOfOfficeData::class); |
|
78 | + $data->method('getUser')->willReturn($user); |
|
79 | + $davServer = $this->createMock(Server::class); |
|
80 | + $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
81 | + $invitationServer->method('getServer')->willReturn($davServer); |
|
82 | + $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
83 | + $caldavPlugin = $this->createMock(Plugin::class); |
|
84 | + $davServer->expects(self::once()) |
|
85 | + ->method('getPlugin') |
|
86 | + ->with('caldav') |
|
87 | + ->willReturn($caldavPlugin); |
|
88 | + $event = new OutOfOfficeScheduledEvent($data); |
|
89 | + |
|
90 | + $this->listener->handle($event); |
|
91 | + } |
|
92 | + |
|
93 | + public function testHandleSchedulingNoCalendarHomeNode(): void { |
|
94 | + $user = $this->createMock(IUser::class); |
|
95 | + $user->method('getUID')->willReturn('user123'); |
|
96 | + $data = $this->createMock(IOutOfOfficeData::class); |
|
97 | + $data->method('getUser')->willReturn($user); |
|
98 | + $davServer = $this->createMock(Server::class); |
|
99 | + $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
100 | + $invitationServer->method('getServer')->willReturn($davServer); |
|
101 | + $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
102 | + $caldavPlugin = $this->createMock(Plugin::class); |
|
103 | + $davServer->expects(self::once()) |
|
104 | + ->method('getPlugin') |
|
105 | + ->with('caldav') |
|
106 | + ->willReturn($caldavPlugin); |
|
107 | + $caldavPlugin->expects(self::once()) |
|
108 | + ->method('getCalendarHomeForPrincipal') |
|
109 | + ->willReturn('/home/calendar'); |
|
110 | + $tree = $this->createMock(Tree::class); |
|
111 | + $davServer->tree = $tree; |
|
112 | + $tree->expects(self::once()) |
|
113 | + ->method('getNodeForPath') |
|
114 | + ->with('/home/calendar') |
|
115 | + ->willThrowException(new NotFound('nope')); |
|
116 | + $event = new OutOfOfficeScheduledEvent($data); |
|
117 | + |
|
118 | + $this->listener->handle($event); |
|
119 | + } |
|
120 | + |
|
121 | + public function testHandleSchedulingPersonalCalendarNotFound(): void { |
|
122 | + $user = $this->createMock(IUser::class); |
|
123 | + $user->method('getUID')->willReturn('user123'); |
|
124 | + $data = $this->createMock(IOutOfOfficeData::class); |
|
125 | + $data->method('getUser')->willReturn($user); |
|
126 | + $davServer = $this->createMock(Server::class); |
|
127 | + $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
128 | + $invitationServer->method('getServer')->willReturn($davServer); |
|
129 | + $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
130 | + $caldavPlugin = $this->createMock(Plugin::class); |
|
131 | + $davServer->expects(self::once()) |
|
132 | + ->method('getPlugin') |
|
133 | + ->with('caldav') |
|
134 | + ->willReturn($caldavPlugin); |
|
135 | + $caldavPlugin->expects(self::once()) |
|
136 | + ->method('getCalendarHomeForPrincipal') |
|
137 | + ->willReturn('/home/calendar'); |
|
138 | + $tree = $this->createMock(Tree::class); |
|
139 | + $davServer->tree = $tree; |
|
140 | + $calendarHome = $this->createMock(CalendarHome::class); |
|
141 | + $tree->expects(self::once()) |
|
142 | + ->method('getNodeForPath') |
|
143 | + ->with('/home/calendar') |
|
144 | + ->willReturn($calendarHome); |
|
145 | + $this->appConfig->expects(self::once()) |
|
146 | + ->method('getUserValue') |
|
147 | + ->with('user123', 'dav', 'defaultCalendar', 'personal') |
|
148 | + ->willReturn('personal-1'); |
|
149 | + $calendarHome->expects(self::once()) |
|
150 | + ->method('getChild') |
|
151 | + ->with('personal-1') |
|
152 | + ->willThrowException(new NotFound('nope')); |
|
153 | + $event = new OutOfOfficeScheduledEvent($data); |
|
154 | + |
|
155 | + $this->listener->handle($event); |
|
156 | + } |
|
157 | + |
|
158 | + public function testHandleSchedulingWithDefaultTimezone(): void { |
|
159 | + $user = $this->createMock(IUser::class); |
|
160 | + $user->method('getUID')->willReturn('user123'); |
|
161 | + $data = $this->createMock(IOutOfOfficeData::class); |
|
162 | + $data->method('getUser')->willReturn($user); |
|
163 | + $data->method('getStartDate') |
|
164 | + ->willReturn((new DateTimeImmutable('2023-12-12T00:00:00Z'))->getTimestamp()); |
|
165 | + $data->method('getEndDate') |
|
166 | + ->willReturn((new DateTimeImmutable('2023-12-13T00:00:00Z'))->getTimestamp()); |
|
167 | + $davServer = $this->createMock(Server::class); |
|
168 | + $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
169 | + $invitationServer->method('getServer')->willReturn($davServer); |
|
170 | + $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
171 | + $caldavPlugin = $this->createMock(Plugin::class); |
|
172 | + $davServer->expects(self::once()) |
|
173 | + ->method('getPlugin') |
|
174 | + ->with('caldav') |
|
175 | + ->willReturn($caldavPlugin); |
|
176 | + $caldavPlugin->expects(self::once()) |
|
177 | + ->method('getCalendarHomeForPrincipal') |
|
178 | + ->willReturn('/home/calendar'); |
|
179 | + $tree = $this->createMock(Tree::class); |
|
180 | + $davServer->tree = $tree; |
|
181 | + $calendarHome = $this->createMock(CalendarHome::class); |
|
182 | + $tree->expects(self::once()) |
|
183 | + ->method('getNodeForPath') |
|
184 | + ->with('/home/calendar') |
|
185 | + ->willReturn($calendarHome); |
|
186 | + $this->appConfig->expects(self::once()) |
|
187 | + ->method('getUserValue') |
|
188 | + ->with('user123', 'dav', 'defaultCalendar', 'personal') |
|
189 | + ->willReturn('personal-1'); |
|
190 | + $calendar = $this->createMock(Calendar::class); |
|
191 | + $this->timezoneService->expects(self::once()) |
|
192 | + ->method('getUserTimezone') |
|
193 | + ->with('user123') |
|
194 | + ->willReturn('Europe/Prague'); |
|
195 | + $calendarHome->expects(self::once()) |
|
196 | + ->method('getChild') |
|
197 | + ->with('personal-1') |
|
198 | + ->willReturn($calendar); |
|
199 | + $calendar->expects(self::once()) |
|
200 | + ->method('createFile') |
|
201 | + ->willReturnCallback(function ($name, $data): void { |
|
202 | + $vcalendar = Reader::read($data); |
|
203 | + if (!($vcalendar instanceof VCalendar)) { |
|
204 | + throw new InvalidArgumentException('Calendar data should be a VCALENDAR'); |
|
205 | + } |
|
206 | + $vevent = $vcalendar->VEVENT; |
|
207 | + if ($vevent === null || !($vevent instanceof VEvent)) { |
|
208 | + throw new InvalidArgumentException('Calendar data should contain a VEVENT'); |
|
209 | + } |
|
210 | + self::assertSame('Europe/Prague', $vevent->DTSTART['TZID']?->getValue()); |
|
211 | + self::assertSame('Europe/Prague', $vevent->DTEND['TZID']?->getValue()); |
|
212 | + }); |
|
213 | + $event = new OutOfOfficeScheduledEvent($data); |
|
214 | + |
|
215 | + $this->listener->handle($event); |
|
216 | + } |
|
217 | + |
|
218 | + public function testHandleChangeNoCalendarHome(): void { |
|
219 | + $user = $this->createMock(IUser::class); |
|
220 | + $user->method('getUID')->willReturn('user123'); |
|
221 | + $data = $this->createMock(IOutOfOfficeData::class); |
|
222 | + $data->method('getUser')->willReturn($user); |
|
223 | + $davServer = $this->createMock(Server::class); |
|
224 | + $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
225 | + $invitationServer->method('getServer')->willReturn($davServer); |
|
226 | + $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
227 | + $caldavPlugin = $this->createMock(Plugin::class); |
|
228 | + $davServer->expects(self::once()) |
|
229 | + ->method('getPlugin') |
|
230 | + ->with('caldav') |
|
231 | + ->willReturn($caldavPlugin); |
|
232 | + $event = new OutOfOfficeChangedEvent($data); |
|
233 | + |
|
234 | + $this->listener->handle($event); |
|
235 | + } |
|
236 | + |
|
237 | + public function testHandleChangeNoCalendarHomeNode(): void { |
|
238 | + $user = $this->createMock(IUser::class); |
|
239 | + $user->method('getUID')->willReturn('user123'); |
|
240 | + $data = $this->createMock(IOutOfOfficeData::class); |
|
241 | + $data->method('getUser')->willReturn($user); |
|
242 | + $davServer = $this->createMock(Server::class); |
|
243 | + $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
244 | + $invitationServer->method('getServer')->willReturn($davServer); |
|
245 | + $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
246 | + $caldavPlugin = $this->createMock(Plugin::class); |
|
247 | + $davServer->expects(self::once()) |
|
248 | + ->method('getPlugin') |
|
249 | + ->with('caldav') |
|
250 | + ->willReturn($caldavPlugin); |
|
251 | + $caldavPlugin->expects(self::once()) |
|
252 | + ->method('getCalendarHomeForPrincipal') |
|
253 | + ->willReturn('/home/calendar'); |
|
254 | + $tree = $this->createMock(Tree::class); |
|
255 | + $davServer->tree = $tree; |
|
256 | + $tree->expects(self::once()) |
|
257 | + ->method('getNodeForPath') |
|
258 | + ->with('/home/calendar') |
|
259 | + ->willThrowException(new NotFound('nope')); |
|
260 | + $event = new OutOfOfficeChangedEvent($data); |
|
261 | + |
|
262 | + $this->listener->handle($event); |
|
263 | + } |
|
264 | + |
|
265 | + public function testHandleChangePersonalCalendarNotFound(): void { |
|
266 | + $user = $this->createMock(IUser::class); |
|
267 | + $user->method('getUID')->willReturn('user123'); |
|
268 | + $data = $this->createMock(IOutOfOfficeData::class); |
|
269 | + $data->method('getUser')->willReturn($user); |
|
270 | + $davServer = $this->createMock(Server::class); |
|
271 | + $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
272 | + $invitationServer->method('getServer')->willReturn($davServer); |
|
273 | + $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
274 | + $caldavPlugin = $this->createMock(Plugin::class); |
|
275 | + $davServer->expects(self::once()) |
|
276 | + ->method('getPlugin') |
|
277 | + ->with('caldav') |
|
278 | + ->willReturn($caldavPlugin); |
|
279 | + $caldavPlugin->expects(self::once()) |
|
280 | + ->method('getCalendarHomeForPrincipal') |
|
281 | + ->willReturn('/home/calendar'); |
|
282 | + $tree = $this->createMock(Tree::class); |
|
283 | + $davServer->tree = $tree; |
|
284 | + $calendarHome = $this->createMock(CalendarHome::class); |
|
285 | + $tree->expects(self::once()) |
|
286 | + ->method('getNodeForPath') |
|
287 | + ->with('/home/calendar') |
|
288 | + ->willReturn($calendarHome); |
|
289 | + $this->appConfig->expects(self::once()) |
|
290 | + ->method('getUserValue') |
|
291 | + ->with('user123', 'dav', 'defaultCalendar', 'personal') |
|
292 | + ->willReturn('personal-1'); |
|
293 | + $calendarHome->expects(self::once()) |
|
294 | + ->method('getChild') |
|
295 | + ->with('personal-1') |
|
296 | + ->willThrowException(new NotFound('nope')); |
|
297 | + $event = new OutOfOfficeChangedEvent($data); |
|
298 | + |
|
299 | + $this->listener->handle($event); |
|
300 | + } |
|
301 | + |
|
302 | + public function testHandleChangeRecreate(): void { |
|
303 | + $user = $this->createMock(IUser::class); |
|
304 | + $user->method('getUID')->willReturn('user123'); |
|
305 | + $data = $this->createMock(IOutOfOfficeData::class); |
|
306 | + $data->method('getUser')->willReturn($user); |
|
307 | + $data->method('getStartDate') |
|
308 | + ->willReturn((new DateTimeImmutable('2023-12-12T00:00:00Z'))->getTimestamp()); |
|
309 | + $data->method('getEndDate') |
|
310 | + ->willReturn((new DateTimeImmutable('2023-12-14T00:00:00Z'))->getTimestamp()); |
|
311 | + $davServer = $this->createMock(Server::class); |
|
312 | + $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
313 | + $invitationServer->method('getServer')->willReturn($davServer); |
|
314 | + $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
315 | + $caldavPlugin = $this->createMock(Plugin::class); |
|
316 | + $davServer->expects(self::once()) |
|
317 | + ->method('getPlugin') |
|
318 | + ->with('caldav') |
|
319 | + ->willReturn($caldavPlugin); |
|
320 | + $caldavPlugin->expects(self::once()) |
|
321 | + ->method('getCalendarHomeForPrincipal') |
|
322 | + ->willReturn('/home/calendar'); |
|
323 | + $tree = $this->createMock(Tree::class); |
|
324 | + $davServer->tree = $tree; |
|
325 | + $calendarHome = $this->createMock(CalendarHome::class); |
|
326 | + $tree->expects(self::once()) |
|
327 | + ->method('getNodeForPath') |
|
328 | + ->with('/home/calendar') |
|
329 | + ->willReturn($calendarHome); |
|
330 | + $this->appConfig->expects(self::once()) |
|
331 | + ->method('getUserValue') |
|
332 | + ->with('user123', 'dav', 'defaultCalendar', 'personal') |
|
333 | + ->willReturn('personal-1'); |
|
334 | + $calendar = $this->createMock(Calendar::class); |
|
335 | + $this->timezoneService->expects(self::once()) |
|
336 | + ->method('getUserTimezone') |
|
337 | + ->with('user123') |
|
338 | + ->willReturn(null); |
|
339 | + $this->timezoneService->expects(self::once()) |
|
340 | + ->method('getDefaultTimezone') |
|
341 | + ->willReturn('Europe/Berlin'); |
|
342 | + $calendarHome->expects(self::once()) |
|
343 | + ->method('getChild') |
|
344 | + ->with('personal-1') |
|
345 | + ->willReturn($calendar); |
|
346 | + $calendar->expects(self::once()) |
|
347 | + ->method('getChild') |
|
348 | + ->willThrowException(new NotFound()); |
|
349 | + $calendar->expects(self::once()) |
|
350 | + ->method('createFile') |
|
351 | + ->willReturnCallback(function ($name, $data): void { |
|
352 | + $vcalendar = Reader::read($data); |
|
353 | + if (!($vcalendar instanceof VCalendar)) { |
|
354 | + throw new InvalidArgumentException('Calendar data should be a VCALENDAR'); |
|
355 | + } |
|
356 | + $vevent = $vcalendar->VEVENT; |
|
357 | + if ($vevent === null || !($vevent instanceof VEvent)) { |
|
358 | + throw new InvalidArgumentException('Calendar data should contain a VEVENT'); |
|
359 | + } |
|
360 | + self::assertSame('Europe/Berlin', $vevent->DTSTART['TZID']?->getValue()); |
|
361 | + self::assertSame('Europe/Berlin', $vevent->DTEND['TZID']?->getValue()); |
|
362 | + }); |
|
363 | + $event = new OutOfOfficeChangedEvent($data); |
|
364 | + |
|
365 | + $this->listener->handle($event); |
|
366 | + } |
|
367 | + |
|
368 | + public function testHandleChangeWithoutTimezone(): void { |
|
369 | + $user = $this->createMock(IUser::class); |
|
370 | + $user->method('getUID')->willReturn('user123'); |
|
371 | + $data = $this->createMock(IOutOfOfficeData::class); |
|
372 | + $data->method('getUser')->willReturn($user); |
|
373 | + $data->method('getStartDate') |
|
374 | + ->willReturn((new DateTimeImmutable('2023-01-12T00:00:00Z'))->getTimestamp()); |
|
375 | + $data->method('getEndDate') |
|
376 | + ->willReturn((new DateTimeImmutable('2023-12-14T00:00:00Z'))->getTimestamp()); |
|
377 | + $davServer = $this->createMock(Server::class); |
|
378 | + $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
379 | + $invitationServer->method('getServer')->willReturn($davServer); |
|
380 | + $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
381 | + $caldavPlugin = $this->createMock(Plugin::class); |
|
382 | + $davServer->expects(self::once()) |
|
383 | + ->method('getPlugin') |
|
384 | + ->with('caldav') |
|
385 | + ->willReturn($caldavPlugin); |
|
386 | + $caldavPlugin->expects(self::once()) |
|
387 | + ->method('getCalendarHomeForPrincipal') |
|
388 | + ->willReturn('/home/calendar'); |
|
389 | + $tree = $this->createMock(Tree::class); |
|
390 | + $davServer->tree = $tree; |
|
391 | + $calendarHome = $this->createMock(CalendarHome::class); |
|
392 | + $tree->expects(self::once()) |
|
393 | + ->method('getNodeForPath') |
|
394 | + ->with('/home/calendar') |
|
395 | + ->willReturn($calendarHome); |
|
396 | + $this->appConfig->expects(self::once()) |
|
397 | + ->method('getUserValue') |
|
398 | + ->with('user123', 'dav', 'defaultCalendar', 'personal') |
|
399 | + ->willReturn('personal-1'); |
|
400 | + $calendar = $this->createMock(Calendar::class); |
|
401 | + $calendarHome->expects(self::once()) |
|
402 | + ->method('getChild') |
|
403 | + ->with('personal-1') |
|
404 | + ->willReturn($calendar); |
|
405 | + $eventNode = $this->createMock(CalendarObject::class); |
|
406 | + $this->timezoneService->expects(self::once()) |
|
407 | + ->method('getUserTimezone') |
|
408 | + ->with('user123') |
|
409 | + ->willReturn(null); |
|
410 | + $this->timezoneService->expects(self::once()) |
|
411 | + ->method('getDefaultTimezone') |
|
412 | + ->willReturn('UTC'); |
|
413 | + $calendar->expects(self::once()) |
|
414 | + ->method('getChild') |
|
415 | + ->willReturn($eventNode); |
|
416 | + $eventNode->expects(self::once()) |
|
417 | + ->method('put') |
|
418 | + ->willReturnCallback(function ($data): void { |
|
419 | + $vcalendar = Reader::read($data); |
|
420 | + if (!($vcalendar instanceof VCalendar)) { |
|
421 | + throw new InvalidArgumentException('Calendar data should be a VCALENDAR'); |
|
422 | + } |
|
423 | + $vevent = $vcalendar->VEVENT; |
|
424 | + if ($vevent === null || !($vevent instanceof VEvent)) { |
|
425 | + throw new InvalidArgumentException('Calendar data should contain a VEVENT'); |
|
426 | + } |
|
427 | + // UTC datetimes are stored without a TZID |
|
428 | + self::assertSame(null, $vevent->DTSTART['TZID']?->getValue()); |
|
429 | + self::assertSame(null, $vevent->DTEND['TZID']?->getValue()); |
|
430 | + }); |
|
431 | + $calendar->expects(self::never()) |
|
432 | + ->method('createFile'); |
|
433 | + $event = new OutOfOfficeChangedEvent($data); |
|
434 | + |
|
435 | + $this->listener->handle($event); |
|
436 | + } |
|
437 | + |
|
438 | + public function testHandleClearNoCalendarHome(): void { |
|
439 | + $user = $this->createMock(IUser::class); |
|
440 | + $user->method('getUID')->willReturn('user123'); |
|
441 | + $data = $this->createMock(IOutOfOfficeData::class); |
|
442 | + $data->method('getUser')->willReturn($user); |
|
443 | + $davServer = $this->createMock(Server::class); |
|
444 | + $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
445 | + $invitationServer->method('getServer')->willReturn($davServer); |
|
446 | + $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
447 | + $caldavPlugin = $this->createMock(Plugin::class); |
|
448 | + $davServer->expects(self::once()) |
|
449 | + ->method('getPlugin') |
|
450 | + ->with('caldav') |
|
451 | + ->willReturn($caldavPlugin); |
|
452 | + $event = new OutOfOfficeClearedEvent($data); |
|
453 | + |
|
454 | + $this->listener->handle($event); |
|
455 | + } |
|
456 | + |
|
457 | + public function testHandleClearNoCalendarHomeNode(): void { |
|
458 | + $user = $this->createMock(IUser::class); |
|
459 | + $user->method('getUID')->willReturn('user123'); |
|
460 | + $data = $this->createMock(IOutOfOfficeData::class); |
|
461 | + $data->method('getUser')->willReturn($user); |
|
462 | + $davServer = $this->createMock(Server::class); |
|
463 | + $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
464 | + $invitationServer->method('getServer')->willReturn($davServer); |
|
465 | + $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
466 | + $caldavPlugin = $this->createMock(Plugin::class); |
|
467 | + $davServer->expects(self::once()) |
|
468 | + ->method('getPlugin') |
|
469 | + ->with('caldav') |
|
470 | + ->willReturn($caldavPlugin); |
|
471 | + $caldavPlugin->expects(self::once()) |
|
472 | + ->method('getCalendarHomeForPrincipal') |
|
473 | + ->willReturn('/home/calendar'); |
|
474 | + $tree = $this->createMock(Tree::class); |
|
475 | + $davServer->tree = $tree; |
|
476 | + $tree->expects(self::once()) |
|
477 | + ->method('getNodeForPath') |
|
478 | + ->with('/home/calendar') |
|
479 | + ->willThrowException(new NotFound('nope')); |
|
480 | + $event = new OutOfOfficeClearedEvent($data); |
|
481 | + |
|
482 | + $this->listener->handle($event); |
|
483 | + } |
|
484 | + |
|
485 | + public function testHandleClearPersonalCalendarNotFound(): void { |
|
486 | + $user = $this->createMock(IUser::class); |
|
487 | + $user->method('getUID')->willReturn('user123'); |
|
488 | + $data = $this->createMock(IOutOfOfficeData::class); |
|
489 | + $data->method('getUser')->willReturn($user); |
|
490 | + $davServer = $this->createMock(Server::class); |
|
491 | + $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
492 | + $invitationServer->method('getServer')->willReturn($davServer); |
|
493 | + $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
494 | + $caldavPlugin = $this->createMock(Plugin::class); |
|
495 | + $davServer->expects(self::once()) |
|
496 | + ->method('getPlugin') |
|
497 | + ->with('caldav') |
|
498 | + ->willReturn($caldavPlugin); |
|
499 | + $caldavPlugin->expects(self::once()) |
|
500 | + ->method('getCalendarHomeForPrincipal') |
|
501 | + ->willReturn('/home/calendar'); |
|
502 | + $tree = $this->createMock(Tree::class); |
|
503 | + $davServer->tree = $tree; |
|
504 | + $calendarHome = $this->createMock(CalendarHome::class); |
|
505 | + $tree->expects(self::once()) |
|
506 | + ->method('getNodeForPath') |
|
507 | + ->with('/home/calendar') |
|
508 | + ->willReturn($calendarHome); |
|
509 | + $this->appConfig->expects(self::once()) |
|
510 | + ->method('getUserValue') |
|
511 | + ->with('user123', 'dav', 'defaultCalendar', 'personal') |
|
512 | + ->willReturn('personal-1'); |
|
513 | + $calendarHome->expects(self::once()) |
|
514 | + ->method('getChild') |
|
515 | + ->with('personal-1') |
|
516 | + ->willThrowException(new NotFound('nope')); |
|
517 | + $event = new OutOfOfficeClearedEvent($data); |
|
518 | + |
|
519 | + $this->listener->handle($event); |
|
520 | + } |
|
521 | + |
|
522 | + public function testHandleClearRecreate(): void { |
|
523 | + $user = $this->createMock(IUser::class); |
|
524 | + $user->method('getUID')->willReturn('user123'); |
|
525 | + $data = $this->createMock(IOutOfOfficeData::class); |
|
526 | + $data->method('getUser')->willReturn($user); |
|
527 | + $davServer = $this->createMock(Server::class); |
|
528 | + $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
529 | + $invitationServer->method('getServer')->willReturn($davServer); |
|
530 | + $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
531 | + $caldavPlugin = $this->createMock(Plugin::class); |
|
532 | + $davServer->expects(self::once()) |
|
533 | + ->method('getPlugin') |
|
534 | + ->with('caldav') |
|
535 | + ->willReturn($caldavPlugin); |
|
536 | + $caldavPlugin->expects(self::once()) |
|
537 | + ->method('getCalendarHomeForPrincipal') |
|
538 | + ->willReturn('/home/calendar'); |
|
539 | + $tree = $this->createMock(Tree::class); |
|
540 | + $davServer->tree = $tree; |
|
541 | + $calendarHome = $this->createMock(CalendarHome::class); |
|
542 | + $tree->expects(self::once()) |
|
543 | + ->method('getNodeForPath') |
|
544 | + ->with('/home/calendar') |
|
545 | + ->willReturn($calendarHome); |
|
546 | + $this->appConfig->expects(self::once()) |
|
547 | + ->method('getUserValue') |
|
548 | + ->with('user123', 'dav', 'defaultCalendar', 'personal') |
|
549 | + ->willReturn('personal-1'); |
|
550 | + $calendar = $this->createMock(Calendar::class); |
|
551 | + $calendarHome->expects(self::once()) |
|
552 | + ->method('getChild') |
|
553 | + ->with('personal-1') |
|
554 | + ->willReturn($calendar); |
|
555 | + $calendar->expects(self::once()) |
|
556 | + ->method('getChild') |
|
557 | + ->willThrowException(new NotFound()); |
|
558 | + $event = new OutOfOfficeClearedEvent($data); |
|
559 | + |
|
560 | + $this->listener->handle($event); |
|
561 | + } |
|
562 | + |
|
563 | + public function testHandleClear(): void { |
|
564 | + $user = $this->createMock(IUser::class); |
|
565 | + $user->method('getUID')->willReturn('user123'); |
|
566 | + $data = $this->createMock(IOutOfOfficeData::class); |
|
567 | + $data->method('getUser')->willReturn($user); |
|
568 | + $davServer = $this->createMock(Server::class); |
|
569 | + $invitationServer = $this->createMock(InvitationResponseServer::class); |
|
570 | + $invitationServer->method('getServer')->willReturn($davServer); |
|
571 | + $this->serverFactory->method('createInviationResponseServer')->willReturn($invitationServer); |
|
572 | + $caldavPlugin = $this->createMock(Plugin::class); |
|
573 | + $davServer->expects(self::once()) |
|
574 | + ->method('getPlugin') |
|
575 | + ->with('caldav') |
|
576 | + ->willReturn($caldavPlugin); |
|
577 | + $caldavPlugin->expects(self::once()) |
|
578 | + ->method('getCalendarHomeForPrincipal') |
|
579 | + ->willReturn('/home/calendar'); |
|
580 | + $tree = $this->createMock(Tree::class); |
|
581 | + $davServer->tree = $tree; |
|
582 | + $calendarHome = $this->createMock(CalendarHome::class); |
|
583 | + $tree->expects(self::once()) |
|
584 | + ->method('getNodeForPath') |
|
585 | + ->with('/home/calendar') |
|
586 | + ->willReturn($calendarHome); |
|
587 | + $this->appConfig->expects(self::once()) |
|
588 | + ->method('getUserValue') |
|
589 | + ->with('user123', 'dav', 'defaultCalendar', 'personal') |
|
590 | + ->willReturn('personal-1'); |
|
591 | + $calendar = $this->createMock(Calendar::class); |
|
592 | + $calendarHome->expects(self::once()) |
|
593 | + ->method('getChild') |
|
594 | + ->with('personal-1') |
|
595 | + ->willReturn($calendar); |
|
596 | + $eventNode = $this->createMock(CalendarObject::class); |
|
597 | + $calendar->expects(self::once()) |
|
598 | + ->method('getChild') |
|
599 | + ->willReturn($eventNode); |
|
600 | + $eventNode->expects(self::once()) |
|
601 | + ->method('delete'); |
|
602 | + $event = new OutOfOfficeClearedEvent($data); |
|
603 | + |
|
604 | + $this->listener->handle($event); |
|
605 | + } |
|
606 | 606 | } |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | ->willReturn($calendar); |
199 | 199 | $calendar->expects(self::once()) |
200 | 200 | ->method('createFile') |
201 | - ->willReturnCallback(function ($name, $data): void { |
|
201 | + ->willReturnCallback(function($name, $data): void { |
|
202 | 202 | $vcalendar = Reader::read($data); |
203 | 203 | if (!($vcalendar instanceof VCalendar)) { |
204 | 204 | throw new InvalidArgumentException('Calendar data should be a VCALENDAR'); |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | ->willThrowException(new NotFound()); |
349 | 349 | $calendar->expects(self::once()) |
350 | 350 | ->method('createFile') |
351 | - ->willReturnCallback(function ($name, $data): void { |
|
351 | + ->willReturnCallback(function($name, $data): void { |
|
352 | 352 | $vcalendar = Reader::read($data); |
353 | 353 | if (!($vcalendar instanceof VCalendar)) { |
354 | 354 | throw new InvalidArgumentException('Calendar data should be a VCALENDAR'); |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | ->willReturn($eventNode); |
416 | 416 | $eventNode->expects(self::once()) |
417 | 417 | ->method('put') |
418 | - ->willReturnCallback(function ($data): void { |
|
418 | + ->willReturnCallback(function($data): void { |
|
419 | 419 | $vcalendar = Reader::read($data); |
420 | 420 | if (!($vcalendar instanceof VCalendar)) { |
421 | 421 | throw new InvalidArgumentException('Calendar data should be a VCALENDAR'); |