aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/SystemTag
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/SystemTag')
-rw-r--r--tests/lib/SystemTag/SystemTagManagerTest.php123
-rw-r--r--tests/lib/SystemTag/SystemTagObjectMapperTest.php11
2 files changed, 53 insertions, 81 deletions
diff --git a/tests/lib/SystemTag/SystemTagManagerTest.php b/tests/lib/SystemTag/SystemTagManagerTest.php
index 94103c52cb1..b443d7222b2 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);
@@ -66,7 +69,7 @@ class SystemTagManagerTest extends TestCase {
$query->delete(SystemTagManager::TAG_TABLE)->execute();
}
- public static function getAllTagsDataProvider() {
+ public static function getAllTagsDataProvider(): array {
return [
[
// no tags at all
@@ -79,23 +82,10 @@ class SystemTagManagerTest extends TestCase {
['two', false, false],
]
],
- [
- // duplicate names, different flags
- [
- ['one', false, false],
- ['one', true, false],
- ['one', false, true],
- ['one', true, true],
- ['two', false, false],
- ['two', false, true],
- ]
- ]
];
}
- /**
- * @dataProvider getAllTagsDataProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('getAllTagsDataProvider')]
public function testGetAllTags($testTags): void {
$testTagsById = [];
foreach ($testTags as $testTag) {
@@ -113,7 +103,7 @@ class SystemTagManagerTest extends TestCase {
}
}
- public static function getAllTagsFilteredDataProvider() {
+ public static function getAllTagsFilteredDataProvider(): array {
return [
[
[
@@ -162,14 +152,14 @@ class SystemTagManagerTest extends TestCase {
[
[
['one', true, false],
- ['one', false, false],
+ ['one_different', false, false],
['two', true, false],
],
null,
'on',
[
['one', true, false],
- ['one', false, false],
+ ['one_different', false, false],
]
],
// filter by name pattern and visibility
@@ -178,7 +168,7 @@ class SystemTagManagerTest extends TestCase {
[
['one', true, false],
['two', true, false],
- ['one', false, false],
+ ['one_different', false, false],
],
true,
'on',
@@ -202,9 +192,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]);
@@ -226,7 +214,7 @@ class SystemTagManagerTest extends TestCase {
}
}
- public static function oneTagMultipleFlagsProvider() {
+ public static function oneTagMultipleFlagsProvider(): array {
return [
['one', false, false],
['one', true, false],
@@ -235,11 +223,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);
@@ -249,14 +235,21 @@ class SystemTagManagerTest extends TestCase {
$this->tagManager->createTag($name, $userVisible, $userAssignable);
}
+ public function testCreateDuplicateWithDifferentFlags(): void {
+ $this->expectException(TagAlreadyExistsException::class);
+
+ // Create a tag with specific flags
+ $this->tagManager->createTag('duplicate', true, false);
+ // Try to create a tag with the same name but different flags - should fail
+ $this->tagManager->createTag('duplicate', false, true);
+ }
+
public function testCreateOverlongName(): void {
$tag = $this->tagManager->createTag('Zona circundante do Palácio Nacional da Ajuda (Jardim das Damas, Salão de Física, Torre Sineira, Paço Velho e Jardim Botânico)', true, true);
$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 +271,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]);
@@ -299,7 +292,7 @@ class SystemTagManagerTest extends TestCase {
$this->tagManager->getTagsByIds([$tag1->getId() . 'suffix']);
}
- public static function updateTagProvider() {
+ public static function updateTagProvider(): array {
return [
[
// update name
@@ -324,9 +317,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,32 +347,20 @@ class SystemTagManagerTest extends TestCase {
}
- /**
- * @dataProvider updateTagProvider
- */
- public function testUpdateTagDuplicate($tagCreate, $tagUpdated): void {
- $this->expectException(\OCP\SystemTag\TagAlreadyExistsException::class);
+ public function testUpdateTagToExistingName(): void {
+ $this->expectException(TagAlreadyExistsException::class);
- $this->tagManager->createTag(
- $tagCreate[0],
- $tagCreate[1],
- $tagCreate[2],
- $tagCreate[3],
- );
- $tag2 = $this->tagManager->createTag(
- $tagUpdated[0],
- $tagUpdated[1],
- $tagUpdated[2],
- $tagUpdated[3],
- );
+ // Create two different tags
+ $tag1 = $this->tagManager->createTag('first', true, true);
+ $tag2 = $this->tagManager->createTag('second', false, false);
- // update to match the first tag
+ // Try to update tag2 to have the same name as tag1 - should fail
$this->tagManager->updateTag(
$tag2->getId(),
- $tagCreate[0],
- $tagCreate[1],
- $tagCreate[2],
- $tagCreate[3],
+ 'first',
+ false,
+ false,
+ null
);
}
@@ -396,7 +375,7 @@ class SystemTagManagerTest extends TestCase {
public function testDeleteNonExistingTag(): void {
- $this->expectException(\OCP\SystemTag\TagNotFoundException::class);
+ $this->expectException(TagNotFoundException::class);
$this->tagManager->deleteTags([100]);
}
@@ -424,7 +403,7 @@ class SystemTagManagerTest extends TestCase {
], $tagIdMapping);
}
- public static function visibilityCheckProvider() {
+ public static function visibilityCheckProvider(): array {
return [
[false, false, false, false],
[true, false, false, true],
@@ -433,9 +412,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())
@@ -451,7 +428,7 @@ class SystemTagManagerTest extends TestCase {
$this->assertEquals($expectedResult, $this->tagManager->canUserSeeTag($tag1, $user));
}
- public static function assignabilityCheckProvider() {
+ public static function assignabilityCheckProvider(): array {
return [
// no groups
[false, false, false, false],
@@ -480,9 +457,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())
@@ -529,7 +504,7 @@ class SystemTagManagerTest extends TestCase {
$this->assertEquals([], $this->tagManager->getTagGroups($tag1));
}
- private function allowedToCreateProvider(): array {
+ public static function allowedToCreateProvider(): array {
return [
[true, null, true],
[true, null, false],
@@ -539,9 +514,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;
@@ -570,16 +543,14 @@ class SystemTagManagerTest extends TestCase {
\OC::$CLI = $oldCli;
}
- private function disallowedToCreateProvider(): array {
+ public static function disallowedToCreateProvider(): array {
return [
[false],
[null],
];
}
- /**
- * @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'],