diff options
Diffstat (limited to 'tests/lib/SystemTag/SystemTagObjectMapperTest.php')
-rw-r--r-- | tests/lib/SystemTag/SystemTagObjectMapperTest.php | 84 |
1 files changed, 46 insertions, 38 deletions
diff --git a/tests/lib/SystemTag/SystemTagObjectMapperTest.php b/tests/lib/SystemTag/SystemTagObjectMapperTest.php index c988db69c30..a43bda3b659 100644 --- a/tests/lib/SystemTag/SystemTagObjectMapperTest.php +++ b/tests/lib/SystemTag/SystemTagObjectMapperTest.php @@ -1,11 +1,9 @@ <?php /** - * Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com> - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - * + * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace Test\SystemTag; @@ -13,12 +11,13 @@ namespace Test\SystemTag; use OC\SystemTag\SystemTag; 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; use OCP\SystemTag\TagNotFoundException; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Test\TestCase; /** @@ -44,7 +43,7 @@ class SystemTagObjectMapperTest extends TestCase { private $connection; /** - * @var EventDispatcherInterface + * @var IEventDispatcher */ private $dispatcher; @@ -66,14 +65,11 @@ 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->getMockBuilder('OCP\SystemTag\ISystemTagManager') - ->getMock(); - - $this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface') - ->getMock(); + $this->tagManager = $this->createMock(ISystemTagManager::class); + $this->dispatcher = $this->createMock(IEventDispatcher::class); $this->tagMapper = new SystemTagObjectMapper( $this->connection, @@ -118,7 +114,7 @@ class SystemTagObjectMapperTest extends TestCase { $query->delete(SystemTagManager::TAG_TABLE)->execute(); } - public function testGetTagIdsForObjects() { + public function testGetTagIdsForObjects(): void { $tagIdMapping = $this->tagMapper->getTagIdsForObjects( ['1', '2', '3', '4'], 'testtype' @@ -132,7 +128,7 @@ class SystemTagObjectMapperTest extends TestCase { ], $tagIdMapping); } - public function testGetTagIdsForNoObjects() { + public function testGetTagIdsForNoObjects(): void { $tagIdMapping = $this->tagMapper->getTagIdsForObjects( [], 'testtype' @@ -141,11 +137,23 @@ class SystemTagObjectMapperTest extends TestCase { $this->assertEquals([], $tagIdMapping); } - public function testGetObjectsForTags() { + public function testGetTagIdsForALotOfObjects(): void { + $ids = range(1, 10500); + $tagIdMapping = $this->tagMapper->getTagIdsForObjects( + $ids, + 'testtype' + ); + + $this->assertEquals(10500, count($tagIdMapping)); + $this->assertEquals([$this->tag1->getId(), $this->tag2->getId()], $tagIdMapping[1]); + } + + public function testGetObjectsForTags(): void { $objectIds = $this->tagMapper->getObjectIdsForTags( [$this->tag1->getId(), $this->tag2->getId(), $this->tag3->getId()], 'testtype' ); + sort($objectIds); $this->assertEquals([ '1', @@ -153,7 +161,7 @@ class SystemTagObjectMapperTest extends TestCase { ], $objectIds); } - public function testGetObjectsForTagsLimit() { + public function testGetObjectsForTagsLimit(): void { $objectIds = $this->tagMapper->getObjectIdsForTags( [$this->tag1->getId()], 'testtype', @@ -165,8 +173,8 @@ class SystemTagObjectMapperTest extends TestCase { ], $objectIds); } - - public function testGetObjectsForTagsLimitWithMultipleTags() { + + public function testGetObjectsForTagsLimitWithMultipleTags(): void { $this->expectException(\InvalidArgumentException::class); $this->tagMapper->getObjectIdsForTags( @@ -176,7 +184,7 @@ class SystemTagObjectMapperTest extends TestCase { ); } - public function testGetObjectsForTagsLimitOffset() { + public function testGetObjectsForTagsLimitOffset(): void { $objectIds = $this->tagMapper->getObjectIdsForTags( [$this->tag1->getId()], 'testtype', @@ -189,9 +197,9 @@ class SystemTagObjectMapperTest extends TestCase { ], $objectIds); } - - public function testGetObjectsForNonExistingTag() { - $this->expectException(\OCP\SystemTag\TagNotFoundException::class); + + public function testGetObjectsForNonExistingTag(): void { + $this->expectException(TagNotFoundException::class); $this->tagMapper->getObjectIdsForTags( [100], @@ -199,7 +207,7 @@ class SystemTagObjectMapperTest extends TestCase { ); } - public function testAssignUnassignTags() { + public function testAssignUnassignTags(): void { $this->tagMapper->unassignTags('1', 'testtype', [$this->tag1->getId()]); $tagIdMapping = $this->tagMapper->getTagIdsForObjects('1', 'testtype'); @@ -217,7 +225,7 @@ class SystemTagObjectMapperTest extends TestCase { ], $tagIdMapping); } - public function testReAssignUnassignTags() { + public function testReAssignUnassignTags(): void { // reassign tag1 $this->tagMapper->assignTags('1', 'testtype', [$this->tag1->getId()]); @@ -227,14 +235,14 @@ class SystemTagObjectMapperTest extends TestCase { $this->assertTrue(true, 'No error when reassigning/unassigning'); } - - public function testAssignNonExistingTags() { - $this->expectException(\OCP\SystemTag\TagNotFoundException::class); + + public function testAssignNonExistingTags(): void { + $this->expectException(TagNotFoundException::class); $this->tagMapper->assignTags('1', 'testtype', [100]); } - public function testAssignNonExistingTagInArray() { + public function testAssignNonExistingTagInArray(): void { $caught = false; try { $this->tagMapper->assignTags('1', 'testtype', [100, $this->tag3->getId()]); @@ -254,14 +262,14 @@ class SystemTagObjectMapperTest extends TestCase { ], $tagIdMapping, 'None of the tags got assigned'); } - - public function testUnassignNonExistingTags() { - $this->expectException(\OCP\SystemTag\TagNotFoundException::class); + + public function testUnassignNonExistingTags(): void { + $this->expectException(TagNotFoundException::class); $this->tagMapper->unassignTags('1', 'testtype', [100]); } - public function testUnassignNonExistingTagsInArray() { + public function testUnassignNonExistingTagsInArray(): void { $caught = false; try { $this->tagMapper->unassignTags('1', 'testtype', [100, $this->tag1->getId()]); @@ -281,7 +289,7 @@ class SystemTagObjectMapperTest extends TestCase { ], $tagIdMapping, 'None of the tags got unassigned'); } - public function testHaveTagAllMatches() { + public function testHaveTagAllMatches(): void { $this->assertTrue( $this->tagMapper->haveTag( ['1'], @@ -333,7 +341,7 @@ class SystemTagObjectMapperTest extends TestCase { ); } - public function testHaveTagAtLeastOneMatch() { + public function testHaveTagAtLeastOneMatch(): void { $this->assertTrue( $this->tagMapper->haveTag( ['1'], @@ -385,9 +393,9 @@ class SystemTagObjectMapperTest extends TestCase { ); } - - public function testHaveTagNonExisting() { - $this->expectException(\OCP\SystemTag\TagNotFoundException::class); + + public function testHaveTagNonExisting(): void { + $this->expectException(TagNotFoundException::class); $this->tagMapper->haveTag( ['1'], |