Fix update share tests

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>
This commit is contained in:
Daniel Calviño Sánchez 2018-10-12 19:55:12 +02:00
parent 8bfbefa117
commit 00e4c8aee4

View file

@ -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')