diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-10-12 17:51:56 +0200 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2024-10-14 17:11:16 +0000 |
commit | dfe8f642cdd9b0da29f03ec9607a385cfc3d53d6 (patch) | |
tree | 6774a484123a2d692feeea6ab71e0488a3b0a918 /tests/lib | |
parent | 4c06e3278dc263afb24b8f0f2316dacc21054c61 (diff) | |
download | nextcloud-server-dfe8f642cdd9b0da29f03ec9607a385cfc3d53d6.tar.gz nextcloud-server-dfe8f642cdd9b0da29f03ec9607a385cfc3d53d6.zip |
fix(share): Return empty string if no label is set
* Resolves: https://github.com/nextcloud/server/issues/48629
While the database supports NULL, the typing has always said it only returns *string*.
So to not break any apps that might trust the typings we should return `''` if the database is set to `NULL`.
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/Share20/DefaultShareProviderTest.php | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/lib/Share20/DefaultShareProviderTest.php b/tests/lib/Share20/DefaultShareProviderTest.php index e498d497427..e89157d29b2 100644 --- a/tests/lib/Share20/DefaultShareProviderTest.php +++ b/tests/lib/Share20/DefaultShareProviderTest.php @@ -884,6 +884,7 @@ class DefaultShareProviderTest extends \Test\TestCase { 'file_target' => $qb->expr()->literal('myTarget'), 'permissions' => $qb->expr()->literal(13), 'token' => $qb->expr()->literal('secrettoken'), + 'label' => $qb->expr()->literal('the label'), ]); $qb->execute(); $id = $qb->getLastInsertId(); @@ -899,10 +900,43 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->assertSame('sharedBy', $share->getSharedBy()); $this->assertSame('secrettoken', $share->getToken()); $this->assertSame('password', $share->getPassword()); + $this->assertSame('the label', $share->getLabel()); $this->assertSame(true, $share->getSendPasswordByTalk()); $this->assertSame(null, $share->getSharedWith()); } + /** + * Assert that if no label is provided the label is correctly, + * as types on IShare, a string and not null + */ + public function testGetShareByTokenNullLabel(): void { + $qb = $this->dbConn->getQueryBuilder(); + + $qb->insert('share') + ->values([ + 'share_type' => $qb->expr()->literal(IShare::TYPE_LINK), + 'password' => $qb->expr()->literal('password'), + 'password_by_talk' => $qb->expr()->literal(true), + 'uid_owner' => $qb->expr()->literal('shareOwner'), + 'uid_initiator' => $qb->expr()->literal('sharedBy'), + 'item_type' => $qb->expr()->literal('file'), + 'file_source' => $qb->expr()->literal(42), + 'file_target' => $qb->expr()->literal('myTarget'), + 'permissions' => $qb->expr()->literal(13), + 'token' => $qb->expr()->literal('secrettoken'), + ]); + $qb->executeStatement(); + $id = $qb->getLastInsertId(); + + $file = $this->createMock(File::class); + + $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf(); + $this->rootFolder->method('getFirstNodeById')->with(42)->willReturn($file); + + $share = $this->provider->getShareByToken('secrettoken'); + $this->assertEquals($id, $share->getId()); + $this->assertSame('', $share->getLabel()); + } public function testGetShareByTokenNotFound() { $this->expectException(\OCP\Share\Exceptions\ShareNotFound::class); |