Completed
Push — master ( 5d14f8...2337bd )
by Robin
27:19 queued 16s
created
apps/dav/tests/unit/Comments/EntityCollectionTest.php 1 patch
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -19,103 +19,103 @@
 block discarded – undo
19 19
 use Psr\Log\LoggerInterface;
20 20
 
21 21
 class EntityCollectionTest extends \Test\TestCase {
22
-	protected ICommentsManager&MockObject $commentsManager;
23
-	protected IUserManager&MockObject $userManager;
24
-	protected LoggerInterface&MockObject $logger;
25
-	protected IUserSession&MockObject $userSession;
26
-	protected EntityCollection $collection;
27
-
28
-	protected function setUp(): void {
29
-		parent::setUp();
30
-
31
-		$this->commentsManager = $this->createMock(ICommentsManager::class);
32
-		$this->userManager = $this->createMock(IUserManager::class);
33
-		$this->userSession = $this->createMock(IUserSession::class);
34
-		$this->logger = $this->createMock(LoggerInterface::class);
35
-
36
-		$this->collection = new EntityCollection(
37
-			'19',
38
-			'files',
39
-			$this->commentsManager,
40
-			$this->userManager,
41
-			$this->userSession,
42
-			$this->logger
43
-		);
44
-	}
45
-
46
-	public function testGetId(): void {
47
-		$this->assertSame($this->collection->getId(), '19');
48
-	}
49
-
50
-	public function testGetChild(): void {
51
-		$this->commentsManager->expects($this->once())
52
-			->method('get')
53
-			->with('55')
54
-			->willReturn(
55
-				$this->getMockBuilder(IComment::class)
56
-					->disableOriginalConstructor()
57
-					->getMock()
58
-			);
59
-
60
-		$node = $this->collection->getChild('55');
61
-		$this->assertInstanceOf(CommentNode::class, $node);
62
-	}
63
-
64
-
65
-	public function testGetChildException(): void {
66
-		$this->expectException(\Sabre\DAV\Exception\NotFound::class);
67
-
68
-		$this->commentsManager->expects($this->once())
69
-			->method('get')
70
-			->with('55')
71
-			->willThrowException(new NotFoundException());
72
-
73
-		$this->collection->getChild('55');
74
-	}
75
-
76
-	public function testGetChildren(): void {
77
-		$this->commentsManager->expects($this->once())
78
-			->method('getForObject')
79
-			->with('files', '19')
80
-			->willReturn([
81
-				$this->getMockBuilder(IComment::class)
82
-					->disableOriginalConstructor()
83
-					->getMock()
84
-			]);
85
-
86
-		$result = $this->collection->getChildren();
87
-
88
-		$this->assertCount(1, $result);
89
-		$this->assertInstanceOf(CommentNode::class, $result[0]);
90
-	}
91
-
92
-	public function testFindChildren(): void {
93
-		$dt = new \DateTime('2016-01-10 18:48:00');
94
-		$this->commentsManager->expects($this->once())
95
-			->method('getForObject')
96
-			->with('files', '19', 5, 15, $dt)
97
-			->willReturn([
98
-				$this->getMockBuilder(IComment::class)
99
-					->disableOriginalConstructor()
100
-					->getMock()
101
-			]);
102
-
103
-		$result = $this->collection->findChildren(5, 15, $dt);
104
-
105
-		$this->assertCount(1, $result);
106
-		$this->assertInstanceOf(CommentNode::class, $result[0]);
107
-	}
108
-
109
-	public function testChildExistsTrue(): void {
110
-		$this->assertTrue($this->collection->childExists('44'));
111
-	}
112
-
113
-	public function testChildExistsFalse(): void {
114
-		$this->commentsManager->expects($this->once())
115
-			->method('get')
116
-			->with('44')
117
-			->willThrowException(new NotFoundException());
118
-
119
-		$this->assertFalse($this->collection->childExists('44'));
120
-	}
22
+    protected ICommentsManager&MockObject $commentsManager;
23
+    protected IUserManager&MockObject $userManager;
24
+    protected LoggerInterface&MockObject $logger;
25
+    protected IUserSession&MockObject $userSession;
26
+    protected EntityCollection $collection;
27
+
28
+    protected function setUp(): void {
29
+        parent::setUp();
30
+
31
+        $this->commentsManager = $this->createMock(ICommentsManager::class);
32
+        $this->userManager = $this->createMock(IUserManager::class);
33
+        $this->userSession = $this->createMock(IUserSession::class);
34
+        $this->logger = $this->createMock(LoggerInterface::class);
35
+
36
+        $this->collection = new EntityCollection(
37
+            '19',
38
+            'files',
39
+            $this->commentsManager,
40
+            $this->userManager,
41
+            $this->userSession,
42
+            $this->logger
43
+        );
44
+    }
45
+
46
+    public function testGetId(): void {
47
+        $this->assertSame($this->collection->getId(), '19');
48
+    }
49
+
50
+    public function testGetChild(): void {
51
+        $this->commentsManager->expects($this->once())
52
+            ->method('get')
53
+            ->with('55')
54
+            ->willReturn(
55
+                $this->getMockBuilder(IComment::class)
56
+                    ->disableOriginalConstructor()
57
+                    ->getMock()
58
+            );
59
+
60
+        $node = $this->collection->getChild('55');
61
+        $this->assertInstanceOf(CommentNode::class, $node);
62
+    }
63
+
64
+
65
+    public function testGetChildException(): void {
66
+        $this->expectException(\Sabre\DAV\Exception\NotFound::class);
67
+
68
+        $this->commentsManager->expects($this->once())
69
+            ->method('get')
70
+            ->with('55')
71
+            ->willThrowException(new NotFoundException());
72
+
73
+        $this->collection->getChild('55');
74
+    }
75
+
76
+    public function testGetChildren(): void {
77
+        $this->commentsManager->expects($this->once())
78
+            ->method('getForObject')
79
+            ->with('files', '19')
80
+            ->willReturn([
81
+                $this->getMockBuilder(IComment::class)
82
+                    ->disableOriginalConstructor()
83
+                    ->getMock()
84
+            ]);
85
+
86
+        $result = $this->collection->getChildren();
87
+
88
+        $this->assertCount(1, $result);
89
+        $this->assertInstanceOf(CommentNode::class, $result[0]);
90
+    }
91
+
92
+    public function testFindChildren(): void {
93
+        $dt = new \DateTime('2016-01-10 18:48:00');
94
+        $this->commentsManager->expects($this->once())
95
+            ->method('getForObject')
96
+            ->with('files', '19', 5, 15, $dt)
97
+            ->willReturn([
98
+                $this->getMockBuilder(IComment::class)
99
+                    ->disableOriginalConstructor()
100
+                    ->getMock()
101
+            ]);
102
+
103
+        $result = $this->collection->findChildren(5, 15, $dt);
104
+
105
+        $this->assertCount(1, $result);
106
+        $this->assertInstanceOf(CommentNode::class, $result[0]);
107
+    }
108
+
109
+    public function testChildExistsTrue(): void {
110
+        $this->assertTrue($this->collection->childExists('44'));
111
+    }
112
+
113
+    public function testChildExistsFalse(): void {
114
+        $this->commentsManager->expects($this->once())
115
+            ->method('get')
116
+            ->with('44')
117
+            ->willThrowException(new NotFoundException());
118
+
119
+        $this->assertFalse($this->collection->childExists('44'));
120
+    }
121 121
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/Service/ExampleContactServiceTest.php 1 patch
Indentation   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -24,171 +24,171 @@
 block discarded – undo
24 24
 use Test\TestCase;
25 25
 
26 26
 class ExampleContactServiceTest extends TestCase {
27
-	protected ExampleContactService $service;
28
-	protected CardDavBackend&MockObject $cardDav;
29
-	protected IAppManager&MockObject $appManager;
30
-	protected IAppDataFactory&MockObject $appDataFactory;
31
-	protected LoggerInterface&MockObject $logger;
32
-	protected IAppConfig&MockObject $appConfig;
33
-	protected IAppData&MockObject $appData;
34
-
35
-	protected function setUp(): void {
36
-		parent::setUp();
37
-
38
-		$this->cardDav = $this->createMock(CardDavBackend::class);
39
-		$this->appDataFactory = $this->createMock(IAppDataFactory::class);
40
-		$this->logger = $this->createMock(LoggerInterface::class);
41
-		$this->appConfig = $this->createMock(IAppConfig::class);
42
-
43
-		$this->appData = $this->createMock(IAppData::class);
44
-		$this->appDataFactory->method('get')
45
-			->with('dav')
46
-			->willReturn($this->appData);
47
-
48
-		$this->service = new ExampleContactService(
49
-			$this->appDataFactory,
50
-			$this->appConfig,
51
-			$this->logger,
52
-			$this->cardDav,
53
-		);
54
-	}
55
-
56
-	public function testCreateDefaultContactWithInvalidCard(): void {
57
-		// Invalid vCard missing required FN property
58
-		$vcardContent = "BEGIN:VCARD\nVERSION:3.0\nEND:VCARD";
59
-		$this->appConfig->method('getAppValueBool')
60
-			->with('enableDefaultContact', true)
61
-			->willReturn(true);
62
-		$folder = $this->createMock(ISimpleFolder::class);
63
-		$file = $this->createMock(ISimpleFile::class);
64
-		$file->method('getContent')->willReturn($vcardContent);
65
-		$folder->method('getFile')->willReturn($file);
66
-		$this->appData->method('getFolder')->willReturn($folder);
67
-
68
-		$this->logger->expects($this->once())
69
-			->method('error')
70
-			->with('Default contact is invalid', $this->anything());
71
-
72
-		$this->cardDav->expects($this->never())
73
-			->method('createCard');
74
-
75
-		$this->service->createDefaultContact(123);
76
-	}
77
-
78
-	public function testUidAndRevAreUpdated(): void {
79
-		$originalUid = 'original-uid';
80
-		$originalRev = '20200101T000000Z';
81
-		$vcardContent = "BEGIN:VCARD\nVERSION:3.0\nFN:Test User\nUID:$originalUid\nREV:$originalRev\nEND:VCARD";
82
-
83
-		$this->appConfig->method('getAppValueBool')
84
-			->with('enableDefaultContact', true)
85
-			->willReturn(true);
86
-		$folder = $this->createMock(ISimpleFolder::class);
87
-		$file = $this->createMock(ISimpleFile::class);
88
-		$file->method('getContent')->willReturn($vcardContent);
89
-		$folder->method('getFile')->willReturn($file);
90
-		$this->appData->method('getFolder')->willReturn($folder);
91
-
92
-		$capturedCardData = null;
93
-		$this->cardDav->expects($this->once())
94
-			->method('createCard')
95
-			->with(
96
-				$this->anything(),
97
-				$this->anything(),
98
-				$this->callback(function ($cardData) use (&$capturedCardData) {
99
-					$capturedCardData = $cardData;
100
-					return true;
101
-				}),
102
-				$this->anything()
103
-			)->willReturn(null);
104
-
105
-		$this->service->createDefaultContact(123);
106
-
107
-		$vcard = \Sabre\VObject\Reader::read($capturedCardData);
108
-		$this->assertNotEquals($originalUid, $vcard->UID->getValue());
109
-		$this->assertTrue(Uuid::isValid($vcard->UID->getValue()));
110
-		$this->assertNotEquals($originalRev, $vcard->REV->getValue());
111
-	}
112
-
113
-	public function testDefaultContactFileDoesNotExist(): void {
114
-		$this->appConfig->method('getAppValueBool')
115
-			->with('enableDefaultContact', true)
116
-			->willReturn(true);
117
-		$this->appData->method('getFolder')->willThrowException(new NotFoundException());
118
-
119
-		$this->cardDav->expects($this->never())
120
-			->method('createCard');
121
-
122
-		$this->service->createDefaultContact(123);
123
-	}
124
-
125
-	public function testUidAndRevAreAddedIfMissing(): void {
126
-		$vcardContent = "BEGIN:VCARD\nVERSION:3.0\nFN:Test User\nEND:VCARD";
127
-
128
-		$this->appConfig->method('getAppValueBool')
129
-			->with('enableDefaultContact', true)
130
-			->willReturn(true);
131
-		$folder = $this->createMock(ISimpleFolder::class);
132
-		$file = $this->createMock(ISimpleFile::class);
133
-		$file->method('getContent')->willReturn($vcardContent);
134
-		$folder->method('getFile')->willReturn($file);
135
-		$this->appData->method('getFolder')->willReturn($folder);
136
-
137
-		$capturedCardData = 'new-card-data';
138
-
139
-		$this->cardDav
140
-			->expects($this->once())
141
-			->method('createCard')
142
-			->with(
143
-				$this->anything(),
144
-				$this->anything(),
145
-				$this->callback(function ($cardData) use (&$capturedCardData) {
146
-					$capturedCardData = $cardData;
147
-					return true;
148
-				}),
149
-				$this->anything()
150
-			);
151
-
152
-		$this->service->createDefaultContact(123);
153
-		$vcard = \Sabre\VObject\Reader::read($capturedCardData);
154
-
155
-		$this->assertNotNull($vcard->REV);
156
-		$this->assertNotNull($vcard->UID);
157
-		$this->assertTrue(Uuid::isValid($vcard->UID->getValue()));
158
-	}
159
-
160
-	public function testDefaultContactIsNotCreatedIfEnabled(): void {
161
-		$this->appConfig->method('getAppValueBool')
162
-			->with('enableDefaultContact', true)
163
-			->willReturn(false);
164
-		$this->logger->expects($this->never())
165
-			->method('error');
166
-		$this->cardDav->expects($this->never())
167
-			->method('createCard');
168
-
169
-		$this->service->createDefaultContact(123);
170
-	}
171
-
172
-	public static function provideDefaultContactEnableData(): array {
173
-		return [[true], [false]];
174
-	}
175
-
176
-	#[\PHPUnit\Framework\Attributes\DataProvider('provideDefaultContactEnableData')]
177
-	public function testIsDefaultContactEnabled(bool $enabled): void {
178
-		$this->appConfig->expects(self::once())
179
-			->method('getAppValueBool')
180
-			->with('enableDefaultContact', true)
181
-			->willReturn($enabled);
182
-
183
-		$this->assertEquals($enabled, $this->service->isDefaultContactEnabled());
184
-	}
185
-
186
-	#[\PHPUnit\Framework\Attributes\DataProvider('provideDefaultContactEnableData')]
187
-	public function testSetDefaultContactEnabled(bool $enabled): void {
188
-		$this->appConfig->expects(self::once())
189
-			->method('setAppValueBool')
190
-			->with('enableDefaultContact', $enabled);
191
-
192
-		$this->service->setDefaultContactEnabled($enabled);
193
-	}
27
+    protected ExampleContactService $service;
28
+    protected CardDavBackend&MockObject $cardDav;
29
+    protected IAppManager&MockObject $appManager;
30
+    protected IAppDataFactory&MockObject $appDataFactory;
31
+    protected LoggerInterface&MockObject $logger;
32
+    protected IAppConfig&MockObject $appConfig;
33
+    protected IAppData&MockObject $appData;
34
+
35
+    protected function setUp(): void {
36
+        parent::setUp();
37
+
38
+        $this->cardDav = $this->createMock(CardDavBackend::class);
39
+        $this->appDataFactory = $this->createMock(IAppDataFactory::class);
40
+        $this->logger = $this->createMock(LoggerInterface::class);
41
+        $this->appConfig = $this->createMock(IAppConfig::class);
42
+
43
+        $this->appData = $this->createMock(IAppData::class);
44
+        $this->appDataFactory->method('get')
45
+            ->with('dav')
46
+            ->willReturn($this->appData);
47
+
48
+        $this->service = new ExampleContactService(
49
+            $this->appDataFactory,
50
+            $this->appConfig,
51
+            $this->logger,
52
+            $this->cardDav,
53
+        );
54
+    }
55
+
56
+    public function testCreateDefaultContactWithInvalidCard(): void {
57
+        // Invalid vCard missing required FN property
58
+        $vcardContent = "BEGIN:VCARD\nVERSION:3.0\nEND:VCARD";
59
+        $this->appConfig->method('getAppValueBool')
60
+            ->with('enableDefaultContact', true)
61
+            ->willReturn(true);
62
+        $folder = $this->createMock(ISimpleFolder::class);
63
+        $file = $this->createMock(ISimpleFile::class);
64
+        $file->method('getContent')->willReturn($vcardContent);
65
+        $folder->method('getFile')->willReturn($file);
66
+        $this->appData->method('getFolder')->willReturn($folder);
67
+
68
+        $this->logger->expects($this->once())
69
+            ->method('error')
70
+            ->with('Default contact is invalid', $this->anything());
71
+
72
+        $this->cardDav->expects($this->never())
73
+            ->method('createCard');
74
+
75
+        $this->service->createDefaultContact(123);
76
+    }
77
+
78
+    public function testUidAndRevAreUpdated(): void {
79
+        $originalUid = 'original-uid';
80
+        $originalRev = '20200101T000000Z';
81
+        $vcardContent = "BEGIN:VCARD\nVERSION:3.0\nFN:Test User\nUID:$originalUid\nREV:$originalRev\nEND:VCARD";
82
+
83
+        $this->appConfig->method('getAppValueBool')
84
+            ->with('enableDefaultContact', true)
85
+            ->willReturn(true);
86
+        $folder = $this->createMock(ISimpleFolder::class);
87
+        $file = $this->createMock(ISimpleFile::class);
88
+        $file->method('getContent')->willReturn($vcardContent);
89
+        $folder->method('getFile')->willReturn($file);
90
+        $this->appData->method('getFolder')->willReturn($folder);
91
+
92
+        $capturedCardData = null;
93
+        $this->cardDav->expects($this->once())
94
+            ->method('createCard')
95
+            ->with(
96
+                $this->anything(),
97
+                $this->anything(),
98
+                $this->callback(function ($cardData) use (&$capturedCardData) {
99
+                    $capturedCardData = $cardData;
100
+                    return true;
101
+                }),
102
+                $this->anything()
103
+            )->willReturn(null);
104
+
105
+        $this->service->createDefaultContact(123);
106
+
107
+        $vcard = \Sabre\VObject\Reader::read($capturedCardData);
108
+        $this->assertNotEquals($originalUid, $vcard->UID->getValue());
109
+        $this->assertTrue(Uuid::isValid($vcard->UID->getValue()));
110
+        $this->assertNotEquals($originalRev, $vcard->REV->getValue());
111
+    }
112
+
113
+    public function testDefaultContactFileDoesNotExist(): void {
114
+        $this->appConfig->method('getAppValueBool')
115
+            ->with('enableDefaultContact', true)
116
+            ->willReturn(true);
117
+        $this->appData->method('getFolder')->willThrowException(new NotFoundException());
118
+
119
+        $this->cardDav->expects($this->never())
120
+            ->method('createCard');
121
+
122
+        $this->service->createDefaultContact(123);
123
+    }
124
+
125
+    public function testUidAndRevAreAddedIfMissing(): void {
126
+        $vcardContent = "BEGIN:VCARD\nVERSION:3.0\nFN:Test User\nEND:VCARD";
127
+
128
+        $this->appConfig->method('getAppValueBool')
129
+            ->with('enableDefaultContact', true)
130
+            ->willReturn(true);
131
+        $folder = $this->createMock(ISimpleFolder::class);
132
+        $file = $this->createMock(ISimpleFile::class);
133
+        $file->method('getContent')->willReturn($vcardContent);
134
+        $folder->method('getFile')->willReturn($file);
135
+        $this->appData->method('getFolder')->willReturn($folder);
136
+
137
+        $capturedCardData = 'new-card-data';
138
+
139
+        $this->cardDav
140
+            ->expects($this->once())
141
+            ->method('createCard')
142
+            ->with(
143
+                $this->anything(),
144
+                $this->anything(),
145
+                $this->callback(function ($cardData) use (&$capturedCardData) {
146
+                    $capturedCardData = $cardData;
147
+                    return true;
148
+                }),
149
+                $this->anything()
150
+            );
151
+
152
+        $this->service->createDefaultContact(123);
153
+        $vcard = \Sabre\VObject\Reader::read($capturedCardData);
154
+
155
+        $this->assertNotNull($vcard->REV);
156
+        $this->assertNotNull($vcard->UID);
157
+        $this->assertTrue(Uuid::isValid($vcard->UID->getValue()));
158
+    }
159
+
160
+    public function testDefaultContactIsNotCreatedIfEnabled(): void {
161
+        $this->appConfig->method('getAppValueBool')
162
+            ->with('enableDefaultContact', true)
163
+            ->willReturn(false);
164
+        $this->logger->expects($this->never())
165
+            ->method('error');
166
+        $this->cardDav->expects($this->never())
167
+            ->method('createCard');
168
+
169
+        $this->service->createDefaultContact(123);
170
+    }
171
+
172
+    public static function provideDefaultContactEnableData(): array {
173
+        return [[true], [false]];
174
+    }
175
+
176
+    #[\PHPUnit\Framework\Attributes\DataProvider('provideDefaultContactEnableData')]
177
+    public function testIsDefaultContactEnabled(bool $enabled): void {
178
+        $this->appConfig->expects(self::once())
179
+            ->method('getAppValueBool')
180
+            ->with('enableDefaultContact', true)
181
+            ->willReturn($enabled);
182
+
183
+        $this->assertEquals($enabled, $this->service->isDefaultContactEnabled());
184
+    }
185
+
186
+    #[\PHPUnit\Framework\Attributes\DataProvider('provideDefaultContactEnableData')]
187
+    public function testSetDefaultContactEnabled(bool $enabled): void {
188
+        $this->appConfig->expects(self::once())
189
+            ->method('setAppValueBool')
190
+            ->with('enableDefaultContact', $enabled);
191
+
192
+        $this->service->setDefaultContactEnabled($enabled);
193
+    }
194 194
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/Service/ExampleEventServiceTest.php 1 patch
Indentation   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -23,174 +23,174 @@
 block discarded – undo
23 23
 use Test\TestCase;
24 24
 
25 25
 class ExampleEventServiceTest extends TestCase {
26
-	private ExampleEventService $service;
27
-
28
-	private CalDavBackend&MockObject $calDavBackend;
29
-	private ISecureRandom&MockObject $random;
30
-	private ITimeFactory&MockObject $time;
31
-	private IAppData&MockObject $appData;
32
-	private IAppConfig&MockObject $appConfig;
33
-	private IL10N&MockObject $l10n;
34
-
35
-	protected function setUp(): void {
36
-		parent::setUp();
37
-
38
-		$this->calDavBackend = $this->createMock(CalDavBackend::class);
39
-		$this->random = $this->createMock(ISecureRandom::class);
40
-		$this->time = $this->createMock(ITimeFactory::class);
41
-		$this->appData = $this->createMock(IAppData::class);
42
-		$this->appConfig = $this->createMock(IAppConfig::class);
43
-		$this->l10n = $this->createMock(IL10N::class);
44
-
45
-		$this->l10n->method('t')
46
-			->willReturnArgument(0);
47
-
48
-		$this->service = new ExampleEventService(
49
-			$this->calDavBackend,
50
-			$this->random,
51
-			$this->time,
52
-			$this->appData,
53
-			$this->appConfig,
54
-			$this->l10n,
55
-		);
56
-	}
57
-
58
-	public static function provideCustomEventData(): array {
59
-		return [
60
-			[file_get_contents(__DIR__ . '/../test_fixtures/example-event.ics')],
61
-			[file_get_contents(__DIR__ . '/../test_fixtures/example-event-with-attendees.ics')],
62
-		];
63
-	}
64
-
65
-	#[\PHPUnit\Framework\Attributes\DataProvider('provideCustomEventData')]
66
-	public function testCreateExampleEventWithCustomEvent($customEventIcs): void {
67
-		$this->appConfig->expects(self::once())
68
-			->method('getValueBool')
69
-			->with('dav', 'create_example_event', true)
70
-			->willReturn(true);
71
-
72
-		$exampleEventFolder = $this->createMock(ISimpleFolder::class);
73
-		$this->appData->expects(self::once())
74
-			->method('getFolder')
75
-			->with('example_event')
76
-			->willReturn($exampleEventFolder);
77
-		$exampleEventFile = $this->createMock(ISimpleFile::class);
78
-		$exampleEventFolder->expects(self::once())
79
-			->method('getFile')
80
-			->with('example_event.ics')
81
-			->willReturn($exampleEventFile);
82
-		$exampleEventFile->expects(self::once())
83
-			->method('getContent')
84
-			->willReturn($customEventIcs);
85
-
86
-		$this->random->expects(self::once())
87
-			->method('generate')
88
-			->with(32, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')
89
-			->willReturn('RANDOM-UID');
90
-
91
-		$now = new \DateTimeImmutable('2025-01-21T00:00:00Z');
92
-		$this->time->expects(self::exactly(2))
93
-			->method('now')
94
-			->willReturn($now);
95
-
96
-		$expectedIcs = file_get_contents(__DIR__ . '/../test_fixtures/example-event-expected.ics');
97
-		$this->calDavBackend->expects(self::once())
98
-			->method('createCalendarObject')
99
-			->with(1000, 'RANDOM-UID.ics', $expectedIcs);
100
-
101
-		$this->service->createExampleEvent(1000);
102
-	}
103
-
104
-	public function testCreateExampleEventWithDefaultEvent(): void {
105
-		$this->appConfig->expects(self::once())
106
-			->method('getValueBool')
107
-			->with('dav', 'create_example_event', true)
108
-			->willReturn(true);
109
-
110
-		$this->appData->expects(self::once())
111
-			->method('getFolder')
112
-			->with('example_event')
113
-			->willThrowException(new NotFoundException());
114
-
115
-		$this->random->expects(self::once())
116
-			->method('generate')
117
-			->with(32, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')
118
-			->willReturn('RANDOM-UID');
119
-
120
-		$now = new \DateTimeImmutable('2025-01-21T00:00:00Z');
121
-		$this->time->expects(self::exactly(3))
122
-			->method('now')
123
-			->willReturn($now);
124
-
125
-		$expectedIcs = file_get_contents(__DIR__ . '/../test_fixtures/example-event-default-expected.ics');
126
-		$this->calDavBackend->expects(self::once())
127
-			->method('createCalendarObject')
128
-			->with(1000, 'RANDOM-UID.ics', $expectedIcs);
129
-
130
-		$this->service->createExampleEvent(1000);
131
-	}
132
-
133
-	public function testCreateExampleWhenDisabled(): void {
134
-		$this->appConfig->expects(self::once())
135
-			->method('getValueBool')
136
-			->with('dav', 'create_example_event', true)
137
-			->willReturn(false);
138
-
139
-		$this->calDavBackend->expects(self::never())
140
-			->method('createCalendarObject');
141
-
142
-		$this->service->createExampleEvent(1000);
143
-	}
144
-
145
-	#[\PHPUnit\Framework\Attributes\DataProvider('provideCustomEventData')]
146
-	public function testGetExampleEventWithCustomEvent($customEventIcs): void {
147
-		$exampleEventFolder = $this->createMock(ISimpleFolder::class);
148
-		$this->appData->expects(self::once())
149
-			->method('getFolder')
150
-			->with('example_event')
151
-			->willReturn($exampleEventFolder);
152
-		$exampleEventFile = $this->createMock(ISimpleFile::class);
153
-		$exampleEventFolder->expects(self::once())
154
-			->method('getFile')
155
-			->with('example_event.ics')
156
-			->willReturn($exampleEventFile);
157
-		$exampleEventFile->expects(self::once())
158
-			->method('getContent')
159
-			->willReturn($customEventIcs);
160
-
161
-		$this->random->expects(self::once())
162
-			->method('generate')
163
-			->with(32, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')
164
-			->willReturn('RANDOM-UID');
165
-
166
-		$now = new \DateTimeImmutable('2025-01-21T00:00:00Z');
167
-		$this->time->expects(self::exactly(2))
168
-			->method('now')
169
-			->willReturn($now);
170
-
171
-		$expectedIcs = file_get_contents(__DIR__ . '/../test_fixtures/example-event-expected.ics');
172
-		$actualIcs = $this->service->getExampleEvent()->getIcs();
173
-		$this->assertEquals($expectedIcs, $actualIcs);
174
-	}
175
-
176
-	public function testGetExampleEventWithDefault(): void {
177
-		$this->appData->expects(self::once())
178
-			->method('getFolder')
179
-			->with('example_event')
180
-			->willThrowException(new NotFoundException());
181
-
182
-		$this->random->expects(self::once())
183
-			->method('generate')
184
-			->with(32, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')
185
-			->willReturn('RANDOM-UID');
186
-
187
-		$now = new \DateTimeImmutable('2025-01-21T00:00:00Z');
188
-		$this->time->expects(self::exactly(3))
189
-			->method('now')
190
-			->willReturn($now);
191
-
192
-		$expectedIcs = file_get_contents(__DIR__ . '/../test_fixtures/example-event-default-expected.ics');
193
-		$actualIcs = $this->service->getExampleEvent()->getIcs();
194
-		$this->assertEquals($expectedIcs, $actualIcs);
195
-	}
26
+    private ExampleEventService $service;
27
+
28
+    private CalDavBackend&MockObject $calDavBackend;
29
+    private ISecureRandom&MockObject $random;
30
+    private ITimeFactory&MockObject $time;
31
+    private IAppData&MockObject $appData;
32
+    private IAppConfig&MockObject $appConfig;
33
+    private IL10N&MockObject $l10n;
34
+
35
+    protected function setUp(): void {
36
+        parent::setUp();
37
+
38
+        $this->calDavBackend = $this->createMock(CalDavBackend::class);
39
+        $this->random = $this->createMock(ISecureRandom::class);
40
+        $this->time = $this->createMock(ITimeFactory::class);
41
+        $this->appData = $this->createMock(IAppData::class);
42
+        $this->appConfig = $this->createMock(IAppConfig::class);
43
+        $this->l10n = $this->createMock(IL10N::class);
44
+
45
+        $this->l10n->method('t')
46
+            ->willReturnArgument(0);
47
+
48
+        $this->service = new ExampleEventService(
49
+            $this->calDavBackend,
50
+            $this->random,
51
+            $this->time,
52
+            $this->appData,
53
+            $this->appConfig,
54
+            $this->l10n,
55
+        );
56
+    }
57
+
58
+    public static function provideCustomEventData(): array {
59
+        return [
60
+            [file_get_contents(__DIR__ . '/../test_fixtures/example-event.ics')],
61
+            [file_get_contents(__DIR__ . '/../test_fixtures/example-event-with-attendees.ics')],
62
+        ];
63
+    }
64
+
65
+    #[\PHPUnit\Framework\Attributes\DataProvider('provideCustomEventData')]
66
+    public function testCreateExampleEventWithCustomEvent($customEventIcs): void {
67
+        $this->appConfig->expects(self::once())
68
+            ->method('getValueBool')
69
+            ->with('dav', 'create_example_event', true)
70
+            ->willReturn(true);
71
+
72
+        $exampleEventFolder = $this->createMock(ISimpleFolder::class);
73
+        $this->appData->expects(self::once())
74
+            ->method('getFolder')
75
+            ->with('example_event')
76
+            ->willReturn($exampleEventFolder);
77
+        $exampleEventFile = $this->createMock(ISimpleFile::class);
78
+        $exampleEventFolder->expects(self::once())
79
+            ->method('getFile')
80
+            ->with('example_event.ics')
81
+            ->willReturn($exampleEventFile);
82
+        $exampleEventFile->expects(self::once())
83
+            ->method('getContent')
84
+            ->willReturn($customEventIcs);
85
+
86
+        $this->random->expects(self::once())
87
+            ->method('generate')
88
+            ->with(32, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')
89
+            ->willReturn('RANDOM-UID');
90
+
91
+        $now = new \DateTimeImmutable('2025-01-21T00:00:00Z');
92
+        $this->time->expects(self::exactly(2))
93
+            ->method('now')
94
+            ->willReturn($now);
95
+
96
+        $expectedIcs = file_get_contents(__DIR__ . '/../test_fixtures/example-event-expected.ics');
97
+        $this->calDavBackend->expects(self::once())
98
+            ->method('createCalendarObject')
99
+            ->with(1000, 'RANDOM-UID.ics', $expectedIcs);
100
+
101
+        $this->service->createExampleEvent(1000);
102
+    }
103
+
104
+    public function testCreateExampleEventWithDefaultEvent(): void {
105
+        $this->appConfig->expects(self::once())
106
+            ->method('getValueBool')
107
+            ->with('dav', 'create_example_event', true)
108
+            ->willReturn(true);
109
+
110
+        $this->appData->expects(self::once())
111
+            ->method('getFolder')
112
+            ->with('example_event')
113
+            ->willThrowException(new NotFoundException());
114
+
115
+        $this->random->expects(self::once())
116
+            ->method('generate')
117
+            ->with(32, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')
118
+            ->willReturn('RANDOM-UID');
119
+
120
+        $now = new \DateTimeImmutable('2025-01-21T00:00:00Z');
121
+        $this->time->expects(self::exactly(3))
122
+            ->method('now')
123
+            ->willReturn($now);
124
+
125
+        $expectedIcs = file_get_contents(__DIR__ . '/../test_fixtures/example-event-default-expected.ics');
126
+        $this->calDavBackend->expects(self::once())
127
+            ->method('createCalendarObject')
128
+            ->with(1000, 'RANDOM-UID.ics', $expectedIcs);
129
+
130
+        $this->service->createExampleEvent(1000);
131
+    }
132
+
133
+    public function testCreateExampleWhenDisabled(): void {
134
+        $this->appConfig->expects(self::once())
135
+            ->method('getValueBool')
136
+            ->with('dav', 'create_example_event', true)
137
+            ->willReturn(false);
138
+
139
+        $this->calDavBackend->expects(self::never())
140
+            ->method('createCalendarObject');
141
+
142
+        $this->service->createExampleEvent(1000);
143
+    }
144
+
145
+    #[\PHPUnit\Framework\Attributes\DataProvider('provideCustomEventData')]
146
+    public function testGetExampleEventWithCustomEvent($customEventIcs): void {
147
+        $exampleEventFolder = $this->createMock(ISimpleFolder::class);
148
+        $this->appData->expects(self::once())
149
+            ->method('getFolder')
150
+            ->with('example_event')
151
+            ->willReturn($exampleEventFolder);
152
+        $exampleEventFile = $this->createMock(ISimpleFile::class);
153
+        $exampleEventFolder->expects(self::once())
154
+            ->method('getFile')
155
+            ->with('example_event.ics')
156
+            ->willReturn($exampleEventFile);
157
+        $exampleEventFile->expects(self::once())
158
+            ->method('getContent')
159
+            ->willReturn($customEventIcs);
160
+
161
+        $this->random->expects(self::once())
162
+            ->method('generate')
163
+            ->with(32, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')
164
+            ->willReturn('RANDOM-UID');
165
+
166
+        $now = new \DateTimeImmutable('2025-01-21T00:00:00Z');
167
+        $this->time->expects(self::exactly(2))
168
+            ->method('now')
169
+            ->willReturn($now);
170
+
171
+        $expectedIcs = file_get_contents(__DIR__ . '/../test_fixtures/example-event-expected.ics');
172
+        $actualIcs = $this->service->getExampleEvent()->getIcs();
173
+        $this->assertEquals($expectedIcs, $actualIcs);
174
+    }
175
+
176
+    public function testGetExampleEventWithDefault(): void {
177
+        $this->appData->expects(self::once())
178
+            ->method('getFolder')
179
+            ->with('example_event')
180
+            ->willThrowException(new NotFoundException());
181
+
182
+        $this->random->expects(self::once())
183
+            ->method('generate')
184
+            ->with(32, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')
185
+            ->willReturn('RANDOM-UID');
186
+
187
+        $now = new \DateTimeImmutable('2025-01-21T00:00:00Z');
188
+        $this->time->expects(self::exactly(3))
189
+            ->method('now')
190
+            ->willReturn($now);
191
+
192
+        $expectedIcs = file_get_contents(__DIR__ . '/../test_fixtures/example-event-default-expected.ics');
193
+        $actualIcs = $this->service->getExampleEvent()->getIcs();
194
+        $this->assertEquals($expectedIcs, $actualIcs);
195
+    }
196 196
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/Avatars/AvatarHomeTest.php 1 patch
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -18,82 +18,82 @@
 block discarded – undo
18 18
 use Test\TestCase;
19 19
 
20 20
 class AvatarHomeTest extends TestCase {
21
-	private AvatarHome $home;
22
-	private IAvatarManager&MockObject $avatarManager;
23
-
24
-	protected function setUp(): void {
25
-		parent::setUp();
26
-		$this->avatarManager = $this->createMock(IAvatarManager::class);
27
-		$this->home = new AvatarHome(['uri' => 'principals/users/admin'], $this->avatarManager);
28
-	}
29
-
30
-	#[\PHPUnit\Framework\Attributes\DataProvider('providesForbiddenMethods')]
31
-	public function testForbiddenMethods($method): void {
32
-		$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
33
-
34
-		$this->home->$method('');
35
-	}
36
-
37
-	public static function providesForbiddenMethods(): array {
38
-		return [
39
-			['createFile'],
40
-			['createDirectory'],
41
-			['delete'],
42
-			['setName']
43
-		];
44
-	}
45
-
46
-	public function testGetName(): void {
47
-		$n = $this->home->getName();
48
-		self::assertEquals('admin', $n);
49
-	}
50
-
51
-	public static function providesTestGetChild(): array {
52
-		return [
53
-			[MethodNotAllowed::class, false, ''],
54
-			[MethodNotAllowed::class, false, 'bla.foo'],
55
-			[MethodNotAllowed::class, false, 'bla.png'],
56
-			[NotFound::class, false, '512.png'],
57
-			[null, true, '512.png'],
58
-		];
59
-	}
60
-
61
-	#[\PHPUnit\Framework\Attributes\DataProvider('providesTestGetChild')]
62
-	public function testGetChild(?string $expectedException, bool $hasAvatar, string $path): void {
63
-		if ($expectedException !== null) {
64
-			$this->expectException($expectedException);
65
-		}
66
-
67
-		$avatar = $this->createMock(IAvatar::class);
68
-		$avatar->method('exists')->willReturn($hasAvatar);
69
-
70
-		$this->avatarManager->expects($this->any())->method('getAvatar')->with('admin')->willReturn($avatar);
71
-		$avatarNode = $this->home->getChild($path);
72
-		$this->assertInstanceOf(AvatarNode::class, $avatarNode);
73
-	}
74
-
75
-	public function testGetChildren(): void {
76
-		$avatarNodes = $this->home->getChildren();
77
-		self::assertEquals(0, count($avatarNodes));
78
-
79
-		$avatar = $this->createMock(IAvatar::class);
80
-		$avatar->expects($this->once())->method('exists')->willReturn(true);
81
-		$this->avatarManager->expects($this->any())->method('getAvatar')->with('admin')->willReturn($avatar);
82
-		$avatarNodes = $this->home->getChildren();
83
-		self::assertEquals(1, count($avatarNodes));
84
-	}
85
-
86
-	#[\PHPUnit\Framework\Attributes\DataProvider('providesTestGetChild')]
87
-	public function testChildExists(?string $expectedException, bool $hasAvatar, string $path): void {
88
-		$avatar = $this->createMock(IAvatar::class);
89
-		$avatar->method('exists')->willReturn($hasAvatar);
90
-
91
-		$this->avatarManager->expects($this->any())->method('getAvatar')->with('admin')->willReturn($avatar);
92
-		$childExists = $this->home->childExists($path);
93
-		$this->assertEquals($hasAvatar, $childExists);
94
-	}
95
-
96
-	public function testGetLastModified(): void {
97
-		self::assertNull($this->home->getLastModified());
98
-	}
21
+    private AvatarHome $home;
22
+    private IAvatarManager&MockObject $avatarManager;
23
+
24
+    protected function setUp(): void {
25
+        parent::setUp();
26
+        $this->avatarManager = $this->createMock(IAvatarManager::class);
27
+        $this->home = new AvatarHome(['uri' => 'principals/users/admin'], $this->avatarManager);
28
+    }
29
+
30
+    #[\PHPUnit\Framework\Attributes\DataProvider('providesForbiddenMethods')]
31
+    public function testForbiddenMethods($method): void {
32
+        $this->expectException(\Sabre\DAV\Exception\Forbidden::class);
33
+
34
+        $this->home->$method('');
35
+    }
36
+
37
+    public static function providesForbiddenMethods(): array {
38
+        return [
39
+            ['createFile'],
40
+            ['createDirectory'],
41
+            ['delete'],
42
+            ['setName']
43
+        ];
44
+    }
45
+
46
+    public function testGetName(): void {
47
+        $n = $this->home->getName();
48
+        self::assertEquals('admin', $n);
49
+    }
50
+
51
+    public static function providesTestGetChild(): array {
52
+        return [
53
+            [MethodNotAllowed::class, false, ''],
54
+            [MethodNotAllowed::class, false, 'bla.foo'],
55
+            [MethodNotAllowed::class, false, 'bla.png'],
56
+            [NotFound::class, false, '512.png'],
57
+            [null, true, '512.png'],
58
+        ];
59
+    }
60
+
61
+    #[\PHPUnit\Framework\Attributes\DataProvider('providesTestGetChild')]
62
+    public function testGetChild(?string $expectedException, bool $hasAvatar, string $path): void {
63
+        if ($expectedException !== null) {
64
+            $this->expectException($expectedException);
65
+        }
66
+
67
+        $avatar = $this->createMock(IAvatar::class);
68
+        $avatar->method('exists')->willReturn($hasAvatar);
69
+
70
+        $this->avatarManager->expects($this->any())->method('getAvatar')->with('admin')->willReturn($avatar);
71
+        $avatarNode = $this->home->getChild($path);
72
+        $this->assertInstanceOf(AvatarNode::class, $avatarNode);
73
+    }
74
+
75
+    public function testGetChildren(): void {
76
+        $avatarNodes = $this->home->getChildren();
77
+        self::assertEquals(0, count($avatarNodes));
78
+
79
+        $avatar = $this->createMock(IAvatar::class);
80
+        $avatar->expects($this->once())->method('exists')->willReturn(true);
81
+        $this->avatarManager->expects($this->any())->method('getAvatar')->with('admin')->willReturn($avatar);
82
+        $avatarNodes = $this->home->getChildren();
83
+        self::assertEquals(1, count($avatarNodes));
84
+    }
85
+
86
+    #[\PHPUnit\Framework\Attributes\DataProvider('providesTestGetChild')]
87
+    public function testChildExists(?string $expectedException, bool $hasAvatar, string $path): void {
88
+        $avatar = $this->createMock(IAvatar::class);
89
+        $avatar->method('exists')->willReturn($hasAvatar);
90
+
91
+        $this->avatarManager->expects($this->any())->method('getAvatar')->with('admin')->willReturn($avatar);
92
+        $childExists = $this->home->childExists($path);
93
+        $this->assertEquals($hasAvatar, $childExists);
94
+    }
95
+
96
+    public function testGetLastModified(): void {
97
+        self::assertNull($this->home->getLastModified());
98
+    }
99 99
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/Migration/RefreshWebcalJobRegistrarTest.php 2 patches
Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -18,102 +18,102 @@
 block discarded – undo
18 18
 use Test\TestCase;
19 19
 
20 20
 class RefreshWebcalJobRegistrarTest extends TestCase {
21
-	private IDBConnection&MockObject $db;
22
-	private IJobList&MockObject $jobList;
23
-	private RefreshWebcalJobRegistrar $migration;
24
-
25
-	protected function setUp(): void {
26
-		parent::setUp();
27
-
28
-		$this->db = $this->createMock(IDBConnection::class);
29
-		$this->jobList = $this->createMock(IJobList::class);
30
-
31
-		$this->migration = new RefreshWebcalJobRegistrar($this->db, $this->jobList);
32
-	}
33
-
34
-	public function testGetName(): void {
35
-		$this->assertEquals($this->migration->getName(), 'Registering background jobs to update cache for webcal calendars');
36
-	}
37
-
38
-	public function testRun(): void {
39
-		$output = $this->createMock(IOutput::class);
40
-
41
-		$queryBuilder = $this->createMock(IQueryBuilder::class);
42
-		$statement = $this->createMock(IResult::class);
43
-
44
-		$this->db->expects($this->once())
45
-			->method('getQueryBuilder')
46
-			->willReturn($queryBuilder);
47
-
48
-		$queryBuilder->expects($this->once())
49
-			->method('select')
50
-			->with(['principaluri', 'uri'])
51
-			->willReturn($queryBuilder);
52
-		$queryBuilder->expects($this->once())
53
-			->method('from')
54
-			->with('calendarsubscriptions')
55
-			->willReturn($queryBuilder);
56
-		$queryBuilder->expects($this->once())
57
-			->method('execute')
58
-			->willReturn($statement);
59
-
60
-		$statement->expects($this->exactly(4))
61
-			->method('fetch')
62
-			->with(\PDO::FETCH_ASSOC)
63
-			->willReturnOnConsecutiveCalls(
64
-				[
65
-					'principaluri' => 'foo1',
66
-					'uri' => 'bar1',
67
-				],
68
-				[
69
-					'principaluri' => 'foo2',
70
-					'uri' => 'bar2',
71
-				],
72
-				[
73
-					'principaluri' => 'foo3',
74
-					'uri' => 'bar3',
75
-				],
76
-				null
77
-			);
78
-
79
-		$this->jobList->expects($this->exactly(3))
80
-			->method('has')
81
-			->willReturnMap([
82
-				[RefreshWebcalJob::class, [
83
-					'principaluri' => 'foo1',
84
-					'uri' => 'bar1',
85
-				], false],
86
-				[RefreshWebcalJob::class, [
87
-					'principaluri' => 'foo2',
88
-					'uri' => 'bar2',
89
-				], true ],
90
-				[RefreshWebcalJob::class, [
91
-					'principaluri' => 'foo3',
92
-					'uri' => 'bar3',
93
-				], false],
94
-			]);
95
-
96
-		$calls = [
97
-			[RefreshWebcalJob::class, [
98
-				'principaluri' => 'foo1',
99
-				'uri' => 'bar1',
100
-			]],
101
-			[RefreshWebcalJob::class, [
102
-				'principaluri' => 'foo3',
103
-				'uri' => 'bar3',
104
-			]]
105
-		];
106
-		$this->jobList->expects($this->exactly(2))
107
-			->method('add')
108
-			->willReturnCallback(function () use (&$calls): void {
109
-				$expected = array_shift($calls);
110
-				$this->assertEquals($expected, func_get_args());
111
-			});
112
-
113
-		$output->expects($this->once())
114
-			->method('info')
115
-			->with('Added 2 background jobs to update webcal calendars');
116
-
117
-		$this->migration->run($output);
118
-	}
21
+    private IDBConnection&MockObject $db;
22
+    private IJobList&MockObject $jobList;
23
+    private RefreshWebcalJobRegistrar $migration;
24
+
25
+    protected function setUp(): void {
26
+        parent::setUp();
27
+
28
+        $this->db = $this->createMock(IDBConnection::class);
29
+        $this->jobList = $this->createMock(IJobList::class);
30
+
31
+        $this->migration = new RefreshWebcalJobRegistrar($this->db, $this->jobList);
32
+    }
33
+
34
+    public function testGetName(): void {
35
+        $this->assertEquals($this->migration->getName(), 'Registering background jobs to update cache for webcal calendars');
36
+    }
37
+
38
+    public function testRun(): void {
39
+        $output = $this->createMock(IOutput::class);
40
+
41
+        $queryBuilder = $this->createMock(IQueryBuilder::class);
42
+        $statement = $this->createMock(IResult::class);
43
+
44
+        $this->db->expects($this->once())
45
+            ->method('getQueryBuilder')
46
+            ->willReturn($queryBuilder);
47
+
48
+        $queryBuilder->expects($this->once())
49
+            ->method('select')
50
+            ->with(['principaluri', 'uri'])
51
+            ->willReturn($queryBuilder);
52
+        $queryBuilder->expects($this->once())
53
+            ->method('from')
54
+            ->with('calendarsubscriptions')
55
+            ->willReturn($queryBuilder);
56
+        $queryBuilder->expects($this->once())
57
+            ->method('execute')
58
+            ->willReturn($statement);
59
+
60
+        $statement->expects($this->exactly(4))
61
+            ->method('fetch')
62
+            ->with(\PDO::FETCH_ASSOC)
63
+            ->willReturnOnConsecutiveCalls(
64
+                [
65
+                    'principaluri' => 'foo1',
66
+                    'uri' => 'bar1',
67
+                ],
68
+                [
69
+                    'principaluri' => 'foo2',
70
+                    'uri' => 'bar2',
71
+                ],
72
+                [
73
+                    'principaluri' => 'foo3',
74
+                    'uri' => 'bar3',
75
+                ],
76
+                null
77
+            );
78
+
79
+        $this->jobList->expects($this->exactly(3))
80
+            ->method('has')
81
+            ->willReturnMap([
82
+                [RefreshWebcalJob::class, [
83
+                    'principaluri' => 'foo1',
84
+                    'uri' => 'bar1',
85
+                ], false],
86
+                [RefreshWebcalJob::class, [
87
+                    'principaluri' => 'foo2',
88
+                    'uri' => 'bar2',
89
+                ], true ],
90
+                [RefreshWebcalJob::class, [
91
+                    'principaluri' => 'foo3',
92
+                    'uri' => 'bar3',
93
+                ], false],
94
+            ]);
95
+
96
+        $calls = [
97
+            [RefreshWebcalJob::class, [
98
+                'principaluri' => 'foo1',
99
+                'uri' => 'bar1',
100
+            ]],
101
+            [RefreshWebcalJob::class, [
102
+                'principaluri' => 'foo3',
103
+                'uri' => 'bar3',
104
+            ]]
105
+        ];
106
+        $this->jobList->expects($this->exactly(2))
107
+            ->method('add')
108
+            ->willReturnCallback(function () use (&$calls): void {
109
+                $expected = array_shift($calls);
110
+                $this->assertEquals($expected, func_get_args());
111
+            });
112
+
113
+        $output->expects($this->once())
114
+            ->method('info')
115
+            ->with('Added 2 background jobs to update webcal calendars');
116
+
117
+        $this->migration->run($output);
118
+    }
119 119
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 				[RefreshWebcalJob::class, [
87 87
 					'principaluri' => 'foo2',
88 88
 					'uri' => 'bar2',
89
-				], true ],
89
+				], true],
90 90
 				[RefreshWebcalJob::class, [
91 91
 					'principaluri' => 'foo3',
92 92
 					'uri' => 'bar3',
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 		];
106 106
 		$this->jobList->expects($this->exactly(2))
107 107
 			->method('add')
108
-			->willReturnCallback(function () use (&$calls): void {
108
+			->willReturnCallback(function() use (&$calls): void {
109 109
 				$expected = array_shift($calls);
110 110
 				$this->assertEquals($expected, func_get_args());
111 111
 			});
Please login to merge, or discard this patch.
dav/tests/unit/Migration/RemoveDeletedUsersCalendarSubscriptionsTest.php 1 patch
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -22,119 +22,119 @@
 block discarded – undo
22 22
 use Test\TestCase;
23 23
 
24 24
 class RemoveDeletedUsersCalendarSubscriptionsTest extends TestCase {
25
-	private IDBConnection&MockObject $dbConnection;
26
-	private IUserManager&MockObject $userManager;
27
-	private IOutput&MockObject $output;
28
-	private RemoveDeletedUsersCalendarSubscriptions $migration;
25
+    private IDBConnection&MockObject $dbConnection;
26
+    private IUserManager&MockObject $userManager;
27
+    private IOutput&MockObject $output;
28
+    private RemoveDeletedUsersCalendarSubscriptions $migration;
29 29
 
30 30
 
31
-	protected function setUp(): void {
32
-		parent::setUp();
33
-
34
-		$this->dbConnection = $this->createMock(IDBConnection::class);
35
-		$this->userManager = $this->createMock(IUserManager::class);
36
-		$this->output = $this->createMock(IOutput::class);
37
-
38
-		$this->migration = new RemoveDeletedUsersCalendarSubscriptions($this->dbConnection, $this->userManager);
39
-	}
40
-
41
-	public function testGetName(): void {
42
-		$this->assertEquals(
43
-			'Clean up old calendar subscriptions from deleted users that were not cleaned-up',
44
-			$this->migration->getName()
45
-		);
46
-	}
47
-
48
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataTestRun')]
49
-	public function testRun(array $subscriptions, array $userExists, int $deletions): void {
50
-		$qb = $this->createMock(IQueryBuilder::class);
51
-
52
-		$qb->method('select')->willReturn($qb);
53
-
54
-		$functionBuilder = $this->createMock(IFunctionBuilder::class);
55
-
56
-		$qb->method('func')->willReturn($functionBuilder);
57
-		$functionBuilder->method('count')->willReturn($this->createMock(IQueryFunction::class));
58
-
59
-		$qb->method('selectDistinct')
60
-			->with(['id', 'principaluri'])
61
-			->willReturn($qb);
62
-
63
-		$qb->method('from')
64
-			->with('calendarsubscriptions')
65
-			->willReturn($qb);
66
-
67
-		$qb->method('setMaxResults')
68
-			->willReturn($qb);
69
-
70
-		$qb->method('setFirstResult')
71
-			->willReturn($qb);
72
-
73
-		$result = $this->createMock(IResult::class);
74
-
75
-		$qb->method('execute')
76
-			->willReturn($result);
77
-
78
-		$result->expects($this->once())
79
-			->method('fetchOne')
80
-			->willReturn(count($subscriptions));
81
-
82
-		$result
83
-			->method('fetch')
84
-			->willReturnOnConsecutiveCalls(...$subscriptions);
85
-
86
-		$qb->method('delete')
87
-			->with('calendarsubscriptions')
88
-			->willReturn($qb);
89
-
90
-		$expr = $this->createMock(IExpressionBuilder::class);
91
-
92
-		$qb->method('expr')->willReturn($expr);
93
-		$qb->method('createNamedParameter')->willReturn($this->createMock(IParameter::class));
94
-		$qb->method('where')->willReturn($qb);
95
-		// Only when user exists
96
-		$qb->expects($this->exactly($deletions))->method('executeStatement');
97
-
98
-		$this->dbConnection->method('getQueryBuilder')->willReturn($qb);
99
-
100
-
101
-		$this->output->expects($this->once())->method('startProgress');
102
-
103
-		$this->output->expects($subscriptions === [] ? $this->never(): $this->once())->method('advance');
104
-		if (count($subscriptions)) {
105
-			$this->userManager->method('userExists')
106
-				->willReturnCallback(function (string $username) use ($userExists) {
107
-					return $userExists[$username];
108
-				});
109
-		}
110
-		$this->output->expects($this->once())->method('finishProgress');
111
-		$this->output->expects($this->once())->method('info')->with(sprintf('%d calendar subscriptions without an user have been cleaned up', $deletions));
112
-
113
-		$this->migration->run($this->output);
114
-	}
115
-
116
-	public static function dataTestRun(): array {
117
-		return [
118
-			[[], [], 0],
119
-			[
120
-				[
121
-					[
122
-						'id' => 1,
123
-						'principaluri' => 'users/principals/foo1',
124
-					],
125
-					[
126
-						'id' => 2,
127
-						'principaluri' => 'users/principals/bar1',
128
-					],
129
-					[
130
-						'id' => 3,
131
-						'principaluri' => 'users/principals/bar1',
132
-					],
133
-					[],
134
-				],
135
-				['foo1' => true, 'bar1' => false],
136
-				2
137
-			],
138
-		];
139
-	}
31
+    protected function setUp(): void {
32
+        parent::setUp();
33
+
34
+        $this->dbConnection = $this->createMock(IDBConnection::class);
35
+        $this->userManager = $this->createMock(IUserManager::class);
36
+        $this->output = $this->createMock(IOutput::class);
37
+
38
+        $this->migration = new RemoveDeletedUsersCalendarSubscriptions($this->dbConnection, $this->userManager);
39
+    }
40
+
41
+    public function testGetName(): void {
42
+        $this->assertEquals(
43
+            'Clean up old calendar subscriptions from deleted users that were not cleaned-up',
44
+            $this->migration->getName()
45
+        );
46
+    }
47
+
48
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataTestRun')]
49
+    public function testRun(array $subscriptions, array $userExists, int $deletions): void {
50
+        $qb = $this->createMock(IQueryBuilder::class);
51
+
52
+        $qb->method('select')->willReturn($qb);
53
+
54
+        $functionBuilder = $this->createMock(IFunctionBuilder::class);
55
+
56
+        $qb->method('func')->willReturn($functionBuilder);
57
+        $functionBuilder->method('count')->willReturn($this->createMock(IQueryFunction::class));
58
+
59
+        $qb->method('selectDistinct')
60
+            ->with(['id', 'principaluri'])
61
+            ->willReturn($qb);
62
+
63
+        $qb->method('from')
64
+            ->with('calendarsubscriptions')
65
+            ->willReturn($qb);
66
+
67
+        $qb->method('setMaxResults')
68
+            ->willReturn($qb);
69
+
70
+        $qb->method('setFirstResult')
71
+            ->willReturn($qb);
72
+
73
+        $result = $this->createMock(IResult::class);
74
+
75
+        $qb->method('execute')
76
+            ->willReturn($result);
77
+
78
+        $result->expects($this->once())
79
+            ->method('fetchOne')
80
+            ->willReturn(count($subscriptions));
81
+
82
+        $result
83
+            ->method('fetch')
84
+            ->willReturnOnConsecutiveCalls(...$subscriptions);
85
+
86
+        $qb->method('delete')
87
+            ->with('calendarsubscriptions')
88
+            ->willReturn($qb);
89
+
90
+        $expr = $this->createMock(IExpressionBuilder::class);
91
+
92
+        $qb->method('expr')->willReturn($expr);
93
+        $qb->method('createNamedParameter')->willReturn($this->createMock(IParameter::class));
94
+        $qb->method('where')->willReturn($qb);
95
+        // Only when user exists
96
+        $qb->expects($this->exactly($deletions))->method('executeStatement');
97
+
98
+        $this->dbConnection->method('getQueryBuilder')->willReturn($qb);
99
+
100
+
101
+        $this->output->expects($this->once())->method('startProgress');
102
+
103
+        $this->output->expects($subscriptions === [] ? $this->never(): $this->once())->method('advance');
104
+        if (count($subscriptions)) {
105
+            $this->userManager->method('userExists')
106
+                ->willReturnCallback(function (string $username) use ($userExists) {
107
+                    return $userExists[$username];
108
+                });
109
+        }
110
+        $this->output->expects($this->once())->method('finishProgress');
111
+        $this->output->expects($this->once())->method('info')->with(sprintf('%d calendar subscriptions without an user have been cleaned up', $deletions));
112
+
113
+        $this->migration->run($this->output);
114
+    }
115
+
116
+    public static function dataTestRun(): array {
117
+        return [
118
+            [[], [], 0],
119
+            [
120
+                [
121
+                    [
122
+                        'id' => 1,
123
+                        'principaluri' => 'users/principals/foo1',
124
+                    ],
125
+                    [
126
+                        'id' => 2,
127
+                        'principaluri' => 'users/principals/bar1',
128
+                    ],
129
+                    [
130
+                        'id' => 3,
131
+                        'principaluri' => 'users/principals/bar1',
132
+                    ],
133
+                    [],
134
+                ],
135
+                ['foo1' => true, 'bar1' => false],
136
+                2
137
+            ],
138
+        ];
139
+    }
140 140
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/Listener/ActivityUpdaterListenerTest.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -20,61 +20,61 @@
 block discarded – undo
20 20
 
21 21
 class ActivityUpdaterListenerTest extends TestCase {
22 22
 
23
-	private ActivityBackend&MockObject $activityBackend;
24
-	private LoggerInterface&MockObject $logger;
25
-	private ActivityUpdaterListener $listener;
23
+    private ActivityBackend&MockObject $activityBackend;
24
+    private LoggerInterface&MockObject $logger;
25
+    private ActivityUpdaterListener $listener;
26 26
 
27
-	protected function setUp(): void {
28
-		parent::setUp();
27
+    protected function setUp(): void {
28
+        parent::setUp();
29 29
 
30
-		$this->activityBackend = $this->createMock(ActivityBackend::class);
31
-		$this->logger = $this->createMock(LoggerInterface::class);
30
+        $this->activityBackend = $this->createMock(ActivityBackend::class);
31
+        $this->logger = $this->createMock(LoggerInterface::class);
32 32
 
33
-		$this->listener = new ActivityUpdaterListener(
34
-			$this->activityBackend,
35
-			$this->logger
36
-		);
37
-	}
33
+        $this->listener = new ActivityUpdaterListener(
34
+            $this->activityBackend,
35
+            $this->logger
36
+        );
37
+    }
38 38
 
39
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataForTestHandleCalendarObjectDeletedEvent')]
40
-	public function testHandleCalendarObjectDeletedEvent(int $calendarId, array $calendarData, array $shares, array $objectData, bool $createsActivity): void {
41
-		$event = new CalendarObjectDeletedEvent($calendarId, $calendarData, $shares, $objectData);
42
-		$this->logger->expects($this->once())->method('debug')->with(
43
-			$createsActivity ? "Activity generated for deleted calendar object in calendar $calendarId" : "Calendar object in calendar $calendarId was already in trashbin, skipping deletion activity"
44
-		);
45
-		$this->activityBackend->expects($createsActivity ? $this->once() : $this->never())->method('onTouchCalendarObject')->with(
46
-			Event::SUBJECT_OBJECT_DELETE,
47
-			$calendarData,
48
-			$shares,
49
-			$objectData
50
-		);
51
-		$this->listener->handle($event);
52
-	}
39
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataForTestHandleCalendarObjectDeletedEvent')]
40
+    public function testHandleCalendarObjectDeletedEvent(int $calendarId, array $calendarData, array $shares, array $objectData, bool $createsActivity): void {
41
+        $event = new CalendarObjectDeletedEvent($calendarId, $calendarData, $shares, $objectData);
42
+        $this->logger->expects($this->once())->method('debug')->with(
43
+            $createsActivity ? "Activity generated for deleted calendar object in calendar $calendarId" : "Calendar object in calendar $calendarId was already in trashbin, skipping deletion activity"
44
+        );
45
+        $this->activityBackend->expects($createsActivity ? $this->once() : $this->never())->method('onTouchCalendarObject')->with(
46
+            Event::SUBJECT_OBJECT_DELETE,
47
+            $calendarData,
48
+            $shares,
49
+            $objectData
50
+        );
51
+        $this->listener->handle($event);
52
+    }
53 53
 
54
-	public static function dataForTestHandleCalendarObjectDeletedEvent(): array {
55
-		return [
56
-			[1, [], [], [], true],
57
-			[1, [], [], ['{' . SharingPlugin::NS_NEXTCLOUD . '}deleted-at' => 120], false],
58
-		];
59
-	}
54
+    public static function dataForTestHandleCalendarObjectDeletedEvent(): array {
55
+        return [
56
+            [1, [], [], [], true],
57
+            [1, [], [], ['{' . SharingPlugin::NS_NEXTCLOUD . '}deleted-at' => 120], false],
58
+        ];
59
+    }
60 60
 
61
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataForTestHandleCalendarDeletedEvent')]
62
-	public function testHandleCalendarDeletedEvent(int $calendarId, array $calendarData, array $shares, bool $createsActivity): void {
63
-		$event = new CalendarDeletedEvent($calendarId, $calendarData, $shares);
64
-		$this->logger->expects($this->once())->method('debug')->with(
65
-			$createsActivity ? "Activity generated for deleted calendar $calendarId" : "Calendar $calendarId was already in trashbin, skipping deletion activity"
66
-		);
67
-		$this->activityBackend->expects($createsActivity ? $this->once() : $this->never())->method('onCalendarDelete')->with(
68
-			$calendarData,
69
-			$shares
70
-		);
71
-		$this->listener->handle($event);
72
-	}
61
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataForTestHandleCalendarDeletedEvent')]
62
+    public function testHandleCalendarDeletedEvent(int $calendarId, array $calendarData, array $shares, bool $createsActivity): void {
63
+        $event = new CalendarDeletedEvent($calendarId, $calendarData, $shares);
64
+        $this->logger->expects($this->once())->method('debug')->with(
65
+            $createsActivity ? "Activity generated for deleted calendar $calendarId" : "Calendar $calendarId was already in trashbin, skipping deletion activity"
66
+        );
67
+        $this->activityBackend->expects($createsActivity ? $this->once() : $this->never())->method('onCalendarDelete')->with(
68
+            $calendarData,
69
+            $shares
70
+        );
71
+        $this->listener->handle($event);
72
+    }
73 73
 
74
-	public static function dataForTestHandleCalendarDeletedEvent(): array {
75
-		return [
76
-			[1, [], [], true],
77
-			[1, ['{' . SharingPlugin::NS_NEXTCLOUD . '}deleted-at' => 120], [], false],
78
-		];
79
-	}
74
+    public static function dataForTestHandleCalendarDeletedEvent(): array {
75
+        return [
76
+            [1, [], [], true],
77
+            [1, ['{' . SharingPlugin::NS_NEXTCLOUD . '}deleted-at' => 120], [], false],
78
+        ];
79
+    }
80 80
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/SystemTag/SystemTagsObjectMappingCollectionTest.php 1 patch
Indentation   +280 added lines, -280 removed lines patch added patch discarded remove patch
@@ -17,331 +17,331 @@
 block discarded – undo
17 17
 use PHPUnit\Framework\MockObject\MockObject;
18 18
 
19 19
 class SystemTagsObjectMappingCollectionTest extends \Test\TestCase {
20
-	private ISystemTagManager&MockObject $tagManager;
21
-	private ISystemTagObjectMapper&MockObject $tagMapper;
22
-	private IUser&MockObject $user;
23
-
24
-	protected function setUp(): void {
25
-		parent::setUp();
26
-
27
-		$this->tagManager = $this->createMock(ISystemTagManager::class);
28
-		$this->tagMapper = $this->createMock(ISystemTagObjectMapper::class);
29
-		$this->user = $this->createMock(IUser::class);
30
-	}
31
-
32
-	public function getNode(array $writableNodeIds = []): SystemTagsObjectMappingCollection {
33
-		return new SystemTagsObjectMappingCollection(
34
-			'111',
35
-			'files',
36
-			$this->user,
37
-			$this->tagManager,
38
-			$this->tagMapper,
39
-			fn ($id): bool => in_array($id, $writableNodeIds),
40
-		);
41
-	}
42
-
43
-	public function testAssignTag(): void {
44
-		$tag = new SystemTag('1', 'Test', true, true);
45
-		$this->tagManager->expects($this->once())
46
-			->method('canUserSeeTag')
47
-			->with($tag)
48
-			->willReturn(true);
49
-		$this->tagManager->expects($this->once())
50
-			->method('canUserAssignTag')
51
-			->with($tag)
52
-			->willReturn(true);
53
-
54
-		$this->tagManager->expects($this->once())
55
-			->method('getTagsByIds')
56
-			->with(['555'])
57
-			->willReturn([$tag]);
58
-		$this->tagMapper->expects($this->once())
59
-			->method('assignTags')
60
-			->with(111, 'files', '555');
61
-
62
-		$this->getNode([111])->createFile('555');
63
-	}
64
-
65
-	public function testAssignTagForbidden(): void {
66
-		$tag = new SystemTag('1', 'Test', true, true);
67
-		$this->tagManager->expects($this->once())
68
-			->method('canUserSeeTag')
69
-			->with($tag)
70
-			->willReturn(true);
71
-		$this->tagManager->expects($this->once())
72
-			->method('canUserAssignTag')
73
-			->with($tag)
74
-			->willReturn(true);
75
-
76
-		$this->tagManager->expects($this->once())
77
-			->method('getTagsByIds')
78
-			->with(['555'])
79
-			->willReturn([$tag]);
80
-		$this->tagMapper->expects($this->never())
81
-			->method('assignTags');
82
-
83
-		$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
84
-		$this->getNode()->createFile('555');
85
-	}
86
-
87
-	public static function permissionsProvider(): array {
88
-		return [
89
-			// invisible, tag does not exist for user
90
-			[false, true, '\Sabre\DAV\Exception\PreconditionFailed'],
91
-			// visible but static, cannot assign tag
92
-			[true, false, '\Sabre\DAV\Exception\Forbidden'],
93
-		];
94
-	}
95
-
96
-	#[\PHPUnit\Framework\Attributes\DataProvider('permissionsProvider')]
97
-	public function testAssignTagNoPermission(bool $userVisible, bool $userAssignable, string $expectedException): void {
98
-		$tag = new SystemTag('1', 'Test', $userVisible, $userAssignable);
99
-		$this->tagManager->expects($this->once())
100
-			->method('canUserSeeTag')
101
-			->with($tag)
102
-			->willReturn($userVisible);
103
-		$this->tagManager->expects($this->any())
104
-			->method('canUserAssignTag')
105
-			->with($tag)
106
-			->willReturn($userAssignable);
107
-
108
-		$this->tagManager->expects($this->once())
109
-			->method('getTagsByIds')
110
-			->with(['555'])
111
-			->willReturn([$tag]);
112
-		$this->tagMapper->expects($this->never())
113
-			->method('assignTags');
114
-
115
-		$thrown = null;
116
-		try {
117
-			$this->getNode()->createFile('555');
118
-		} catch (\Exception $e) {
119
-			$thrown = $e;
120
-		}
121
-
122
-		$this->assertInstanceOf($expectedException, $thrown);
123
-	}
124
-
125
-
126
-	public function testAssignTagNotFound(): void {
127
-		$this->expectException(\Sabre\DAV\Exception\PreconditionFailed::class);
128
-
129
-		$this->tagManager->expects($this->once())
130
-			->method('getTagsByIds')
131
-			->with(['555'])
132
-			->willThrowException(new TagNotFoundException());
133
-
134
-		$this->getNode()->createFile('555');
135
-	}
136
-
137
-
138
-	public function testForbiddenCreateDirectory(): void {
139
-		$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
140
-
141
-		$this->getNode()->createDirectory('789');
142
-	}
143
-
144
-	public function testGetChild(): void {
145
-		$tag = new SystemTag('555', 'TheTag', true, false);
146
-		$this->tagManager->expects($this->once())
147
-			->method('canUserSeeTag')
148
-			->with($tag)
149
-			->willReturn(true);
150
-
151
-		$this->tagMapper->expects($this->once())
152
-			->method('haveTag')
153
-			->with([111], 'files', '555', true)
154
-			->willReturn(true);
155
-
156
-		$this->tagManager->expects($this->once())
157
-			->method('getTagsByIds')
158
-			->with(['555'])
159
-			->willReturn(['555' => $tag]);
160
-
161
-		$childNode = $this->getNode()->getChild('555');
162
-
163
-		$this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagMappingNode', $childNode);
164
-		$this->assertEquals('555', $childNode->getName());
165
-	}
166
-
167
-
168
-	public function testGetChildNonVisible(): void {
169
-		$this->expectException(\Sabre\DAV\Exception\NotFound::class);
170
-
171
-		$tag = new SystemTag('555', 'TheTag', false, false);
172
-		$this->tagManager->expects($this->once())
173
-			->method('canUserSeeTag')
174
-			->with($tag)
175
-			->willReturn(false);
176
-
177
-		$this->tagMapper->expects($this->once())
178
-			->method('haveTag')
179
-			->with([111], 'files', '555', true)
180
-			->willReturn(true);
20
+    private ISystemTagManager&MockObject $tagManager;
21
+    private ISystemTagObjectMapper&MockObject $tagMapper;
22
+    private IUser&MockObject $user;
23
+
24
+    protected function setUp(): void {
25
+        parent::setUp();
26
+
27
+        $this->tagManager = $this->createMock(ISystemTagManager::class);
28
+        $this->tagMapper = $this->createMock(ISystemTagObjectMapper::class);
29
+        $this->user = $this->createMock(IUser::class);
30
+    }
31
+
32
+    public function getNode(array $writableNodeIds = []): SystemTagsObjectMappingCollection {
33
+        return new SystemTagsObjectMappingCollection(
34
+            '111',
35
+            'files',
36
+            $this->user,
37
+            $this->tagManager,
38
+            $this->tagMapper,
39
+            fn ($id): bool => in_array($id, $writableNodeIds),
40
+        );
41
+    }
42
+
43
+    public function testAssignTag(): void {
44
+        $tag = new SystemTag('1', 'Test', true, true);
45
+        $this->tagManager->expects($this->once())
46
+            ->method('canUserSeeTag')
47
+            ->with($tag)
48
+            ->willReturn(true);
49
+        $this->tagManager->expects($this->once())
50
+            ->method('canUserAssignTag')
51
+            ->with($tag)
52
+            ->willReturn(true);
53
+
54
+        $this->tagManager->expects($this->once())
55
+            ->method('getTagsByIds')
56
+            ->with(['555'])
57
+            ->willReturn([$tag]);
58
+        $this->tagMapper->expects($this->once())
59
+            ->method('assignTags')
60
+            ->with(111, 'files', '555');
61
+
62
+        $this->getNode([111])->createFile('555');
63
+    }
64
+
65
+    public function testAssignTagForbidden(): void {
66
+        $tag = new SystemTag('1', 'Test', true, true);
67
+        $this->tagManager->expects($this->once())
68
+            ->method('canUserSeeTag')
69
+            ->with($tag)
70
+            ->willReturn(true);
71
+        $this->tagManager->expects($this->once())
72
+            ->method('canUserAssignTag')
73
+            ->with($tag)
74
+            ->willReturn(true);
75
+
76
+        $this->tagManager->expects($this->once())
77
+            ->method('getTagsByIds')
78
+            ->with(['555'])
79
+            ->willReturn([$tag]);
80
+        $this->tagMapper->expects($this->never())
81
+            ->method('assignTags');
82
+
83
+        $this->expectException(\Sabre\DAV\Exception\Forbidden::class);
84
+        $this->getNode()->createFile('555');
85
+    }
86
+
87
+    public static function permissionsProvider(): array {
88
+        return [
89
+            // invisible, tag does not exist for user
90
+            [false, true, '\Sabre\DAV\Exception\PreconditionFailed'],
91
+            // visible but static, cannot assign tag
92
+            [true, false, '\Sabre\DAV\Exception\Forbidden'],
93
+        ];
94
+    }
95
+
96
+    #[\PHPUnit\Framework\Attributes\DataProvider('permissionsProvider')]
97
+    public function testAssignTagNoPermission(bool $userVisible, bool $userAssignable, string $expectedException): void {
98
+        $tag = new SystemTag('1', 'Test', $userVisible, $userAssignable);
99
+        $this->tagManager->expects($this->once())
100
+            ->method('canUserSeeTag')
101
+            ->with($tag)
102
+            ->willReturn($userVisible);
103
+        $this->tagManager->expects($this->any())
104
+            ->method('canUserAssignTag')
105
+            ->with($tag)
106
+            ->willReturn($userAssignable);
107
+
108
+        $this->tagManager->expects($this->once())
109
+            ->method('getTagsByIds')
110
+            ->with(['555'])
111
+            ->willReturn([$tag]);
112
+        $this->tagMapper->expects($this->never())
113
+            ->method('assignTags');
114
+
115
+        $thrown = null;
116
+        try {
117
+            $this->getNode()->createFile('555');
118
+        } catch (\Exception $e) {
119
+            $thrown = $e;
120
+        }
121
+
122
+        $this->assertInstanceOf($expectedException, $thrown);
123
+    }
124
+
125
+
126
+    public function testAssignTagNotFound(): void {
127
+        $this->expectException(\Sabre\DAV\Exception\PreconditionFailed::class);
128
+
129
+        $this->tagManager->expects($this->once())
130
+            ->method('getTagsByIds')
131
+            ->with(['555'])
132
+            ->willThrowException(new TagNotFoundException());
133
+
134
+        $this->getNode()->createFile('555');
135
+    }
136
+
137
+
138
+    public function testForbiddenCreateDirectory(): void {
139
+        $this->expectException(\Sabre\DAV\Exception\Forbidden::class);
140
+
141
+        $this->getNode()->createDirectory('789');
142
+    }
143
+
144
+    public function testGetChild(): void {
145
+        $tag = new SystemTag('555', 'TheTag', true, false);
146
+        $this->tagManager->expects($this->once())
147
+            ->method('canUserSeeTag')
148
+            ->with($tag)
149
+            ->willReturn(true);
150
+
151
+        $this->tagMapper->expects($this->once())
152
+            ->method('haveTag')
153
+            ->with([111], 'files', '555', true)
154
+            ->willReturn(true);
155
+
156
+        $this->tagManager->expects($this->once())
157
+            ->method('getTagsByIds')
158
+            ->with(['555'])
159
+            ->willReturn(['555' => $tag]);
160
+
161
+        $childNode = $this->getNode()->getChild('555');
162
+
163
+        $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagMappingNode', $childNode);
164
+        $this->assertEquals('555', $childNode->getName());
165
+    }
166
+
167
+
168
+    public function testGetChildNonVisible(): void {
169
+        $this->expectException(\Sabre\DAV\Exception\NotFound::class);
170
+
171
+        $tag = new SystemTag('555', 'TheTag', false, false);
172
+        $this->tagManager->expects($this->once())
173
+            ->method('canUserSeeTag')
174
+            ->with($tag)
175
+            ->willReturn(false);
176
+
177
+        $this->tagMapper->expects($this->once())
178
+            ->method('haveTag')
179
+            ->with([111], 'files', '555', true)
180
+            ->willReturn(true);
181 181
 
182
-		$this->tagManager->expects($this->once())
183
-			->method('getTagsByIds')
184
-			->with(['555'])
185
-			->willReturn(['555' => $tag]);
182
+        $this->tagManager->expects($this->once())
183
+            ->method('getTagsByIds')
184
+            ->with(['555'])
185
+            ->willReturn(['555' => $tag]);
186 186
 
187
-		$this->getNode()->getChild('555');
188
-	}
187
+        $this->getNode()->getChild('555');
188
+    }
189 189
 
190 190
 
191
-	public function testGetChildRelationNotFound(): void {
192
-		$this->expectException(\Sabre\DAV\Exception\NotFound::class);
191
+    public function testGetChildRelationNotFound(): void {
192
+        $this->expectException(\Sabre\DAV\Exception\NotFound::class);
193 193
 
194
-		$this->tagMapper->expects($this->once())
195
-			->method('haveTag')
196
-			->with([111], 'files', '777')
197
-			->willReturn(false);
194
+        $this->tagMapper->expects($this->once())
195
+            ->method('haveTag')
196
+            ->with([111], 'files', '777')
197
+            ->willReturn(false);
198 198
 
199
-		$this->getNode()->getChild('777');
200
-	}
199
+        $this->getNode()->getChild('777');
200
+    }
201 201
 
202 202
 
203
-	public function testGetChildInvalidId(): void {
204
-		$this->expectException(\Sabre\DAV\Exception\BadRequest::class);
203
+    public function testGetChildInvalidId(): void {
204
+        $this->expectException(\Sabre\DAV\Exception\BadRequest::class);
205 205
 
206
-		$this->tagMapper->expects($this->once())
207
-			->method('haveTag')
208
-			->with([111], 'files', 'badid')
209
-			->willThrowException(new \InvalidArgumentException());
206
+        $this->tagMapper->expects($this->once())
207
+            ->method('haveTag')
208
+            ->with([111], 'files', 'badid')
209
+            ->willThrowException(new \InvalidArgumentException());
210 210
 
211
-		$this->getNode()->getChild('badid');
212
-	}
211
+        $this->getNode()->getChild('badid');
212
+    }
213 213
 
214 214
 
215
-	public function testGetChildTagDoesNotExist(): void {
216
-		$this->expectException(\Sabre\DAV\Exception\NotFound::class);
215
+    public function testGetChildTagDoesNotExist(): void {
216
+        $this->expectException(\Sabre\DAV\Exception\NotFound::class);
217 217
 
218
-		$this->tagMapper->expects($this->once())
219
-			->method('haveTag')
220
-			->with([111], 'files', '777')
221
-			->willThrowException(new TagNotFoundException());
218
+        $this->tagMapper->expects($this->once())
219
+            ->method('haveTag')
220
+            ->with([111], 'files', '777')
221
+            ->willThrowException(new TagNotFoundException());
222 222
 
223
-		$this->getNode()->getChild('777');
224
-	}
223
+        $this->getNode()->getChild('777');
224
+    }
225 225
 
226
-	public function testGetChildren(): void {
227
-		$tag1 = new SystemTag('555', 'TagOne', true, false);
228
-		$tag2 = new SystemTag('556', 'TagTwo', true, true);
229
-		$tag3 = new SystemTag('557', 'InvisibleTag', false, true);
226
+    public function testGetChildren(): void {
227
+        $tag1 = new SystemTag('555', 'TagOne', true, false);
228
+        $tag2 = new SystemTag('556', 'TagTwo', true, true);
229
+        $tag3 = new SystemTag('557', 'InvisibleTag', false, true);
230 230
 
231
-		$this->tagMapper->expects($this->once())
232
-			->method('getTagIdsForObjects')
233
-			->with([111], 'files')
234
-			->willReturn(['111' => ['555', '556', '557']]);
231
+        $this->tagMapper->expects($this->once())
232
+            ->method('getTagIdsForObjects')
233
+            ->with([111], 'files')
234
+            ->willReturn(['111' => ['555', '556', '557']]);
235 235
 
236
-		$this->tagManager->expects($this->once())
237
-			->method('getTagsByIds')
238
-			->with(['555', '556', '557'])
239
-			->willReturn(['555' => $tag1, '556' => $tag2, '557' => $tag3]);
236
+        $this->tagManager->expects($this->once())
237
+            ->method('getTagsByIds')
238
+            ->with(['555', '556', '557'])
239
+            ->willReturn(['555' => $tag1, '556' => $tag2, '557' => $tag3]);
240 240
 
241
-		$this->tagManager->expects($this->exactly(3))
242
-			->method('canUserSeeTag')
243
-			->willReturnCallback(function ($tag) {
244
-				return $tag->isUserVisible();
245
-			});
241
+        $this->tagManager->expects($this->exactly(3))
242
+            ->method('canUserSeeTag')
243
+            ->willReturnCallback(function ($tag) {
244
+                return $tag->isUserVisible();
245
+            });
246 246
 
247
-		$children = $this->getNode()->getChildren();
247
+        $children = $this->getNode()->getChildren();
248 248
 
249
-		$this->assertCount(2, $children);
249
+        $this->assertCount(2, $children);
250 250
 
251
-		$this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagMappingNode', $children[0]);
252
-		$this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagMappingNode', $children[1]);
251
+        $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagMappingNode', $children[0]);
252
+        $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagMappingNode', $children[1]);
253 253
 
254
-		$this->assertEquals(111, $children[0]->getObjectId());
255
-		$this->assertEquals('files', $children[0]->getObjectType());
256
-		$this->assertEquals($tag1, $children[0]->getSystemTag());
254
+        $this->assertEquals(111, $children[0]->getObjectId());
255
+        $this->assertEquals('files', $children[0]->getObjectType());
256
+        $this->assertEquals($tag1, $children[0]->getSystemTag());
257 257
 
258
-		$this->assertEquals(111, $children[1]->getObjectId());
259
-		$this->assertEquals('files', $children[1]->getObjectType());
260
-		$this->assertEquals($tag2, $children[1]->getSystemTag());
261
-	}
258
+        $this->assertEquals(111, $children[1]->getObjectId());
259
+        $this->assertEquals('files', $children[1]->getObjectType());
260
+        $this->assertEquals($tag2, $children[1]->getSystemTag());
261
+    }
262 262
 
263
-	public function testChildExistsWithVisibleTag(): void {
264
-		$tag = new SystemTag('555', 'TagOne', true, false);
263
+    public function testChildExistsWithVisibleTag(): void {
264
+        $tag = new SystemTag('555', 'TagOne', true, false);
265 265
 
266
-		$this->tagMapper->expects($this->once())
267
-			->method('haveTag')
268
-			->with([111], 'files', '555')
269
-			->willReturn(true);
266
+        $this->tagMapper->expects($this->once())
267
+            ->method('haveTag')
268
+            ->with([111], 'files', '555')
269
+            ->willReturn(true);
270 270
 
271
-		$this->tagManager->expects($this->once())
272
-			->method('canUserSeeTag')
273
-			->with($tag)
274
-			->willReturn(true);
271
+        $this->tagManager->expects($this->once())
272
+            ->method('canUserSeeTag')
273
+            ->with($tag)
274
+            ->willReturn(true);
275 275
 
276
-		$this->tagManager->expects($this->once())
277
-			->method('getTagsByIds')
278
-			->with(['555'])
279
-			->willReturn([$tag]);
276
+        $this->tagManager->expects($this->once())
277
+            ->method('getTagsByIds')
278
+            ->with(['555'])
279
+            ->willReturn([$tag]);
280 280
 
281
-		$this->assertTrue($this->getNode()->childExists('555'));
282
-	}
281
+        $this->assertTrue($this->getNode()->childExists('555'));
282
+    }
283 283
 
284
-	public function testChildExistsWithInvisibleTag(): void {
285
-		$tag = new SystemTag('555', 'TagOne', false, false);
284
+    public function testChildExistsWithInvisibleTag(): void {
285
+        $tag = new SystemTag('555', 'TagOne', false, false);
286 286
 
287
-		$this->tagMapper->expects($this->once())
288
-			->method('haveTag')
289
-			->with([111], 'files', '555')
290
-			->willReturn(true);
287
+        $this->tagMapper->expects($this->once())
288
+            ->method('haveTag')
289
+            ->with([111], 'files', '555')
290
+            ->willReturn(true);
291 291
 
292
-		$this->tagManager->expects($this->once())
293
-			->method('getTagsByIds')
294
-			->with(['555'])
295
-			->willReturn([$tag]);
292
+        $this->tagManager->expects($this->once())
293
+            ->method('getTagsByIds')
294
+            ->with(['555'])
295
+            ->willReturn([$tag]);
296 296
 
297
-		$this->assertFalse($this->getNode()->childExists('555'));
298
-	}
297
+        $this->assertFalse($this->getNode()->childExists('555'));
298
+    }
299 299
 
300
-	public function testChildExistsNotFound(): void {
301
-		$this->tagMapper->expects($this->once())
302
-			->method('haveTag')
303
-			->with([111], 'files', '555')
304
-			->willReturn(false);
300
+    public function testChildExistsNotFound(): void {
301
+        $this->tagMapper->expects($this->once())
302
+            ->method('haveTag')
303
+            ->with([111], 'files', '555')
304
+            ->willReturn(false);
305 305
 
306
-		$this->assertFalse($this->getNode()->childExists('555'));
307
-	}
306
+        $this->assertFalse($this->getNode()->childExists('555'));
307
+    }
308 308
 
309
-	public function testChildExistsTagNotFound(): void {
310
-		$this->tagMapper->expects($this->once())
311
-			->method('haveTag')
312
-			->with([111], 'files', '555')
313
-			->willThrowException(new TagNotFoundException());
309
+    public function testChildExistsTagNotFound(): void {
310
+        $this->tagMapper->expects($this->once())
311
+            ->method('haveTag')
312
+            ->with([111], 'files', '555')
313
+            ->willThrowException(new TagNotFoundException());
314 314
 
315
-		$this->assertFalse($this->getNode()->childExists('555'));
316
-	}
315
+        $this->assertFalse($this->getNode()->childExists('555'));
316
+    }
317 317
 
318 318
 
319
-	public function testChildExistsInvalidId(): void {
320
-		$this->expectException(\Sabre\DAV\Exception\BadRequest::class);
319
+    public function testChildExistsInvalidId(): void {
320
+        $this->expectException(\Sabre\DAV\Exception\BadRequest::class);
321 321
 
322
-		$this->tagMapper->expects($this->once())
323
-			->method('haveTag')
324
-			->with([111], 'files', '555')
325
-			->willThrowException(new \InvalidArgumentException());
322
+        $this->tagMapper->expects($this->once())
323
+            ->method('haveTag')
324
+            ->with([111], 'files', '555')
325
+            ->willThrowException(new \InvalidArgumentException());
326 326
 
327
-		$this->getNode()->childExists('555');
328
-	}
327
+        $this->getNode()->childExists('555');
328
+    }
329 329
 
330 330
 
331
-	public function testDelete(): void {
332
-		$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
331
+    public function testDelete(): void {
332
+        $this->expectException(\Sabre\DAV\Exception\Forbidden::class);
333 333
 
334
-		$this->getNode()->delete();
335
-	}
334
+        $this->getNode()->delete();
335
+    }
336 336
 
337 337
 
338
-	public function testSetName(): void {
339
-		$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
338
+    public function testSetName(): void {
339
+        $this->expectException(\Sabre\DAV\Exception\Forbidden::class);
340 340
 
341
-		$this->getNode()->setName('somethingelse');
342
-	}
341
+        $this->getNode()->setName('somethingelse');
342
+    }
343 343
 
344
-	public function testGetName(): void {
345
-		$this->assertEquals('111', $this->getNode()->getName());
346
-	}
344
+    public function testGetName(): void {
345
+        $this->assertEquals('111', $this->getNode()->getName());
346
+    }
347 347
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/SystemTag/SystemTagsByIdCollectionTest.php 1 patch
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -19,206 +19,206 @@
 block discarded – undo
19 19
 use PHPUnit\Framework\MockObject\MockObject;
20 20
 
21 21
 class SystemTagsByIdCollectionTest extends \Test\TestCase {
22
-	private ISystemTagManager&MockObject $tagManager;
23
-	private IUser&MockObject $user;
22
+    private ISystemTagManager&MockObject $tagManager;
23
+    private IUser&MockObject $user;
24 24
 
25
-	protected function setUp(): void {
26
-		parent::setUp();
25
+    protected function setUp(): void {
26
+        parent::setUp();
27 27
 
28
-		$this->tagManager = $this->createMock(ISystemTagManager::class);
29
-	}
28
+        $this->tagManager = $this->createMock(ISystemTagManager::class);
29
+    }
30 30
 
31
-	public function getNode(bool $isAdmin = true) {
32
-		$this->user = $this->createMock(IUser::class);
33
-		$this->user->expects($this->any())
34
-			->method('getUID')
35
-			->willReturn('testuser');
31
+    public function getNode(bool $isAdmin = true) {
32
+        $this->user = $this->createMock(IUser::class);
33
+        $this->user->expects($this->any())
34
+            ->method('getUID')
35
+            ->willReturn('testuser');
36 36
 
37
-		/** @var IUserSession&MockObject */
38
-		$userSession = $this->createMock(IUserSession::class);
39
-		$userSession->expects($this->any())
40
-			->method('getUser')
41
-			->willReturn($this->user);
37
+        /** @var IUserSession&MockObject */
38
+        $userSession = $this->createMock(IUserSession::class);
39
+        $userSession->expects($this->any())
40
+            ->method('getUser')
41
+            ->willReturn($this->user);
42 42
 
43
-		/** @var IGroupManager&MockObject */
44
-		$groupManager = $this->createMock(IGroupManager::class);
45
-		$groupManager->expects($this->any())
46
-			->method('isAdmin')
47
-			->with('testuser')
48
-			->willReturn($isAdmin);
43
+        /** @var IGroupManager&MockObject */
44
+        $groupManager = $this->createMock(IGroupManager::class);
45
+        $groupManager->expects($this->any())
46
+            ->method('isAdmin')
47
+            ->with('testuser')
48
+            ->willReturn($isAdmin);
49 49
 
50
-		/** @var ISystemTagObjectMapper&MockObject */
51
-		$tagMapper = $this->createMock(ISystemTagObjectMapper::class);
52
-		return new SystemTagsByIdCollection(
53
-			$this->tagManager,
54
-			$userSession,
55
-			$groupManager,
56
-			$tagMapper,
57
-		);
58
-	}
50
+        /** @var ISystemTagObjectMapper&MockObject */
51
+        $tagMapper = $this->createMock(ISystemTagObjectMapper::class);
52
+        return new SystemTagsByIdCollection(
53
+            $this->tagManager,
54
+            $userSession,
55
+            $groupManager,
56
+            $tagMapper,
57
+        );
58
+    }
59 59
 
60
-	public static function adminFlagProvider(): array {
61
-		return [[true], [false]];
62
-	}
60
+    public static function adminFlagProvider(): array {
61
+        return [[true], [false]];
62
+    }
63 63
 
64 64
 
65
-	public function testForbiddenCreateFile(): void {
66
-		$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
65
+    public function testForbiddenCreateFile(): void {
66
+        $this->expectException(\Sabre\DAV\Exception\Forbidden::class);
67 67
 
68
-		$this->getNode()->createFile('555');
69
-	}
68
+        $this->getNode()->createFile('555');
69
+    }
70 70
 
71 71
 
72
-	public function testForbiddenCreateDirectory(): void {
73
-		$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
72
+    public function testForbiddenCreateDirectory(): void {
73
+        $this->expectException(\Sabre\DAV\Exception\Forbidden::class);
74 74
 
75
-		$this->getNode()->createDirectory('789');
76
-	}
75
+        $this->getNode()->createDirectory('789');
76
+    }
77 77
 
78
-	public function testGetChild(): void {
79
-		$tag = new SystemTag('123', 'Test', true, false);
80
-		$this->tagManager->expects($this->once())
81
-			->method('canUserSeeTag')
82
-			->with($tag)
83
-			->willReturn(true);
78
+    public function testGetChild(): void {
79
+        $tag = new SystemTag('123', 'Test', true, false);
80
+        $this->tagManager->expects($this->once())
81
+            ->method('canUserSeeTag')
82
+            ->with($tag)
83
+            ->willReturn(true);
84 84
 
85
-		$this->tagManager->expects($this->once())
86
-			->method('getTagsByIds')
87
-			->with(['123'])
88
-			->willReturn([$tag]);
85
+        $this->tagManager->expects($this->once())
86
+            ->method('getTagsByIds')
87
+            ->with(['123'])
88
+            ->willReturn([$tag]);
89 89
 
90
-		$childNode = $this->getNode()->getChild('123');
90
+        $childNode = $this->getNode()->getChild('123');
91 91
 
92
-		$this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $childNode);
93
-		$this->assertEquals('123', $childNode->getName());
94
-		$this->assertEquals($tag, $childNode->getSystemTag());
95
-	}
92
+        $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $childNode);
93
+        $this->assertEquals('123', $childNode->getName());
94
+        $this->assertEquals($tag, $childNode->getSystemTag());
95
+    }
96 96
 
97 97
 
98
-	public function testGetChildInvalidName(): void {
99
-		$this->expectException(\Sabre\DAV\Exception\BadRequest::class);
98
+    public function testGetChildInvalidName(): void {
99
+        $this->expectException(\Sabre\DAV\Exception\BadRequest::class);
100 100
 
101
-		$this->tagManager->expects($this->once())
102
-			->method('getTagsByIds')
103
-			->with(['invalid'])
104
-			->willThrowException(new \InvalidArgumentException());
101
+        $this->tagManager->expects($this->once())
102
+            ->method('getTagsByIds')
103
+            ->with(['invalid'])
104
+            ->willThrowException(new \InvalidArgumentException());
105 105
 
106
-		$this->getNode()->getChild('invalid');
107
-	}
106
+        $this->getNode()->getChild('invalid');
107
+    }
108 108
 
109 109
 
110
-	public function testGetChildNotFound(): void {
111
-		$this->expectException(\Sabre\DAV\Exception\NotFound::class);
110
+    public function testGetChildNotFound(): void {
111
+        $this->expectException(\Sabre\DAV\Exception\NotFound::class);
112 112
 
113
-		$this->tagManager->expects($this->once())
114
-			->method('getTagsByIds')
115
-			->with(['444'])
116
-			->willThrowException(new TagNotFoundException());
113
+        $this->tagManager->expects($this->once())
114
+            ->method('getTagsByIds')
115
+            ->with(['444'])
116
+            ->willThrowException(new TagNotFoundException());
117 117
 
118
-		$this->getNode()->getChild('444');
119
-	}
118
+        $this->getNode()->getChild('444');
119
+    }
120 120
 
121 121
 
122
-	public function testGetChildUserNotVisible(): void {
123
-		$this->expectException(\Sabre\DAV\Exception\NotFound::class);
122
+    public function testGetChildUserNotVisible(): void {
123
+        $this->expectException(\Sabre\DAV\Exception\NotFound::class);
124 124
 
125
-		$tag = new SystemTag('123', 'Test', false, false);
125
+        $tag = new SystemTag('123', 'Test', false, false);
126 126
 
127
-		$this->tagManager->expects($this->once())
128
-			->method('getTagsByIds')
129
-			->with(['123'])
130
-			->willReturn([$tag]);
127
+        $this->tagManager->expects($this->once())
128
+            ->method('getTagsByIds')
129
+            ->with(['123'])
130
+            ->willReturn([$tag]);
131 131
 
132
-		$this->getNode(false)->getChild('123');
133
-	}
132
+        $this->getNode(false)->getChild('123');
133
+    }
134 134
 
135
-	public function testGetChildrenAdmin(): void {
136
-		$tag1 = new SystemTag('123', 'One', true, false);
137
-		$tag2 = new SystemTag('456', 'Two', true, true);
135
+    public function testGetChildrenAdmin(): void {
136
+        $tag1 = new SystemTag('123', 'One', true, false);
137
+        $tag2 = new SystemTag('456', 'Two', true, true);
138 138
 
139
-		$this->tagManager->expects($this->once())
140
-			->method('getAllTags')
141
-			->with(null)
142
-			->willReturn([$tag1, $tag2]);
139
+        $this->tagManager->expects($this->once())
140
+            ->method('getAllTags')
141
+            ->with(null)
142
+            ->willReturn([$tag1, $tag2]);
143 143
 
144
-		$children = $this->getNode(true)->getChildren();
144
+        $children = $this->getNode(true)->getChildren();
145 145
 
146
-		$this->assertCount(2, $children);
146
+        $this->assertCount(2, $children);
147 147
 
148
-		$this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $children[0]);
149
-		$this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $children[1]);
150
-		$this->assertEquals($tag1, $children[0]->getSystemTag());
151
-		$this->assertEquals($tag2, $children[1]->getSystemTag());
152
-	}
148
+        $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $children[0]);
149
+        $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $children[1]);
150
+        $this->assertEquals($tag1, $children[0]->getSystemTag());
151
+        $this->assertEquals($tag2, $children[1]->getSystemTag());
152
+    }
153 153
 
154
-	public function testGetChildrenNonAdmin(): void {
155
-		$tag1 = new SystemTag('123', 'One', true, false);
156
-		$tag2 = new SystemTag('456', 'Two', true, true);
154
+    public function testGetChildrenNonAdmin(): void {
155
+        $tag1 = new SystemTag('123', 'One', true, false);
156
+        $tag2 = new SystemTag('456', 'Two', true, true);
157 157
 
158
-		$this->tagManager->expects($this->once())
159
-			->method('getAllTags')
160
-			->with(true)
161
-			->willReturn([$tag1, $tag2]);
158
+        $this->tagManager->expects($this->once())
159
+            ->method('getAllTags')
160
+            ->with(true)
161
+            ->willReturn([$tag1, $tag2]);
162 162
 
163
-		$children = $this->getNode(false)->getChildren();
163
+        $children = $this->getNode(false)->getChildren();
164 164
 
165
-		$this->assertCount(2, $children);
165
+        $this->assertCount(2, $children);
166 166
 
167
-		$this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $children[0]);
168
-		$this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $children[1]);
169
-		$this->assertEquals($tag1, $children[0]->getSystemTag());
170
-		$this->assertEquals($tag2, $children[1]->getSystemTag());
171
-	}
167
+        $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $children[0]);
168
+        $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $children[1]);
169
+        $this->assertEquals($tag1, $children[0]->getSystemTag());
170
+        $this->assertEquals($tag2, $children[1]->getSystemTag());
171
+    }
172 172
 
173
-	public function testGetChildrenEmpty(): void {
174
-		$this->tagManager->expects($this->once())
175
-			->method('getAllTags')
176
-			->with(null)
177
-			->willReturn([]);
178
-		$this->assertCount(0, $this->getNode()->getChildren());
179
-	}
173
+    public function testGetChildrenEmpty(): void {
174
+        $this->tagManager->expects($this->once())
175
+            ->method('getAllTags')
176
+            ->with(null)
177
+            ->willReturn([]);
178
+        $this->assertCount(0, $this->getNode()->getChildren());
179
+    }
180 180
 
181
-	public static function childExistsProvider(): array {
182
-		return [
183
-			[true, true],
184
-			[false, false],
185
-		];
186
-	}
181
+    public static function childExistsProvider(): array {
182
+        return [
183
+            [true, true],
184
+            [false, false],
185
+        ];
186
+    }
187 187
 
188
-	#[\PHPUnit\Framework\Attributes\DataProvider('childExistsProvider')]
189
-	public function testChildExists(bool $userVisible, bool $expectedResult): void {
190
-		$tag = new SystemTag('123', 'One', $userVisible, false);
191
-		$this->tagManager->expects($this->once())
192
-			->method('canUserSeeTag')
193
-			->with($tag)
194
-			->willReturn($userVisible);
188
+    #[\PHPUnit\Framework\Attributes\DataProvider('childExistsProvider')]
189
+    public function testChildExists(bool $userVisible, bool $expectedResult): void {
190
+        $tag = new SystemTag('123', 'One', $userVisible, false);
191
+        $this->tagManager->expects($this->once())
192
+            ->method('canUserSeeTag')
193
+            ->with($tag)
194
+            ->willReturn($userVisible);
195 195
 
196
-		$this->tagManager->expects($this->once())
197
-			->method('getTagsByIds')
198
-			->with(['123'])
199
-			->willReturn([$tag]);
196
+        $this->tagManager->expects($this->once())
197
+            ->method('getTagsByIds')
198
+            ->with(['123'])
199
+            ->willReturn([$tag]);
200 200
 
201
-		$this->assertEquals($expectedResult, $this->getNode()->childExists('123'));
202
-	}
201
+        $this->assertEquals($expectedResult, $this->getNode()->childExists('123'));
202
+    }
203 203
 
204
-	public function testChildExistsNotFound(): void {
205
-		$this->tagManager->expects($this->once())
206
-			->method('getTagsByIds')
207
-			->with(['123'])
208
-			->willThrowException(new TagNotFoundException());
204
+    public function testChildExistsNotFound(): void {
205
+        $this->tagManager->expects($this->once())
206
+            ->method('getTagsByIds')
207
+            ->with(['123'])
208
+            ->willThrowException(new TagNotFoundException());
209 209
 
210
-		$this->assertFalse($this->getNode()->childExists('123'));
211
-	}
210
+        $this->assertFalse($this->getNode()->childExists('123'));
211
+    }
212 212
 
213 213
 
214
-	public function testChildExistsBadRequest(): void {
215
-		$this->expectException(\Sabre\DAV\Exception\BadRequest::class);
214
+    public function testChildExistsBadRequest(): void {
215
+        $this->expectException(\Sabre\DAV\Exception\BadRequest::class);
216 216
 
217
-		$this->tagManager->expects($this->once())
218
-			->method('getTagsByIds')
219
-			->with(['invalid'])
220
-			->willThrowException(new \InvalidArgumentException());
217
+        $this->tagManager->expects($this->once())
218
+            ->method('getTagsByIds')
219
+            ->with(['invalid'])
220
+            ->willThrowException(new \InvalidArgumentException());
221 221
 
222
-		$this->getNode()->childExists('invalid');
223
-	}
222
+        $this->getNode()->childExists('invalid');
223
+    }
224 224
 }
Please login to merge, or discard this patch.