From 00e4c8aee4cbf2cf7ba71da8a1321dadf08f3409 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= <danxuliu@gmail.com>
Date: Fri, 12 Oct 2018 19:55:12 +0200
Subject: [PATCH] Fix update share tests
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The update share tests only checked that the share returned by
"update()" had the expected values. However, as "update()" returns the
same share that was given as a parameter the tests were not really
verifying that the values were updated in the database.

In a similar way, the test that checked that a password was removed did
not set a password first, so even if the database returned null it could
be simply returning the default value for the share; a password must be
set first to ensure that it is removed.

Besides that, a typo was fixed too that made the checks on the original
share instead of on the one returned by "update()"; right now it is the
same share, so the change makes no difference, but it is how the check
should be done anyway.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
---
 .../lib/Share20/DefaultShareProviderTest.php  | 52 ++++++++++++++++++-
 1 file changed, 50 insertions(+), 2 deletions(-)

diff --git a/tests/lib/Share20/DefaultShareProviderTest.php b/tests/lib/Share20/DefaultShareProviderTest.php
index 19f37160627..d368304453f 100644
--- a/tests/lib/Share20/DefaultShareProviderTest.php
+++ b/tests/lib/Share20/DefaultShareProviderTest.php
@@ -1788,6 +1788,14 @@ class DefaultShareProviderTest extends \Test\TestCase {
 		$this->assertSame('user4', $share2->getSharedBy());
 		$this->assertSame('user5', $share2->getShareOwner());
 		$this->assertSame(1, $share2->getPermissions());
+
+		$share2 = $this->provider->getShareById($id);
+
+		$this->assertEquals($id, $share2->getId());
+		$this->assertSame('user3', $share2->getSharedWith());
+		$this->assertSame('user4', $share2->getSharedBy());
+		$this->assertSame('user5', $share2->getShareOwner());
+		$this->assertSame(1, $share2->getPermissions());
 	}
 
 	public function testUpdateLink() {
@@ -1833,7 +1841,15 @@ class DefaultShareProviderTest extends \Test\TestCase {
 		$share2 = $this->provider->update($share);
 
 		$this->assertEquals($id, $share2->getId());
-		$this->assertEquals('password', $share->getPassword());
+		$this->assertEquals('password', $share2->getPassword());
+		$this->assertSame('user4', $share2->getSharedBy());
+		$this->assertSame('user5', $share2->getShareOwner());
+		$this->assertSame(1, $share2->getPermissions());
+
+		$share2 = $this->provider->getShareById($id);
+
+		$this->assertEquals($id, $share2->getId());
+		$this->assertEquals('password', $share2->getPassword());
 		$this->assertSame('user4', $share2->getSharedBy());
 		$this->assertSame('user5', $share2->getShareOwner());
 		$this->assertSame(1, $share2->getPermissions());
@@ -1843,6 +1859,12 @@ class DefaultShareProviderTest extends \Test\TestCase {
 		$id = $this->addShareToDB(\OCP\Share::SHARE_TYPE_LINK, 'foo', 'user1', 'user2',
 			'file', 42, 'target', 31, null, null);
 
+		$qb = $this->dbConn->getQueryBuilder();
+		$qb->update('share');
+		$qb->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
+		$qb->set('password', $qb->createNamedParameter('password'));
+		$this->assertEquals(1, $qb->execute());
+
 		$users = [];
 		for($i = 0; $i < 6; $i++) {
 			$user = $this->createMock(IUser::class);
@@ -1882,7 +1904,15 @@ class DefaultShareProviderTest extends \Test\TestCase {
 		$share2 = $this->provider->update($share);
 
 		$this->assertEquals($id, $share2->getId());
-		$this->assertEquals(null, $share->getPassword());
+		$this->assertEquals(null, $share2->getPassword());
+		$this->assertSame('user4', $share2->getSharedBy());
+		$this->assertSame('user5', $share2->getShareOwner());
+		$this->assertSame(1, $share2->getPermissions());
+
+		$share2 = $this->provider->getShareById($id);
+
+		$this->assertEquals($id, $share2->getId());
+		$this->assertEquals(null, $share2->getPassword());
 		$this->assertSame('user4', $share2->getSharedBy());
 		$this->assertSame('user5', $share2->getShareOwner());
 		$this->assertSame(1, $share2->getPermissions());
@@ -1949,6 +1979,15 @@ class DefaultShareProviderTest extends \Test\TestCase {
 		$this->assertSame('user4', $share2->getSharedBy());
 		$this->assertSame('user5', $share2->getShareOwner());
 		$this->assertSame(1, $share2->getPermissions());
+
+		$share2 = $this->provider->getShareById($id);
+
+		$this->assertEquals($id, $share2->getId());
+		// Group shares do not allow updating the recipient
+		$this->assertSame('group0', $share2->getSharedWith());
+		$this->assertSame('user4', $share2->getSharedBy());
+		$this->assertSame('user5', $share2->getShareOwner());
+		$this->assertSame(1, $share2->getPermissions());
 	}
 
 	public function testUpdateGroupSubShares() {
@@ -2019,6 +2058,15 @@ class DefaultShareProviderTest extends \Test\TestCase {
 		$this->assertSame('user5', $share2->getShareOwner());
 		$this->assertSame(1, $share2->getPermissions());
 
+		$share2 = $this->provider->getShareById($id);
+
+		$this->assertEquals($id, $share2->getId());
+		// Group shares do not allow updating the recipient
+		$this->assertSame('group0', $share2->getSharedWith());
+		$this->assertSame('user4', $share2->getSharedBy());
+		$this->assertSame('user5', $share2->getShareOwner());
+		$this->assertSame(1, $share2->getPermissions());
+
 		$qb = $this->dbConn->getQueryBuilder();
 		$stmt = $qb->select('*')
 			->from('share')
-- 
GitLab