diff options
Diffstat (limited to 'tests/lib/SystemTag')
-rw-r--r-- | tests/lib/SystemTag/SystemTagManagerTest.php | 55 | ||||
-rw-r--r-- | tests/lib/SystemTag/SystemTagObjectMapperTest.php | 11 |
2 files changed, 25 insertions, 41 deletions
diff --git a/tests/lib/SystemTag/SystemTagManagerTest.php b/tests/lib/SystemTag/SystemTagManagerTest.php index 4627ebbf546..7bbe86aabe7 100644 --- a/tests/lib/SystemTag/SystemTagManagerTest.php +++ b/tests/lib/SystemTag/SystemTagManagerTest.php @@ -16,8 +16,11 @@ use OCP\IDBConnection; use OCP\IGroupManager; use OCP\IUser; use OCP\IUserSession; +use OCP\Server; use OCP\SystemTag\ISystemTag; use OCP\SystemTag\ISystemTagManager; +use OCP\SystemTag\TagAlreadyExistsException; +use OCP\SystemTag\TagNotFoundException; use Test\TestCase; /** @@ -37,7 +40,7 @@ class SystemTagManagerTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = Server::get(IDBConnection::class); $this->dispatcher = $this->createMock(IEventDispatcher::class); $this->groupManager = $this->createMock(IGroupManager::class); @@ -93,9 +96,7 @@ class SystemTagManagerTest extends TestCase { ]; } - /** - * @dataProvider getAllTagsDataProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('getAllTagsDataProvider')] public function testGetAllTags($testTags): void { $testTagsById = []; foreach ($testTags as $testTag) { @@ -202,9 +203,7 @@ class SystemTagManagerTest extends TestCase { ]; } - /** - * @dataProvider getAllTagsFilteredDataProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('getAllTagsFilteredDataProvider')] public function testGetAllTagsFiltered($testTags, $visibilityFilter, $nameSearch, $expectedResults): void { foreach ($testTags as $testTag) { $this->tagManager->createTag($testTag[0], $testTag[1], $testTag[2]); @@ -235,11 +234,9 @@ class SystemTagManagerTest extends TestCase { ]; } - /** - * @dataProvider oneTagMultipleFlagsProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('oneTagMultipleFlagsProvider')] public function testCreateDuplicate($name, $userVisible, $userAssignable): void { - $this->expectException(\OCP\SystemTag\TagAlreadyExistsException::class); + $this->expectException(TagAlreadyExistsException::class); try { $this->tagManager->createTag($name, $userVisible, $userAssignable); @@ -254,9 +251,7 @@ class SystemTagManagerTest extends TestCase { $this->assertSame('Zona circundante do Palácio Nacional da Ajuda (Jardim das Damas', $tag->getName()); // 63 characters but 64 bytes due to "á" } - /** - * @dataProvider oneTagMultipleFlagsProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('oneTagMultipleFlagsProvider')] public function testGetExistingTag($name, $userVisible, $userAssignable): void { $tag1 = $this->tagManager->createTag($name, $userVisible, $userAssignable); $tag2 = $this->tagManager->getTag($name, $userVisible, $userAssignable); @@ -278,14 +273,14 @@ class SystemTagManagerTest extends TestCase { public function testGetNonExistingTag(): void { - $this->expectException(\OCP\SystemTag\TagNotFoundException::class); + $this->expectException(TagNotFoundException::class); $this->tagManager->getTag('nonexist', false, false); } public function testGetNonExistingTagsById(): void { - $this->expectException(\OCP\SystemTag\TagNotFoundException::class); + $this->expectException(TagNotFoundException::class); $tag1 = $this->tagManager->createTag('one', true, false); $this->tagManager->getTagsByIds([$tag1->getId(), 100, 101]); @@ -324,9 +319,7 @@ class SystemTagManagerTest extends TestCase { ]; } - /** - * @dataProvider updateTagProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('updateTagProvider')] public function testUpdateTag($tagCreate, $tagUpdated): void { $tag1 = $this->tagManager->createTag( $tagCreate[0], @@ -356,11 +349,9 @@ class SystemTagManagerTest extends TestCase { } - /** - * @dataProvider updateTagProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('updateTagProvider')] public function testUpdateTagDuplicate($tagCreate, $tagUpdated): void { - $this->expectException(\OCP\SystemTag\TagAlreadyExistsException::class); + $this->expectException(TagAlreadyExistsException::class); $this->tagManager->createTag( $tagCreate[0], @@ -396,7 +387,7 @@ class SystemTagManagerTest extends TestCase { public function testDeleteNonExistingTag(): void { - $this->expectException(\OCP\SystemTag\TagNotFoundException::class); + $this->expectException(TagNotFoundException::class); $this->tagManager->deleteTags([100]); } @@ -433,9 +424,7 @@ class SystemTagManagerTest extends TestCase { ]; } - /** - * @dataProvider visibilityCheckProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('visibilityCheckProvider')] public function testVisibilityCheck($userVisible, $userAssignable, $isAdmin, $expectedResult): void { $user = $this->getMockBuilder(IUser::class)->getMock(); $user->expects($this->any()) @@ -480,9 +469,7 @@ class SystemTagManagerTest extends TestCase { ]; } - /** - * @dataProvider assignabilityCheckProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('assignabilityCheckProvider')] public function testAssignabilityCheck($userVisible, $userAssignable, $isAdmin, $expectedResult, $userGroupIds = [], $tagGroupIds = []): void { $user = $this->getMockBuilder(IUser::class)->getMock(); $user->expects($this->any()) @@ -539,9 +526,7 @@ class SystemTagManagerTest extends TestCase { ]; } - /** - * @dataProvider allowedToCreateProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('allowedToCreateProvider')] public function testAllowedToCreateTag(bool $isCli, ?bool $isAdmin, bool $isRestricted): void { $oldCli = \OC::$CLI; \OC::$CLI = $isCli; @@ -577,9 +562,7 @@ class SystemTagManagerTest extends TestCase { ]; } - /** - * @dataProvider disallowedToCreateProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('disallowedToCreateProvider')] public function testDisallowedToCreateTag(?bool $isAdmin): void { $oldCli = \OC::$CLI; \OC::$CLI = false; diff --git a/tests/lib/SystemTag/SystemTagObjectMapperTest.php b/tests/lib/SystemTag/SystemTagObjectMapperTest.php index 3569c98b5bc..a43bda3b659 100644 --- a/tests/lib/SystemTag/SystemTagObjectMapperTest.php +++ b/tests/lib/SystemTag/SystemTagObjectMapperTest.php @@ -13,6 +13,7 @@ use OC\SystemTag\SystemTagManager; use OC\SystemTag\SystemTagObjectMapper; use OCP\EventDispatcher\IEventDispatcher; use OCP\IDBConnection; +use OCP\Server; use OCP\SystemTag\ISystemTag; use OCP\SystemTag\ISystemTagManager; use OCP\SystemTag\ISystemTagObjectMapper; @@ -64,7 +65,7 @@ class SystemTagObjectMapperTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = Server::get(IDBConnection::class); $this->pruneTagsTables(); $this->tagManager = $this->createMock(ISystemTagManager::class); @@ -198,7 +199,7 @@ class SystemTagObjectMapperTest extends TestCase { public function testGetObjectsForNonExistingTag(): void { - $this->expectException(\OCP\SystemTag\TagNotFoundException::class); + $this->expectException(TagNotFoundException::class); $this->tagMapper->getObjectIdsForTags( [100], @@ -236,7 +237,7 @@ class SystemTagObjectMapperTest extends TestCase { public function testAssignNonExistingTags(): void { - $this->expectException(\OCP\SystemTag\TagNotFoundException::class); + $this->expectException(TagNotFoundException::class); $this->tagMapper->assignTags('1', 'testtype', [100]); } @@ -263,7 +264,7 @@ class SystemTagObjectMapperTest extends TestCase { public function testUnassignNonExistingTags(): void { - $this->expectException(\OCP\SystemTag\TagNotFoundException::class); + $this->expectException(TagNotFoundException::class); $this->tagMapper->unassignTags('1', 'testtype', [100]); } @@ -394,7 +395,7 @@ class SystemTagObjectMapperTest extends TestCase { public function testHaveTagNonExisting(): void { - $this->expectException(\OCP\SystemTag\TagNotFoundException::class); + $this->expectException(TagNotFoundException::class); $this->tagMapper->haveTag( ['1'], |