diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index f0488637485..c3fb8737420 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -72,7 +72,7 @@ class Manager extends PublicEmitter implements IUserManager { /** * @param \OCP\IConfig $config */ - public function __construct(IConfig $config = null) { + public function __construct(IConfig $config) { $this->config = $config; $cachedUsers = &$this->cachedUsers; $this->listen('\OC\User', 'postDelete', function ($user) use (&$cachedUsers) { @@ -389,25 +389,23 @@ class Manager extends PublicEmitter implements IUserManager { $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); $queryBuilder->select($queryBuilder->createFunction('COUNT(*)')) ->from('preferences') - ->where($queryBuilder->expr()->eq( - 'appid', $queryBuilder->createNamedParameter('login')) - ) - ->andWhere($queryBuilder->expr()->eq( - 'configkey', $queryBuilder->createNamedParameter('lastLogin')) - ) - ->andWhere($queryBuilder->expr()->isNotNull('configvalue') - ); + ->where($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('login'))) + ->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('lastLogin'))) + ->andWhere($queryBuilder->expr()->isNotNull('configvalue')); $query = $queryBuilder->execute(); - return (int)$query->fetchColumn(); + + $result = (int)$query->fetchColumn(); + $query->closeCursor(); + + return $result; } /** * @param \Closure $callback - * @param string $search * @since 9.2.0 */ - public function callForSeenUsers (\Closure $callback) { + public function callForSeenUsers(\Closure $callback) { $limit = 1000; $offset = 0; do { @@ -462,8 +460,11 @@ class Manager extends PublicEmitter implements IUserManager { $result[] = $row['userid']; } + $query->closeCursor(); + return $result; } + /** * @param string $email * @return IUser[] diff --git a/lib/public/IUserManager.php b/lib/public/IUserManager.php index 854622335c8..5220a0c65c7 100644 --- a/lib/public/IUserManager.php +++ b/lib/public/IUserManager.php @@ -142,7 +142,7 @@ interface IUserManager { * @param string $search * @since 9.0.0 */ - public function callForAllUsers (\Closure $callback, $search = ''); + public function callForAllUsers(\Closure $callback, $search = ''); /** * returns how many users have logged in once @@ -154,10 +154,9 @@ interface IUserManager { /** * @param \Closure $callback - * @param string $search * @since 9.2.0 */ - public function callForSeenUsers (\Closure $callback); + public function callForSeenUsers(\Closure $callback); /** * @param string $email diff --git a/tests/lib/Files/Config/UserMountCacheTest.php b/tests/lib/Files/Config/UserMountCacheTest.php index 51d488e6dee..376f0a0276c 100644 --- a/tests/lib/Files/Config/UserMountCacheTest.php +++ b/tests/lib/Files/Config/UserMountCacheTest.php @@ -13,6 +13,7 @@ use OC\Files\Mount\MountPoint; use OC\Log; use OC\User\Manager; use OCP\Files\Config\ICachedMountInfo; +use OCP\IConfig; use OCP\IDBConnection; use OCP\IUserManager; use Test\TestCase; @@ -42,7 +43,7 @@ class UserMountCacheTest extends TestCase { public function setUp() { $this->fileIds = []; $this->connection = \OC::$server->getDatabaseConnection(); - $this->userManager = new Manager(null); + $this->userManager = new Manager($this->createMock(IConfig::class)); $userBackend = new Dummy(); $userBackend->createUser('u1', ''); $userBackend->createUser('u2', ''); diff --git a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php index 55b38d546de..245f39f5e2e 100644 --- a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php +++ b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php @@ -121,7 +121,7 @@ class EncryptionTest extends Storage { $this->util = $this->getMockBuilder('\OC\Encryption\Util') ->setMethods(['getUidAndFilename', 'isFile', 'isExcluded']) - ->setConstructorArgs([new View(), new Manager(), $this->groupManager, $this->config, $this->arrayCache]) + ->setConstructorArgs([new View(), new Manager($this->config), $this->groupManager, $this->config, $this->arrayCache]) ->getMock(); $this->util->expects($this->any()) ->method('getUidAndFilename') @@ -547,7 +547,7 @@ class EncryptionTest extends Storage { ->setConstructorArgs( [ new View(), - new Manager(), + new Manager($this->config), $this->groupManager, $this->config, $this->arrayCache @@ -612,7 +612,7 @@ class EncryptionTest extends Storage { ->disableOriginalConstructor()->getMock(); $util = $this->getMockBuilder('\OC\Encryption\Util') - ->setConstructorArgs([new View(), new Manager(), $this->groupManager, $this->config, $this->arrayCache]) + ->setConstructorArgs([new View(), new Manager($this->config), $this->groupManager, $this->config, $this->arrayCache]) ->getMock(); $cache = $this->getMockBuilder('\OC\Files\Cache\Cache') diff --git a/tests/lib/Files/Stream/EncryptionTest.php b/tests/lib/Files/Stream/EncryptionTest.php index 6f3c879f9e6..e072dd6718d 100644 --- a/tests/lib/Files/Stream/EncryptionTest.php +++ b/tests/lib/Files/Stream/EncryptionTest.php @@ -43,7 +43,7 @@ class EncryptionTest extends \Test\TestCase { $file->expects($this->any())->method('getAccessList')->willReturn([]); $util = $this->getMockBuilder('\OC\Encryption\Util') ->setMethods(['getUidAndFilename']) - ->setConstructorArgs([new View(), new \OC\User\Manager(), $groupManager, $config, $arrayCache]) + ->setConstructorArgs([new View(), new \OC\User\Manager($config), $groupManager, $config, $arrayCache]) ->getMock(); $util->expects($this->any()) ->method('getUidAndFilename') diff --git a/tests/lib/User/ManagerTest.php b/tests/lib/User/ManagerTest.php index 8cad7f4241a..123271bcc8f 100644 --- a/tests/lib/User/ManagerTest.php +++ b/tests/lib/User/ManagerTest.php @@ -9,6 +9,7 @@ namespace Test\User; use OC\User\Database; +use OCP\IConfig; use OCP\IUser; use Test\TestCase; @@ -20,9 +21,19 @@ use Test\TestCase; * @package Test\User */ class ManagerTest extends TestCase { + + /** @var IConfig */ + private $config; + + public function setUp() { + parent::setUp(); + + $this->config = $this->createMock(IConfig::class); + } + public function testGetBackends() { $userDummyBackend = $this->createMock(\Test\Util\User\Dummy::class); - $manager = new \OC\User\Manager(); + $manager = new \OC\User\Manager($this->config); $manager->registerBackend($userDummyBackend); $this->assertEquals([$userDummyBackend], $manager->getBackends()); $dummyDatabaseBackend = $this->createMock(Database::class); @@ -41,7 +52,7 @@ class ManagerTest extends TestCase { ->with($this->equalTo('foo')) ->will($this->returnValue(true)); - $manager = new \OC\User\Manager(); + $manager = new \OC\User\Manager($this->config); $manager->registerBackend($backend); $this->assertTrue($manager->userExists('foo')); @@ -57,14 +68,14 @@ class ManagerTest extends TestCase { ->with($this->equalTo('foo')) ->will($this->returnValue(false)); - $manager = new \OC\User\Manager(); + $manager = new \OC\User\Manager($this->config); $manager->registerBackend($backend); $this->assertFalse($manager->userExists('foo')); } public function testUserExistsNoBackends() { - $manager = new \OC\User\Manager(); + $manager = new \OC\User\Manager($this->config); $this->assertFalse($manager->userExists('foo')); } @@ -88,7 +99,7 @@ class ManagerTest extends TestCase { ->with($this->equalTo('foo')) ->will($this->returnValue(true)); - $manager = new \OC\User\Manager(); + $manager = new \OC\User\Manager($this->config); $manager->registerBackend($backend1); $manager->registerBackend($backend2); @@ -112,7 +123,7 @@ class ManagerTest extends TestCase { $backend2->expects($this->never()) ->method('userExists'); - $manager = new \OC\User\Manager(); + $manager = new \OC\User\Manager($this->config); $manager->registerBackend($backend1); $manager->registerBackend($backend2); @@ -139,7 +150,7 @@ class ManagerTest extends TestCase { } })); - $manager = new \OC\User\Manager(); + $manager = new \OC\User\Manager($this->config); $manager->registerBackend($backend); $user = $manager->checkPassword('foo', 'bar'); @@ -158,7 +169,7 @@ class ManagerTest extends TestCase { ->method('implementsActions') ->will($this->returnValue(false)); - $manager = new \OC\User\Manager(); + $manager = new \OC\User\Manager($this->config); $manager->registerBackend($backend); $this->assertFalse($manager->checkPassword('foo', 'bar')); @@ -174,7 +185,7 @@ class ManagerTest extends TestCase { ->with($this->equalTo('foo')) ->will($this->returnValue(true)); - $manager = new \OC\User\Manager(); + $manager = new \OC\User\Manager($this->config); $manager->registerBackend($backend); $this->assertEquals('foo', $manager->get('foo')->getUID()); @@ -190,7 +201,7 @@ class ManagerTest extends TestCase { ->with($this->equalTo('foo')) ->will($this->returnValue(false)); - $manager = new \OC\User\Manager(); + $manager = new \OC\User\Manager($this->config); $manager->registerBackend($backend); $this->assertEquals(null, $manager->get('foo')); @@ -206,7 +217,7 @@ class ManagerTest extends TestCase { ->with($this->equalTo('fo')) ->will($this->returnValue(array('foo', 'afoo'))); - $manager = new \OC\User\Manager(); + $manager = new \OC\User\Manager($this->config); $manager->registerBackend($backend); $result = $manager->search('fo'); @@ -234,7 +245,7 @@ class ManagerTest extends TestCase { ->with($this->equalTo('fo'), $this->equalTo(3), $this->equalTo(1)) ->will($this->returnValue(array('foo3'))); - $manager = new \OC\User\Manager(); + $manager = new \OC\User\Manager($this->config); $manager->registerBackend($backend1); $manager->registerBackend($backend2); @@ -263,7 +274,7 @@ class ManagerTest extends TestCase { ->with($this->equalTo('foo')) ->will($this->returnValue(false)); - $manager = new \OC\User\Manager(); + $manager = new \OC\User\Manager($this->config); $manager->registerBackend($backend); $user = $manager->createUser('foo', 'bar'); @@ -290,7 +301,7 @@ class ManagerTest extends TestCase { ->with($this->equalTo('foo')) ->will($this->returnValue(true)); - $manager = new \OC\User\Manager(); + $manager = new \OC\User\Manager($this->config); $manager->registerBackend($backend); $manager->createUser('foo', 'bar'); @@ -313,14 +324,14 @@ class ManagerTest extends TestCase { ->with($this->equalTo('foo')) ->will($this->returnValue(false)); - $manager = new \OC\User\Manager(); + $manager = new \OC\User\Manager($this->config); $manager->registerBackend($backend); $this->assertFalse($manager->createUser('foo', 'bar')); } public function testCreateUserNoBackends() { - $manager = new \OC\User\Manager(); + $manager = new \OC\User\Manager($this->config); $this->assertFalse($manager->createUser('foo', 'bar')); } @@ -361,7 +372,7 @@ class ManagerTest extends TestCase { ->with($this->equalTo('foo')) ->will($this->returnValue(true)); - $manager = new \OC\User\Manager(); + $manager = new \OC\User\Manager($this->config); $manager->registerBackend($backend1); $manager->registerBackend($backend2); @@ -369,7 +380,7 @@ class ManagerTest extends TestCase { } public function testCountUsersNoBackend() { - $manager = new \OC\User\Manager(); + $manager = new \OC\User\Manager($this->config); $result = $manager->countUsers(); $this->assertTrue(is_array($result)); @@ -394,7 +405,7 @@ class ManagerTest extends TestCase { ->method('getBackendName') ->will($this->returnValue('Mock_Test_Util_User_Dummy')); - $manager = new \OC\User\Manager(); + $manager = new \OC\User\Manager($this->config); $manager->registerBackend($backend); $result = $manager->countUsers(); @@ -435,7 +446,7 @@ class ManagerTest extends TestCase { ->method('getBackendName') ->will($this->returnValue('Mock_Test_Util_User_Dummy')); - $manager = new \OC\User\Manager(); + $manager = new \OC\User\Manager($this->config); $manager->registerBackend($backend1); $manager->registerBackend($backend2); diff --git a/tests/lib/User/SessionTest.php b/tests/lib/User/SessionTest.php index 1b3d5cc4601..268d8e10e5a 100644 --- a/tests/lib/User/SessionTest.php +++ b/tests/lib/User/SessionTest.php @@ -190,7 +190,10 @@ class SessionTest extends \Test\TestCase { unset($managerMethods[$i]); } } - $manager = $this->getMockBuilder(Manager::class)->setMethods($managerMethods)->getMock(); + $manager = $this->getMockBuilder(Manager::class) + ->setMethods($managerMethods) + ->setConstructorArgs([$this->config]) + ->getMock(); $backend = $this->createMock(\Test\Util\User\Dummy::class); @@ -245,7 +248,10 @@ class SessionTest extends \Test\TestCase { unset($managerMethods[$i]); } } - $manager = $this->getMockBuilder(Manager::class)->setMethods($managerMethods)->getMock(); + $manager = $this->getMockBuilder(Manager::class) + ->setMethods($managerMethods) + ->setConstructorArgs([$this->config]) + ->getMock(); $backend = $this->createMock(\Test\Util\User\Dummy::class); @@ -277,7 +283,10 @@ class SessionTest extends \Test\TestCase { unset($managerMethods[$i]); } } - $manager = $this->getMockBuilder(Manager::class)->setMethods($managerMethods)->getMock(); + $manager = $this->getMockBuilder(Manager::class) + ->setMethods($managerMethods) + ->setConstructorArgs([$this->config]) + ->getMock(); $backend = $this->createMock(\Test\Util\User\Dummy::class); $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config); @@ -527,7 +536,10 @@ class SessionTest extends \Test\TestCase { unset($managerMethods[$i]); } } - $manager = $this->getMockBuilder(Manager::class)->setMethods($managerMethods)->getMock(); + $manager = $this->getMockBuilder(Manager::class) + ->setMethods($managerMethods) + ->setConstructorArgs([$this->config]) + ->getMock(); $backend = $this->createMock(\Test\Util\User\Dummy::class); @@ -577,7 +589,10 @@ class SessionTest extends \Test\TestCase { unset($managerMethods[$i]); } } - $manager = $this->getMockBuilder(Manager::class)->setMethods($managerMethods)->getMock(); + $manager = $this->getMockBuilder(Manager::class) + ->setMethods($managerMethods) + ->setConstructorArgs([$this->config]) + ->getMock(); $backend = $this->createMock(\Test\Util\User\Dummy::class); @@ -621,7 +636,10 @@ class SessionTest extends \Test\TestCase { unset($managerMethods[$i]); } } - $manager = $this->getMockBuilder(Manager::class)->setMethods($managerMethods)->getMock(); + $manager = $this->getMockBuilder(Manager::class) + ->setMethods($managerMethods) + ->setConstructorArgs([$this->config]) + ->getMock(); $backend = $this->createMock(\Test\Util\User\Dummy::class);