diff --git a/lib/private/AllConfig.php b/lib/private/AllConfig.php index 30e7fa0b626b..c243162e2410 100644 --- a/lib/private/AllConfig.php +++ b/lib/private/AllConfig.php @@ -290,7 +290,7 @@ public function getUserValue($userId, $appName, $key, $default = '') { public function getUserKeys($userId, $appName) { $data = $this->getUserValues($userId); if (isset($data[$appName])) { - return \array_keys($data[$appName]); + return array_map('strval', array_keys($data[$appName])); } return []; } diff --git a/tests/lib/AllConfigTest.php b/tests/lib/AllConfigTest.php index c4aaa2b019d1..a0209e340ed2 100644 --- a/tests/lib/AllConfigTest.php +++ b/tests/lib/AllConfigTest.php @@ -7,8 +7,11 @@ */ namespace Test; +use OCP\IDBConnection; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\GenericEvent; +use OC\SystemConfig; /** * Class AllConfigTest @@ -17,11 +20,11 @@ * * @package Test */ -class AllConfigTest extends \Test\TestCase { - /** @var \OCP\IDBConnection */ +class AllConfigTest extends TestCase { + /** @var IDBConnection */ protected $connection; - /** @var EventDispatcher */ + /** @var EventDispatcher | MockObject*/ protected $eventDispatcher; protected function getConfig($systemConfig = null, $connection = null) { @@ -30,15 +33,12 @@ protected function getConfig($systemConfig = null, $connection = null) { if ($this->connection === null) { $this->connection = \OC::$server->getDatabaseConnection(); } - if ($connection === null) { - $connection = $this->connection; - } if ($systemConfig === null) { - $systemConfig = $this->getMockBuilder('\OC\SystemConfig') + $systemConfig = $this->getMockBuilder(SystemConfig::class) ->disableOriginalConstructor() ->getMock(); } - return new \OC\AllConfig($systemConfig, $this->eventDispatcher, $connection); + return new \OC\AllConfig($systemConfig, $this->eventDispatcher); } public function testDeleteUserValue() { @@ -491,4 +491,29 @@ public function testGetUsersForUserValue() { // cleanup $this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`'); } + + public function testGetUserKeysAllInts(): void { + $config = $this->getConfig(); + + // preparation - add something to the database + $data = [ + ['userFetch', 'appFetch1', '123', 'value'], + ['userFetch', 'appFetch1', '456', 'value'], + ]; + foreach ($data as $entry) { + $this->connection->executeUpdate( + 'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' . + '`configkey`, `configvalue`) VALUES (?, ?, ?, ?)', + $entry + ); + } + + $value = $config->getUserKeys('userFetch', 'appFetch1'); + $this->assertEquals(['123', '456'], $value); + $this->assertIsString($value[0]); + $this->assertIsString($value[1]); + + // cleanup + $this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`'); + } }