Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/private/AllConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}
Expand Down
41 changes: 33 additions & 8 deletions tests/lib/AllConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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() {
Expand Down Expand Up @@ -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`');
}
}