From 248857715cb17b65db3b143de6d284e31acdcfa9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 13 Aug 2024 09:53:59 +0200 Subject: [PATCH] fix(test): Fix existing test as good as possible Signed-off-by: Joas Schilling --- tests/Album/AlbumMapperTest.php | 61 ++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/tests/Album/AlbumMapperTest.php b/tests/Album/AlbumMapperTest.php index 05dc5515d..15f6997eb 100644 --- a/tests/Album/AlbumMapperTest.php +++ b/tests/Album/AlbumMapperTest.php @@ -17,6 +17,10 @@ use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Files\IMimeTypeLoader; use OCP\IDBConnection; +use OCP\IGroupManager; +use OCP\IL10N; +use OCP\IUserManager; +use OCP\Security\ISecureRandom; use Test\TestCase; /** @@ -30,8 +34,16 @@ class AlbumMapperTest extends TestCase { private $mimeLoader; /** @var AlbumMapper */ private $mapper; - /** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */ + /** @var ITimeFactory|MockObject */ private $timeFactory; + /** @var IUserManager|MockObject */ + private $userManager; + /** @var IGroupManager|MockObject */ + private $groupManager; + /** @var IL10N|MockObject */ + private $l10n; + /** @var ISecureRandom|MockObject */ + private $secureRandom; private int $time = 100; protected function setUp(): void { @@ -41,11 +53,23 @@ protected function setUp(): void { $this->connection = \OC::$server->get(IDBConnection::class); $this->mimeLoader = \OC::$server->get(IMimeTypeLoader::class); $this->timeFactory = $this->createMock(ITimeFactory::class); + $this->userManager = $this->createMock(IUserManager::class); + $this->groupManager = $this->createMock(IGroupManager::class); + $this->l10n = $this->createMock(IL10N::class); + $this->secureRandom = $this->createMock(ISecureRandom::class); $this->timeFactory->method('getTime')->willReturnCallback(function () { return $this->time; }); - $this->mapper = new AlbumMapper($this->connection, $this->mimeLoader, $this->timeFactory); + $this->mapper = new AlbumMapper( + $this->connection, + $this->mimeLoader, + $this->timeFactory, + $this->userManager, + $this->groupManager, + $this->l10n, + $this->secureRandom, + ); } protected function tearDown():void { @@ -152,6 +176,8 @@ public function testCreateUpdateGet() { $this->assertEquals("nowhere", $retrievedAlbum->getLocation()); } + /** + * Disabled as the function does no longer exist public function testEmptyFiles() { $album1 = $this->mapper->create("user1", "album1"); @@ -165,9 +191,9 @@ public function testAddFiles() { $fileId1 = $this->createFile("file1", "text/plain"); $fileId2 = $this->createFile("file2", "image/png"); - $this->mapper->addFile($album1->getId(), $fileId1); - $this->mapper->addFile($album1->getId(), $fileId2); - $this->mapper->addFile($album2->getId(), $fileId1); + $this->mapper->addFile($album1->getId(), $fileId1, 'user1'); + $this->mapper->addFile($album1->getId(), $fileId2, 'user1'); + $this->mapper->addFile($album2->getId(), $fileId1, 'user1'); $albumsWithFiles = $this->mapper->getForUserWithFiles("user1"); usort($albumsWithFiles, function (AlbumWithFiles $a, AlbumWithFiles $b) { @@ -182,8 +208,8 @@ public function testAddFiles() { return $a->getFileId() <=> $b->getFileId(); }); $this->assertCount(2, $files); - $this->assertEquals(new AlbumFile($fileId1, "file1", "text/plain", 10, 10000, "dummy", 100), $albumsWithFiles[0]->getFiles()[0]); - $this->assertEquals(new AlbumFile($fileId2, "file2", "image/png", 10, 10000, "dummy", 100), $albumsWithFiles[0]->getFiles()[1]); + $this->assertEquals(new AlbumFile($fileId1, "file1", "text/plain", 10, 10000, "dummy", 100, 'user1'), $albumsWithFiles[0]->getFiles()[0]); + $this->assertEquals(new AlbumFile($fileId2, "file2", "image/png", 10, 10000, "dummy", 100, 'user1'), $albumsWithFiles[0]->getFiles()[1]); $this->assertEquals($album2->getId(), $albumsWithFiles[1]->getAlbum()->getId()); $this->assertEquals($fileId1, $albumsWithFiles[1]->getAlbum()->getLastAddedPhoto()); @@ -193,7 +219,7 @@ public function testAddFiles() { return $a->getFileId() <=> $b->getFileId(); }); $this->assertCount(1, $files); - $this->assertEquals(new AlbumFile($fileId1, "file1", "text/plain", 10, 10000, "dummy", 100), $albumsWithFiles[0]->getFiles()[0]); + $this->assertEquals(new AlbumFile($fileId1, "file1", "text/plain", 10, 10000, "dummy", 100, 'user1'), $albumsWithFiles[0]->getFiles()[0]); } public function testAddRemoveFiles() { @@ -204,11 +230,11 @@ public function testAddRemoveFiles() { $fileId3 = $this->createFile("file3", "image/png"); $this->time = 110; - $this->mapper->addFile($album1->getId(), $fileId1); + $this->mapper->addFile($album1->getId(), $fileId1, 'user1'); $this->time = 120; - $this->mapper->addFile($album1->getId(), $fileId2); + $this->mapper->addFile($album1->getId(), $fileId2, 'user1'); $this->time = 130; - $this->mapper->addFile($album1->getId(), $fileId3); + $this->mapper->addFile($album1->getId(), $fileId3, 'user1'); $albumsWithFiles = $this->mapper->getForUserWithFiles("user1"); usort($albumsWithFiles, function (AlbumWithFiles $a, AlbumWithFiles $b) { @@ -223,9 +249,9 @@ public function testAddRemoveFiles() { return $a->getFileId() <=> $b->getFileId(); }); $this->assertCount(3, $files); - $this->assertEquals(new AlbumFile($fileId1, "file1", "text/plain", 10, 10000, "dummy", 110), $albumsWithFiles[0]->getFiles()[0]); - $this->assertEquals(new AlbumFile($fileId2, "file2", "image/png", 10, 10000, "dummy", 120), $albumsWithFiles[0]->getFiles()[1]); - $this->assertEquals(new AlbumFile($fileId3, "file3", "image/png", 10, 10000, "dummy", 130), $albumsWithFiles[0]->getFiles()[2]); + $this->assertEquals(new AlbumFile($fileId1, "file1", "text/plain", 10, 10000, "dummy", 110, 'user1'), $albumsWithFiles[0]->getFiles()[0]); + $this->assertEquals(new AlbumFile($fileId2, "file2", "image/png", 10, 10000, "dummy", 120, 'user1'), $albumsWithFiles[0]->getFiles()[1]); + $this->assertEquals(new AlbumFile($fileId3, "file3", "image/png", 10, 10000, "dummy", 130, 'user1'), $albumsWithFiles[0]->getFiles()[2]); @@ -244,8 +270,8 @@ public function testAddRemoveFiles() { return $a->getFileId() <=> $b->getFileId(); }); $this->assertCount(2, $files); - $this->assertEquals(new AlbumFile($fileId1, "file1", "text/plain", 10, 10000, "dummy", 110), $albumsWithFiles[0]->getFiles()[0]); - $this->assertEquals(new AlbumFile($fileId3, "file3", "image/png", 10, 10000, "dummy", 130), $albumsWithFiles[0]->getFiles()[1]); + $this->assertEquals(new AlbumFile($fileId1, "file1", "text/plain", 10, 10000, "dummy", 110, 'user1'), $albumsWithFiles[0]->getFiles()[0]); + $this->assertEquals(new AlbumFile($fileId3, "file3", "image/png", 10, 10000, "dummy", 130, 'user1'), $albumsWithFiles[0]->getFiles()[1]); @@ -264,7 +290,7 @@ public function testAddRemoveFiles() { return $a->getFileId() <=> $b->getFileId(); }); $this->assertCount(1, $files); - $this->assertEquals(new AlbumFile($fileId1, "file1", "text/plain", 10, 10000, "dummy", 110), $albumsWithFiles[0]->getFiles()[0]); + $this->assertEquals(new AlbumFile($fileId1, "file1", "text/plain", 10, 10000, "dummy", 110, 'user1'), $albumsWithFiles[0]->getFiles()[0]); @@ -281,4 +307,5 @@ public function testAddRemoveFiles() { $files = $albumsWithFiles[0]->getFiles(); $this->assertCount(0, $files); } + */ }