@@ -21,170 +21,170 @@ |
||
21 | 21 | use TypeError; |
22 | 22 | |
23 | 23 | class EventTest extends TestCase { |
24 | - protected IUserManager&MockObject $userManager; |
|
25 | - protected IGroupManager&MockObject $groupManager; |
|
26 | - protected IURLGenerator&MockObject $url; |
|
27 | - protected IAppManager&MockObject $appManager; |
|
28 | - protected IFactory&MockObject $i10nFactory; |
|
29 | - protected IManager&MockObject $activityManager; |
|
30 | - protected IEventMerger&MockObject $eventMerger; |
|
31 | - protected Event&MockObject $provider; |
|
24 | + protected IUserManager&MockObject $userManager; |
|
25 | + protected IGroupManager&MockObject $groupManager; |
|
26 | + protected IURLGenerator&MockObject $url; |
|
27 | + protected IAppManager&MockObject $appManager; |
|
28 | + protected IFactory&MockObject $i10nFactory; |
|
29 | + protected IManager&MockObject $activityManager; |
|
30 | + protected IEventMerger&MockObject $eventMerger; |
|
31 | + protected Event&MockObject $provider; |
|
32 | 32 | |
33 | - protected function setUp(): void { |
|
34 | - parent::setUp(); |
|
35 | - $this->i10nFactory = $this->createMock(IFactory::class); |
|
36 | - $this->userManager = $this->createMock(IUserManager::class); |
|
37 | - $this->groupManager = $this->createMock(IGroupManager::class); |
|
38 | - $this->activityManager = $this->createMock(IManager::class); |
|
39 | - $this->url = $this->createMock(IURLGenerator::class); |
|
40 | - $this->appManager = $this->createMock(IAppManager::class); |
|
41 | - $this->eventMerger = $this->createMock(IEventMerger::class); |
|
42 | - $this->provider = $this->getMockBuilder(Event::class) |
|
43 | - ->setConstructorArgs([ |
|
44 | - $this->i10nFactory, |
|
45 | - $this->url, |
|
46 | - $this->activityManager, |
|
47 | - $this->userManager, |
|
48 | - $this->groupManager, |
|
49 | - $this->eventMerger, |
|
50 | - $this->appManager |
|
51 | - ]) |
|
52 | - ->onlyMethods(['parse']) |
|
53 | - ->getMock(); |
|
54 | - } |
|
33 | + protected function setUp(): void { |
|
34 | + parent::setUp(); |
|
35 | + $this->i10nFactory = $this->createMock(IFactory::class); |
|
36 | + $this->userManager = $this->createMock(IUserManager::class); |
|
37 | + $this->groupManager = $this->createMock(IGroupManager::class); |
|
38 | + $this->activityManager = $this->createMock(IManager::class); |
|
39 | + $this->url = $this->createMock(IURLGenerator::class); |
|
40 | + $this->appManager = $this->createMock(IAppManager::class); |
|
41 | + $this->eventMerger = $this->createMock(IEventMerger::class); |
|
42 | + $this->provider = $this->getMockBuilder(Event::class) |
|
43 | + ->setConstructorArgs([ |
|
44 | + $this->i10nFactory, |
|
45 | + $this->url, |
|
46 | + $this->activityManager, |
|
47 | + $this->userManager, |
|
48 | + $this->groupManager, |
|
49 | + $this->eventMerger, |
|
50 | + $this->appManager |
|
51 | + ]) |
|
52 | + ->onlyMethods(['parse']) |
|
53 | + ->getMock(); |
|
54 | + } |
|
55 | 55 | |
56 | - public static function dataGenerateObjectParameter(): array { |
|
57 | - $link = [ |
|
58 | - 'object_uri' => 'someuuid.ics', |
|
59 | - 'calendar_uri' => 'personal', |
|
60 | - 'owner' => 'someuser' |
|
61 | - ]; |
|
56 | + public static function dataGenerateObjectParameter(): array { |
|
57 | + $link = [ |
|
58 | + 'object_uri' => 'someuuid.ics', |
|
59 | + 'calendar_uri' => 'personal', |
|
60 | + 'owner' => 'someuser' |
|
61 | + ]; |
|
62 | 62 | |
63 | - return [ |
|
64 | - [23, 'c1', $link, true], |
|
65 | - [23, 'c1', $link, false], |
|
66 | - [42, 'c2', null], |
|
67 | - ]; |
|
68 | - } |
|
63 | + return [ |
|
64 | + [23, 'c1', $link, true], |
|
65 | + [23, 'c1', $link, false], |
|
66 | + [42, 'c2', null], |
|
67 | + ]; |
|
68 | + } |
|
69 | 69 | |
70 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataGenerateObjectParameter')] |
|
71 | - public function testGenerateObjectParameter(int $id, string $name, ?array $link, bool $calendarAppEnabled = true): void { |
|
72 | - $affectedUser = 'otheruser'; |
|
73 | - if ($link) { |
|
74 | - $affectedUser = $link['owner']; |
|
75 | - $generatedLink = [ |
|
76 | - 'objectId' => base64_encode('/remote.php/dav/calendars/' . $link['owner'] . '/' . $link['calendar_uri'] . '/' . $link['object_uri']), |
|
77 | - ]; |
|
78 | - $this->appManager->expects($this->once()) |
|
79 | - ->method('isEnabledForUser') |
|
80 | - ->with('calendar') |
|
81 | - ->willReturn($calendarAppEnabled); |
|
82 | - if ($calendarAppEnabled) { |
|
83 | - $this->url->expects($this->once()) |
|
84 | - ->method('getWebroot'); |
|
85 | - $this->url->expects($this->once()) |
|
86 | - ->method('linkToRouteAbsolute') |
|
87 | - ->with('calendar.view.indexdirect.edit', $generatedLink) |
|
88 | - ->willReturn('fullLink'); |
|
89 | - } |
|
90 | - } |
|
91 | - $objectParameter = ['id' => $id, 'name' => $name]; |
|
92 | - if ($link) { |
|
93 | - $objectParameter['link'] = $link; |
|
94 | - } |
|
95 | - $result = [ |
|
96 | - 'type' => 'calendar-event', |
|
97 | - 'id' => $id, |
|
98 | - 'name' => $name, |
|
99 | - ]; |
|
100 | - if ($link && $calendarAppEnabled) { |
|
101 | - $result['link'] = 'fullLink'; |
|
102 | - } |
|
103 | - $this->assertEquals($result, $this->invokePrivate($this->provider, 'generateObjectParameter', [$objectParameter, $affectedUser])); |
|
104 | - } |
|
70 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataGenerateObjectParameter')] |
|
71 | + public function testGenerateObjectParameter(int $id, string $name, ?array $link, bool $calendarAppEnabled = true): void { |
|
72 | + $affectedUser = 'otheruser'; |
|
73 | + if ($link) { |
|
74 | + $affectedUser = $link['owner']; |
|
75 | + $generatedLink = [ |
|
76 | + 'objectId' => base64_encode('/remote.php/dav/calendars/' . $link['owner'] . '/' . $link['calendar_uri'] . '/' . $link['object_uri']), |
|
77 | + ]; |
|
78 | + $this->appManager->expects($this->once()) |
|
79 | + ->method('isEnabledForUser') |
|
80 | + ->with('calendar') |
|
81 | + ->willReturn($calendarAppEnabled); |
|
82 | + if ($calendarAppEnabled) { |
|
83 | + $this->url->expects($this->once()) |
|
84 | + ->method('getWebroot'); |
|
85 | + $this->url->expects($this->once()) |
|
86 | + ->method('linkToRouteAbsolute') |
|
87 | + ->with('calendar.view.indexdirect.edit', $generatedLink) |
|
88 | + ->willReturn('fullLink'); |
|
89 | + } |
|
90 | + } |
|
91 | + $objectParameter = ['id' => $id, 'name' => $name]; |
|
92 | + if ($link) { |
|
93 | + $objectParameter['link'] = $link; |
|
94 | + } |
|
95 | + $result = [ |
|
96 | + 'type' => 'calendar-event', |
|
97 | + 'id' => $id, |
|
98 | + 'name' => $name, |
|
99 | + ]; |
|
100 | + if ($link && $calendarAppEnabled) { |
|
101 | + $result['link'] = 'fullLink'; |
|
102 | + } |
|
103 | + $this->assertEquals($result, $this->invokePrivate($this->provider, 'generateObjectParameter', [$objectParameter, $affectedUser])); |
|
104 | + } |
|
105 | 105 | |
106 | - public static function generateObjectParameterLinkEncodingDataProvider(): array { |
|
107 | - return [ |
|
108 | - [ // Shared calendar |
|
109 | - [ |
|
110 | - 'object_uri' => 'someuuid.ics', |
|
111 | - 'calendar_uri' => 'personal', |
|
112 | - 'owner' => 'sharer' |
|
113 | - ], |
|
114 | - base64_encode('/remote.php/dav/calendars/sharee/personal_shared_by_sharer/someuuid.ics'), |
|
115 | - ], |
|
116 | - [ // Shared calendar with umlauts |
|
117 | - [ |
|
118 | - 'object_uri' => 'someuuid.ics', |
|
119 | - 'calendar_uri' => 'umlaut_äüöß', |
|
120 | - 'owner' => 'sharer' |
|
121 | - ], |
|
122 | - base64_encode('/remote.php/dav/calendars/sharee/umlaut_%c3%a4%c3%bc%c3%b6%c3%9f_shared_by_sharer/someuuid.ics'), |
|
123 | - ], |
|
124 | - [ // Shared calendar with umlauts and mixed casing |
|
125 | - [ |
|
126 | - 'object_uri' => 'someuuid.ics', |
|
127 | - 'calendar_uri' => 'Umlaut_äüöß', |
|
128 | - 'owner' => 'sharer' |
|
129 | - ], |
|
130 | - base64_encode('/remote.php/dav/calendars/sharee/Umlaut_%c3%a4%c3%bc%c3%b6%c3%9f_shared_by_sharer/someuuid.ics'), |
|
131 | - ], |
|
132 | - [ // Owned calendar with umlauts |
|
133 | - [ |
|
134 | - 'object_uri' => 'someuuid.ics', |
|
135 | - 'calendar_uri' => 'umlaut_äüöß', |
|
136 | - 'owner' => 'sharee' |
|
137 | - ], |
|
138 | - base64_encode('/remote.php/dav/calendars/sharee/umlaut_%c3%a4%c3%bc%c3%b6%c3%9f/someuuid.ics'), |
|
139 | - ], |
|
140 | - [ // Owned calendar with umlauts and mixed casing |
|
141 | - [ |
|
142 | - 'object_uri' => 'someuuid.ics', |
|
143 | - 'calendar_uri' => 'Umlaut_äüöß', |
|
144 | - 'owner' => 'sharee' |
|
145 | - ], |
|
146 | - base64_encode('/remote.php/dav/calendars/sharee/Umlaut_%c3%a4%c3%bc%c3%b6%c3%9f/someuuid.ics'), |
|
147 | - ], |
|
148 | - ]; |
|
149 | - } |
|
106 | + public static function generateObjectParameterLinkEncodingDataProvider(): array { |
|
107 | + return [ |
|
108 | + [ // Shared calendar |
|
109 | + [ |
|
110 | + 'object_uri' => 'someuuid.ics', |
|
111 | + 'calendar_uri' => 'personal', |
|
112 | + 'owner' => 'sharer' |
|
113 | + ], |
|
114 | + base64_encode('/remote.php/dav/calendars/sharee/personal_shared_by_sharer/someuuid.ics'), |
|
115 | + ], |
|
116 | + [ // Shared calendar with umlauts |
|
117 | + [ |
|
118 | + 'object_uri' => 'someuuid.ics', |
|
119 | + 'calendar_uri' => 'umlaut_äüöß', |
|
120 | + 'owner' => 'sharer' |
|
121 | + ], |
|
122 | + base64_encode('/remote.php/dav/calendars/sharee/umlaut_%c3%a4%c3%bc%c3%b6%c3%9f_shared_by_sharer/someuuid.ics'), |
|
123 | + ], |
|
124 | + [ // Shared calendar with umlauts and mixed casing |
|
125 | + [ |
|
126 | + 'object_uri' => 'someuuid.ics', |
|
127 | + 'calendar_uri' => 'Umlaut_äüöß', |
|
128 | + 'owner' => 'sharer' |
|
129 | + ], |
|
130 | + base64_encode('/remote.php/dav/calendars/sharee/Umlaut_%c3%a4%c3%bc%c3%b6%c3%9f_shared_by_sharer/someuuid.ics'), |
|
131 | + ], |
|
132 | + [ // Owned calendar with umlauts |
|
133 | + [ |
|
134 | + 'object_uri' => 'someuuid.ics', |
|
135 | + 'calendar_uri' => 'umlaut_äüöß', |
|
136 | + 'owner' => 'sharee' |
|
137 | + ], |
|
138 | + base64_encode('/remote.php/dav/calendars/sharee/umlaut_%c3%a4%c3%bc%c3%b6%c3%9f/someuuid.ics'), |
|
139 | + ], |
|
140 | + [ // Owned calendar with umlauts and mixed casing |
|
141 | + [ |
|
142 | + 'object_uri' => 'someuuid.ics', |
|
143 | + 'calendar_uri' => 'Umlaut_äüöß', |
|
144 | + 'owner' => 'sharee' |
|
145 | + ], |
|
146 | + base64_encode('/remote.php/dav/calendars/sharee/Umlaut_%c3%a4%c3%bc%c3%b6%c3%9f/someuuid.ics'), |
|
147 | + ], |
|
148 | + ]; |
|
149 | + } |
|
150 | 150 | |
151 | - #[\PHPUnit\Framework\Attributes\DataProvider('generateObjectParameterLinkEncodingDataProvider')] |
|
152 | - public function testGenerateObjectParameterLinkEncoding(array $link, string $objectId): void { |
|
153 | - $generatedLink = [ |
|
154 | - 'objectId' => $objectId, |
|
155 | - ]; |
|
156 | - $this->appManager->expects($this->once()) |
|
157 | - ->method('isEnabledForUser') |
|
158 | - ->with('calendar') |
|
159 | - ->willReturn(true); |
|
160 | - $this->url->expects($this->once()) |
|
161 | - ->method('getWebroot'); |
|
162 | - $this->url->expects($this->once()) |
|
163 | - ->method('linkToRouteAbsolute') |
|
164 | - ->with('calendar.view.indexdirect.edit', $generatedLink) |
|
165 | - ->willReturn('fullLink'); |
|
166 | - $objectParameter = ['id' => 42, 'name' => 'calendar', 'link' => $link]; |
|
167 | - $result = [ |
|
168 | - 'type' => 'calendar-event', |
|
169 | - 'id' => 42, |
|
170 | - 'name' => 'calendar', |
|
171 | - 'link' => 'fullLink', |
|
172 | - ]; |
|
173 | - $this->assertEquals($result, $this->invokePrivate($this->provider, 'generateObjectParameter', [$objectParameter, 'sharee'])); |
|
174 | - } |
|
151 | + #[\PHPUnit\Framework\Attributes\DataProvider('generateObjectParameterLinkEncodingDataProvider')] |
|
152 | + public function testGenerateObjectParameterLinkEncoding(array $link, string $objectId): void { |
|
153 | + $generatedLink = [ |
|
154 | + 'objectId' => $objectId, |
|
155 | + ]; |
|
156 | + $this->appManager->expects($this->once()) |
|
157 | + ->method('isEnabledForUser') |
|
158 | + ->with('calendar') |
|
159 | + ->willReturn(true); |
|
160 | + $this->url->expects($this->once()) |
|
161 | + ->method('getWebroot'); |
|
162 | + $this->url->expects($this->once()) |
|
163 | + ->method('linkToRouteAbsolute') |
|
164 | + ->with('calendar.view.indexdirect.edit', $generatedLink) |
|
165 | + ->willReturn('fullLink'); |
|
166 | + $objectParameter = ['id' => 42, 'name' => 'calendar', 'link' => $link]; |
|
167 | + $result = [ |
|
168 | + 'type' => 'calendar-event', |
|
169 | + 'id' => 42, |
|
170 | + 'name' => 'calendar', |
|
171 | + 'link' => 'fullLink', |
|
172 | + ]; |
|
173 | + $this->assertEquals($result, $this->invokePrivate($this->provider, 'generateObjectParameter', [$objectParameter, 'sharee'])); |
|
174 | + } |
|
175 | 175 | |
176 | - public static function dataGenerateObjectParameterThrows(): array { |
|
177 | - return [ |
|
178 | - ['event', TypeError::class], |
|
179 | - [['name' => 'event']], |
|
180 | - [['id' => 42]], |
|
181 | - ]; |
|
182 | - } |
|
176 | + public static function dataGenerateObjectParameterThrows(): array { |
|
177 | + return [ |
|
178 | + ['event', TypeError::class], |
|
179 | + [['name' => 'event']], |
|
180 | + [['id' => 42]], |
|
181 | + ]; |
|
182 | + } |
|
183 | 183 | |
184 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataGenerateObjectParameterThrows')] |
|
185 | - public function testGenerateObjectParameterThrows(string|array $eventData, string $exception = InvalidArgumentException::class): void { |
|
186 | - $this->expectException($exception); |
|
184 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataGenerateObjectParameterThrows')] |
|
185 | + public function testGenerateObjectParameterThrows(string|array $eventData, string $exception = InvalidArgumentException::class): void { |
|
186 | + $this->expectException($exception); |
|
187 | 187 | |
188 | - $this->invokePrivate($this->provider, 'generateObjectParameter', [$eventData, 'no_user']); |
|
189 | - } |
|
188 | + $this->invokePrivate($this->provider, 'generateObjectParameter', [$eventData, 'no_user']); |
|
189 | + } |
|
190 | 190 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | if ($link) { |
74 | 74 | $affectedUser = $link['owner']; |
75 | 75 | $generatedLink = [ |
76 | - 'objectId' => base64_encode('/remote.php/dav/calendars/' . $link['owner'] . '/' . $link['calendar_uri'] . '/' . $link['object_uri']), |
|
76 | + 'objectId' => base64_encode('/remote.php/dav/calendars/'.$link['owner'].'/'.$link['calendar_uri'].'/'.$link['object_uri']), |
|
77 | 77 | ]; |
78 | 78 | $this->appManager->expects($this->once()) |
79 | 79 | ->method('isEnabledForUser') |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | |
106 | 106 | public static function generateObjectParameterLinkEncodingDataProvider(): array { |
107 | 107 | return [ |
108 | - [ // Shared calendar |
|
108 | + [// Shared calendar |
|
109 | 109 | [ |
110 | 110 | 'object_uri' => 'someuuid.ics', |
111 | 111 | 'calendar_uri' => 'personal', |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | ], |
114 | 114 | base64_encode('/remote.php/dav/calendars/sharee/personal_shared_by_sharer/someuuid.ics'), |
115 | 115 | ], |
116 | - [ // Shared calendar with umlauts |
|
116 | + [// Shared calendar with umlauts |
|
117 | 117 | [ |
118 | 118 | 'object_uri' => 'someuuid.ics', |
119 | 119 | 'calendar_uri' => 'umlaut_äüöß', |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | ], |
122 | 122 | base64_encode('/remote.php/dav/calendars/sharee/umlaut_%c3%a4%c3%bc%c3%b6%c3%9f_shared_by_sharer/someuuid.ics'), |
123 | 123 | ], |
124 | - [ // Shared calendar with umlauts and mixed casing |
|
124 | + [// Shared calendar with umlauts and mixed casing |
|
125 | 125 | [ |
126 | 126 | 'object_uri' => 'someuuid.ics', |
127 | 127 | 'calendar_uri' => 'Umlaut_äüöß', |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | ], |
130 | 130 | base64_encode('/remote.php/dav/calendars/sharee/Umlaut_%c3%a4%c3%bc%c3%b6%c3%9f_shared_by_sharer/someuuid.ics'), |
131 | 131 | ], |
132 | - [ // Owned calendar with umlauts |
|
132 | + [// Owned calendar with umlauts |
|
133 | 133 | [ |
134 | 134 | 'object_uri' => 'someuuid.ics', |
135 | 135 | 'calendar_uri' => 'umlaut_äüöß', |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | ], |
138 | 138 | base64_encode('/remote.php/dav/calendars/sharee/umlaut_%c3%a4%c3%bc%c3%b6%c3%9f/someuuid.ics'), |
139 | 139 | ], |
140 | - [ // Owned calendar with umlauts and mixed casing |
|
140 | + [// Owned calendar with umlauts and mixed casing |
|
141 | 141 | [ |
142 | 142 | 'object_uri' => 'someuuid.ics', |
143 | 143 | 'calendar_uri' => 'Umlaut_äüöß', |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | } |
183 | 183 | |
184 | 184 | #[\PHPUnit\Framework\Attributes\DataProvider('dataGenerateObjectParameterThrows')] |
185 | - public function testGenerateObjectParameterThrows(string|array $eventData, string $exception = InvalidArgumentException::class): void { |
|
185 | + public function testGenerateObjectParameterThrows(string | array $eventData, string $exception = InvalidArgumentException::class): void { |
|
186 | 186 | $this->expectException($exception); |
187 | 187 | |
188 | 188 | $this->invokePrivate($this->provider, 'generateObjectParameter', [$eventData, 'no_user']); |
@@ -17,100 +17,100 @@ |
||
17 | 17 | use Test\TestCase; |
18 | 18 | |
19 | 19 | class BaseTest extends TestCase { |
20 | - protected IUserManager&MockObject $userManager; |
|
21 | - protected IGroupManager&MockObject $groupManager; |
|
22 | - protected IURLGenerator&MockObject $url; |
|
23 | - protected Base&MockObject $provider; |
|
20 | + protected IUserManager&MockObject $userManager; |
|
21 | + protected IGroupManager&MockObject $groupManager; |
|
22 | + protected IURLGenerator&MockObject $url; |
|
23 | + protected Base&MockObject $provider; |
|
24 | 24 | |
25 | - protected function setUp(): void { |
|
26 | - parent::setUp(); |
|
27 | - $this->userManager = $this->createMock(IUserManager::class); |
|
28 | - $this->groupManager = $this->createMock(IGroupManager::class); |
|
29 | - $this->url = $this->createMock(IURLGenerator::class); |
|
30 | - $this->provider = $this->getMockBuilder(Base::class) |
|
31 | - ->setConstructorArgs([ |
|
32 | - $this->userManager, |
|
33 | - $this->groupManager, |
|
34 | - $this->url, |
|
35 | - ]) |
|
36 | - ->onlyMethods(['parse']) |
|
37 | - ->getMock(); |
|
38 | - } |
|
25 | + protected function setUp(): void { |
|
26 | + parent::setUp(); |
|
27 | + $this->userManager = $this->createMock(IUserManager::class); |
|
28 | + $this->groupManager = $this->createMock(IGroupManager::class); |
|
29 | + $this->url = $this->createMock(IURLGenerator::class); |
|
30 | + $this->provider = $this->getMockBuilder(Base::class) |
|
31 | + ->setConstructorArgs([ |
|
32 | + $this->userManager, |
|
33 | + $this->groupManager, |
|
34 | + $this->url, |
|
35 | + ]) |
|
36 | + ->onlyMethods(['parse']) |
|
37 | + ->getMock(); |
|
38 | + } |
|
39 | 39 | |
40 | - public static function dataSetSubjects(): array { |
|
41 | - return [ |
|
42 | - ['abc', []], |
|
43 | - ['{actor} created {calendar}', ['actor' => ['name' => 'abc'], 'calendar' => ['name' => 'xyz']]], |
|
44 | - ]; |
|
45 | - } |
|
40 | + public static function dataSetSubjects(): array { |
|
41 | + return [ |
|
42 | + ['abc', []], |
|
43 | + ['{actor} created {calendar}', ['actor' => ['name' => 'abc'], 'calendar' => ['name' => 'xyz']]], |
|
44 | + ]; |
|
45 | + } |
|
46 | 46 | |
47 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataSetSubjects')] |
|
48 | - public function testSetSubjects(string $subject, array $parameters): void { |
|
49 | - $event = $this->createMock(IEvent::class); |
|
50 | - $event->expects($this->once()) |
|
51 | - ->method('setRichSubject') |
|
52 | - ->with($subject, $parameters) |
|
53 | - ->willReturnSelf(); |
|
54 | - $event->expects($this->never()) |
|
55 | - ->method('setParsedSubject'); |
|
47 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataSetSubjects')] |
|
48 | + public function testSetSubjects(string $subject, array $parameters): void { |
|
49 | + $event = $this->createMock(IEvent::class); |
|
50 | + $event->expects($this->once()) |
|
51 | + ->method('setRichSubject') |
|
52 | + ->with($subject, $parameters) |
|
53 | + ->willReturnSelf(); |
|
54 | + $event->expects($this->never()) |
|
55 | + ->method('setParsedSubject'); |
|
56 | 56 | |
57 | - $this->invokePrivate($this->provider, 'setSubjects', [$event, $subject, $parameters]); |
|
58 | - } |
|
57 | + $this->invokePrivate($this->provider, 'setSubjects', [$event, $subject, $parameters]); |
|
58 | + } |
|
59 | 59 | |
60 | - public static function dataGenerateCalendarParameter(): array { |
|
61 | - return [ |
|
62 | - [['id' => 23, 'uri' => 'foo', 'name' => 'bar'], 'bar'], |
|
63 | - [['id' => 42, 'uri' => 'foo', 'name' => 'Personal'], 'Personal'], |
|
64 | - [['id' => 42, 'uri' => 'personal', 'name' => 'bar'], 'bar'], |
|
65 | - [['id' => 42, 'uri' => 'personal', 'name' => 'Personal'], 't(Personal)'], |
|
66 | - ]; |
|
67 | - } |
|
60 | + public static function dataGenerateCalendarParameter(): array { |
|
61 | + return [ |
|
62 | + [['id' => 23, 'uri' => 'foo', 'name' => 'bar'], 'bar'], |
|
63 | + [['id' => 42, 'uri' => 'foo', 'name' => 'Personal'], 'Personal'], |
|
64 | + [['id' => 42, 'uri' => 'personal', 'name' => 'bar'], 'bar'], |
|
65 | + [['id' => 42, 'uri' => 'personal', 'name' => 'Personal'], 't(Personal)'], |
|
66 | + ]; |
|
67 | + } |
|
68 | 68 | |
69 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataGenerateCalendarParameter')] |
|
70 | - public function testGenerateCalendarParameter(array $data, string $name): void { |
|
71 | - $l = $this->createMock(IL10N::class); |
|
72 | - $l->expects($this->any()) |
|
73 | - ->method('t') |
|
74 | - ->willReturnCallback(function ($string, $args) { |
|
75 | - return 't(' . vsprintf($string, $args) . ')'; |
|
76 | - }); |
|
69 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataGenerateCalendarParameter')] |
|
70 | + public function testGenerateCalendarParameter(array $data, string $name): void { |
|
71 | + $l = $this->createMock(IL10N::class); |
|
72 | + $l->expects($this->any()) |
|
73 | + ->method('t') |
|
74 | + ->willReturnCallback(function ($string, $args) { |
|
75 | + return 't(' . vsprintf($string, $args) . ')'; |
|
76 | + }); |
|
77 | 77 | |
78 | - $this->assertEquals([ |
|
79 | - 'type' => 'calendar', |
|
80 | - 'id' => $data['id'], |
|
81 | - 'name' => $name, |
|
82 | - ], $this->invokePrivate($this->provider, 'generateCalendarParameter', [$data, $l])); |
|
83 | - } |
|
78 | + $this->assertEquals([ |
|
79 | + 'type' => 'calendar', |
|
80 | + 'id' => $data['id'], |
|
81 | + 'name' => $name, |
|
82 | + ], $this->invokePrivate($this->provider, 'generateCalendarParameter', [$data, $l])); |
|
83 | + } |
|
84 | 84 | |
85 | - public static function dataGenerateLegacyCalendarParameter(): array { |
|
86 | - return [ |
|
87 | - [23, 'c1'], |
|
88 | - [42, 'c2'], |
|
89 | - ]; |
|
90 | - } |
|
85 | + public static function dataGenerateLegacyCalendarParameter(): array { |
|
86 | + return [ |
|
87 | + [23, 'c1'], |
|
88 | + [42, 'c2'], |
|
89 | + ]; |
|
90 | + } |
|
91 | 91 | |
92 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataGenerateLegacyCalendarParameter')] |
|
93 | - public function testGenerateLegacyCalendarParameter(int $id, string $name): void { |
|
94 | - $this->assertEquals([ |
|
95 | - 'type' => 'calendar', |
|
96 | - 'id' => $id, |
|
97 | - 'name' => $name, |
|
98 | - ], $this->invokePrivate($this->provider, 'generateLegacyCalendarParameter', [$id, $name])); |
|
99 | - } |
|
92 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataGenerateLegacyCalendarParameter')] |
|
93 | + public function testGenerateLegacyCalendarParameter(int $id, string $name): void { |
|
94 | + $this->assertEquals([ |
|
95 | + 'type' => 'calendar', |
|
96 | + 'id' => $id, |
|
97 | + 'name' => $name, |
|
98 | + ], $this->invokePrivate($this->provider, 'generateLegacyCalendarParameter', [$id, $name])); |
|
99 | + } |
|
100 | 100 | |
101 | - public static function dataGenerateGroupParameter(): array { |
|
102 | - return [ |
|
103 | - ['g1'], |
|
104 | - ['g2'], |
|
105 | - ]; |
|
106 | - } |
|
101 | + public static function dataGenerateGroupParameter(): array { |
|
102 | + return [ |
|
103 | + ['g1'], |
|
104 | + ['g2'], |
|
105 | + ]; |
|
106 | + } |
|
107 | 107 | |
108 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataGenerateGroupParameter')] |
|
109 | - public function testGenerateGroupParameter(string $gid): void { |
|
110 | - $this->assertEquals([ |
|
111 | - 'type' => 'user-group', |
|
112 | - 'id' => $gid, |
|
113 | - 'name' => $gid, |
|
114 | - ], $this->invokePrivate($this->provider, 'generateGroupParameter', [$gid])); |
|
115 | - } |
|
108 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataGenerateGroupParameter')] |
|
109 | + public function testGenerateGroupParameter(string $gid): void { |
|
110 | + $this->assertEquals([ |
|
111 | + 'type' => 'user-group', |
|
112 | + 'id' => $gid, |
|
113 | + 'name' => $gid, |
|
114 | + ], $this->invokePrivate($this->provider, 'generateGroupParameter', [$gid])); |
|
115 | + } |
|
116 | 116 | } |
@@ -15,69 +15,69 @@ |
||
15 | 15 | use Test\TestCase; |
16 | 16 | |
17 | 17 | class GenericTest extends TestCase { |
18 | - public static function dataSettings(): array { |
|
19 | - return [ |
|
20 | - [Calendar::class], |
|
21 | - [Event::class], |
|
22 | - [Todo::class], |
|
23 | - ]; |
|
24 | - } |
|
18 | + public static function dataSettings(): array { |
|
19 | + return [ |
|
20 | + [Calendar::class], |
|
21 | + [Event::class], |
|
22 | + [Todo::class], |
|
23 | + ]; |
|
24 | + } |
|
25 | 25 | |
26 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
27 | - public function testImplementsInterface(string $settingClass): void { |
|
28 | - $setting = Server::get($settingClass); |
|
29 | - $this->assertInstanceOf(ISetting::class, $setting); |
|
30 | - } |
|
26 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
27 | + public function testImplementsInterface(string $settingClass): void { |
|
28 | + $setting = Server::get($settingClass); |
|
29 | + $this->assertInstanceOf(ISetting::class, $setting); |
|
30 | + } |
|
31 | 31 | |
32 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
33 | - public function testGetIdentifier(string $settingClass): void { |
|
34 | - /** @var ISetting $setting */ |
|
35 | - $setting = Server::get($settingClass); |
|
36 | - $this->assertIsString($setting->getIdentifier()); |
|
37 | - } |
|
32 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
33 | + public function testGetIdentifier(string $settingClass): void { |
|
34 | + /** @var ISetting $setting */ |
|
35 | + $setting = Server::get($settingClass); |
|
36 | + $this->assertIsString($setting->getIdentifier()); |
|
37 | + } |
|
38 | 38 | |
39 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
40 | - public function testGetName(string $settingClass): void { |
|
41 | - /** @var ISetting $setting */ |
|
42 | - $setting = Server::get($settingClass); |
|
43 | - $this->assertIsString($setting->getName()); |
|
44 | - } |
|
39 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
40 | + public function testGetName(string $settingClass): void { |
|
41 | + /** @var ISetting $setting */ |
|
42 | + $setting = Server::get($settingClass); |
|
43 | + $this->assertIsString($setting->getName()); |
|
44 | + } |
|
45 | 45 | |
46 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
47 | - public function testGetPriority(string $settingClass): void { |
|
48 | - /** @var ISetting $setting */ |
|
49 | - $setting = Server::get($settingClass); |
|
50 | - $priority = $setting->getPriority(); |
|
51 | - $this->assertIsInt($setting->getPriority()); |
|
52 | - $this->assertGreaterThanOrEqual(0, $priority); |
|
53 | - $this->assertLessThanOrEqual(100, $priority); |
|
54 | - } |
|
46 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
47 | + public function testGetPriority(string $settingClass): void { |
|
48 | + /** @var ISetting $setting */ |
|
49 | + $setting = Server::get($settingClass); |
|
50 | + $priority = $setting->getPriority(); |
|
51 | + $this->assertIsInt($setting->getPriority()); |
|
52 | + $this->assertGreaterThanOrEqual(0, $priority); |
|
53 | + $this->assertLessThanOrEqual(100, $priority); |
|
54 | + } |
|
55 | 55 | |
56 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
57 | - public function testCanChangeStream(string $settingClass): void { |
|
58 | - /** @var ISetting $setting */ |
|
59 | - $setting = Server::get($settingClass); |
|
60 | - $this->assertIsBool($setting->canChangeStream()); |
|
61 | - } |
|
56 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
57 | + public function testCanChangeStream(string $settingClass): void { |
|
58 | + /** @var ISetting $setting */ |
|
59 | + $setting = Server::get($settingClass); |
|
60 | + $this->assertIsBool($setting->canChangeStream()); |
|
61 | + } |
|
62 | 62 | |
63 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
64 | - public function testIsDefaultEnabledStream(string $settingClass): void { |
|
65 | - /** @var ISetting $setting */ |
|
66 | - $setting = Server::get($settingClass); |
|
67 | - $this->assertIsBool($setting->isDefaultEnabledStream()); |
|
68 | - } |
|
63 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
64 | + public function testIsDefaultEnabledStream(string $settingClass): void { |
|
65 | + /** @var ISetting $setting */ |
|
66 | + $setting = Server::get($settingClass); |
|
67 | + $this->assertIsBool($setting->isDefaultEnabledStream()); |
|
68 | + } |
|
69 | 69 | |
70 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
71 | - public function testCanChangeMail(string $settingClass): void { |
|
72 | - /** @var ISetting $setting */ |
|
73 | - $setting = Server::get($settingClass); |
|
74 | - $this->assertIsBool($setting->canChangeMail()); |
|
75 | - } |
|
70 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
71 | + public function testCanChangeMail(string $settingClass): void { |
|
72 | + /** @var ISetting $setting */ |
|
73 | + $setting = Server::get($settingClass); |
|
74 | + $this->assertIsBool($setting->canChangeMail()); |
|
75 | + } |
|
76 | 76 | |
77 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
78 | - public function testIsDefaultEnabledMail(string $settingClass): void { |
|
79 | - /** @var ISetting $setting */ |
|
80 | - $setting = Server::get($settingClass); |
|
81 | - $this->assertIsBool($setting->isDefaultEnabledMail()); |
|
82 | - } |
|
77 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
78 | + public function testIsDefaultEnabledMail(string $settingClass): void { |
|
79 | + /** @var ISetting $setting */ |
|
80 | + $setting = Server::get($settingClass); |
|
81 | + $this->assertIsBool($setting->isDefaultEnabledMail()); |
|
82 | + } |
|
83 | 83 | } |
@@ -17,62 +17,62 @@ |
||
17 | 17 | * @group DB |
18 | 18 | */ |
19 | 19 | class GenericTest extends TestCase { |
20 | - public static function dataFilters(): array { |
|
21 | - return [ |
|
22 | - [Calendar::class], |
|
23 | - [Todo::class], |
|
24 | - ]; |
|
25 | - } |
|
20 | + public static function dataFilters(): array { |
|
21 | + return [ |
|
22 | + [Calendar::class], |
|
23 | + [Todo::class], |
|
24 | + ]; |
|
25 | + } |
|
26 | 26 | |
27 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
28 | - public function testImplementsInterface(string $filterClass): void { |
|
29 | - $filter = Server::get($filterClass); |
|
30 | - $this->assertInstanceOf(IFilter::class, $filter); |
|
31 | - } |
|
27 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
28 | + public function testImplementsInterface(string $filterClass): void { |
|
29 | + $filter = Server::get($filterClass); |
|
30 | + $this->assertInstanceOf(IFilter::class, $filter); |
|
31 | + } |
|
32 | 32 | |
33 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
34 | - public function testGetIdentifier(string $filterClass): void { |
|
35 | - /** @var IFilter $filter */ |
|
36 | - $filter = Server::get($filterClass); |
|
37 | - $this->assertIsString($filter->getIdentifier()); |
|
38 | - } |
|
33 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
34 | + public function testGetIdentifier(string $filterClass): void { |
|
35 | + /** @var IFilter $filter */ |
|
36 | + $filter = Server::get($filterClass); |
|
37 | + $this->assertIsString($filter->getIdentifier()); |
|
38 | + } |
|
39 | 39 | |
40 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
41 | - public function testGetName(string $filterClass): void { |
|
42 | - /** @var IFilter $filter */ |
|
43 | - $filter = Server::get($filterClass); |
|
44 | - $this->assertIsString($filter->getName()); |
|
45 | - } |
|
40 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
41 | + public function testGetName(string $filterClass): void { |
|
42 | + /** @var IFilter $filter */ |
|
43 | + $filter = Server::get($filterClass); |
|
44 | + $this->assertIsString($filter->getName()); |
|
45 | + } |
|
46 | 46 | |
47 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
48 | - public function testGetPriority(string $filterClass): void { |
|
49 | - /** @var IFilter $filter */ |
|
50 | - $filter = Server::get($filterClass); |
|
51 | - $priority = $filter->getPriority(); |
|
52 | - $this->assertIsInt($filter->getPriority()); |
|
53 | - $this->assertGreaterThanOrEqual(0, $priority); |
|
54 | - $this->assertLessThanOrEqual(100, $priority); |
|
55 | - } |
|
47 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
48 | + public function testGetPriority(string $filterClass): void { |
|
49 | + /** @var IFilter $filter */ |
|
50 | + $filter = Server::get($filterClass); |
|
51 | + $priority = $filter->getPriority(); |
|
52 | + $this->assertIsInt($filter->getPriority()); |
|
53 | + $this->assertGreaterThanOrEqual(0, $priority); |
|
54 | + $this->assertLessThanOrEqual(100, $priority); |
|
55 | + } |
|
56 | 56 | |
57 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
58 | - public function testGetIcon(string $filterClass): void { |
|
59 | - /** @var IFilter $filter */ |
|
60 | - $filter = Server::get($filterClass); |
|
61 | - $this->assertIsString($filter->getIcon()); |
|
62 | - $this->assertStringStartsWith('http', $filter->getIcon()); |
|
63 | - } |
|
57 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
58 | + public function testGetIcon(string $filterClass): void { |
|
59 | + /** @var IFilter $filter */ |
|
60 | + $filter = Server::get($filterClass); |
|
61 | + $this->assertIsString($filter->getIcon()); |
|
62 | + $this->assertStringStartsWith('http', $filter->getIcon()); |
|
63 | + } |
|
64 | 64 | |
65 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
66 | - public function testFilterTypes(string $filterClass): void { |
|
67 | - /** @var IFilter $filter */ |
|
68 | - $filter = Server::get($filterClass); |
|
69 | - $this->assertIsArray($filter->filterTypes([])); |
|
70 | - } |
|
65 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
66 | + public function testFilterTypes(string $filterClass): void { |
|
67 | + /** @var IFilter $filter */ |
|
68 | + $filter = Server::get($filterClass); |
|
69 | + $this->assertIsArray($filter->filterTypes([])); |
|
70 | + } |
|
71 | 71 | |
72 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
73 | - public function testAllowedApps(string $filterClass): void { |
|
74 | - /** @var IFilter $filter */ |
|
75 | - $filter = Server::get($filterClass); |
|
76 | - $this->assertIsArray($filter->allowedApps()); |
|
77 | - } |
|
72 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
73 | + public function testAllowedApps(string $filterClass): void { |
|
74 | + /** @var IFilter $filter */ |
|
75 | + $filter = Server::get($filterClass); |
|
76 | + $this->assertIsArray($filter->allowedApps()); |
|
77 | + } |
|
78 | 78 | } |
@@ -15,53 +15,53 @@ |
||
15 | 15 | use Test\TestCase; |
16 | 16 | |
17 | 17 | class TodoTest extends TestCase { |
18 | - protected IURLGenerator&MockObject $url; |
|
19 | - protected IFilter $filter; |
|
18 | + protected IURLGenerator&MockObject $url; |
|
19 | + protected IFilter $filter; |
|
20 | 20 | |
21 | - protected function setUp(): void { |
|
22 | - parent::setUp(); |
|
23 | - $this->url = $this->createMock(IURLGenerator::class); |
|
24 | - $l = $this->createMock(IL10N::class); |
|
25 | - $l->expects($this->any()) |
|
26 | - ->method('t') |
|
27 | - ->willReturnCallback(function ($string, $args) { |
|
28 | - return vsprintf($string, $args); |
|
29 | - }); |
|
21 | + protected function setUp(): void { |
|
22 | + parent::setUp(); |
|
23 | + $this->url = $this->createMock(IURLGenerator::class); |
|
24 | + $l = $this->createMock(IL10N::class); |
|
25 | + $l->expects($this->any()) |
|
26 | + ->method('t') |
|
27 | + ->willReturnCallback(function ($string, $args) { |
|
28 | + return vsprintf($string, $args); |
|
29 | + }); |
|
30 | 30 | |
31 | - $this->filter = new Todo( |
|
32 | - $l, $this->url |
|
33 | - ); |
|
34 | - } |
|
31 | + $this->filter = new Todo( |
|
32 | + $l, $this->url |
|
33 | + ); |
|
34 | + } |
|
35 | 35 | |
36 | - public function testGetIcon(): void { |
|
37 | - $this->url->expects($this->once()) |
|
38 | - ->method('imagePath') |
|
39 | - ->with('core', 'actions/checkmark.svg') |
|
40 | - ->willReturn('path-to-icon'); |
|
36 | + public function testGetIcon(): void { |
|
37 | + $this->url->expects($this->once()) |
|
38 | + ->method('imagePath') |
|
39 | + ->with('core', 'actions/checkmark.svg') |
|
40 | + ->willReturn('path-to-icon'); |
|
41 | 41 | |
42 | - $this->url->expects($this->once()) |
|
43 | - ->method('getAbsoluteURL') |
|
44 | - ->with('path-to-icon') |
|
45 | - ->willReturn('absolute-path-to-icon'); |
|
42 | + $this->url->expects($this->once()) |
|
43 | + ->method('getAbsoluteURL') |
|
44 | + ->with('path-to-icon') |
|
45 | + ->willReturn('absolute-path-to-icon'); |
|
46 | 46 | |
47 | - $this->assertEquals('absolute-path-to-icon', $this->filter->getIcon()); |
|
48 | - } |
|
47 | + $this->assertEquals('absolute-path-to-icon', $this->filter->getIcon()); |
|
48 | + } |
|
49 | 49 | |
50 | - public static function dataFilterTypes(): array { |
|
51 | - return [ |
|
52 | - [[], []], |
|
53 | - [['calendar_todo'], ['calendar_todo']], |
|
54 | - [['calendar', 'calendar_event', 'calendar_todo'], ['calendar_todo']], |
|
55 | - [['calendar', 'calendar_todo', 'files'], ['calendar_todo']], |
|
56 | - ]; |
|
57 | - } |
|
50 | + public static function dataFilterTypes(): array { |
|
51 | + return [ |
|
52 | + [[], []], |
|
53 | + [['calendar_todo'], ['calendar_todo']], |
|
54 | + [['calendar', 'calendar_event', 'calendar_todo'], ['calendar_todo']], |
|
55 | + [['calendar', 'calendar_todo', 'files'], ['calendar_todo']], |
|
56 | + ]; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @param string[] $types |
|
61 | - * @param string[] $expected |
|
62 | - */ |
|
63 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataFilterTypes')] |
|
64 | - public function testFilterTypes(array $types, array $expected): void { |
|
65 | - $this->assertEquals($expected, $this->filter->filterTypes($types)); |
|
66 | - } |
|
59 | + /** |
|
60 | + * @param string[] $types |
|
61 | + * @param string[] $expected |
|
62 | + */ |
|
63 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilterTypes')] |
|
64 | + public function testFilterTypes(array $types, array $expected): void { |
|
65 | + $this->assertEquals($expected, $this->filter->filterTypes($types)); |
|
66 | + } |
|
67 | 67 | } |
@@ -15,53 +15,53 @@ |
||
15 | 15 | use Test\TestCase; |
16 | 16 | |
17 | 17 | class CalendarTest extends TestCase { |
18 | - protected IURLGenerator&MockObject $url; |
|
19 | - protected IFilter $filter; |
|
18 | + protected IURLGenerator&MockObject $url; |
|
19 | + protected IFilter $filter; |
|
20 | 20 | |
21 | - protected function setUp(): void { |
|
22 | - parent::setUp(); |
|
23 | - $this->url = $this->createMock(IURLGenerator::class); |
|
24 | - $l = $this->createMock(IL10N::class); |
|
25 | - $l->expects($this->any()) |
|
26 | - ->method('t') |
|
27 | - ->willReturnCallback(function ($string, $args) { |
|
28 | - return vsprintf($string, $args); |
|
29 | - }); |
|
21 | + protected function setUp(): void { |
|
22 | + parent::setUp(); |
|
23 | + $this->url = $this->createMock(IURLGenerator::class); |
|
24 | + $l = $this->createMock(IL10N::class); |
|
25 | + $l->expects($this->any()) |
|
26 | + ->method('t') |
|
27 | + ->willReturnCallback(function ($string, $args) { |
|
28 | + return vsprintf($string, $args); |
|
29 | + }); |
|
30 | 30 | |
31 | - $this->filter = new Calendar( |
|
32 | - $l, $this->url |
|
33 | - ); |
|
34 | - } |
|
31 | + $this->filter = new Calendar( |
|
32 | + $l, $this->url |
|
33 | + ); |
|
34 | + } |
|
35 | 35 | |
36 | - public function testGetIcon(): void { |
|
37 | - $this->url->expects($this->once()) |
|
38 | - ->method('imagePath') |
|
39 | - ->with('core', 'places/calendar.svg') |
|
40 | - ->willReturn('path-to-icon'); |
|
36 | + public function testGetIcon(): void { |
|
37 | + $this->url->expects($this->once()) |
|
38 | + ->method('imagePath') |
|
39 | + ->with('core', 'places/calendar.svg') |
|
40 | + ->willReturn('path-to-icon'); |
|
41 | 41 | |
42 | - $this->url->expects($this->once()) |
|
43 | - ->method('getAbsoluteURL') |
|
44 | - ->with('path-to-icon') |
|
45 | - ->willReturn('absolute-path-to-icon'); |
|
42 | + $this->url->expects($this->once()) |
|
43 | + ->method('getAbsoluteURL') |
|
44 | + ->with('path-to-icon') |
|
45 | + ->willReturn('absolute-path-to-icon'); |
|
46 | 46 | |
47 | - $this->assertEquals('absolute-path-to-icon', $this->filter->getIcon()); |
|
48 | - } |
|
47 | + $this->assertEquals('absolute-path-to-icon', $this->filter->getIcon()); |
|
48 | + } |
|
49 | 49 | |
50 | - public static function dataFilterTypes(): array { |
|
51 | - return [ |
|
52 | - [[], []], |
|
53 | - [['calendar', 'calendar_event'], ['calendar', 'calendar_event']], |
|
54 | - [['calendar', 'calendar_event', 'calendar_todo'], ['calendar', 'calendar_event']], |
|
55 | - [['calendar', 'calendar_event', 'files'], ['calendar', 'calendar_event']], |
|
56 | - ]; |
|
57 | - } |
|
50 | + public static function dataFilterTypes(): array { |
|
51 | + return [ |
|
52 | + [[], []], |
|
53 | + [['calendar', 'calendar_event'], ['calendar', 'calendar_event']], |
|
54 | + [['calendar', 'calendar_event', 'calendar_todo'], ['calendar', 'calendar_event']], |
|
55 | + [['calendar', 'calendar_event', 'files'], ['calendar', 'calendar_event']], |
|
56 | + ]; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @param string[] $types |
|
61 | - * @param string[] $expected |
|
62 | - */ |
|
63 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataFilterTypes')] |
|
64 | - public function testFilterTypes(array $types, array $expected): void { |
|
65 | - $this->assertEquals($expected, $this->filter->filterTypes($types)); |
|
66 | - } |
|
59 | + /** |
|
60 | + * @param string[] $types |
|
61 | + * @param string[] $expected |
|
62 | + */ |
|
63 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilterTypes')] |
|
64 | + public function testFilterTypes(array $types, array $expected): void { |
|
65 | + $this->assertEquals($expected, $this->filter->filterTypes($types)); |
|
66 | + } |
|
67 | 67 | } |
@@ -21,329 +21,329 @@ |
||
21 | 21 | use Test\TestCase; |
22 | 22 | |
23 | 23 | class BackendTest extends TestCase { |
24 | - protected IManager&MockObject $activityManager; |
|
25 | - protected IGroupManager&MockObject $groupManager; |
|
26 | - protected IUserSession&MockObject $userSession; |
|
27 | - protected IAppManager&MockObject $appManager; |
|
28 | - protected IUserManager&MockObject $userManager; |
|
29 | - |
|
30 | - protected function setUp(): void { |
|
31 | - parent::setUp(); |
|
32 | - $this->activityManager = $this->createMock(IManager::class); |
|
33 | - $this->groupManager = $this->createMock(IGroupManager::class); |
|
34 | - $this->userSession = $this->createMock(IUserSession::class); |
|
35 | - $this->appManager = $this->createMock(IAppManager::class); |
|
36 | - $this->userManager = $this->createMock(IUserManager::class); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * @return Backend|(Backend&MockObject) |
|
41 | - */ |
|
42 | - protected function getBackend(array $methods = []): Backend { |
|
43 | - if (empty($methods)) { |
|
44 | - return new Backend( |
|
45 | - $this->activityManager, |
|
46 | - $this->groupManager, |
|
47 | - $this->userSession, |
|
48 | - $this->appManager, |
|
49 | - $this->userManager |
|
50 | - ); |
|
51 | - } else { |
|
52 | - return $this->getMockBuilder(Backend::class) |
|
53 | - ->setConstructorArgs([ |
|
54 | - $this->activityManager, |
|
55 | - $this->groupManager, |
|
56 | - $this->userSession, |
|
57 | - $this->appManager, |
|
58 | - $this->userManager |
|
59 | - ]) |
|
60 | - ->onlyMethods($methods) |
|
61 | - ->getMock(); |
|
62 | - } |
|
63 | - } |
|
64 | - |
|
65 | - public static function dataCallTriggerCalendarActivity(): array { |
|
66 | - return [ |
|
67 | - ['onCalendarAdd', [['data']], Calendar::SUBJECT_ADD, [['data'], [], []]], |
|
68 | - ['onCalendarUpdate', [['data'], ['shares'], ['changed-properties']], Calendar::SUBJECT_UPDATE, [['data'], ['shares'], ['changed-properties']]], |
|
69 | - ['onCalendarDelete', [['data'], ['shares']], Calendar::SUBJECT_DELETE, [['data'], ['shares'], []]], |
|
70 | - ['onCalendarPublication', [['data'], true], Calendar::SUBJECT_PUBLISH, [['data'], [], []]], |
|
71 | - ]; |
|
72 | - } |
|
73 | - |
|
74 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataCallTriggerCalendarActivity')] |
|
75 | - public function testCallTriggerCalendarActivity(string $method, array $payload, string $expectedSubject, array $expectedPayload): void { |
|
76 | - $backend = $this->getBackend(['triggerCalendarActivity']); |
|
77 | - $backend->expects($this->once()) |
|
78 | - ->method('triggerCalendarActivity') |
|
79 | - ->willReturnCallback(function () use ($expectedPayload, $expectedSubject): void { |
|
80 | - $arguments = func_get_args(); |
|
81 | - $this->assertSame($expectedSubject, array_shift($arguments)); |
|
82 | - $this->assertEquals($expectedPayload, $arguments); |
|
83 | - }); |
|
84 | - |
|
85 | - call_user_func_array([$backend, $method], $payload); |
|
86 | - } |
|
87 | - |
|
88 | - public static function dataTriggerCalendarActivity(): array { |
|
89 | - return [ |
|
90 | - // Add calendar |
|
91 | - [Calendar::SUBJECT_ADD, [], [], [], '', '', null, []], |
|
92 | - [Calendar::SUBJECT_ADD, [ |
|
93 | - 'principaluri' => 'principal/user/admin', |
|
94 | - 'id' => 42, |
|
95 | - 'uri' => 'this-uri', |
|
96 | - '{DAV:}displayname' => 'Name of calendar', |
|
97 | - ], [], [], '', 'admin', null, ['admin']], |
|
98 | - [Calendar::SUBJECT_ADD, [ |
|
99 | - 'principaluri' => 'principal/user/admin', |
|
100 | - 'id' => 42, |
|
101 | - 'uri' => 'this-uri', |
|
102 | - '{DAV:}displayname' => 'Name of calendar', |
|
103 | - ], [], [], 'test2', 'test2', null, ['admin']], |
|
104 | - |
|
105 | - // Update calendar |
|
106 | - [Calendar::SUBJECT_UPDATE, [], [], [], '', '', null, []], |
|
107 | - // No visible change - owner only |
|
108 | - [Calendar::SUBJECT_UPDATE, [ |
|
109 | - 'principaluri' => 'principal/user/admin', |
|
110 | - 'id' => 42, |
|
111 | - 'uri' => 'this-uri', |
|
112 | - '{DAV:}displayname' => 'Name of calendar', |
|
113 | - ], ['shares'], [], '', 'admin', null, ['admin']], |
|
114 | - // Visible change |
|
115 | - [Calendar::SUBJECT_UPDATE, [ |
|
116 | - 'principaluri' => 'principal/user/admin', |
|
117 | - 'id' => 42, |
|
118 | - 'uri' => 'this-uri', |
|
119 | - '{DAV:}displayname' => 'Name of calendar', |
|
120 | - ], ['shares'], ['{DAV:}displayname' => 'Name'], '', 'admin', ['user1'], ['user1', 'admin']], |
|
121 | - [Calendar::SUBJECT_UPDATE, [ |
|
122 | - 'principaluri' => 'principal/user/admin', |
|
123 | - 'id' => 42, |
|
124 | - 'uri' => 'this-uri', |
|
125 | - '{DAV:}displayname' => 'Name of calendar', |
|
126 | - ], ['shares'], ['{DAV:}displayname' => 'Name'], 'test2', 'test2', ['user1'], ['user1', 'admin']], |
|
127 | - |
|
128 | - // Delete calendar |
|
129 | - [Calendar::SUBJECT_DELETE, [], [], [], '', '', null, []], |
|
130 | - [Calendar::SUBJECT_DELETE, [ |
|
131 | - 'principaluri' => 'principal/user/admin', |
|
132 | - 'id' => 42, |
|
133 | - 'uri' => 'this-uri', |
|
134 | - '{DAV:}displayname' => 'Name of calendar', |
|
135 | - ], ['shares'], [], '', 'admin', [], ['admin']], |
|
136 | - [Calendar::SUBJECT_DELETE, [ |
|
137 | - 'principaluri' => 'principal/user/admin', |
|
138 | - 'id' => 42, |
|
139 | - 'uri' => 'this-uri', |
|
140 | - '{DAV:}displayname' => 'Name of calendar', |
|
141 | - ], ['shares'], [], '', 'admin', ['user1'], ['user1', 'admin']], |
|
142 | - [Calendar::SUBJECT_DELETE, [ |
|
143 | - 'principaluri' => 'principal/user/admin', |
|
144 | - 'id' => 42, |
|
145 | - 'uri' => 'this-uri', |
|
146 | - '{DAV:}displayname' => 'Name of calendar', |
|
147 | - ], ['shares'], [], 'test2', 'test2', ['user1'], ['user1', 'admin']], |
|
148 | - |
|
149 | - // Publish calendar |
|
150 | - [Calendar::SUBJECT_PUBLISH, [], [], [], '', '', null, []], |
|
151 | - [Calendar::SUBJECT_PUBLISH, [ |
|
152 | - 'principaluri' => 'principal/user/admin', |
|
153 | - 'id' => 42, |
|
154 | - 'uri' => 'this-uri', |
|
155 | - '{DAV:}displayname' => 'Name of calendar', |
|
156 | - ], ['shares'], [], '', 'admin', [], ['admin']], |
|
157 | - |
|
158 | - // Unpublish calendar |
|
159 | - [Calendar::SUBJECT_UNPUBLISH, [], [], [], '', '', null, []], |
|
160 | - [Calendar::SUBJECT_UNPUBLISH, [ |
|
161 | - 'principaluri' => 'principal/user/admin', |
|
162 | - 'id' => 42, |
|
163 | - 'uri' => 'this-uri', |
|
164 | - '{DAV:}displayname' => 'Name of calendar', |
|
165 | - ], ['shares'], [], '', 'admin', [], ['admin']], |
|
166 | - ]; |
|
167 | - } |
|
168 | - |
|
169 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTriggerCalendarActivity')] |
|
170 | - public function testTriggerCalendarActivity(string $action, array $data, array $shares, array $changedProperties, string $currentUser, string $author, ?array $shareUsers, array $users): void { |
|
171 | - $backend = $this->getBackend(['getUsersForShares']); |
|
172 | - |
|
173 | - if ($shareUsers === null) { |
|
174 | - $backend->expects($this->never()) |
|
175 | - ->method('getUsersForShares'); |
|
176 | - } else { |
|
177 | - $backend->expects($this->once()) |
|
178 | - ->method('getUsersForShares') |
|
179 | - ->with($shares) |
|
180 | - ->willReturn($shareUsers); |
|
181 | - } |
|
182 | - |
|
183 | - if ($author !== '') { |
|
184 | - if ($currentUser !== '') { |
|
185 | - $this->userSession->expects($this->once()) |
|
186 | - ->method('getUser') |
|
187 | - ->willReturn($this->getUserMock($currentUser)); |
|
188 | - } else { |
|
189 | - $this->userSession->expects($this->once()) |
|
190 | - ->method('getUser') |
|
191 | - ->willReturn(null); |
|
192 | - } |
|
193 | - |
|
194 | - $event = $this->createMock(IEvent::class); |
|
195 | - $this->activityManager->expects($this->once()) |
|
196 | - ->method('generateEvent') |
|
197 | - ->willReturn($event); |
|
198 | - |
|
199 | - $event->expects($this->once()) |
|
200 | - ->method('setApp') |
|
201 | - ->with('dav') |
|
202 | - ->willReturnSelf(); |
|
203 | - $event->expects($this->once()) |
|
204 | - ->method('setObject') |
|
205 | - ->with('calendar', $data['id']) |
|
206 | - ->willReturnSelf(); |
|
207 | - $event->expects($this->once()) |
|
208 | - ->method('setType') |
|
209 | - ->with('calendar') |
|
210 | - ->willReturnSelf(); |
|
211 | - $event->expects($this->once()) |
|
212 | - ->method('setAuthor') |
|
213 | - ->with($author) |
|
214 | - ->willReturnSelf(); |
|
215 | - |
|
216 | - $this->userManager->expects($action === Calendar::SUBJECT_DELETE ? $this->exactly(sizeof($users)) : $this->never()) |
|
217 | - ->method('userExists') |
|
218 | - ->willReturn(true); |
|
219 | - |
|
220 | - $event->expects($this->exactly(sizeof($users))) |
|
221 | - ->method('setAffectedUser') |
|
222 | - ->willReturnSelf(); |
|
223 | - $event->expects($this->exactly(sizeof($users))) |
|
224 | - ->method('setSubject') |
|
225 | - ->willReturnSelf(); |
|
226 | - $this->activityManager->expects($this->exactly(sizeof($users))) |
|
227 | - ->method('publish') |
|
228 | - ->with($event); |
|
229 | - } else { |
|
230 | - $this->activityManager->expects($this->never()) |
|
231 | - ->method('generateEvent'); |
|
232 | - } |
|
233 | - |
|
234 | - $this->invokePrivate($backend, 'triggerCalendarActivity', [$action, $data, $shares, $changedProperties]); |
|
235 | - } |
|
236 | - |
|
237 | - public function testUserDeletionDoesNotCreateActivity(): void { |
|
238 | - $backend = $this->getBackend(); |
|
239 | - |
|
240 | - $this->userManager->expects($this->once()) |
|
241 | - ->method('userExists') |
|
242 | - ->willReturn(false); |
|
243 | - |
|
244 | - $this->activityManager->expects($this->never()) |
|
245 | - ->method('publish'); |
|
246 | - |
|
247 | - $this->invokePrivate($backend, 'triggerCalendarActivity', [Calendar::SUBJECT_DELETE, [ |
|
248 | - 'principaluri' => 'principal/user/admin', |
|
249 | - 'id' => 42, |
|
250 | - 'uri' => 'this-uri', |
|
251 | - '{DAV:}displayname' => 'Name of calendar', |
|
252 | - ], [], []]); |
|
253 | - } |
|
254 | - |
|
255 | - public static function dataGetUsersForShares(): array { |
|
256 | - return [ |
|
257 | - [ |
|
258 | - [], |
|
259 | - [], |
|
260 | - [], |
|
261 | - ], |
|
262 | - [ |
|
263 | - [ |
|
264 | - ['{http://owncloud.org/ns}principal' => 'principal/users/user1'], |
|
265 | - ['{http://owncloud.org/ns}principal' => 'principal/users/user2'], |
|
266 | - ['{http://owncloud.org/ns}principal' => 'principal/users/user2'], |
|
267 | - ['{http://owncloud.org/ns}principal' => 'principal/users/user2'], |
|
268 | - ['{http://owncloud.org/ns}principal' => 'principal/users/user3'], |
|
269 | - ], |
|
270 | - [], |
|
271 | - ['user1', 'user2', 'user3'], |
|
272 | - ], |
|
273 | - [ |
|
274 | - [ |
|
275 | - ['{http://owncloud.org/ns}principal' => 'principal/users/user1'], |
|
276 | - ['{http://owncloud.org/ns}principal' => 'principal/users/user2'], |
|
277 | - ['{http://owncloud.org/ns}principal' => 'principal/users/user2'], |
|
278 | - ['{http://owncloud.org/ns}principal' => 'principal/groups/group2'], |
|
279 | - ['{http://owncloud.org/ns}principal' => 'principal/groups/group3'], |
|
280 | - ], |
|
281 | - ['group2' => null, 'group3' => null], |
|
282 | - ['user1', 'user2'], |
|
283 | - ], |
|
284 | - [ |
|
285 | - [ |
|
286 | - ['{http://owncloud.org/ns}principal' => 'principal/users/user1'], |
|
287 | - ['{http://owncloud.org/ns}principal' => 'principal/users/user2'], |
|
288 | - ['{http://owncloud.org/ns}principal' => 'principal/users/user2'], |
|
289 | - ['{http://owncloud.org/ns}principal' => 'principal/groups/group2'], |
|
290 | - ['{http://owncloud.org/ns}principal' => 'principal/groups/group3'], |
|
291 | - ], |
|
292 | - ['group2' => ['user1', 'user2', 'user3'], 'group3' => ['user2', 'user3', 'user4']], |
|
293 | - ['user1', 'user2', 'user3', 'user4'], |
|
294 | - ], |
|
295 | - ]; |
|
296 | - } |
|
297 | - |
|
298 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataGetUsersForShares')] |
|
299 | - public function testGetUsersForShares(array $shares, array $groups, array $expected): void { |
|
300 | - $backend = $this->getBackend(); |
|
301 | - |
|
302 | - $getGroups = []; |
|
303 | - foreach ($groups as $gid => $members) { |
|
304 | - if ($members === null) { |
|
305 | - $getGroups[] = [$gid, null]; |
|
306 | - continue; |
|
307 | - } |
|
308 | - |
|
309 | - $group = $this->createMock(IGroup::class); |
|
310 | - $group->expects($this->once()) |
|
311 | - ->method('getUsers') |
|
312 | - ->willReturn($this->getUsers($members)); |
|
313 | - |
|
314 | - $getGroups[] = [$gid, $group]; |
|
315 | - } |
|
316 | - |
|
317 | - $this->groupManager->expects($this->exactly(sizeof($getGroups))) |
|
318 | - ->method('get') |
|
319 | - ->willReturnMap($getGroups); |
|
320 | - |
|
321 | - $users = $this->invokePrivate($backend, 'getUsersForShares', [$shares]); |
|
322 | - sort($users); |
|
323 | - $this->assertEquals($expected, $users); |
|
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * @param string[] $users |
|
328 | - * @return IUser[]&MockObject[] |
|
329 | - */ |
|
330 | - protected function getUsers(array $users) { |
|
331 | - $list = []; |
|
332 | - foreach ($users as $user) { |
|
333 | - $list[] = $this->getUserMock($user); |
|
334 | - } |
|
335 | - return $list; |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * @param string $uid |
|
340 | - * @return IUser&MockObject |
|
341 | - */ |
|
342 | - protected function getUserMock($uid) { |
|
343 | - $user = $this->createMock(IUser::class); |
|
344 | - $user->expects($this->once()) |
|
345 | - ->method('getUID') |
|
346 | - ->willReturn($uid); |
|
347 | - return $user; |
|
348 | - } |
|
24 | + protected IManager&MockObject $activityManager; |
|
25 | + protected IGroupManager&MockObject $groupManager; |
|
26 | + protected IUserSession&MockObject $userSession; |
|
27 | + protected IAppManager&MockObject $appManager; |
|
28 | + protected IUserManager&MockObject $userManager; |
|
29 | + |
|
30 | + protected function setUp(): void { |
|
31 | + parent::setUp(); |
|
32 | + $this->activityManager = $this->createMock(IManager::class); |
|
33 | + $this->groupManager = $this->createMock(IGroupManager::class); |
|
34 | + $this->userSession = $this->createMock(IUserSession::class); |
|
35 | + $this->appManager = $this->createMock(IAppManager::class); |
|
36 | + $this->userManager = $this->createMock(IUserManager::class); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * @return Backend|(Backend&MockObject) |
|
41 | + */ |
|
42 | + protected function getBackend(array $methods = []): Backend { |
|
43 | + if (empty($methods)) { |
|
44 | + return new Backend( |
|
45 | + $this->activityManager, |
|
46 | + $this->groupManager, |
|
47 | + $this->userSession, |
|
48 | + $this->appManager, |
|
49 | + $this->userManager |
|
50 | + ); |
|
51 | + } else { |
|
52 | + return $this->getMockBuilder(Backend::class) |
|
53 | + ->setConstructorArgs([ |
|
54 | + $this->activityManager, |
|
55 | + $this->groupManager, |
|
56 | + $this->userSession, |
|
57 | + $this->appManager, |
|
58 | + $this->userManager |
|
59 | + ]) |
|
60 | + ->onlyMethods($methods) |
|
61 | + ->getMock(); |
|
62 | + } |
|
63 | + } |
|
64 | + |
|
65 | + public static function dataCallTriggerCalendarActivity(): array { |
|
66 | + return [ |
|
67 | + ['onCalendarAdd', [['data']], Calendar::SUBJECT_ADD, [['data'], [], []]], |
|
68 | + ['onCalendarUpdate', [['data'], ['shares'], ['changed-properties']], Calendar::SUBJECT_UPDATE, [['data'], ['shares'], ['changed-properties']]], |
|
69 | + ['onCalendarDelete', [['data'], ['shares']], Calendar::SUBJECT_DELETE, [['data'], ['shares'], []]], |
|
70 | + ['onCalendarPublication', [['data'], true], Calendar::SUBJECT_PUBLISH, [['data'], [], []]], |
|
71 | + ]; |
|
72 | + } |
|
73 | + |
|
74 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataCallTriggerCalendarActivity')] |
|
75 | + public function testCallTriggerCalendarActivity(string $method, array $payload, string $expectedSubject, array $expectedPayload): void { |
|
76 | + $backend = $this->getBackend(['triggerCalendarActivity']); |
|
77 | + $backend->expects($this->once()) |
|
78 | + ->method('triggerCalendarActivity') |
|
79 | + ->willReturnCallback(function () use ($expectedPayload, $expectedSubject): void { |
|
80 | + $arguments = func_get_args(); |
|
81 | + $this->assertSame($expectedSubject, array_shift($arguments)); |
|
82 | + $this->assertEquals($expectedPayload, $arguments); |
|
83 | + }); |
|
84 | + |
|
85 | + call_user_func_array([$backend, $method], $payload); |
|
86 | + } |
|
87 | + |
|
88 | + public static function dataTriggerCalendarActivity(): array { |
|
89 | + return [ |
|
90 | + // Add calendar |
|
91 | + [Calendar::SUBJECT_ADD, [], [], [], '', '', null, []], |
|
92 | + [Calendar::SUBJECT_ADD, [ |
|
93 | + 'principaluri' => 'principal/user/admin', |
|
94 | + 'id' => 42, |
|
95 | + 'uri' => 'this-uri', |
|
96 | + '{DAV:}displayname' => 'Name of calendar', |
|
97 | + ], [], [], '', 'admin', null, ['admin']], |
|
98 | + [Calendar::SUBJECT_ADD, [ |
|
99 | + 'principaluri' => 'principal/user/admin', |
|
100 | + 'id' => 42, |
|
101 | + 'uri' => 'this-uri', |
|
102 | + '{DAV:}displayname' => 'Name of calendar', |
|
103 | + ], [], [], 'test2', 'test2', null, ['admin']], |
|
104 | + |
|
105 | + // Update calendar |
|
106 | + [Calendar::SUBJECT_UPDATE, [], [], [], '', '', null, []], |
|
107 | + // No visible change - owner only |
|
108 | + [Calendar::SUBJECT_UPDATE, [ |
|
109 | + 'principaluri' => 'principal/user/admin', |
|
110 | + 'id' => 42, |
|
111 | + 'uri' => 'this-uri', |
|
112 | + '{DAV:}displayname' => 'Name of calendar', |
|
113 | + ], ['shares'], [], '', 'admin', null, ['admin']], |
|
114 | + // Visible change |
|
115 | + [Calendar::SUBJECT_UPDATE, [ |
|
116 | + 'principaluri' => 'principal/user/admin', |
|
117 | + 'id' => 42, |
|
118 | + 'uri' => 'this-uri', |
|
119 | + '{DAV:}displayname' => 'Name of calendar', |
|
120 | + ], ['shares'], ['{DAV:}displayname' => 'Name'], '', 'admin', ['user1'], ['user1', 'admin']], |
|
121 | + [Calendar::SUBJECT_UPDATE, [ |
|
122 | + 'principaluri' => 'principal/user/admin', |
|
123 | + 'id' => 42, |
|
124 | + 'uri' => 'this-uri', |
|
125 | + '{DAV:}displayname' => 'Name of calendar', |
|
126 | + ], ['shares'], ['{DAV:}displayname' => 'Name'], 'test2', 'test2', ['user1'], ['user1', 'admin']], |
|
127 | + |
|
128 | + // Delete calendar |
|
129 | + [Calendar::SUBJECT_DELETE, [], [], [], '', '', null, []], |
|
130 | + [Calendar::SUBJECT_DELETE, [ |
|
131 | + 'principaluri' => 'principal/user/admin', |
|
132 | + 'id' => 42, |
|
133 | + 'uri' => 'this-uri', |
|
134 | + '{DAV:}displayname' => 'Name of calendar', |
|
135 | + ], ['shares'], [], '', 'admin', [], ['admin']], |
|
136 | + [Calendar::SUBJECT_DELETE, [ |
|
137 | + 'principaluri' => 'principal/user/admin', |
|
138 | + 'id' => 42, |
|
139 | + 'uri' => 'this-uri', |
|
140 | + '{DAV:}displayname' => 'Name of calendar', |
|
141 | + ], ['shares'], [], '', 'admin', ['user1'], ['user1', 'admin']], |
|
142 | + [Calendar::SUBJECT_DELETE, [ |
|
143 | + 'principaluri' => 'principal/user/admin', |
|
144 | + 'id' => 42, |
|
145 | + 'uri' => 'this-uri', |
|
146 | + '{DAV:}displayname' => 'Name of calendar', |
|
147 | + ], ['shares'], [], 'test2', 'test2', ['user1'], ['user1', 'admin']], |
|
148 | + |
|
149 | + // Publish calendar |
|
150 | + [Calendar::SUBJECT_PUBLISH, [], [], [], '', '', null, []], |
|
151 | + [Calendar::SUBJECT_PUBLISH, [ |
|
152 | + 'principaluri' => 'principal/user/admin', |
|
153 | + 'id' => 42, |
|
154 | + 'uri' => 'this-uri', |
|
155 | + '{DAV:}displayname' => 'Name of calendar', |
|
156 | + ], ['shares'], [], '', 'admin', [], ['admin']], |
|
157 | + |
|
158 | + // Unpublish calendar |
|
159 | + [Calendar::SUBJECT_UNPUBLISH, [], [], [], '', '', null, []], |
|
160 | + [Calendar::SUBJECT_UNPUBLISH, [ |
|
161 | + 'principaluri' => 'principal/user/admin', |
|
162 | + 'id' => 42, |
|
163 | + 'uri' => 'this-uri', |
|
164 | + '{DAV:}displayname' => 'Name of calendar', |
|
165 | + ], ['shares'], [], '', 'admin', [], ['admin']], |
|
166 | + ]; |
|
167 | + } |
|
168 | + |
|
169 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTriggerCalendarActivity')] |
|
170 | + public function testTriggerCalendarActivity(string $action, array $data, array $shares, array $changedProperties, string $currentUser, string $author, ?array $shareUsers, array $users): void { |
|
171 | + $backend = $this->getBackend(['getUsersForShares']); |
|
172 | + |
|
173 | + if ($shareUsers === null) { |
|
174 | + $backend->expects($this->never()) |
|
175 | + ->method('getUsersForShares'); |
|
176 | + } else { |
|
177 | + $backend->expects($this->once()) |
|
178 | + ->method('getUsersForShares') |
|
179 | + ->with($shares) |
|
180 | + ->willReturn($shareUsers); |
|
181 | + } |
|
182 | + |
|
183 | + if ($author !== '') { |
|
184 | + if ($currentUser !== '') { |
|
185 | + $this->userSession->expects($this->once()) |
|
186 | + ->method('getUser') |
|
187 | + ->willReturn($this->getUserMock($currentUser)); |
|
188 | + } else { |
|
189 | + $this->userSession->expects($this->once()) |
|
190 | + ->method('getUser') |
|
191 | + ->willReturn(null); |
|
192 | + } |
|
193 | + |
|
194 | + $event = $this->createMock(IEvent::class); |
|
195 | + $this->activityManager->expects($this->once()) |
|
196 | + ->method('generateEvent') |
|
197 | + ->willReturn($event); |
|
198 | + |
|
199 | + $event->expects($this->once()) |
|
200 | + ->method('setApp') |
|
201 | + ->with('dav') |
|
202 | + ->willReturnSelf(); |
|
203 | + $event->expects($this->once()) |
|
204 | + ->method('setObject') |
|
205 | + ->with('calendar', $data['id']) |
|
206 | + ->willReturnSelf(); |
|
207 | + $event->expects($this->once()) |
|
208 | + ->method('setType') |
|
209 | + ->with('calendar') |
|
210 | + ->willReturnSelf(); |
|
211 | + $event->expects($this->once()) |
|
212 | + ->method('setAuthor') |
|
213 | + ->with($author) |
|
214 | + ->willReturnSelf(); |
|
215 | + |
|
216 | + $this->userManager->expects($action === Calendar::SUBJECT_DELETE ? $this->exactly(sizeof($users)) : $this->never()) |
|
217 | + ->method('userExists') |
|
218 | + ->willReturn(true); |
|
219 | + |
|
220 | + $event->expects($this->exactly(sizeof($users))) |
|
221 | + ->method('setAffectedUser') |
|
222 | + ->willReturnSelf(); |
|
223 | + $event->expects($this->exactly(sizeof($users))) |
|
224 | + ->method('setSubject') |
|
225 | + ->willReturnSelf(); |
|
226 | + $this->activityManager->expects($this->exactly(sizeof($users))) |
|
227 | + ->method('publish') |
|
228 | + ->with($event); |
|
229 | + } else { |
|
230 | + $this->activityManager->expects($this->never()) |
|
231 | + ->method('generateEvent'); |
|
232 | + } |
|
233 | + |
|
234 | + $this->invokePrivate($backend, 'triggerCalendarActivity', [$action, $data, $shares, $changedProperties]); |
|
235 | + } |
|
236 | + |
|
237 | + public function testUserDeletionDoesNotCreateActivity(): void { |
|
238 | + $backend = $this->getBackend(); |
|
239 | + |
|
240 | + $this->userManager->expects($this->once()) |
|
241 | + ->method('userExists') |
|
242 | + ->willReturn(false); |
|
243 | + |
|
244 | + $this->activityManager->expects($this->never()) |
|
245 | + ->method('publish'); |
|
246 | + |
|
247 | + $this->invokePrivate($backend, 'triggerCalendarActivity', [Calendar::SUBJECT_DELETE, [ |
|
248 | + 'principaluri' => 'principal/user/admin', |
|
249 | + 'id' => 42, |
|
250 | + 'uri' => 'this-uri', |
|
251 | + '{DAV:}displayname' => 'Name of calendar', |
|
252 | + ], [], []]); |
|
253 | + } |
|
254 | + |
|
255 | + public static function dataGetUsersForShares(): array { |
|
256 | + return [ |
|
257 | + [ |
|
258 | + [], |
|
259 | + [], |
|
260 | + [], |
|
261 | + ], |
|
262 | + [ |
|
263 | + [ |
|
264 | + ['{http://owncloud.org/ns}principal' => 'principal/users/user1'], |
|
265 | + ['{http://owncloud.org/ns}principal' => 'principal/users/user2'], |
|
266 | + ['{http://owncloud.org/ns}principal' => 'principal/users/user2'], |
|
267 | + ['{http://owncloud.org/ns}principal' => 'principal/users/user2'], |
|
268 | + ['{http://owncloud.org/ns}principal' => 'principal/users/user3'], |
|
269 | + ], |
|
270 | + [], |
|
271 | + ['user1', 'user2', 'user3'], |
|
272 | + ], |
|
273 | + [ |
|
274 | + [ |
|
275 | + ['{http://owncloud.org/ns}principal' => 'principal/users/user1'], |
|
276 | + ['{http://owncloud.org/ns}principal' => 'principal/users/user2'], |
|
277 | + ['{http://owncloud.org/ns}principal' => 'principal/users/user2'], |
|
278 | + ['{http://owncloud.org/ns}principal' => 'principal/groups/group2'], |
|
279 | + ['{http://owncloud.org/ns}principal' => 'principal/groups/group3'], |
|
280 | + ], |
|
281 | + ['group2' => null, 'group3' => null], |
|
282 | + ['user1', 'user2'], |
|
283 | + ], |
|
284 | + [ |
|
285 | + [ |
|
286 | + ['{http://owncloud.org/ns}principal' => 'principal/users/user1'], |
|
287 | + ['{http://owncloud.org/ns}principal' => 'principal/users/user2'], |
|
288 | + ['{http://owncloud.org/ns}principal' => 'principal/users/user2'], |
|
289 | + ['{http://owncloud.org/ns}principal' => 'principal/groups/group2'], |
|
290 | + ['{http://owncloud.org/ns}principal' => 'principal/groups/group3'], |
|
291 | + ], |
|
292 | + ['group2' => ['user1', 'user2', 'user3'], 'group3' => ['user2', 'user3', 'user4']], |
|
293 | + ['user1', 'user2', 'user3', 'user4'], |
|
294 | + ], |
|
295 | + ]; |
|
296 | + } |
|
297 | + |
|
298 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetUsersForShares')] |
|
299 | + public function testGetUsersForShares(array $shares, array $groups, array $expected): void { |
|
300 | + $backend = $this->getBackend(); |
|
301 | + |
|
302 | + $getGroups = []; |
|
303 | + foreach ($groups as $gid => $members) { |
|
304 | + if ($members === null) { |
|
305 | + $getGroups[] = [$gid, null]; |
|
306 | + continue; |
|
307 | + } |
|
308 | + |
|
309 | + $group = $this->createMock(IGroup::class); |
|
310 | + $group->expects($this->once()) |
|
311 | + ->method('getUsers') |
|
312 | + ->willReturn($this->getUsers($members)); |
|
313 | + |
|
314 | + $getGroups[] = [$gid, $group]; |
|
315 | + } |
|
316 | + |
|
317 | + $this->groupManager->expects($this->exactly(sizeof($getGroups))) |
|
318 | + ->method('get') |
|
319 | + ->willReturnMap($getGroups); |
|
320 | + |
|
321 | + $users = $this->invokePrivate($backend, 'getUsersForShares', [$shares]); |
|
322 | + sort($users); |
|
323 | + $this->assertEquals($expected, $users); |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * @param string[] $users |
|
328 | + * @return IUser[]&MockObject[] |
|
329 | + */ |
|
330 | + protected function getUsers(array $users) { |
|
331 | + $list = []; |
|
332 | + foreach ($users as $user) { |
|
333 | + $list[] = $this->getUserMock($user); |
|
334 | + } |
|
335 | + return $list; |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * @param string $uid |
|
340 | + * @return IUser&MockObject |
|
341 | + */ |
|
342 | + protected function getUserMock($uid) { |
|
343 | + $user = $this->createMock(IUser::class); |
|
344 | + $user->expects($this->once()) |
|
345 | + ->method('getUID') |
|
346 | + ->willReturn($uid); |
|
347 | + return $user; |
|
348 | + } |
|
349 | 349 | } |
@@ -17,104 +17,104 @@ |
||
17 | 17 | use function rewind; |
18 | 18 | |
19 | 19 | class AppCalendarTest extends TestCase { |
20 | - private string $principal = 'principals/users/foo'; |
|
21 | - |
|
22 | - private AppCalendar $appCalendar; |
|
23 | - private AppCalendar $writeableAppCalendar; |
|
24 | - |
|
25 | - private ICalendar&MockObject $calendar; |
|
26 | - private ICalendar&MockObject $writeableCalendar; |
|
27 | - |
|
28 | - protected function setUp(): void { |
|
29 | - parent::setUp(); |
|
30 | - |
|
31 | - $this->calendar = $this->getMockBuilder(ICalendar::class)->getMock(); |
|
32 | - $this->calendar->method('getPermissions') |
|
33 | - ->willReturn(Constants::PERMISSION_READ); |
|
34 | - |
|
35 | - $this->writeableCalendar = $this->getMockBuilder(ICreateFromString::class)->getMock(); |
|
36 | - $this->writeableCalendar->method('getPermissions') |
|
37 | - ->willReturn(Constants::PERMISSION_READ | Constants::PERMISSION_CREATE); |
|
38 | - |
|
39 | - $this->appCalendar = new AppCalendar('dav-wrapper', $this->calendar, $this->principal); |
|
40 | - $this->writeableAppCalendar = new AppCalendar('dav-wrapper', $this->writeableCalendar, $this->principal); |
|
41 | - } |
|
42 | - |
|
43 | - public function testGetPrincipal():void { |
|
44 | - // Check that the correct name is returned |
|
45 | - $this->assertEquals($this->principal, $this->appCalendar->getOwner()); |
|
46 | - $this->assertEquals($this->principal, $this->writeableAppCalendar->getOwner()); |
|
47 | - } |
|
48 | - |
|
49 | - public function testDelete(): void { |
|
50 | - $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
51 | - $this->expectExceptionMessage('Deleting an entry is not implemented'); |
|
52 | - |
|
53 | - $this->appCalendar->delete(); |
|
54 | - } |
|
55 | - |
|
56 | - public function testCreateFile(): void { |
|
57 | - $calls = [ |
|
58 | - ['some-name', 'data'], |
|
59 | - ['other-name', ''], |
|
60 | - ['name', 'some data'], |
|
61 | - ]; |
|
62 | - $this->writeableCalendar->expects($this->exactly(3)) |
|
63 | - ->method('createFromString') |
|
64 | - ->willReturnCallback(function () use (&$calls): void { |
|
65 | - $expected = array_shift($calls); |
|
66 | - $this->assertEquals($expected, func_get_args()); |
|
67 | - }); |
|
68 | - |
|
69 | - // pass data |
|
70 | - $this->assertNull($this->writeableAppCalendar->createFile('some-name', 'data')); |
|
71 | - // null is empty string |
|
72 | - $this->assertNull($this->writeableAppCalendar->createFile('other-name', null)); |
|
73 | - // resource to data |
|
74 | - $fp = fopen('php://memory', 'r+'); |
|
75 | - fwrite($fp, 'some data'); |
|
76 | - rewind($fp); |
|
77 | - $this->assertNull($this->writeableAppCalendar->createFile('name', $fp)); |
|
78 | - fclose($fp); |
|
79 | - } |
|
80 | - |
|
81 | - public function testCreateFile_readOnly(): void { |
|
82 | - // If writing is not supported |
|
83 | - $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
84 | - $this->expectExceptionMessage('Creating a new entry is not allowed'); |
|
85 | - |
|
86 | - $this->appCalendar->createFile('some-name', 'data'); |
|
87 | - } |
|
88 | - |
|
89 | - public function testSetACL(): void { |
|
90 | - $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
91 | - $this->expectExceptionMessage('Setting ACL is not supported on this node'); |
|
92 | - |
|
93 | - $this->appCalendar->setACL([]); |
|
94 | - } |
|
95 | - |
|
96 | - public function testGetACL():void { |
|
97 | - $expectedRO = [ |
|
98 | - [ |
|
99 | - 'privilege' => '{DAV:}read', |
|
100 | - 'principal' => $this->principal, |
|
101 | - 'protected' => true, |
|
102 | - ], |
|
103 | - [ |
|
104 | - 'privilege' => '{DAV:}write-properties', |
|
105 | - 'principal' => $this->principal, |
|
106 | - 'protected' => true, |
|
107 | - ] |
|
108 | - ]; |
|
109 | - $expectedRW = $expectedRO; |
|
110 | - $expectedRW[] = [ |
|
111 | - 'privilege' => '{DAV:}write', |
|
112 | - 'principal' => $this->principal, |
|
113 | - 'protected' => true, |
|
114 | - ]; |
|
115 | - |
|
116 | - // Check that the correct ACL is returned (default be only readable) |
|
117 | - $this->assertEquals($expectedRO, $this->appCalendar->getACL()); |
|
118 | - $this->assertEquals($expectedRW, $this->writeableAppCalendar->getACL()); |
|
119 | - } |
|
20 | + private string $principal = 'principals/users/foo'; |
|
21 | + |
|
22 | + private AppCalendar $appCalendar; |
|
23 | + private AppCalendar $writeableAppCalendar; |
|
24 | + |
|
25 | + private ICalendar&MockObject $calendar; |
|
26 | + private ICalendar&MockObject $writeableCalendar; |
|
27 | + |
|
28 | + protected function setUp(): void { |
|
29 | + parent::setUp(); |
|
30 | + |
|
31 | + $this->calendar = $this->getMockBuilder(ICalendar::class)->getMock(); |
|
32 | + $this->calendar->method('getPermissions') |
|
33 | + ->willReturn(Constants::PERMISSION_READ); |
|
34 | + |
|
35 | + $this->writeableCalendar = $this->getMockBuilder(ICreateFromString::class)->getMock(); |
|
36 | + $this->writeableCalendar->method('getPermissions') |
|
37 | + ->willReturn(Constants::PERMISSION_READ | Constants::PERMISSION_CREATE); |
|
38 | + |
|
39 | + $this->appCalendar = new AppCalendar('dav-wrapper', $this->calendar, $this->principal); |
|
40 | + $this->writeableAppCalendar = new AppCalendar('dav-wrapper', $this->writeableCalendar, $this->principal); |
|
41 | + } |
|
42 | + |
|
43 | + public function testGetPrincipal():void { |
|
44 | + // Check that the correct name is returned |
|
45 | + $this->assertEquals($this->principal, $this->appCalendar->getOwner()); |
|
46 | + $this->assertEquals($this->principal, $this->writeableAppCalendar->getOwner()); |
|
47 | + } |
|
48 | + |
|
49 | + public function testDelete(): void { |
|
50 | + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
51 | + $this->expectExceptionMessage('Deleting an entry is not implemented'); |
|
52 | + |
|
53 | + $this->appCalendar->delete(); |
|
54 | + } |
|
55 | + |
|
56 | + public function testCreateFile(): void { |
|
57 | + $calls = [ |
|
58 | + ['some-name', 'data'], |
|
59 | + ['other-name', ''], |
|
60 | + ['name', 'some data'], |
|
61 | + ]; |
|
62 | + $this->writeableCalendar->expects($this->exactly(3)) |
|
63 | + ->method('createFromString') |
|
64 | + ->willReturnCallback(function () use (&$calls): void { |
|
65 | + $expected = array_shift($calls); |
|
66 | + $this->assertEquals($expected, func_get_args()); |
|
67 | + }); |
|
68 | + |
|
69 | + // pass data |
|
70 | + $this->assertNull($this->writeableAppCalendar->createFile('some-name', 'data')); |
|
71 | + // null is empty string |
|
72 | + $this->assertNull($this->writeableAppCalendar->createFile('other-name', null)); |
|
73 | + // resource to data |
|
74 | + $fp = fopen('php://memory', 'r+'); |
|
75 | + fwrite($fp, 'some data'); |
|
76 | + rewind($fp); |
|
77 | + $this->assertNull($this->writeableAppCalendar->createFile('name', $fp)); |
|
78 | + fclose($fp); |
|
79 | + } |
|
80 | + |
|
81 | + public function testCreateFile_readOnly(): void { |
|
82 | + // If writing is not supported |
|
83 | + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
84 | + $this->expectExceptionMessage('Creating a new entry is not allowed'); |
|
85 | + |
|
86 | + $this->appCalendar->createFile('some-name', 'data'); |
|
87 | + } |
|
88 | + |
|
89 | + public function testSetACL(): void { |
|
90 | + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
91 | + $this->expectExceptionMessage('Setting ACL is not supported on this node'); |
|
92 | + |
|
93 | + $this->appCalendar->setACL([]); |
|
94 | + } |
|
95 | + |
|
96 | + public function testGetACL():void { |
|
97 | + $expectedRO = [ |
|
98 | + [ |
|
99 | + 'privilege' => '{DAV:}read', |
|
100 | + 'principal' => $this->principal, |
|
101 | + 'protected' => true, |
|
102 | + ], |
|
103 | + [ |
|
104 | + 'privilege' => '{DAV:}write-properties', |
|
105 | + 'principal' => $this->principal, |
|
106 | + 'protected' => true, |
|
107 | + ] |
|
108 | + ]; |
|
109 | + $expectedRW = $expectedRO; |
|
110 | + $expectedRW[] = [ |
|
111 | + 'privilege' => '{DAV:}write', |
|
112 | + 'principal' => $this->principal, |
|
113 | + 'protected' => true, |
|
114 | + ]; |
|
115 | + |
|
116 | + // Check that the correct ACL is returned (default be only readable) |
|
117 | + $this->assertEquals($expectedRO, $this->appCalendar->getACL()); |
|
118 | + $this->assertEquals($expectedRW, $this->writeableAppCalendar->getACL()); |
|
119 | + } |
|
120 | 120 | } |
@@ -61,7 +61,7 @@ |
||
61 | 61 | ]; |
62 | 62 | $this->writeableCalendar->expects($this->exactly(3)) |
63 | 63 | ->method('createFromString') |
64 | - ->willReturnCallback(function () use (&$calls): void { |
|
64 | + ->willReturnCallback(function() use (&$calls): void { |
|
65 | 65 | $expected = array_shift($calls); |
66 | 66 | $this->assertEquals($expected, func_get_args()); |
67 | 67 | }); |
@@ -36,735 +36,735 @@ |
||
36 | 36 | use Test\TestCase; |
37 | 37 | |
38 | 38 | class PluginTest extends TestCase { |
39 | - private Plugin $plugin; |
|
40 | - private Server&MockObject $server; |
|
41 | - private IConfig&MockObject $config; |
|
42 | - private LoggerInterface&MockObject $logger; |
|
43 | - private DefaultCalendarValidator $calendarValidator; |
|
44 | - |
|
45 | - protected function setUp(): void { |
|
46 | - parent::setUp(); |
|
47 | - |
|
48 | - $this->config = $this->createMock(IConfig::class); |
|
49 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
50 | - $this->calendarValidator = new DefaultCalendarValidator(); |
|
51 | - |
|
52 | - $this->server = $this->createMock(Server::class); |
|
53 | - $this->server->httpResponse = $this->createMock(ResponseInterface::class); |
|
54 | - $this->server->xml = new Service(); |
|
55 | - |
|
56 | - $this->plugin = new Plugin($this->config, $this->logger, $this->calendarValidator); |
|
57 | - $this->plugin->initialize($this->server); |
|
58 | - } |
|
59 | - |
|
60 | - public function testInitialize(): void { |
|
61 | - $calls = [ |
|
62 | - // Sabre\CalDAV\Schedule\Plugin events |
|
63 | - ['method:POST', [$this->plugin, 'httpPost'], 100], |
|
64 | - ['propFind', [$this->plugin, 'propFind'], 100], |
|
65 | - ['propPatch', [$this->plugin, 'propPatch'], 100], |
|
66 | - ['calendarObjectChange', [$this->plugin, 'calendarObjectChange'], 100], |
|
67 | - ['beforeUnbind', [$this->plugin, 'beforeUnbind'], 100], |
|
68 | - ['schedule', [$this->plugin, 'scheduleLocalDelivery'], 100], |
|
69 | - ['getSupportedPrivilegeSet', [$this->plugin, 'getSupportedPrivilegeSet'], 100], |
|
70 | - // OCA\DAV\CalDAV\Schedule\Plugin events |
|
71 | - ['propFind', [$this->plugin, 'propFindDefaultCalendarUrl'], 90], |
|
72 | - ['afterWriteContent', [$this->plugin, 'dispatchSchedulingResponses'], 100], |
|
73 | - ['afterCreateFile', [$this->plugin, 'dispatchSchedulingResponses'], 100], |
|
74 | - ]; |
|
75 | - $this->server->expects($this->exactly(count($calls))) |
|
76 | - ->method('on') |
|
77 | - ->willReturnCallback(function () use (&$calls): void { |
|
78 | - $expected = array_shift($calls); |
|
79 | - $this->assertEquals($expected, func_get_args()); |
|
80 | - }); |
|
81 | - |
|
82 | - $this->plugin->initialize($this->server); |
|
83 | - } |
|
84 | - |
|
85 | - public function testGetAddressesForPrincipal(): void { |
|
86 | - $href = $this->createMock(Href::class); |
|
87 | - $href |
|
88 | - ->expects($this->once()) |
|
89 | - ->method('getHrefs') |
|
90 | - ->willReturn(['[email protected]', '[email protected]']); |
|
91 | - $this->server |
|
92 | - ->expects($this->once()) |
|
93 | - ->method('getProperties') |
|
94 | - ->with( |
|
95 | - 'MyPrincipal', |
|
96 | - [ |
|
97 | - '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set', |
|
98 | - ] |
|
99 | - ) |
|
100 | - ->willReturn([ |
|
101 | - '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set' => $href |
|
102 | - ]); |
|
103 | - |
|
104 | - $result = $this->invokePrivate($this->plugin, 'getAddressesForPrincipal', ['MyPrincipal']); |
|
105 | - $this->assertSame(['[email protected]', '[email protected]'], $result); |
|
106 | - } |
|
107 | - |
|
108 | - public function testGetAddressesForPrincipalEmpty(): void { |
|
109 | - $this->server |
|
110 | - ->expects($this->once()) |
|
111 | - ->method('getProperties') |
|
112 | - ->with( |
|
113 | - 'MyPrincipal', |
|
114 | - [ |
|
115 | - '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set', |
|
116 | - ] |
|
117 | - ) |
|
118 | - ->willReturn(null); |
|
119 | - |
|
120 | - $result = $this->invokePrivate($this->plugin, 'getAddressesForPrincipal', ['MyPrincipal']); |
|
121 | - $this->assertSame([], $result); |
|
122 | - } |
|
123 | - |
|
124 | - public function testStripOffMailTo(): void { |
|
125 | - $this->assertEquals('[email protected]', $this->invokePrivate($this->plugin, 'stripOffMailTo', ['[email protected]'])); |
|
126 | - $this->assertEquals('[email protected]', $this->invokePrivate($this->plugin, 'stripOffMailTo', ['mailto:[email protected]'])); |
|
127 | - } |
|
128 | - |
|
129 | - public function testGetAttendeeRSVP(): void { |
|
130 | - $property1 = $this->createMock(CalAddress::class); |
|
131 | - $parameter1 = $this->createMock(Parameter::class); |
|
132 | - $property1->expects($this->once()) |
|
133 | - ->method('offsetGet') |
|
134 | - ->with('RSVP') |
|
135 | - ->willReturn($parameter1); |
|
136 | - $parameter1->expects($this->once()) |
|
137 | - ->method('getValue') |
|
138 | - ->with() |
|
139 | - ->willReturn('TRUE'); |
|
140 | - |
|
141 | - $property2 = $this->createMock(CalAddress::class); |
|
142 | - $parameter2 = $this->createMock(Parameter::class); |
|
143 | - $property2->expects($this->once()) |
|
144 | - ->method('offsetGet') |
|
145 | - ->with('RSVP') |
|
146 | - ->willReturn($parameter2); |
|
147 | - $parameter2->expects($this->once()) |
|
148 | - ->method('getValue') |
|
149 | - ->with() |
|
150 | - ->willReturn('FALSE'); |
|
151 | - |
|
152 | - $property3 = $this->createMock(CalAddress::class); |
|
153 | - $property3->expects($this->once()) |
|
154 | - ->method('offsetGet') |
|
155 | - ->with('RSVP') |
|
156 | - ->willReturn(null); |
|
157 | - |
|
158 | - $this->assertTrue($this->invokePrivate($this->plugin, 'getAttendeeRSVP', [$property1])); |
|
159 | - $this->assertFalse($this->invokePrivate($this->plugin, 'getAttendeeRSVP', [$property2])); |
|
160 | - $this->assertFalse($this->invokePrivate($this->plugin, 'getAttendeeRSVP', [$property3])); |
|
161 | - } |
|
162 | - |
|
163 | - public static function propFindDefaultCalendarUrlProvider(): array { |
|
164 | - return [ |
|
165 | - [ |
|
166 | - 'principals/users/myuser', |
|
167 | - 'calendars/myuser', |
|
168 | - false, |
|
169 | - CalDavBackend::PERSONAL_CALENDAR_URI, |
|
170 | - CalDavBackend::PERSONAL_CALENDAR_NAME, |
|
171 | - true |
|
172 | - ], |
|
173 | - [ |
|
174 | - 'principals/users/myuser', |
|
175 | - 'calendars/myuser', |
|
176 | - false, |
|
177 | - CalDavBackend::PERSONAL_CALENDAR_URI, |
|
178 | - CalDavBackend::PERSONAL_CALENDAR_NAME, |
|
179 | - true, |
|
180 | - true |
|
181 | - ], |
|
182 | - [ |
|
183 | - 'principals/users/myuser', |
|
184 | - 'calendars/myuser', |
|
185 | - false, |
|
186 | - CalDavBackend::PERSONAL_CALENDAR_URI, |
|
187 | - CalDavBackend::PERSONAL_CALENDAR_NAME, |
|
188 | - false, |
|
189 | - false, |
|
190 | - true |
|
191 | - ], |
|
192 | - [ |
|
193 | - 'principals/users/myuser', |
|
194 | - 'calendars/myuser', |
|
195 | - false, |
|
196 | - CalDavBackend::PERSONAL_CALENDAR_URI, |
|
197 | - CalDavBackend::PERSONAL_CALENDAR_NAME, |
|
198 | - false |
|
199 | - ], |
|
200 | - [ |
|
201 | - 'principals/users/myuser', |
|
202 | - null, |
|
203 | - false, |
|
204 | - CalDavBackend::PERSONAL_CALENDAR_URI, |
|
205 | - CalDavBackend::PERSONAL_CALENDAR_NAME, |
|
206 | - true |
|
207 | - ], |
|
208 | - [ |
|
209 | - 'principals/users/myuser', |
|
210 | - 'calendars/myuser', |
|
211 | - false, |
|
212 | - CalDavBackend::PERSONAL_CALENDAR_URI, |
|
213 | - CalDavBackend::PERSONAL_CALENDAR_NAME, |
|
214 | - true, |
|
215 | - false, |
|
216 | - false, |
|
217 | - false, |
|
218 | - ], |
|
219 | - [ |
|
220 | - 'principals/users/myuser', |
|
221 | - 'calendars/myuser', |
|
222 | - false, |
|
223 | - 'my_other_calendar', |
|
224 | - 'My Other Calendar', |
|
225 | - true |
|
226 | - ], |
|
227 | - [ |
|
228 | - 'principals/calendar-resources', |
|
229 | - 'system-calendars/calendar-resources/myuser', |
|
230 | - true, |
|
231 | - CalDavBackend::RESOURCE_BOOKING_CALENDAR_URI, |
|
232 | - CalDavBackend::RESOURCE_BOOKING_CALENDAR_NAME, |
|
233 | - true |
|
234 | - ], |
|
235 | - [ |
|
236 | - 'principals/calendar-resources', |
|
237 | - 'system-calendars/calendar-resources/myuser', |
|
238 | - true, |
|
239 | - CalDavBackend::RESOURCE_BOOKING_CALENDAR_URI, |
|
240 | - CalDavBackend::RESOURCE_BOOKING_CALENDAR_NAME, |
|
241 | - false |
|
242 | - ], |
|
243 | - [ |
|
244 | - 'principals/something-else', |
|
245 | - 'calendars/whatever', |
|
246 | - false, |
|
247 | - CalDavBackend::PERSONAL_CALENDAR_URI, |
|
248 | - CalDavBackend::PERSONAL_CALENDAR_NAME, |
|
249 | - true |
|
250 | - ], |
|
251 | - ]; |
|
252 | - } |
|
253 | - |
|
254 | - #[\PHPUnit\Framework\Attributes\DataProvider('propFindDefaultCalendarUrlProvider')] |
|
255 | - public function testPropFindDefaultCalendarUrl(string $principalUri, ?string $calendarHome, bool $isResource, string $calendarUri, string $displayName, bool $exists, bool $deleted = false, bool $hasExistingCalendars = false, bool $propertiesForPath = true): void { |
|
256 | - $propFind = new PropFind( |
|
257 | - $principalUri, |
|
258 | - [ |
|
259 | - Plugin::SCHEDULE_DEFAULT_CALENDAR_URL |
|
260 | - ], |
|
261 | - 0 |
|
262 | - ); |
|
263 | - /** @var IPrincipal&MockObject $node */ |
|
264 | - $node = $this->getMockBuilder(IPrincipal::class) |
|
265 | - ->disableOriginalConstructor() |
|
266 | - ->getMock(); |
|
267 | - |
|
268 | - $node->expects($this->once()) |
|
269 | - ->method('getPrincipalUrl') |
|
270 | - ->with() |
|
271 | - ->willReturn($principalUri); |
|
272 | - |
|
273 | - $calDAVPlugin = $this->getMockBuilder(CalDAVPlugin::class) |
|
274 | - ->disableOriginalConstructor() |
|
275 | - ->getMock(); |
|
276 | - |
|
277 | - $calDAVPlugin->expects($this->once()) |
|
278 | - ->method('getCalendarHomeForPrincipal') |
|
279 | - ->willReturn($calendarHome); |
|
280 | - |
|
281 | - $this->server->expects($this->once()) |
|
282 | - ->method('getPlugin') |
|
283 | - ->with('caldav') |
|
284 | - ->willReturn($calDAVPlugin); |
|
285 | - if (!$calendarHome) { |
|
286 | - $this->plugin->propFindDefaultCalendarUrl($propFind, $node); |
|
287 | - |
|
288 | - $this->assertNull($propFind->get(Plugin::SCHEDULE_DEFAULT_CALENDAR_URL)); |
|
289 | - return; |
|
290 | - } |
|
291 | - if ($principalUri === 'principals/something-else') { |
|
292 | - $this->plugin->propFindDefaultCalendarUrl($propFind, $node); |
|
293 | - |
|
294 | - $this->assertNull($propFind->get(Plugin::SCHEDULE_DEFAULT_CALENDAR_URL)); |
|
295 | - return; |
|
296 | - } |
|
297 | - |
|
298 | - if (!$isResource) { |
|
299 | - $this->config->expects($this->once()) |
|
300 | - ->method('getUserValue') |
|
301 | - ->with('myuser', 'dav', 'defaultCalendar', CalDavBackend::PERSONAL_CALENDAR_URI) |
|
302 | - ->willReturn($calendarUri); |
|
303 | - } |
|
304 | - |
|
305 | - $calendarHomeObject = $this->createMock(CalendarHome::class); |
|
306 | - $calendarHomeObject->expects($this->once()) |
|
307 | - ->method('childExists') |
|
308 | - ->with($calendarUri) |
|
309 | - ->willReturn($exists); |
|
310 | - |
|
311 | - if ($exists) { |
|
312 | - $calendar = $this->createMock(Calendar::class); |
|
313 | - $calendar->expects($this->once())->method('isDeleted')->willReturn($deleted); |
|
314 | - $calendarHomeObject->expects($deleted && !$hasExistingCalendars ? $this->exactly(2) : $this->once())->method('getChild')->with($calendarUri)->willReturn($calendar); |
|
315 | - } |
|
316 | - |
|
317 | - $calendarBackend = $this->createMock(CalDavBackend::class); |
|
318 | - $calendarUri = $hasExistingCalendars ? 'custom' : $calendarUri; |
|
319 | - $displayName = $hasExistingCalendars ? 'Custom Calendar' : $displayName; |
|
320 | - |
|
321 | - $existingCalendars = $hasExistingCalendars ? [ |
|
322 | - new Calendar( |
|
323 | - $calendarBackend, |
|
324 | - ['uri' => 'deleted', '{DAV:}displayname' => 'A deleted calendar', TrashbinPlugin::PROPERTY_DELETED_AT => 42], |
|
325 | - $this->createMock(IL10N::class), |
|
326 | - $this->config, |
|
327 | - $this->createMock(LoggerInterface::class) |
|
328 | - ), |
|
329 | - new Calendar( |
|
330 | - $calendarBackend, |
|
331 | - ['uri' => $calendarUri, '{DAV:}displayname' => $displayName], |
|
332 | - $this->createMock(IL10N::class), |
|
333 | - $this->config, |
|
334 | - $this->createMock(LoggerInterface::class) |
|
335 | - ) |
|
336 | - ] : []; |
|
337 | - |
|
338 | - if (!$exists || $deleted) { |
|
339 | - if (!$hasExistingCalendars) { |
|
340 | - $calendarBackend->expects($this->once()) |
|
341 | - ->method('createCalendar') |
|
342 | - ->with($principalUri, $calendarUri, [ |
|
343 | - '{DAV:}displayname' => $displayName, |
|
344 | - ]); |
|
345 | - |
|
346 | - $calendarHomeObject->expects($this->exactly($deleted ? 2 : 1)) |
|
347 | - ->method('getCalDAVBackend') |
|
348 | - ->with() |
|
349 | - ->willReturn($calendarBackend); |
|
350 | - } |
|
351 | - |
|
352 | - if (!$isResource) { |
|
353 | - $calendarHomeObject->expects($this->once()) |
|
354 | - ->method('getChildren') |
|
355 | - ->with() |
|
356 | - ->willReturn($existingCalendars); |
|
357 | - } |
|
358 | - } |
|
359 | - |
|
360 | - /** @var Tree&MockObject $tree */ |
|
361 | - $tree = $this->createMock(Tree::class); |
|
362 | - $tree->expects($this->once()) |
|
363 | - ->method('getNodeForPath') |
|
364 | - ->with($calendarHome) |
|
365 | - ->willReturn($calendarHomeObject); |
|
366 | - $this->server->tree = $tree; |
|
367 | - |
|
368 | - $properties = $propertiesForPath ? [ |
|
369 | - ['href' => '/remote.php/dav/' . $calendarHome . '/' . $calendarUri] |
|
370 | - ] : []; |
|
371 | - |
|
372 | - $this->server->expects($this->once()) |
|
373 | - ->method('getPropertiesForPath') |
|
374 | - ->with($calendarHome . '/' . $calendarUri, [], 1) |
|
375 | - ->willReturn($properties); |
|
376 | - |
|
377 | - $this->plugin->propFindDefaultCalendarUrl($propFind, $node); |
|
378 | - |
|
379 | - if (!$propertiesForPath) { |
|
380 | - $this->assertNull($propFind->get(Plugin::SCHEDULE_DEFAULT_CALENDAR_URL)); |
|
381 | - return; |
|
382 | - } |
|
383 | - |
|
384 | - /** @var LocalHref $result */ |
|
385 | - $result = $propFind->get(Plugin::SCHEDULE_DEFAULT_CALENDAR_URL); |
|
386 | - $this->assertEquals('/remote.php/dav/' . $calendarHome . '/' . $calendarUri, $result->getHref()); |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Test Calendar Event Creation for Personal Calendar |
|
391 | - * |
|
392 | - * Should generate 2 messages for attendees User 2 and User External |
|
393 | - */ |
|
394 | - public function testCalendarObjectChangePersonalCalendarCreate(): void { |
|
395 | - |
|
396 | - // define place holders |
|
397 | - /** @var Message[] $iTipMessages */ |
|
398 | - $iTipMessages = []; |
|
399 | - // construct calendar node |
|
400 | - $calendarNode = new Calendar( |
|
401 | - $this->createMock(BackendInterface::class), |
|
402 | - [ |
|
403 | - 'uri' => 'personal', |
|
404 | - 'principaluri' => 'principals/users/user1', |
|
405 | - '{DAV:}displayname' => 'Calendar Shared By User1', |
|
406 | - ], |
|
407 | - $this->createMock(IL10N::class), |
|
408 | - $this->config, |
|
409 | - $this->logger |
|
410 | - ); |
|
411 | - // construct server request object |
|
412 | - $request = new Request( |
|
413 | - 'PUT', |
|
414 | - '/remote.php/dav/calendars/user1/personal/B0DC78AE-6DD7-47E3-80BE-89F23E6D5383.ics' |
|
415 | - ); |
|
416 | - $request->setBaseUrl('/remote.php/dav/'); |
|
417 | - // construct server response object |
|
418 | - $response = new Response(); |
|
419 | - // construct server tree object |
|
420 | - $tree = $this->createMock(Tree::class); |
|
421 | - $tree->expects($this->once()) |
|
422 | - ->method('getNodeForPath') |
|
423 | - ->with('calendars/user1/personal') |
|
424 | - ->willReturn($calendarNode); |
|
425 | - // construct server properties and returns |
|
426 | - $this->server->httpRequest = $request; |
|
427 | - $this->server->tree = $tree; |
|
428 | - $this->server->expects($this->exactly(1))->method('getProperties') |
|
429 | - ->willReturnMap([ |
|
430 | - [ |
|
431 | - 'principals/users/user1', |
|
432 | - ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set'], |
|
433 | - ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set' => new LocalHref( |
|
434 | - ['mailto:[email protected]','/remote.php/dav/principals/users/user1/'] |
|
435 | - )] |
|
436 | - ] |
|
437 | - ]); |
|
438 | - $this->server->expects($this->exactly(2))->method('emit')->willReturnCallback( |
|
439 | - function (string $eventName, array $arguments = [], ?callable $continueCallBack = null) use (&$iTipMessages) { |
|
440 | - $this->assertEquals('schedule', $eventName); |
|
441 | - $this->assertCount(1, $arguments); |
|
442 | - $iTipMessages[] = $arguments[0]; |
|
443 | - return true; |
|
444 | - } |
|
445 | - ); |
|
446 | - // construct calendar with a 1 hour event and same start/end time zones |
|
447 | - $vCalendar = new VCalendar(); |
|
448 | - $vEvent = $vCalendar->add('VEVENT', []); |
|
449 | - $vEvent->UID->setValue('96a0e6b1-d886-4a55-a60d-152b31401dcc'); |
|
450 | - $vEvent->add('DTSTART', '20240701T080000', ['TZID' => 'America/Toronto']); |
|
451 | - $vEvent->add('DTEND', '20240701T090000', ['TZID' => 'America/Toronto']); |
|
452 | - $vEvent->add('SUMMARY', 'Test Recurring Event'); |
|
453 | - $vEvent->add('ORGANIZER', 'mailto:[email protected]', ['CN' => 'User One']); |
|
454 | - $vEvent->add('ATTENDEE', 'mailto:[email protected]', [ |
|
455 | - 'CN' => 'User Two', |
|
456 | - 'CUTYPE' => 'INDIVIDUAL', |
|
457 | - 'PARTSTAT' => 'NEEDS-ACTION', |
|
458 | - 'ROLE' => 'REQ-PARTICIPANT', |
|
459 | - 'RSVP' => 'TRUE' |
|
460 | - ]); |
|
461 | - $vEvent->add('ATTENDEE', 'mailto:[email protected]', [ |
|
462 | - 'CN' => 'User External', |
|
463 | - 'CUTYPE' => 'INDIVIDUAL', |
|
464 | - 'PARTSTAT' => 'NEEDS-ACTION', |
|
465 | - 'ROLE' => 'REQ-PARTICIPANT', |
|
466 | - 'RSVP' => 'TRUE' |
|
467 | - ]); |
|
468 | - // define flags |
|
469 | - $newFlag = true; |
|
470 | - $modifiedFlag = false; |
|
471 | - // execute method |
|
472 | - $this->plugin->calendarObjectChange( |
|
473 | - $request, |
|
474 | - $response, |
|
475 | - $vCalendar, |
|
476 | - 'calendars/user1/personal', |
|
477 | - $modifiedFlag, |
|
478 | - $newFlag |
|
479 | - ); |
|
480 | - // test for correct iTip message count |
|
481 | - $this->assertCount(2, $iTipMessages); |
|
482 | - // test for Sharer Attendee |
|
483 | - $this->assertEquals('mailto:[email protected]', $iTipMessages[0]->sender); |
|
484 | - $this->assertEquals('mailto:[email protected]', $iTipMessages[0]->recipient); |
|
485 | - $this->assertTrue($iTipMessages[0]->significantChange); |
|
486 | - // test for External Attendee |
|
487 | - $this->assertEquals('mailto:[email protected]', $iTipMessages[1]->sender); |
|
488 | - $this->assertEquals('mailto:[email protected]', $iTipMessages[1]->recipient); |
|
489 | - $this->assertTrue($iTipMessages[1]->significantChange); |
|
490 | - |
|
491 | - } |
|
492 | - |
|
493 | - /** |
|
494 | - * Test Calendar Event Creation for Shared Calendar as Sharer/Owner |
|
495 | - * |
|
496 | - * Should generate 3 messages for attendees User 2 (Sharee), User 3 (Non-Sharee) and User External |
|
497 | - */ |
|
498 | - public function testCalendarObjectChangeSharedCalendarSharerCreate(): void { |
|
499 | - |
|
500 | - // define place holders |
|
501 | - /** @var Message[] $iTipMessages */ |
|
502 | - $iTipMessages = []; |
|
503 | - // construct calendar node |
|
504 | - $calendarNode = new Calendar( |
|
505 | - $this->createMock(BackendInterface::class), |
|
506 | - [ |
|
507 | - 'uri' => 'calendar_shared_by_user1', |
|
508 | - 'principaluri' => 'principals/users/user1', |
|
509 | - '{DAV:}displayname' => 'Calendar Shared By User1', |
|
510 | - '{http://owncloud.org/ns}owner-principal' => 'principals/users/user1' |
|
511 | - ], |
|
512 | - $this->createMock(IL10N::class), |
|
513 | - $this->config, |
|
514 | - $this->logger |
|
515 | - ); |
|
516 | - // construct server request object |
|
517 | - $request = new Request( |
|
518 | - 'PUT', |
|
519 | - '/remote.php/dav/calendars/user1/calendar_shared_by_user1/B0DC78AE-6DD7-47E3-80BE-89F23E6D5383.ics' |
|
520 | - ); |
|
521 | - $request->setBaseUrl('/remote.php/dav/'); |
|
522 | - // construct server response object |
|
523 | - $response = new Response(); |
|
524 | - // construct server tree object |
|
525 | - $tree = $this->createMock(Tree::class); |
|
526 | - $tree->expects($this->once()) |
|
527 | - ->method('getNodeForPath') |
|
528 | - ->with('calendars/user1/calendar_shared_by_user1') |
|
529 | - ->willReturn($calendarNode); |
|
530 | - // construct server properties and returns |
|
531 | - $this->server->httpRequest = $request; |
|
532 | - $this->server->tree = $tree; |
|
533 | - $this->server->expects($this->exactly(1))->method('getProperties') |
|
534 | - ->willReturnMap([ |
|
535 | - [ |
|
536 | - 'principals/users/user1', |
|
537 | - ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set'], |
|
538 | - ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set' => new LocalHref( |
|
539 | - ['mailto:[email protected]','/remote.php/dav/principals/users/user1/'] |
|
540 | - )] |
|
541 | - ] |
|
542 | - ]); |
|
543 | - $this->server->expects($this->exactly(3))->method('emit')->willReturnCallback( |
|
544 | - function (string $eventName, array $arguments = [], ?callable $continueCallBack = null) use (&$iTipMessages) { |
|
545 | - $this->assertEquals('schedule', $eventName); |
|
546 | - $this->assertCount(1, $arguments); |
|
547 | - $iTipMessages[] = $arguments[0]; |
|
548 | - return true; |
|
549 | - } |
|
550 | - ); |
|
551 | - // construct calendar with a 1 hour event and same start/end time zones |
|
552 | - $vCalendar = new VCalendar(); |
|
553 | - $vEvent = $vCalendar->add('VEVENT', []); |
|
554 | - $vEvent->UID->setValue('96a0e6b1-d886-4a55-a60d-152b31401dcc'); |
|
555 | - $vEvent->add('DTSTART', '20240701T080000', ['TZID' => 'America/Toronto']); |
|
556 | - $vEvent->add('DTEND', '20240701T090000', ['TZID' => 'America/Toronto']); |
|
557 | - $vEvent->add('SUMMARY', 'Test Recurring Event'); |
|
558 | - $vEvent->add('ORGANIZER', 'mailto:[email protected]', ['CN' => 'User One']); |
|
559 | - $vEvent->add('ATTENDEE', 'mailto:[email protected]', [ |
|
560 | - 'CN' => 'User Two', |
|
561 | - 'CUTYPE' => 'INDIVIDUAL', |
|
562 | - 'PARTSTAT' => 'NEEDS-ACTION', |
|
563 | - 'ROLE' => 'REQ-PARTICIPANT', |
|
564 | - 'RSVP' => 'TRUE' |
|
565 | - ]); |
|
566 | - $vEvent->add('ATTENDEE', 'mailto:[email protected]', [ |
|
567 | - 'CN' => 'User Three', |
|
568 | - 'CUTYPE' => 'INDIVIDUAL', |
|
569 | - 'PARTSTAT' => 'NEEDS-ACTION', |
|
570 | - 'ROLE' => 'REQ-PARTICIPANT', |
|
571 | - 'RSVP' => 'TRUE' |
|
572 | - ]); |
|
573 | - $vEvent->add('ATTENDEE', 'mailto:[email protected]', [ |
|
574 | - 'CN' => 'User External', |
|
575 | - 'CUTYPE' => 'INDIVIDUAL', |
|
576 | - 'PARTSTAT' => 'NEEDS-ACTION', |
|
577 | - 'ROLE' => 'REQ-PARTICIPANT', |
|
578 | - 'RSVP' => 'TRUE' |
|
579 | - ]); |
|
580 | - // define flags |
|
581 | - $newFlag = true; |
|
582 | - $modifiedFlag = false; |
|
583 | - // execute method |
|
584 | - $this->plugin->calendarObjectChange( |
|
585 | - $request, |
|
586 | - $response, |
|
587 | - $vCalendar, |
|
588 | - 'calendars/user1/calendar_shared_by_user1', |
|
589 | - $modifiedFlag, |
|
590 | - $newFlag |
|
591 | - ); |
|
592 | - // test for correct iTip message count |
|
593 | - $this->assertCount(3, $iTipMessages); |
|
594 | - // test for Sharer Attendee |
|
595 | - $this->assertEquals('mailto:[email protected]', $iTipMessages[0]->sender); |
|
596 | - $this->assertEquals('mailto:[email protected]', $iTipMessages[0]->recipient); |
|
597 | - $this->assertTrue($iTipMessages[0]->significantChange); |
|
598 | - // test for Non Shee Attendee |
|
599 | - $this->assertEquals('mailto:[email protected]', $iTipMessages[1]->sender); |
|
600 | - $this->assertEquals('mailto:[email protected]', $iTipMessages[1]->recipient); |
|
601 | - $this->assertTrue($iTipMessages[1]->significantChange); |
|
602 | - // test for External Attendee |
|
603 | - $this->assertEquals('mailto:[email protected]', $iTipMessages[2]->sender); |
|
604 | - $this->assertEquals('mailto:[email protected]', $iTipMessages[2]->recipient); |
|
605 | - $this->assertTrue($iTipMessages[2]->significantChange); |
|
606 | - |
|
607 | - } |
|
608 | - |
|
609 | - /** |
|
610 | - * Test Calendar Event Creation for Shared Calendar as Shree |
|
611 | - * |
|
612 | - * Should generate 3 messages for attendees User 1 (Sharer/Owner), User 3 (Non-Sharee) and User External |
|
613 | - */ |
|
614 | - public function testCalendarObjectChangeSharedCalendarShreeCreate(): void { |
|
615 | - |
|
616 | - // define place holders |
|
617 | - /** @var Message[] $iTipMessages */ |
|
618 | - $iTipMessages = []; |
|
619 | - // construct calendar node |
|
620 | - $calendarNode = new Calendar( |
|
621 | - $this->createMock(BackendInterface::class), |
|
622 | - [ |
|
623 | - 'uri' => 'calendar_shared_by_user1', |
|
624 | - 'principaluri' => 'principals/users/user2', |
|
625 | - '{DAV:}displayname' => 'Calendar Shared By User1', |
|
626 | - '{http://owncloud.org/ns}owner-principal' => 'principals/users/user1' |
|
627 | - ], |
|
628 | - $this->createMock(IL10N::class), |
|
629 | - $this->config, |
|
630 | - $this->logger |
|
631 | - ); |
|
632 | - // construct server request object |
|
633 | - $request = new Request( |
|
634 | - 'PUT', |
|
635 | - '/remote.php/dav/calendars/user2/calendar_shared_by_user1/B0DC78AE-6DD7-47E3-80BE-89F23E6D5383.ics' |
|
636 | - ); |
|
637 | - $request->setBaseUrl('/remote.php/dav/'); |
|
638 | - // construct server response object |
|
639 | - $response = new Response(); |
|
640 | - // construct server tree object |
|
641 | - $tree = $this->createMock(Tree::class); |
|
642 | - $tree->expects($this->once()) |
|
643 | - ->method('getNodeForPath') |
|
644 | - ->with('calendars/user2/calendar_shared_by_user1') |
|
645 | - ->willReturn($calendarNode); |
|
646 | - // construct server properties and returns |
|
647 | - $this->server->httpRequest = $request; |
|
648 | - $this->server->tree = $tree; |
|
649 | - $this->server->expects($this->exactly(2))->method('getProperties') |
|
650 | - ->willReturnMap([ |
|
651 | - [ |
|
652 | - 'principals/users/user1', |
|
653 | - ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set'], |
|
654 | - ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set' => new LocalHref( |
|
655 | - ['mailto:[email protected]','/remote.php/dav/principals/users/user1/'] |
|
656 | - )] |
|
657 | - ], |
|
658 | - [ |
|
659 | - 'principals/users/user2', |
|
660 | - ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set'], |
|
661 | - ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set' => new LocalHref( |
|
662 | - ['mailto:[email protected]','/remote.php/dav/principals/users/user2/'] |
|
663 | - )] |
|
664 | - ] |
|
665 | - ]); |
|
666 | - $this->server->expects($this->exactly(3))->method('emit')->willReturnCallback( |
|
667 | - function (string $eventName, array $arguments = [], ?callable $continueCallBack = null) use (&$iTipMessages) { |
|
668 | - $this->assertEquals('schedule', $eventName); |
|
669 | - $this->assertCount(1, $arguments); |
|
670 | - $iTipMessages[] = $arguments[0]; |
|
671 | - return true; |
|
672 | - } |
|
673 | - ); |
|
674 | - // construct calendar with a 1 hour event and same start/end time zones |
|
675 | - $vCalendar = new VCalendar(); |
|
676 | - $vEvent = $vCalendar->add('VEVENT', []); |
|
677 | - $vEvent->UID->setValue('96a0e6b1-d886-4a55-a60d-152b31401dcc'); |
|
678 | - $vEvent->add('DTSTART', '20240701T080000', ['TZID' => 'America/Toronto']); |
|
679 | - $vEvent->add('DTEND', '20240701T090000', ['TZID' => 'America/Toronto']); |
|
680 | - $vEvent->add('SUMMARY', 'Test Recurring Event'); |
|
681 | - $vEvent->add('ORGANIZER', 'mailto:[email protected]', ['CN' => 'User Two']); |
|
682 | - $vEvent->add('ATTENDEE', 'mailto:[email protected]', [ |
|
683 | - 'CN' => 'User One', |
|
684 | - 'CUTYPE' => 'INDIVIDUAL', |
|
685 | - 'PARTSTAT' => 'NEEDS-ACTION', |
|
686 | - 'ROLE' => 'REQ-PARTICIPANT', |
|
687 | - 'RSVP' => 'TRUE' |
|
688 | - ]); |
|
689 | - $vEvent->add('ATTENDEE', 'mailto:[email protected]', [ |
|
690 | - 'CN' => 'User Three', |
|
691 | - 'CUTYPE' => 'INDIVIDUAL', |
|
692 | - 'PARTSTAT' => 'NEEDS-ACTION', |
|
693 | - 'ROLE' => 'REQ-PARTICIPANT', |
|
694 | - 'RSVP' => 'TRUE' |
|
695 | - ]); |
|
696 | - $vEvent->add('ATTENDEE', 'mailto:[email protected]', [ |
|
697 | - 'CN' => 'User External', |
|
698 | - 'CUTYPE' => 'INDIVIDUAL', |
|
699 | - 'PARTSTAT' => 'NEEDS-ACTION', |
|
700 | - 'ROLE' => 'REQ-PARTICIPANT', |
|
701 | - 'RSVP' => 'TRUE' |
|
702 | - ]); |
|
703 | - // define flags |
|
704 | - $newFlag = true; |
|
705 | - $modifiedFlag = false; |
|
706 | - // execute method |
|
707 | - $this->plugin->calendarObjectChange( |
|
708 | - $request, |
|
709 | - $response, |
|
710 | - $vCalendar, |
|
711 | - 'calendars/user2/calendar_shared_by_user1', |
|
712 | - $modifiedFlag, |
|
713 | - $newFlag |
|
714 | - ); |
|
715 | - // test for correct iTip message count |
|
716 | - $this->assertCount(3, $iTipMessages); |
|
717 | - // test for Sharer Attendee |
|
718 | - $this->assertEquals('mailto:[email protected]', $iTipMessages[0]->sender); |
|
719 | - $this->assertEquals('mailto:[email protected]', $iTipMessages[0]->recipient); |
|
720 | - $this->assertTrue($iTipMessages[0]->significantChange); |
|
721 | - // test for Non Shee Attendee |
|
722 | - $this->assertEquals('mailto:[email protected]', $iTipMessages[1]->sender); |
|
723 | - $this->assertEquals('mailto:[email protected]', $iTipMessages[1]->recipient); |
|
724 | - $this->assertTrue($iTipMessages[1]->significantChange); |
|
725 | - // test for External Attendee |
|
726 | - $this->assertEquals('mailto:[email protected]', $iTipMessages[2]->sender); |
|
727 | - $this->assertEquals('mailto:[email protected]', $iTipMessages[2]->recipient); |
|
728 | - $this->assertTrue($iTipMessages[2]->significantChange); |
|
729 | - |
|
730 | - } |
|
731 | - |
|
732 | - /** |
|
733 | - * Test Calendar Event Creation with iTip and iMip disabled |
|
734 | - * |
|
735 | - * Should generate 2 messages for attendees User 2 and User External |
|
736 | - */ |
|
737 | - public function testCalendarObjectChangeWithSchedulingDisabled(): void { |
|
738 | - // construct server request |
|
739 | - $request = new Request( |
|
740 | - 'PUT', |
|
741 | - '/remote.php/dav/calendars/user1/personal/B0DC78AE-6DD7-47E3-80BE-89F23E6D5383.ics', |
|
742 | - ['x-nc-scheduling' => 'false'] |
|
743 | - ); |
|
744 | - $request->setBaseUrl('/remote.php/dav/'); |
|
745 | - // construct server response |
|
746 | - $response = new Response(); |
|
747 | - // construct server tree |
|
748 | - $tree = $this->createMock(Tree::class); |
|
749 | - $tree->expects($this->never()) |
|
750 | - ->method('getNodeForPath'); |
|
751 | - // construct server properties and returns |
|
752 | - $this->server->httpRequest = $request; |
|
753 | - $this->server->tree = $tree; |
|
754 | - // construct empty calendar event |
|
755 | - $vCalendar = new VCalendar(); |
|
756 | - $vEvent = $vCalendar->add('VEVENT', []); |
|
757 | - // define flags |
|
758 | - $newFlag = true; |
|
759 | - $modifiedFlag = false; |
|
760 | - // execute method |
|
761 | - $this->plugin->calendarObjectChange( |
|
762 | - $request, |
|
763 | - $response, |
|
764 | - $vCalendar, |
|
765 | - 'calendars/user1/personal', |
|
766 | - $modifiedFlag, |
|
767 | - $newFlag |
|
768 | - ); |
|
769 | - } |
|
39 | + private Plugin $plugin; |
|
40 | + private Server&MockObject $server; |
|
41 | + private IConfig&MockObject $config; |
|
42 | + private LoggerInterface&MockObject $logger; |
|
43 | + private DefaultCalendarValidator $calendarValidator; |
|
44 | + |
|
45 | + protected function setUp(): void { |
|
46 | + parent::setUp(); |
|
47 | + |
|
48 | + $this->config = $this->createMock(IConfig::class); |
|
49 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
50 | + $this->calendarValidator = new DefaultCalendarValidator(); |
|
51 | + |
|
52 | + $this->server = $this->createMock(Server::class); |
|
53 | + $this->server->httpResponse = $this->createMock(ResponseInterface::class); |
|
54 | + $this->server->xml = new Service(); |
|
55 | + |
|
56 | + $this->plugin = new Plugin($this->config, $this->logger, $this->calendarValidator); |
|
57 | + $this->plugin->initialize($this->server); |
|
58 | + } |
|
59 | + |
|
60 | + public function testInitialize(): void { |
|
61 | + $calls = [ |
|
62 | + // Sabre\CalDAV\Schedule\Plugin events |
|
63 | + ['method:POST', [$this->plugin, 'httpPost'], 100], |
|
64 | + ['propFind', [$this->plugin, 'propFind'], 100], |
|
65 | + ['propPatch', [$this->plugin, 'propPatch'], 100], |
|
66 | + ['calendarObjectChange', [$this->plugin, 'calendarObjectChange'], 100], |
|
67 | + ['beforeUnbind', [$this->plugin, 'beforeUnbind'], 100], |
|
68 | + ['schedule', [$this->plugin, 'scheduleLocalDelivery'], 100], |
|
69 | + ['getSupportedPrivilegeSet', [$this->plugin, 'getSupportedPrivilegeSet'], 100], |
|
70 | + // OCA\DAV\CalDAV\Schedule\Plugin events |
|
71 | + ['propFind', [$this->plugin, 'propFindDefaultCalendarUrl'], 90], |
|
72 | + ['afterWriteContent', [$this->plugin, 'dispatchSchedulingResponses'], 100], |
|
73 | + ['afterCreateFile', [$this->plugin, 'dispatchSchedulingResponses'], 100], |
|
74 | + ]; |
|
75 | + $this->server->expects($this->exactly(count($calls))) |
|
76 | + ->method('on') |
|
77 | + ->willReturnCallback(function () use (&$calls): void { |
|
78 | + $expected = array_shift($calls); |
|
79 | + $this->assertEquals($expected, func_get_args()); |
|
80 | + }); |
|
81 | + |
|
82 | + $this->plugin->initialize($this->server); |
|
83 | + } |
|
84 | + |
|
85 | + public function testGetAddressesForPrincipal(): void { |
|
86 | + $href = $this->createMock(Href::class); |
|
87 | + $href |
|
88 | + ->expects($this->once()) |
|
89 | + ->method('getHrefs') |
|
90 | + ->willReturn(['[email protected]', '[email protected]']); |
|
91 | + $this->server |
|
92 | + ->expects($this->once()) |
|
93 | + ->method('getProperties') |
|
94 | + ->with( |
|
95 | + 'MyPrincipal', |
|
96 | + [ |
|
97 | + '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set', |
|
98 | + ] |
|
99 | + ) |
|
100 | + ->willReturn([ |
|
101 | + '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set' => $href |
|
102 | + ]); |
|
103 | + |
|
104 | + $result = $this->invokePrivate($this->plugin, 'getAddressesForPrincipal', ['MyPrincipal']); |
|
105 | + $this->assertSame(['[email protected]', '[email protected]'], $result); |
|
106 | + } |
|
107 | + |
|
108 | + public function testGetAddressesForPrincipalEmpty(): void { |
|
109 | + $this->server |
|
110 | + ->expects($this->once()) |
|
111 | + ->method('getProperties') |
|
112 | + ->with( |
|
113 | + 'MyPrincipal', |
|
114 | + [ |
|
115 | + '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set', |
|
116 | + ] |
|
117 | + ) |
|
118 | + ->willReturn(null); |
|
119 | + |
|
120 | + $result = $this->invokePrivate($this->plugin, 'getAddressesForPrincipal', ['MyPrincipal']); |
|
121 | + $this->assertSame([], $result); |
|
122 | + } |
|
123 | + |
|
124 | + public function testStripOffMailTo(): void { |
|
125 | + $this->assertEquals('[email protected]', $this->invokePrivate($this->plugin, 'stripOffMailTo', ['[email protected]'])); |
|
126 | + $this->assertEquals('[email protected]', $this->invokePrivate($this->plugin, 'stripOffMailTo', ['mailto:[email protected]'])); |
|
127 | + } |
|
128 | + |
|
129 | + public function testGetAttendeeRSVP(): void { |
|
130 | + $property1 = $this->createMock(CalAddress::class); |
|
131 | + $parameter1 = $this->createMock(Parameter::class); |
|
132 | + $property1->expects($this->once()) |
|
133 | + ->method('offsetGet') |
|
134 | + ->with('RSVP') |
|
135 | + ->willReturn($parameter1); |
|
136 | + $parameter1->expects($this->once()) |
|
137 | + ->method('getValue') |
|
138 | + ->with() |
|
139 | + ->willReturn('TRUE'); |
|
140 | + |
|
141 | + $property2 = $this->createMock(CalAddress::class); |
|
142 | + $parameter2 = $this->createMock(Parameter::class); |
|
143 | + $property2->expects($this->once()) |
|
144 | + ->method('offsetGet') |
|
145 | + ->with('RSVP') |
|
146 | + ->willReturn($parameter2); |
|
147 | + $parameter2->expects($this->once()) |
|
148 | + ->method('getValue') |
|
149 | + ->with() |
|
150 | + ->willReturn('FALSE'); |
|
151 | + |
|
152 | + $property3 = $this->createMock(CalAddress::class); |
|
153 | + $property3->expects($this->once()) |
|
154 | + ->method('offsetGet') |
|
155 | + ->with('RSVP') |
|
156 | + ->willReturn(null); |
|
157 | + |
|
158 | + $this->assertTrue($this->invokePrivate($this->plugin, 'getAttendeeRSVP', [$property1])); |
|
159 | + $this->assertFalse($this->invokePrivate($this->plugin, 'getAttendeeRSVP', [$property2])); |
|
160 | + $this->assertFalse($this->invokePrivate($this->plugin, 'getAttendeeRSVP', [$property3])); |
|
161 | + } |
|
162 | + |
|
163 | + public static function propFindDefaultCalendarUrlProvider(): array { |
|
164 | + return [ |
|
165 | + [ |
|
166 | + 'principals/users/myuser', |
|
167 | + 'calendars/myuser', |
|
168 | + false, |
|
169 | + CalDavBackend::PERSONAL_CALENDAR_URI, |
|
170 | + CalDavBackend::PERSONAL_CALENDAR_NAME, |
|
171 | + true |
|
172 | + ], |
|
173 | + [ |
|
174 | + 'principals/users/myuser', |
|
175 | + 'calendars/myuser', |
|
176 | + false, |
|
177 | + CalDavBackend::PERSONAL_CALENDAR_URI, |
|
178 | + CalDavBackend::PERSONAL_CALENDAR_NAME, |
|
179 | + true, |
|
180 | + true |
|
181 | + ], |
|
182 | + [ |
|
183 | + 'principals/users/myuser', |
|
184 | + 'calendars/myuser', |
|
185 | + false, |
|
186 | + CalDavBackend::PERSONAL_CALENDAR_URI, |
|
187 | + CalDavBackend::PERSONAL_CALENDAR_NAME, |
|
188 | + false, |
|
189 | + false, |
|
190 | + true |
|
191 | + ], |
|
192 | + [ |
|
193 | + 'principals/users/myuser', |
|
194 | + 'calendars/myuser', |
|
195 | + false, |
|
196 | + CalDavBackend::PERSONAL_CALENDAR_URI, |
|
197 | + CalDavBackend::PERSONAL_CALENDAR_NAME, |
|
198 | + false |
|
199 | + ], |
|
200 | + [ |
|
201 | + 'principals/users/myuser', |
|
202 | + null, |
|
203 | + false, |
|
204 | + CalDavBackend::PERSONAL_CALENDAR_URI, |
|
205 | + CalDavBackend::PERSONAL_CALENDAR_NAME, |
|
206 | + true |
|
207 | + ], |
|
208 | + [ |
|
209 | + 'principals/users/myuser', |
|
210 | + 'calendars/myuser', |
|
211 | + false, |
|
212 | + CalDavBackend::PERSONAL_CALENDAR_URI, |
|
213 | + CalDavBackend::PERSONAL_CALENDAR_NAME, |
|
214 | + true, |
|
215 | + false, |
|
216 | + false, |
|
217 | + false, |
|
218 | + ], |
|
219 | + [ |
|
220 | + 'principals/users/myuser', |
|
221 | + 'calendars/myuser', |
|
222 | + false, |
|
223 | + 'my_other_calendar', |
|
224 | + 'My Other Calendar', |
|
225 | + true |
|
226 | + ], |
|
227 | + [ |
|
228 | + 'principals/calendar-resources', |
|
229 | + 'system-calendars/calendar-resources/myuser', |
|
230 | + true, |
|
231 | + CalDavBackend::RESOURCE_BOOKING_CALENDAR_URI, |
|
232 | + CalDavBackend::RESOURCE_BOOKING_CALENDAR_NAME, |
|
233 | + true |
|
234 | + ], |
|
235 | + [ |
|
236 | + 'principals/calendar-resources', |
|
237 | + 'system-calendars/calendar-resources/myuser', |
|
238 | + true, |
|
239 | + CalDavBackend::RESOURCE_BOOKING_CALENDAR_URI, |
|
240 | + CalDavBackend::RESOURCE_BOOKING_CALENDAR_NAME, |
|
241 | + false |
|
242 | + ], |
|
243 | + [ |
|
244 | + 'principals/something-else', |
|
245 | + 'calendars/whatever', |
|
246 | + false, |
|
247 | + CalDavBackend::PERSONAL_CALENDAR_URI, |
|
248 | + CalDavBackend::PERSONAL_CALENDAR_NAME, |
|
249 | + true |
|
250 | + ], |
|
251 | + ]; |
|
252 | + } |
|
253 | + |
|
254 | + #[\PHPUnit\Framework\Attributes\DataProvider('propFindDefaultCalendarUrlProvider')] |
|
255 | + public function testPropFindDefaultCalendarUrl(string $principalUri, ?string $calendarHome, bool $isResource, string $calendarUri, string $displayName, bool $exists, bool $deleted = false, bool $hasExistingCalendars = false, bool $propertiesForPath = true): void { |
|
256 | + $propFind = new PropFind( |
|
257 | + $principalUri, |
|
258 | + [ |
|
259 | + Plugin::SCHEDULE_DEFAULT_CALENDAR_URL |
|
260 | + ], |
|
261 | + 0 |
|
262 | + ); |
|
263 | + /** @var IPrincipal&MockObject $node */ |
|
264 | + $node = $this->getMockBuilder(IPrincipal::class) |
|
265 | + ->disableOriginalConstructor() |
|
266 | + ->getMock(); |
|
267 | + |
|
268 | + $node->expects($this->once()) |
|
269 | + ->method('getPrincipalUrl') |
|
270 | + ->with() |
|
271 | + ->willReturn($principalUri); |
|
272 | + |
|
273 | + $calDAVPlugin = $this->getMockBuilder(CalDAVPlugin::class) |
|
274 | + ->disableOriginalConstructor() |
|
275 | + ->getMock(); |
|
276 | + |
|
277 | + $calDAVPlugin->expects($this->once()) |
|
278 | + ->method('getCalendarHomeForPrincipal') |
|
279 | + ->willReturn($calendarHome); |
|
280 | + |
|
281 | + $this->server->expects($this->once()) |
|
282 | + ->method('getPlugin') |
|
283 | + ->with('caldav') |
|
284 | + ->willReturn($calDAVPlugin); |
|
285 | + if (!$calendarHome) { |
|
286 | + $this->plugin->propFindDefaultCalendarUrl($propFind, $node); |
|
287 | + |
|
288 | + $this->assertNull($propFind->get(Plugin::SCHEDULE_DEFAULT_CALENDAR_URL)); |
|
289 | + return; |
|
290 | + } |
|
291 | + if ($principalUri === 'principals/something-else') { |
|
292 | + $this->plugin->propFindDefaultCalendarUrl($propFind, $node); |
|
293 | + |
|
294 | + $this->assertNull($propFind->get(Plugin::SCHEDULE_DEFAULT_CALENDAR_URL)); |
|
295 | + return; |
|
296 | + } |
|
297 | + |
|
298 | + if (!$isResource) { |
|
299 | + $this->config->expects($this->once()) |
|
300 | + ->method('getUserValue') |
|
301 | + ->with('myuser', 'dav', 'defaultCalendar', CalDavBackend::PERSONAL_CALENDAR_URI) |
|
302 | + ->willReturn($calendarUri); |
|
303 | + } |
|
304 | + |
|
305 | + $calendarHomeObject = $this->createMock(CalendarHome::class); |
|
306 | + $calendarHomeObject->expects($this->once()) |
|
307 | + ->method('childExists') |
|
308 | + ->with($calendarUri) |
|
309 | + ->willReturn($exists); |
|
310 | + |
|
311 | + if ($exists) { |
|
312 | + $calendar = $this->createMock(Calendar::class); |
|
313 | + $calendar->expects($this->once())->method('isDeleted')->willReturn($deleted); |
|
314 | + $calendarHomeObject->expects($deleted && !$hasExistingCalendars ? $this->exactly(2) : $this->once())->method('getChild')->with($calendarUri)->willReturn($calendar); |
|
315 | + } |
|
316 | + |
|
317 | + $calendarBackend = $this->createMock(CalDavBackend::class); |
|
318 | + $calendarUri = $hasExistingCalendars ? 'custom' : $calendarUri; |
|
319 | + $displayName = $hasExistingCalendars ? 'Custom Calendar' : $displayName; |
|
320 | + |
|
321 | + $existingCalendars = $hasExistingCalendars ? [ |
|
322 | + new Calendar( |
|
323 | + $calendarBackend, |
|
324 | + ['uri' => 'deleted', '{DAV:}displayname' => 'A deleted calendar', TrashbinPlugin::PROPERTY_DELETED_AT => 42], |
|
325 | + $this->createMock(IL10N::class), |
|
326 | + $this->config, |
|
327 | + $this->createMock(LoggerInterface::class) |
|
328 | + ), |
|
329 | + new Calendar( |
|
330 | + $calendarBackend, |
|
331 | + ['uri' => $calendarUri, '{DAV:}displayname' => $displayName], |
|
332 | + $this->createMock(IL10N::class), |
|
333 | + $this->config, |
|
334 | + $this->createMock(LoggerInterface::class) |
|
335 | + ) |
|
336 | + ] : []; |
|
337 | + |
|
338 | + if (!$exists || $deleted) { |
|
339 | + if (!$hasExistingCalendars) { |
|
340 | + $calendarBackend->expects($this->once()) |
|
341 | + ->method('createCalendar') |
|
342 | + ->with($principalUri, $calendarUri, [ |
|
343 | + '{DAV:}displayname' => $displayName, |
|
344 | + ]); |
|
345 | + |
|
346 | + $calendarHomeObject->expects($this->exactly($deleted ? 2 : 1)) |
|
347 | + ->method('getCalDAVBackend') |
|
348 | + ->with() |
|
349 | + ->willReturn($calendarBackend); |
|
350 | + } |
|
351 | + |
|
352 | + if (!$isResource) { |
|
353 | + $calendarHomeObject->expects($this->once()) |
|
354 | + ->method('getChildren') |
|
355 | + ->with() |
|
356 | + ->willReturn($existingCalendars); |
|
357 | + } |
|
358 | + } |
|
359 | + |
|
360 | + /** @var Tree&MockObject $tree */ |
|
361 | + $tree = $this->createMock(Tree::class); |
|
362 | + $tree->expects($this->once()) |
|
363 | + ->method('getNodeForPath') |
|
364 | + ->with($calendarHome) |
|
365 | + ->willReturn($calendarHomeObject); |
|
366 | + $this->server->tree = $tree; |
|
367 | + |
|
368 | + $properties = $propertiesForPath ? [ |
|
369 | + ['href' => '/remote.php/dav/' . $calendarHome . '/' . $calendarUri] |
|
370 | + ] : []; |
|
371 | + |
|
372 | + $this->server->expects($this->once()) |
|
373 | + ->method('getPropertiesForPath') |
|
374 | + ->with($calendarHome . '/' . $calendarUri, [], 1) |
|
375 | + ->willReturn($properties); |
|
376 | + |
|
377 | + $this->plugin->propFindDefaultCalendarUrl($propFind, $node); |
|
378 | + |
|
379 | + if (!$propertiesForPath) { |
|
380 | + $this->assertNull($propFind->get(Plugin::SCHEDULE_DEFAULT_CALENDAR_URL)); |
|
381 | + return; |
|
382 | + } |
|
383 | + |
|
384 | + /** @var LocalHref $result */ |
|
385 | + $result = $propFind->get(Plugin::SCHEDULE_DEFAULT_CALENDAR_URL); |
|
386 | + $this->assertEquals('/remote.php/dav/' . $calendarHome . '/' . $calendarUri, $result->getHref()); |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Test Calendar Event Creation for Personal Calendar |
|
391 | + * |
|
392 | + * Should generate 2 messages for attendees User 2 and User External |
|
393 | + */ |
|
394 | + public function testCalendarObjectChangePersonalCalendarCreate(): void { |
|
395 | + |
|
396 | + // define place holders |
|
397 | + /** @var Message[] $iTipMessages */ |
|
398 | + $iTipMessages = []; |
|
399 | + // construct calendar node |
|
400 | + $calendarNode = new Calendar( |
|
401 | + $this->createMock(BackendInterface::class), |
|
402 | + [ |
|
403 | + 'uri' => 'personal', |
|
404 | + 'principaluri' => 'principals/users/user1', |
|
405 | + '{DAV:}displayname' => 'Calendar Shared By User1', |
|
406 | + ], |
|
407 | + $this->createMock(IL10N::class), |
|
408 | + $this->config, |
|
409 | + $this->logger |
|
410 | + ); |
|
411 | + // construct server request object |
|
412 | + $request = new Request( |
|
413 | + 'PUT', |
|
414 | + '/remote.php/dav/calendars/user1/personal/B0DC78AE-6DD7-47E3-80BE-89F23E6D5383.ics' |
|
415 | + ); |
|
416 | + $request->setBaseUrl('/remote.php/dav/'); |
|
417 | + // construct server response object |
|
418 | + $response = new Response(); |
|
419 | + // construct server tree object |
|
420 | + $tree = $this->createMock(Tree::class); |
|
421 | + $tree->expects($this->once()) |
|
422 | + ->method('getNodeForPath') |
|
423 | + ->with('calendars/user1/personal') |
|
424 | + ->willReturn($calendarNode); |
|
425 | + // construct server properties and returns |
|
426 | + $this->server->httpRequest = $request; |
|
427 | + $this->server->tree = $tree; |
|
428 | + $this->server->expects($this->exactly(1))->method('getProperties') |
|
429 | + ->willReturnMap([ |
|
430 | + [ |
|
431 | + 'principals/users/user1', |
|
432 | + ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set'], |
|
433 | + ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set' => new LocalHref( |
|
434 | + ['mailto:[email protected]','/remote.php/dav/principals/users/user1/'] |
|
435 | + )] |
|
436 | + ] |
|
437 | + ]); |
|
438 | + $this->server->expects($this->exactly(2))->method('emit')->willReturnCallback( |
|
439 | + function (string $eventName, array $arguments = [], ?callable $continueCallBack = null) use (&$iTipMessages) { |
|
440 | + $this->assertEquals('schedule', $eventName); |
|
441 | + $this->assertCount(1, $arguments); |
|
442 | + $iTipMessages[] = $arguments[0]; |
|
443 | + return true; |
|
444 | + } |
|
445 | + ); |
|
446 | + // construct calendar with a 1 hour event and same start/end time zones |
|
447 | + $vCalendar = new VCalendar(); |
|
448 | + $vEvent = $vCalendar->add('VEVENT', []); |
|
449 | + $vEvent->UID->setValue('96a0e6b1-d886-4a55-a60d-152b31401dcc'); |
|
450 | + $vEvent->add('DTSTART', '20240701T080000', ['TZID' => 'America/Toronto']); |
|
451 | + $vEvent->add('DTEND', '20240701T090000', ['TZID' => 'America/Toronto']); |
|
452 | + $vEvent->add('SUMMARY', 'Test Recurring Event'); |
|
453 | + $vEvent->add('ORGANIZER', 'mailto:[email protected]', ['CN' => 'User One']); |
|
454 | + $vEvent->add('ATTENDEE', 'mailto:[email protected]', [ |
|
455 | + 'CN' => 'User Two', |
|
456 | + 'CUTYPE' => 'INDIVIDUAL', |
|
457 | + 'PARTSTAT' => 'NEEDS-ACTION', |
|
458 | + 'ROLE' => 'REQ-PARTICIPANT', |
|
459 | + 'RSVP' => 'TRUE' |
|
460 | + ]); |
|
461 | + $vEvent->add('ATTENDEE', 'mailto:[email protected]', [ |
|
462 | + 'CN' => 'User External', |
|
463 | + 'CUTYPE' => 'INDIVIDUAL', |
|
464 | + 'PARTSTAT' => 'NEEDS-ACTION', |
|
465 | + 'ROLE' => 'REQ-PARTICIPANT', |
|
466 | + 'RSVP' => 'TRUE' |
|
467 | + ]); |
|
468 | + // define flags |
|
469 | + $newFlag = true; |
|
470 | + $modifiedFlag = false; |
|
471 | + // execute method |
|
472 | + $this->plugin->calendarObjectChange( |
|
473 | + $request, |
|
474 | + $response, |
|
475 | + $vCalendar, |
|
476 | + 'calendars/user1/personal', |
|
477 | + $modifiedFlag, |
|
478 | + $newFlag |
|
479 | + ); |
|
480 | + // test for correct iTip message count |
|
481 | + $this->assertCount(2, $iTipMessages); |
|
482 | + // test for Sharer Attendee |
|
483 | + $this->assertEquals('mailto:[email protected]', $iTipMessages[0]->sender); |
|
484 | + $this->assertEquals('mailto:[email protected]', $iTipMessages[0]->recipient); |
|
485 | + $this->assertTrue($iTipMessages[0]->significantChange); |
|
486 | + // test for External Attendee |
|
487 | + $this->assertEquals('mailto:[email protected]', $iTipMessages[1]->sender); |
|
488 | + $this->assertEquals('mailto:[email protected]', $iTipMessages[1]->recipient); |
|
489 | + $this->assertTrue($iTipMessages[1]->significantChange); |
|
490 | + |
|
491 | + } |
|
492 | + |
|
493 | + /** |
|
494 | + * Test Calendar Event Creation for Shared Calendar as Sharer/Owner |
|
495 | + * |
|
496 | + * Should generate 3 messages for attendees User 2 (Sharee), User 3 (Non-Sharee) and User External |
|
497 | + */ |
|
498 | + public function testCalendarObjectChangeSharedCalendarSharerCreate(): void { |
|
499 | + |
|
500 | + // define place holders |
|
501 | + /** @var Message[] $iTipMessages */ |
|
502 | + $iTipMessages = []; |
|
503 | + // construct calendar node |
|
504 | + $calendarNode = new Calendar( |
|
505 | + $this->createMock(BackendInterface::class), |
|
506 | + [ |
|
507 | + 'uri' => 'calendar_shared_by_user1', |
|
508 | + 'principaluri' => 'principals/users/user1', |
|
509 | + '{DAV:}displayname' => 'Calendar Shared By User1', |
|
510 | + '{http://owncloud.org/ns}owner-principal' => 'principals/users/user1' |
|
511 | + ], |
|
512 | + $this->createMock(IL10N::class), |
|
513 | + $this->config, |
|
514 | + $this->logger |
|
515 | + ); |
|
516 | + // construct server request object |
|
517 | + $request = new Request( |
|
518 | + 'PUT', |
|
519 | + '/remote.php/dav/calendars/user1/calendar_shared_by_user1/B0DC78AE-6DD7-47E3-80BE-89F23E6D5383.ics' |
|
520 | + ); |
|
521 | + $request->setBaseUrl('/remote.php/dav/'); |
|
522 | + // construct server response object |
|
523 | + $response = new Response(); |
|
524 | + // construct server tree object |
|
525 | + $tree = $this->createMock(Tree::class); |
|
526 | + $tree->expects($this->once()) |
|
527 | + ->method('getNodeForPath') |
|
528 | + ->with('calendars/user1/calendar_shared_by_user1') |
|
529 | + ->willReturn($calendarNode); |
|
530 | + // construct server properties and returns |
|
531 | + $this->server->httpRequest = $request; |
|
532 | + $this->server->tree = $tree; |
|
533 | + $this->server->expects($this->exactly(1))->method('getProperties') |
|
534 | + ->willReturnMap([ |
|
535 | + [ |
|
536 | + 'principals/users/user1', |
|
537 | + ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set'], |
|
538 | + ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set' => new LocalHref( |
|
539 | + ['mailto:[email protected]','/remote.php/dav/principals/users/user1/'] |
|
540 | + )] |
|
541 | + ] |
|
542 | + ]); |
|
543 | + $this->server->expects($this->exactly(3))->method('emit')->willReturnCallback( |
|
544 | + function (string $eventName, array $arguments = [], ?callable $continueCallBack = null) use (&$iTipMessages) { |
|
545 | + $this->assertEquals('schedule', $eventName); |
|
546 | + $this->assertCount(1, $arguments); |
|
547 | + $iTipMessages[] = $arguments[0]; |
|
548 | + return true; |
|
549 | + } |
|
550 | + ); |
|
551 | + // construct calendar with a 1 hour event and same start/end time zones |
|
552 | + $vCalendar = new VCalendar(); |
|
553 | + $vEvent = $vCalendar->add('VEVENT', []); |
|
554 | + $vEvent->UID->setValue('96a0e6b1-d886-4a55-a60d-152b31401dcc'); |
|
555 | + $vEvent->add('DTSTART', '20240701T080000', ['TZID' => 'America/Toronto']); |
|
556 | + $vEvent->add('DTEND', '20240701T090000', ['TZID' => 'America/Toronto']); |
|
557 | + $vEvent->add('SUMMARY', 'Test Recurring Event'); |
|
558 | + $vEvent->add('ORGANIZER', 'mailto:[email protected]', ['CN' => 'User One']); |
|
559 | + $vEvent->add('ATTENDEE', 'mailto:[email protected]', [ |
|
560 | + 'CN' => 'User Two', |
|
561 | + 'CUTYPE' => 'INDIVIDUAL', |
|
562 | + 'PARTSTAT' => 'NEEDS-ACTION', |
|
563 | + 'ROLE' => 'REQ-PARTICIPANT', |
|
564 | + 'RSVP' => 'TRUE' |
|
565 | + ]); |
|
566 | + $vEvent->add('ATTENDEE', 'mailto:[email protected]', [ |
|
567 | + 'CN' => 'User Three', |
|
568 | + 'CUTYPE' => 'INDIVIDUAL', |
|
569 | + 'PARTSTAT' => 'NEEDS-ACTION', |
|
570 | + 'ROLE' => 'REQ-PARTICIPANT', |
|
571 | + 'RSVP' => 'TRUE' |
|
572 | + ]); |
|
573 | + $vEvent->add('ATTENDEE', 'mailto:[email protected]', [ |
|
574 | + 'CN' => 'User External', |
|
575 | + 'CUTYPE' => 'INDIVIDUAL', |
|
576 | + 'PARTSTAT' => 'NEEDS-ACTION', |
|
577 | + 'ROLE' => 'REQ-PARTICIPANT', |
|
578 | + 'RSVP' => 'TRUE' |
|
579 | + ]); |
|
580 | + // define flags |
|
581 | + $newFlag = true; |
|
582 | + $modifiedFlag = false; |
|
583 | + // execute method |
|
584 | + $this->plugin->calendarObjectChange( |
|
585 | + $request, |
|
586 | + $response, |
|
587 | + $vCalendar, |
|
588 | + 'calendars/user1/calendar_shared_by_user1', |
|
589 | + $modifiedFlag, |
|
590 | + $newFlag |
|
591 | + ); |
|
592 | + // test for correct iTip message count |
|
593 | + $this->assertCount(3, $iTipMessages); |
|
594 | + // test for Sharer Attendee |
|
595 | + $this->assertEquals('mailto:[email protected]', $iTipMessages[0]->sender); |
|
596 | + $this->assertEquals('mailto:[email protected]', $iTipMessages[0]->recipient); |
|
597 | + $this->assertTrue($iTipMessages[0]->significantChange); |
|
598 | + // test for Non Shee Attendee |
|
599 | + $this->assertEquals('mailto:[email protected]', $iTipMessages[1]->sender); |
|
600 | + $this->assertEquals('mailto:[email protected]', $iTipMessages[1]->recipient); |
|
601 | + $this->assertTrue($iTipMessages[1]->significantChange); |
|
602 | + // test for External Attendee |
|
603 | + $this->assertEquals('mailto:[email protected]', $iTipMessages[2]->sender); |
|
604 | + $this->assertEquals('mailto:[email protected]', $iTipMessages[2]->recipient); |
|
605 | + $this->assertTrue($iTipMessages[2]->significantChange); |
|
606 | + |
|
607 | + } |
|
608 | + |
|
609 | + /** |
|
610 | + * Test Calendar Event Creation for Shared Calendar as Shree |
|
611 | + * |
|
612 | + * Should generate 3 messages for attendees User 1 (Sharer/Owner), User 3 (Non-Sharee) and User External |
|
613 | + */ |
|
614 | + public function testCalendarObjectChangeSharedCalendarShreeCreate(): void { |
|
615 | + |
|
616 | + // define place holders |
|
617 | + /** @var Message[] $iTipMessages */ |
|
618 | + $iTipMessages = []; |
|
619 | + // construct calendar node |
|
620 | + $calendarNode = new Calendar( |
|
621 | + $this->createMock(BackendInterface::class), |
|
622 | + [ |
|
623 | + 'uri' => 'calendar_shared_by_user1', |
|
624 | + 'principaluri' => 'principals/users/user2', |
|
625 | + '{DAV:}displayname' => 'Calendar Shared By User1', |
|
626 | + '{http://owncloud.org/ns}owner-principal' => 'principals/users/user1' |
|
627 | + ], |
|
628 | + $this->createMock(IL10N::class), |
|
629 | + $this->config, |
|
630 | + $this->logger |
|
631 | + ); |
|
632 | + // construct server request object |
|
633 | + $request = new Request( |
|
634 | + 'PUT', |
|
635 | + '/remote.php/dav/calendars/user2/calendar_shared_by_user1/B0DC78AE-6DD7-47E3-80BE-89F23E6D5383.ics' |
|
636 | + ); |
|
637 | + $request->setBaseUrl('/remote.php/dav/'); |
|
638 | + // construct server response object |
|
639 | + $response = new Response(); |
|
640 | + // construct server tree object |
|
641 | + $tree = $this->createMock(Tree::class); |
|
642 | + $tree->expects($this->once()) |
|
643 | + ->method('getNodeForPath') |
|
644 | + ->with('calendars/user2/calendar_shared_by_user1') |
|
645 | + ->willReturn($calendarNode); |
|
646 | + // construct server properties and returns |
|
647 | + $this->server->httpRequest = $request; |
|
648 | + $this->server->tree = $tree; |
|
649 | + $this->server->expects($this->exactly(2))->method('getProperties') |
|
650 | + ->willReturnMap([ |
|
651 | + [ |
|
652 | + 'principals/users/user1', |
|
653 | + ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set'], |
|
654 | + ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set' => new LocalHref( |
|
655 | + ['mailto:[email protected]','/remote.php/dav/principals/users/user1/'] |
|
656 | + )] |
|
657 | + ], |
|
658 | + [ |
|
659 | + 'principals/users/user2', |
|
660 | + ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set'], |
|
661 | + ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set' => new LocalHref( |
|
662 | + ['mailto:[email protected]','/remote.php/dav/principals/users/user2/'] |
|
663 | + )] |
|
664 | + ] |
|
665 | + ]); |
|
666 | + $this->server->expects($this->exactly(3))->method('emit')->willReturnCallback( |
|
667 | + function (string $eventName, array $arguments = [], ?callable $continueCallBack = null) use (&$iTipMessages) { |
|
668 | + $this->assertEquals('schedule', $eventName); |
|
669 | + $this->assertCount(1, $arguments); |
|
670 | + $iTipMessages[] = $arguments[0]; |
|
671 | + return true; |
|
672 | + } |
|
673 | + ); |
|
674 | + // construct calendar with a 1 hour event and same start/end time zones |
|
675 | + $vCalendar = new VCalendar(); |
|
676 | + $vEvent = $vCalendar->add('VEVENT', []); |
|
677 | + $vEvent->UID->setValue('96a0e6b1-d886-4a55-a60d-152b31401dcc'); |
|
678 | + $vEvent->add('DTSTART', '20240701T080000', ['TZID' => 'America/Toronto']); |
|
679 | + $vEvent->add('DTEND', '20240701T090000', ['TZID' => 'America/Toronto']); |
|
680 | + $vEvent->add('SUMMARY', 'Test Recurring Event'); |
|
681 | + $vEvent->add('ORGANIZER', 'mailto:[email protected]', ['CN' => 'User Two']); |
|
682 | + $vEvent->add('ATTENDEE', 'mailto:[email protected]', [ |
|
683 | + 'CN' => 'User One', |
|
684 | + 'CUTYPE' => 'INDIVIDUAL', |
|
685 | + 'PARTSTAT' => 'NEEDS-ACTION', |
|
686 | + 'ROLE' => 'REQ-PARTICIPANT', |
|
687 | + 'RSVP' => 'TRUE' |
|
688 | + ]); |
|
689 | + $vEvent->add('ATTENDEE', 'mailto:[email protected]', [ |
|
690 | + 'CN' => 'User Three', |
|
691 | + 'CUTYPE' => 'INDIVIDUAL', |
|
692 | + 'PARTSTAT' => 'NEEDS-ACTION', |
|
693 | + 'ROLE' => 'REQ-PARTICIPANT', |
|
694 | + 'RSVP' => 'TRUE' |
|
695 | + ]); |
|
696 | + $vEvent->add('ATTENDEE', 'mailto:[email protected]', [ |
|
697 | + 'CN' => 'User External', |
|
698 | + 'CUTYPE' => 'INDIVIDUAL', |
|
699 | + 'PARTSTAT' => 'NEEDS-ACTION', |
|
700 | + 'ROLE' => 'REQ-PARTICIPANT', |
|
701 | + 'RSVP' => 'TRUE' |
|
702 | + ]); |
|
703 | + // define flags |
|
704 | + $newFlag = true; |
|
705 | + $modifiedFlag = false; |
|
706 | + // execute method |
|
707 | + $this->plugin->calendarObjectChange( |
|
708 | + $request, |
|
709 | + $response, |
|
710 | + $vCalendar, |
|
711 | + 'calendars/user2/calendar_shared_by_user1', |
|
712 | + $modifiedFlag, |
|
713 | + $newFlag |
|
714 | + ); |
|
715 | + // test for correct iTip message count |
|
716 | + $this->assertCount(3, $iTipMessages); |
|
717 | + // test for Sharer Attendee |
|
718 | + $this->assertEquals('mailto:[email protected]', $iTipMessages[0]->sender); |
|
719 | + $this->assertEquals('mailto:[email protected]', $iTipMessages[0]->recipient); |
|
720 | + $this->assertTrue($iTipMessages[0]->significantChange); |
|
721 | + // test for Non Shee Attendee |
|
722 | + $this->assertEquals('mailto:[email protected]', $iTipMessages[1]->sender); |
|
723 | + $this->assertEquals('mailto:[email protected]', $iTipMessages[1]->recipient); |
|
724 | + $this->assertTrue($iTipMessages[1]->significantChange); |
|
725 | + // test for External Attendee |
|
726 | + $this->assertEquals('mailto:[email protected]', $iTipMessages[2]->sender); |
|
727 | + $this->assertEquals('mailto:[email protected]', $iTipMessages[2]->recipient); |
|
728 | + $this->assertTrue($iTipMessages[2]->significantChange); |
|
729 | + |
|
730 | + } |
|
731 | + |
|
732 | + /** |
|
733 | + * Test Calendar Event Creation with iTip and iMip disabled |
|
734 | + * |
|
735 | + * Should generate 2 messages for attendees User 2 and User External |
|
736 | + */ |
|
737 | + public function testCalendarObjectChangeWithSchedulingDisabled(): void { |
|
738 | + // construct server request |
|
739 | + $request = new Request( |
|
740 | + 'PUT', |
|
741 | + '/remote.php/dav/calendars/user1/personal/B0DC78AE-6DD7-47E3-80BE-89F23E6D5383.ics', |
|
742 | + ['x-nc-scheduling' => 'false'] |
|
743 | + ); |
|
744 | + $request->setBaseUrl('/remote.php/dav/'); |
|
745 | + // construct server response |
|
746 | + $response = new Response(); |
|
747 | + // construct server tree |
|
748 | + $tree = $this->createMock(Tree::class); |
|
749 | + $tree->expects($this->never()) |
|
750 | + ->method('getNodeForPath'); |
|
751 | + // construct server properties and returns |
|
752 | + $this->server->httpRequest = $request; |
|
753 | + $this->server->tree = $tree; |
|
754 | + // construct empty calendar event |
|
755 | + $vCalendar = new VCalendar(); |
|
756 | + $vEvent = $vCalendar->add('VEVENT', []); |
|
757 | + // define flags |
|
758 | + $newFlag = true; |
|
759 | + $modifiedFlag = false; |
|
760 | + // execute method |
|
761 | + $this->plugin->calendarObjectChange( |
|
762 | + $request, |
|
763 | + $response, |
|
764 | + $vCalendar, |
|
765 | + 'calendars/user1/personal', |
|
766 | + $modifiedFlag, |
|
767 | + $newFlag |
|
768 | + ); |
|
769 | + } |
|
770 | 770 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | ]; |
75 | 75 | $this->server->expects($this->exactly(count($calls))) |
76 | 76 | ->method('on') |
77 | - ->willReturnCallback(function () use (&$calls): void { |
|
77 | + ->willReturnCallback(function() use (&$calls): void { |
|
78 | 78 | $expected = array_shift($calls); |
79 | 79 | $this->assertEquals($expected, func_get_args()); |
80 | 80 | }); |
@@ -366,12 +366,12 @@ discard block |
||
366 | 366 | $this->server->tree = $tree; |
367 | 367 | |
368 | 368 | $properties = $propertiesForPath ? [ |
369 | - ['href' => '/remote.php/dav/' . $calendarHome . '/' . $calendarUri] |
|
369 | + ['href' => '/remote.php/dav/'.$calendarHome.'/'.$calendarUri] |
|
370 | 370 | ] : []; |
371 | 371 | |
372 | 372 | $this->server->expects($this->once()) |
373 | 373 | ->method('getPropertiesForPath') |
374 | - ->with($calendarHome . '/' . $calendarUri, [], 1) |
|
374 | + ->with($calendarHome.'/'.$calendarUri, [], 1) |
|
375 | 375 | ->willReturn($properties); |
376 | 376 | |
377 | 377 | $this->plugin->propFindDefaultCalendarUrl($propFind, $node); |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | |
384 | 384 | /** @var LocalHref $result */ |
385 | 385 | $result = $propFind->get(Plugin::SCHEDULE_DEFAULT_CALENDAR_URL); |
386 | - $this->assertEquals('/remote.php/dav/' . $calendarHome . '/' . $calendarUri, $result->getHref()); |
|
386 | + $this->assertEquals('/remote.php/dav/'.$calendarHome.'/'.$calendarUri, $result->getHref()); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
@@ -431,12 +431,12 @@ discard block |
||
431 | 431 | 'principals/users/user1', |
432 | 432 | ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set'], |
433 | 433 | ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set' => new LocalHref( |
434 | - ['mailto:[email protected]','/remote.php/dav/principals/users/user1/'] |
|
434 | + ['mailto:[email protected]', '/remote.php/dav/principals/users/user1/'] |
|
435 | 435 | )] |
436 | 436 | ] |
437 | 437 | ]); |
438 | 438 | $this->server->expects($this->exactly(2))->method('emit')->willReturnCallback( |
439 | - function (string $eventName, array $arguments = [], ?callable $continueCallBack = null) use (&$iTipMessages) { |
|
439 | + function(string $eventName, array $arguments = [], ?callable $continueCallBack = null) use (&$iTipMessages) { |
|
440 | 440 | $this->assertEquals('schedule', $eventName); |
441 | 441 | $this->assertCount(1, $arguments); |
442 | 442 | $iTipMessages[] = $arguments[0]; |
@@ -536,12 +536,12 @@ discard block |
||
536 | 536 | 'principals/users/user1', |
537 | 537 | ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set'], |
538 | 538 | ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set' => new LocalHref( |
539 | - ['mailto:[email protected]','/remote.php/dav/principals/users/user1/'] |
|
539 | + ['mailto:[email protected]', '/remote.php/dav/principals/users/user1/'] |
|
540 | 540 | )] |
541 | 541 | ] |
542 | 542 | ]); |
543 | 543 | $this->server->expects($this->exactly(3))->method('emit')->willReturnCallback( |
544 | - function (string $eventName, array $arguments = [], ?callable $continueCallBack = null) use (&$iTipMessages) { |
|
544 | + function(string $eventName, array $arguments = [], ?callable $continueCallBack = null) use (&$iTipMessages) { |
|
545 | 545 | $this->assertEquals('schedule', $eventName); |
546 | 546 | $this->assertCount(1, $arguments); |
547 | 547 | $iTipMessages[] = $arguments[0]; |
@@ -652,19 +652,19 @@ discard block |
||
652 | 652 | 'principals/users/user1', |
653 | 653 | ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set'], |
654 | 654 | ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set' => new LocalHref( |
655 | - ['mailto:[email protected]','/remote.php/dav/principals/users/user1/'] |
|
655 | + ['mailto:[email protected]', '/remote.php/dav/principals/users/user1/'] |
|
656 | 656 | )] |
657 | 657 | ], |
658 | 658 | [ |
659 | 659 | 'principals/users/user2', |
660 | 660 | ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set'], |
661 | 661 | ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set' => new LocalHref( |
662 | - ['mailto:[email protected]','/remote.php/dav/principals/users/user2/'] |
|
662 | + ['mailto:[email protected]', '/remote.php/dav/principals/users/user2/'] |
|
663 | 663 | )] |
664 | 664 | ] |
665 | 665 | ]); |
666 | 666 | $this->server->expects($this->exactly(3))->method('emit')->willReturnCallback( |
667 | - function (string $eventName, array $arguments = [], ?callable $continueCallBack = null) use (&$iTipMessages) { |
|
667 | + function(string $eventName, array $arguments = [], ?callable $continueCallBack = null) use (&$iTipMessages) { |
|
668 | 668 | $this->assertEquals('schedule', $eventName); |
669 | 669 | $this->assertCount(1, $arguments); |
670 | 670 | $iTipMessages[] = $arguments[0]; |