diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2020-10-26 14:44:15 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2020-10-26 16:05:28 +0100 |
commit | fd1fd5afa4712166cbb136d4df197bf7e37545af (patch) | |
tree | 7dcf7f64c5e3b409e5c5fc40681965a42a4d47b9 /apps/user_ldap/tests/User | |
parent | 951887e922bfc47613f0cfda5e7798df2b4286d6 (diff) | |
download | nextcloud-server-fd1fd5afa4712166cbb136d4df197bf7e37545af.tar.gz nextcloud-server-fd1fd5afa4712166cbb136d4df197bf7e37545af.zip |
user share manager to determine share ownership
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/user_ldap/tests/User')
-rw-r--r-- | apps/user_ldap/tests/User/DeletedUsersIndexTest.php | 6 | ||||
-rw-r--r-- | apps/user_ldap/tests/User/ManagerTest.php | 11 | ||||
-rw-r--r-- | apps/user_ldap/tests/User/OfflineUserTest.php | 50 |
3 files changed, 34 insertions, 33 deletions
diff --git a/apps/user_ldap/tests/User/DeletedUsersIndexTest.php b/apps/user_ldap/tests/User/DeletedUsersIndexTest.php index 77fdd31c173..8435078051c 100644 --- a/apps/user_ldap/tests/User/DeletedUsersIndexTest.php +++ b/apps/user_ldap/tests/User/DeletedUsersIndexTest.php @@ -30,6 +30,7 @@ use OCA\User_LDAP\Mapping\UserMapping; use OCA\User_LDAP\User\DeletedUsersIndex; use OCP\IConfig; use OCP\IDBConnection; +use OCP\Share\IManager; /** * Class DeletedUsersIndexTest @@ -50,6 +51,8 @@ class DeletedUsersIndexTest extends \Test\TestCase { /** @var UserMapping|\PHPUnit\Framework\MockObject\MockObject */ protected $mapping; + /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */ + protected $shareManager; protected function setUp(): void { parent::setUp(); @@ -62,8 +65,9 @@ class DeletedUsersIndexTest extends \Test\TestCase { $this->config->deleteAppFromAllUsers('user_ldap'); $this->mapping = $this->createMock(UserMapping::class); + $this->shareManager = $this->createMock(IManager::class); - $this->dui = new DeletedUsersIndex($this->config, $this->db, $this->mapping); + $this->dui = new DeletedUsersIndex($this->config, $this->mapping, $this->shareManager); } protected function tearDown(): void { diff --git a/apps/user_ldap/tests/User/ManagerTest.php b/apps/user_ldap/tests/User/ManagerTest.php index 18499da9a86..9f6d43a9a24 100644 --- a/apps/user_ldap/tests/User/ManagerTest.php +++ b/apps/user_ldap/tests/User/ManagerTest.php @@ -42,6 +42,7 @@ use OCP\IDBConnection; use OCP\Image; use OCP\IUserManager; use OCP\Notification\IManager as INotificationManager; +use OCP\Share\IManager; /** * Class Test_User_Manager @@ -86,6 +87,8 @@ class ManagerTest extends \Test\TestCase { /** @var Manager */ protected $manager; + /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */ + protected $shareManager; protected function setUp(): void { parent::setUp(); @@ -96,11 +99,11 @@ class ManagerTest extends \Test\TestCase { $this->log = $this->createMock(LogWrapper::class); $this->avatarManager = $this->createMock(IAvatarManager::class); $this->image = $this->createMock(Image::class); - $this->dbc = $this->createMock(IDBConnection::class); $this->ncUserManager = $this->createMock(IUserManager::class); $this->notificationManager = $this->createMock(INotificationManager::class); - $this->ldapWrapper = $this->createMock(ILDAPWrapper::class); + $this->shareManager = $this->createMock(IManager::class); + $this->connection = new Connection($this->ldapWrapper, '', null); $this->access->expects($this->any()) @@ -114,9 +117,9 @@ class ManagerTest extends \Test\TestCase { $this->log, $this->avatarManager, $this->image, - $this->dbc, $this->ncUserManager, - $this->notificationManager + $this->notificationManager, + $this->shareManager ); $this->manager->setLdapAccess($this->access); diff --git a/apps/user_ldap/tests/User/OfflineUserTest.php b/apps/user_ldap/tests/User/OfflineUserTest.php index 298e1708a58..5736b2664d9 100644 --- a/apps/user_ldap/tests/User/OfflineUserTest.php +++ b/apps/user_ldap/tests/User/OfflineUserTest.php @@ -25,11 +25,11 @@ declare(strict_types=1); namespace OCA\User_LDAP\Tests\User; -use Doctrine\DBAL\Driver\Statement; use OCA\User_LDAP\Mapping\UserMapping; use OCA\User_LDAP\User\OfflineUser; use OCP\IConfig; -use OCP\IDBConnection; +use OCP\Share\IManager; +use OCP\Share\IShare; use Test\TestCase; class OfflineUserTest extends TestCase { @@ -42,53 +42,47 @@ class OfflineUserTest extends TestCase { protected $uid; /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ protected $config; - /** @var IDBConnection|\PHPUnit\Framework\MockObject\MockObject */ - protected $dbc; + /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */ + protected $shareManager; public function setUp(): void { $this->uid = 'deborah'; $this->config = $this->createMock(IConfig::class); - $this->dbc = $this->createMock(IDBConnection::class); $this->mapping = $this->createMock(UserMapping::class); + $this->shareManager = $this->createMock(IManager::class); $this->offlineUser = new OfflineUser( $this->uid, $this->config, - $this->dbc, - $this->mapping + $this->mapping, + $this->shareManager ); } public function shareOwnerProvider(): array { - // tests for none, one, many return [ - [ 0, 0, false], - [ 1, 0, true], - [ 0, 1, true], - [ 1, 1, true], - [ 2, 0, true], - [ 0, 2, true], - [ 2, 2, true], + [[], false], + [[IShare::TYPE_USER], true], + [[IShare::TYPE_GROUP, IShare::TYPE_LINK], true], + [[IShare::TYPE_EMAIL, IShare::TYPE_REMOTE, IShare::TYPE_CIRCLE], true], + [[IShare::TYPE_GUEST, IShare::TYPE_REMOTE_GROUP, IShare::TYPE_ROOM], true], ]; } /** * @dataProvider shareOwnerProvider */ - public function testHasActiveShares(int $internalOwnerships, int $externalOwnerships, bool $expected) { - $queryMock = $this->createMock(Statement::class); - $queryMock->expects($this->atLeastOnce()) - ->method('execute'); - $queryMock->expects($this->atLeastOnce()) - ->method('rowCount') - ->willReturnOnConsecutiveCalls( - $internalOwnerships > 0 ? 1 : 0, - $externalOwnerships > 0 ? 1 : 0 - ); + public function testHasActiveShares(array $existingShareTypes, bool $expected) { + $shareMock = $this->createMock(IShare::class); - $this->dbc->expects($this->atLeastOnce()) - ->method('prepare') - ->willReturn($queryMock); + $this->shareManager->expects($this->atLeastOnce()) + ->method('getSharesBy') + ->willReturnCallback(function (string $uid, int $shareType) use ($existingShareTypes, $shareMock) { + if (in_array($shareType, $existingShareTypes)) { + return [$shareMock]; + } + return []; + }); $this->assertSame($expected, $this->offlineUser->getHasActiveShares()); } |