2014-11-19 14:18:32 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2014 Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Test;
|
|
|
|
|
2015-11-03 03:52:41 +03:00
|
|
|
/**
|
2016-05-19 10:27:21 +03:00
|
|
|
* Class AllConfigTest
|
2015-11-03 03:52:41 +03:00
|
|
|
*
|
|
|
|
* @group DB
|
|
|
|
*
|
|
|
|
* @package Test
|
|
|
|
*/
|
2017-04-20 13:27:32 +03:00
|
|
|
use OCP\IDBConnection;
|
|
|
|
|
2016-05-19 10:27:21 +03:00
|
|
|
class AllConfigTest extends \Test\TestCase {
|
2014-11-19 14:18:32 +03:00
|
|
|
|
|
|
|
/** @var \OCP\IDBConnection */
|
|
|
|
protected $connection;
|
|
|
|
|
|
|
|
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) {
|
2015-12-18 13:24:15 +03:00
|
|
|
$systemConfig = $this->getMockBuilder('\OC\SystemConfig')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2014-11-19 14:18:32 +03:00
|
|
|
}
|
|
|
|
return new \OC\AllConfig($systemConfig, $connection);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDeleteUserValue() {
|
|
|
|
$config = $this->getConfig();
|
|
|
|
|
|
|
|
// preparation - add something to the database
|
|
|
|
$this->connection->executeUpdate(
|
|
|
|
'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' .
|
|
|
|
'`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
|
2020-03-26 11:30:18 +03:00
|
|
|
['userDelete', 'appDelete', 'keyDelete', 'valueDelete']
|
2014-11-19 14:18:32 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
$config->deleteUserValue('userDelete', 'appDelete', 'keyDelete');
|
|
|
|
|
|
|
|
$result = $this->connection->executeQuery(
|
|
|
|
'SELECT COUNT(*) AS `count` FROM `*PREFIX*preferences` WHERE `userid` = ?',
|
2020-03-26 11:30:18 +03:00
|
|
|
['userDelete']
|
2014-11-19 14:18:32 +03:00
|
|
|
)->fetch();
|
|
|
|
$actualCount = $result['count'];
|
|
|
|
|
|
|
|
$this->assertEquals(0, $actualCount, 'There was one value in the database and after the tests there should be no entry left.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSetUserValue() {
|
|
|
|
$selectAllSQL = 'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?';
|
|
|
|
$config = $this->getConfig();
|
|
|
|
|
|
|
|
$config->setUserValue('userSet', 'appSet', 'keySet', 'valueSet');
|
|
|
|
|
2020-03-26 11:30:18 +03:00
|
|
|
$result = $this->connection->executeQuery($selectAllSQL, ['userSet'])->fetchAll();
|
2014-11-19 14:18:32 +03:00
|
|
|
|
|
|
|
$this->assertEquals(1, count($result));
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->assertEquals([
|
2014-11-19 14:18:32 +03:00
|
|
|
'userid' => 'userSet',
|
|
|
|
'appid' => 'appSet',
|
|
|
|
'configkey' => 'keySet',
|
|
|
|
'configvalue' => 'valueSet'
|
2020-03-26 11:30:18 +03:00
|
|
|
], $result[0]);
|
2014-11-19 14:18:32 +03:00
|
|
|
|
|
|
|
// test if the method overwrites existing database entries
|
|
|
|
$config->setUserValue('userSet', 'appSet', 'keySet', 'valueSet2');
|
|
|
|
|
2020-03-26 11:30:18 +03:00
|
|
|
$result = $this->connection->executeQuery($selectAllSQL, ['userSet'])->fetchAll();
|
2014-11-19 14:18:32 +03:00
|
|
|
|
|
|
|
$this->assertEquals(1, count($result));
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->assertEquals([
|
2014-11-19 14:18:32 +03:00
|
|
|
'userid' => 'userSet',
|
|
|
|
'appid' => 'appSet',
|
|
|
|
'configkey' => 'keySet',
|
|
|
|
'configvalue' => 'valueSet2'
|
2020-03-26 11:30:18 +03:00
|
|
|
], $result[0]);
|
2014-11-19 14:18:32 +03:00
|
|
|
|
|
|
|
// cleanup - it therefore relies on the successful execution of the previous test
|
|
|
|
$config->deleteUserValue('userSet', 'appSet', 'keySet');
|
|
|
|
}
|
|
|
|
|
2014-12-03 23:31:29 +03:00
|
|
|
public function testSetUserValueWithPreCondition() {
|
2015-08-24 15:21:09 +03:00
|
|
|
$config = $this->getConfig();
|
2014-12-03 23:31:29 +03:00
|
|
|
|
|
|
|
$selectAllSQL = 'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?';
|
|
|
|
|
|
|
|
$config->setUserValue('userPreCond', 'appPreCond', 'keyPreCond', 'valuePreCond');
|
|
|
|
|
2020-03-26 11:30:18 +03:00
|
|
|
$result = $this->connection->executeQuery($selectAllSQL, ['userPreCond'])->fetchAll();
|
2014-12-03 23:31:29 +03:00
|
|
|
|
|
|
|
$this->assertEquals(1, count($result));
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->assertEquals([
|
2014-12-03 23:31:29 +03:00
|
|
|
'userid' => 'userPreCond',
|
|
|
|
'appid' => 'appPreCond',
|
|
|
|
'configkey' => 'keyPreCond',
|
|
|
|
'configvalue' => 'valuePreCond'
|
2020-03-26 11:30:18 +03:00
|
|
|
], $result[0]);
|
2014-12-03 23:31:29 +03:00
|
|
|
|
|
|
|
// test if the method overwrites existing database entries with valid precond
|
|
|
|
$config->setUserValue('userPreCond', 'appPreCond', 'keyPreCond', 'valuePreCond2', 'valuePreCond');
|
|
|
|
|
2020-03-26 11:30:18 +03:00
|
|
|
$result = $this->connection->executeQuery($selectAllSQL, ['userPreCond'])->fetchAll();
|
2014-12-03 23:31:29 +03:00
|
|
|
|
|
|
|
$this->assertEquals(1, count($result));
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->assertEquals([
|
2014-12-03 23:31:29 +03:00
|
|
|
'userid' => 'userPreCond',
|
|
|
|
'appid' => 'appPreCond',
|
|
|
|
'configkey' => 'keyPreCond',
|
|
|
|
'configvalue' => 'valuePreCond2'
|
2020-03-26 11:30:18 +03:00
|
|
|
], $result[0]);
|
2014-12-03 23:31:29 +03:00
|
|
|
|
|
|
|
// cleanup
|
|
|
|
$config->deleteUserValue('userPreCond', 'appPreCond', 'keyPreCond');
|
|
|
|
}
|
|
|
|
|
2016-06-06 11:28:10 +03:00
|
|
|
public function dataSetUserValueUnexpectedValue() {
|
|
|
|
return [
|
|
|
|
[true],
|
|
|
|
[false],
|
|
|
|
[null],
|
|
|
|
[new \stdClass()],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataSetUserValueUnexpectedValue
|
|
|
|
* @param mixed $value
|
|
|
|
*/
|
|
|
|
public function testSetUserValueUnexpectedValue($value) {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\UnexpectedValueException::class);
|
|
|
|
|
2016-06-06 11:28:10 +03:00
|
|
|
$config = $this->getConfig();
|
|
|
|
$config->setUserValue('userSetBool', 'appSetBool', 'keySetBool', $value);
|
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
|
2014-12-03 23:31:29 +03:00
|
|
|
public function testSetUserValueWithPreConditionFailure() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\PreConditionNotMetException::class);
|
|
|
|
|
2015-08-24 15:21:09 +03:00
|
|
|
$config = $this->getConfig();
|
2014-12-03 23:31:29 +03:00
|
|
|
|
|
|
|
$selectAllSQL = 'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?';
|
|
|
|
|
|
|
|
$config->setUserValue('userPreCond1', 'appPreCond', 'keyPreCond', 'valuePreCond');
|
|
|
|
|
2020-03-26 11:30:18 +03:00
|
|
|
$result = $this->connection->executeQuery($selectAllSQL, ['userPreCond1'])->fetchAll();
|
2014-12-03 23:31:29 +03:00
|
|
|
|
|
|
|
$this->assertEquals(1, count($result));
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->assertEquals([
|
2014-12-03 23:31:29 +03:00
|
|
|
'userid' => 'userPreCond1',
|
|
|
|
'appid' => 'appPreCond',
|
|
|
|
'configkey' => 'keyPreCond',
|
|
|
|
'configvalue' => 'valuePreCond'
|
2020-03-26 11:30:18 +03:00
|
|
|
], $result[0]);
|
2014-12-03 23:31:29 +03:00
|
|
|
|
|
|
|
// test if the method overwrites existing database entries with valid precond
|
|
|
|
$config->setUserValue('userPreCond1', 'appPreCond', 'keyPreCond', 'valuePreCond2', 'valuePreCond3');
|
|
|
|
|
2020-03-26 11:30:18 +03:00
|
|
|
$result = $this->connection->executeQuery($selectAllSQL, ['userPreCond1'])->fetchAll();
|
2014-12-03 23:31:29 +03:00
|
|
|
|
|
|
|
$this->assertEquals(1, count($result));
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->assertEquals([
|
2014-12-03 23:31:29 +03:00
|
|
|
'userid' => 'userPreCond1',
|
|
|
|
'appid' => 'appPreCond',
|
|
|
|
'configkey' => 'keyPreCond',
|
|
|
|
'configvalue' => 'valuePreCond'
|
2020-03-26 11:30:18 +03:00
|
|
|
], $result[0]);
|
2014-12-03 23:31:29 +03:00
|
|
|
|
|
|
|
// cleanup
|
|
|
|
$config->deleteUserValue('userPreCond1', 'appPreCond', 'keyPreCond');
|
|
|
|
}
|
|
|
|
|
2014-11-19 14:18:32 +03:00
|
|
|
public function testSetUserValueUnchanged() {
|
2014-12-04 11:35:01 +03:00
|
|
|
// TODO - FIXME until the dependency injection is handled properly (in AllConfig)
|
|
|
|
$this->markTestSkipped('Skipped because this is just testable if database connection can be injected');
|
|
|
|
|
2014-11-19 14:18:32 +03:00
|
|
|
$resultMock = $this->getMockBuilder('\Doctrine\DBAL\Driver\Statement')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$resultMock->expects($this->once())
|
|
|
|
->method('fetchColumn')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('valueSetUnchanged');
|
2014-11-19 14:18:32 +03:00
|
|
|
|
2017-04-20 13:27:32 +03:00
|
|
|
$connectionMock = $this->createMock(IDBConnection::class);
|
2014-11-19 14:18:32 +03:00
|
|
|
$connectionMock->expects($this->once())
|
|
|
|
->method('executeQuery')
|
|
|
|
->with($this->equalTo('SELECT `configvalue` FROM `*PREFIX*preferences` '.
|
|
|
|
'WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'),
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->equalTo(['userSetUnchanged', 'appSetUnchanged', 'keySetUnchanged']))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($resultMock);
|
2014-11-19 14:18:32 +03:00
|
|
|
$connectionMock->expects($this->never())
|
|
|
|
->method('executeUpdate');
|
|
|
|
|
|
|
|
$config = $this->getConfig(null, $connectionMock);
|
|
|
|
|
|
|
|
$config->setUserValue('userSetUnchanged', 'appSetUnchanged', 'keySetUnchanged', 'valueSetUnchanged');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetUserValue() {
|
|
|
|
$config = $this->getConfig();
|
|
|
|
|
|
|
|
// setup - it therefore relies on the successful execution of the previous test
|
|
|
|
$config->setUserValue('userGet', 'appGet', 'keyGet', 'valueGet');
|
|
|
|
$value = $config->getUserValue('userGet', 'appGet', 'keyGet');
|
|
|
|
|
|
|
|
$this->assertEquals('valueGet', $value);
|
|
|
|
|
|
|
|
$result = $this->connection->executeQuery(
|
|
|
|
'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?',
|
2020-03-26 11:30:18 +03:00
|
|
|
['userGet']
|
2014-11-19 14:18:32 +03:00
|
|
|
)->fetchAll();
|
|
|
|
|
|
|
|
$this->assertEquals(1, count($result));
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->assertEquals([
|
2014-11-19 14:18:32 +03:00
|
|
|
'userid' => 'userGet',
|
|
|
|
'appid' => 'appGet',
|
|
|
|
'configkey' => 'keyGet',
|
|
|
|
'configvalue' => 'valueGet'
|
2020-03-26 11:30:18 +03:00
|
|
|
], $result[0]);
|
2014-11-19 14:18:32 +03:00
|
|
|
|
|
|
|
// drop data from database - but the config option should be cached in the config object
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences` WHERE `userid` = ?', ['userGet']);
|
2014-11-19 14:18:32 +03:00
|
|
|
|
|
|
|
// testing the caching mechanism
|
|
|
|
$value = $config->getUserValue('userGet', 'appGet', 'keyGet');
|
|
|
|
|
|
|
|
$this->assertEquals('valueGet', $value);
|
|
|
|
|
|
|
|
$result = $this->connection->executeQuery(
|
|
|
|
'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?',
|
2020-03-26 11:30:18 +03:00
|
|
|
['userGet']
|
2014-11-19 14:18:32 +03:00
|
|
|
)->fetchAll();
|
|
|
|
|
|
|
|
$this->assertEquals(0, count($result));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetUserKeys() {
|
|
|
|
$config = $this->getConfig();
|
|
|
|
|
|
|
|
// preparation - add something to the database
|
2020-03-26 11:30:18 +03:00
|
|
|
$data = [
|
|
|
|
['userFetch', 'appFetch1', 'keyFetch1', 'value1'],
|
|
|
|
['userFetch', 'appFetch1', 'keyFetch2', 'value2'],
|
|
|
|
['userFetch', 'appFetch2', 'keyFetch3', 'value3'],
|
|
|
|
['userFetch', 'appFetch1', 'keyFetch4', 'value4'],
|
|
|
|
['userFetch', 'appFetch4', 'keyFetch1', 'value5'],
|
|
|
|
['userFetch', 'appFetch5', 'keyFetch1', 'value6'],
|
|
|
|
['userFetch2', 'appFetch', 'keyFetch1', 'value7']
|
|
|
|
];
|
2014-11-19 14:18:32 +03:00
|
|
|
foreach ($data as $entry) {
|
|
|
|
$this->connection->executeUpdate(
|
|
|
|
'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' .
|
|
|
|
'`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
|
|
|
|
$entry
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$value = $config->getUserKeys('userFetch', 'appFetch1');
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->assertEquals(['keyFetch1', 'keyFetch2', 'keyFetch4'], $value);
|
2014-11-19 14:18:32 +03:00
|
|
|
|
|
|
|
$value = $config->getUserKeys('userFetch2', 'appFetch');
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->assertEquals(['keyFetch1'], $value);
|
2014-11-19 14:18:32 +03:00
|
|
|
|
|
|
|
// cleanup
|
|
|
|
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetUserValueDefault() {
|
|
|
|
$config = $this->getConfig();
|
|
|
|
|
|
|
|
$this->assertEquals('', $config->getUserValue('userGetUnset', 'appGetUnset', 'keyGetUnset'));
|
|
|
|
$this->assertEquals(null, $config->getUserValue('userGetUnset', 'appGetUnset', 'keyGetUnset', null));
|
|
|
|
$this->assertEquals('foobar', $config->getUserValue('userGetUnset', 'appGetUnset', 'keyGetUnset', 'foobar'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetUserValueForUsers() {
|
|
|
|
$config = $this->getConfig();
|
|
|
|
|
|
|
|
// preparation - add something to the database
|
2020-03-26 11:30:18 +03:00
|
|
|
$data = [
|
|
|
|
['userFetch1', 'appFetch2', 'keyFetch1', 'value1'],
|
|
|
|
['userFetch2', 'appFetch2', 'keyFetch1', 'value2'],
|
|
|
|
['userFetch3', 'appFetch2', 'keyFetch1', 3],
|
|
|
|
['userFetch4', 'appFetch2', 'keyFetch1', 'value4'],
|
|
|
|
['userFetch5', 'appFetch2', 'keyFetch1', 'value5'],
|
|
|
|
['userFetch6', 'appFetch2', 'keyFetch1', 'value6'],
|
|
|
|
['userFetch7', 'appFetch2', 'keyFetch1', 'value7']
|
|
|
|
];
|
2014-11-19 14:18:32 +03:00
|
|
|
foreach ($data as $entry) {
|
|
|
|
$this->connection->executeUpdate(
|
|
|
|
'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' .
|
|
|
|
'`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
|
|
|
|
$entry
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$value = $config->getUserValueForUsers('appFetch2', 'keyFetch1',
|
2020-03-26 11:30:18 +03:00
|
|
|
['userFetch1', 'userFetch2', 'userFetch3', 'userFetch5']);
|
|
|
|
$this->assertEquals([
|
2014-11-19 14:18:32 +03:00
|
|
|
'userFetch1' => 'value1',
|
|
|
|
'userFetch2' => 'value2',
|
|
|
|
'userFetch3' => 3,
|
|
|
|
'userFetch5' => 'value5'
|
2020-03-26 11:30:18 +03:00
|
|
|
], $value);
|
2014-11-19 14:18:32 +03:00
|
|
|
|
|
|
|
$value = $config->getUserValueForUsers('appFetch2', 'keyFetch1',
|
2020-03-26 11:30:18 +03:00
|
|
|
['userFetch1', 'userFetch4', 'userFetch9']);
|
|
|
|
$this->assertEquals([
|
2014-11-19 14:18:32 +03:00
|
|
|
'userFetch1' => 'value1',
|
|
|
|
'userFetch4' => 'value4'
|
2020-03-26 11:30:18 +03:00
|
|
|
], $value, 'userFetch9 is an non-existent user and should not be shown.');
|
2014-11-19 14:18:32 +03:00
|
|
|
|
|
|
|
// cleanup
|
|
|
|
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDeleteAllUserValues() {
|
|
|
|
$config = $this->getConfig();
|
|
|
|
|
|
|
|
// preparation - add something to the database
|
2020-03-26 11:30:18 +03:00
|
|
|
$data = [
|
|
|
|
['userFetch3', 'appFetch1', 'keyFetch1', 'value1'],
|
|
|
|
['userFetch3', 'appFetch1', 'keyFetch2', 'value2'],
|
|
|
|
['userFetch3', 'appFetch2', 'keyFetch3', 'value3'],
|
|
|
|
['userFetch3', 'appFetch1', 'keyFetch4', 'value4'],
|
|
|
|
['userFetch3', 'appFetch4', 'keyFetch1', 'value5'],
|
|
|
|
['userFetch3', 'appFetch5', 'keyFetch1', 'value6'],
|
|
|
|
['userFetch4', 'appFetch2', 'keyFetch1', 'value7']
|
|
|
|
];
|
2014-11-19 14:18:32 +03:00
|
|
|
foreach ($data as $entry) {
|
|
|
|
$this->connection->executeUpdate(
|
|
|
|
'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' .
|
|
|
|
'`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
|
|
|
|
$entry
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$config->deleteAllUserValues('userFetch3');
|
|
|
|
|
|
|
|
$result = $this->connection->executeQuery(
|
|
|
|
'SELECT COUNT(*) AS `count` FROM `*PREFIX*preferences`'
|
|
|
|
)->fetch();
|
|
|
|
$actualCount = $result['count'];
|
|
|
|
|
|
|
|
$this->assertEquals(1, $actualCount, 'After removing `userFetch3` there should be exactly 1 entry left.');
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDeleteAppFromAllUsers() {
|
|
|
|
$config = $this->getConfig();
|
|
|
|
|
|
|
|
// preparation - add something to the database
|
2020-03-26 11:30:18 +03:00
|
|
|
$data = [
|
|
|
|
['userFetch5', 'appFetch1', 'keyFetch1', 'value1'],
|
|
|
|
['userFetch5', 'appFetch1', 'keyFetch2', 'value2'],
|
|
|
|
['userFetch5', 'appFetch2', 'keyFetch3', 'value3'],
|
|
|
|
['userFetch5', 'appFetch1', 'keyFetch4', 'value4'],
|
|
|
|
['userFetch5', 'appFetch4', 'keyFetch1', 'value5'],
|
|
|
|
['userFetch5', 'appFetch5', 'keyFetch1', 'value6'],
|
|
|
|
['userFetch6', 'appFetch2', 'keyFetch1', 'value7']
|
|
|
|
];
|
2014-11-19 14:18:32 +03:00
|
|
|
foreach ($data as $entry) {
|
|
|
|
$this->connection->executeUpdate(
|
|
|
|
'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' .
|
|
|
|
'`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
|
|
|
|
$entry
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$config->deleteAppFromAllUsers('appFetch1');
|
|
|
|
|
|
|
|
$result = $this->connection->executeQuery(
|
|
|
|
'SELECT COUNT(*) AS `count` FROM `*PREFIX*preferences`'
|
|
|
|
)->fetch();
|
|
|
|
$actualCount = $result['count'];
|
|
|
|
|
|
|
|
$this->assertEquals(4, $actualCount, 'After removing `appFetch1` there should be exactly 4 entries left.');
|
|
|
|
|
|
|
|
$config->deleteAppFromAllUsers('appFetch2');
|
|
|
|
|
|
|
|
$result = $this->connection->executeQuery(
|
|
|
|
'SELECT COUNT(*) AS `count` FROM `*PREFIX*preferences`'
|
|
|
|
)->fetch();
|
|
|
|
$actualCount = $result['count'];
|
|
|
|
|
|
|
|
$this->assertEquals(2, $actualCount, 'After removing `appFetch2` there should be exactly 2 entries left.');
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetUsersForUserValue() {
|
|
|
|
// mock the check for the database to run the correct SQL statements for each database type
|
2015-12-18 13:24:15 +03:00
|
|
|
$systemConfig = $this->getMockBuilder('\OC\SystemConfig')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2014-11-19 14:18:32 +03:00
|
|
|
$systemConfig->expects($this->once())
|
|
|
|
->method('getValue')
|
|
|
|
->with($this->equalTo('dbtype'),
|
|
|
|
$this->equalTo('sqlite'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(\OC::$server->getConfig()->getSystemValue('dbtype', 'sqlite'));
|
2014-11-19 14:18:32 +03:00
|
|
|
$config = $this->getConfig($systemConfig);
|
|
|
|
|
|
|
|
// preparation - add something to the database
|
2020-03-26 11:30:18 +03:00
|
|
|
$data = [
|
|
|
|
['user1', 'appFetch9', 'keyFetch9', 'value9'],
|
|
|
|
['user2', 'appFetch9', 'keyFetch9', 'value9'],
|
|
|
|
['user3', 'appFetch9', 'keyFetch9', 'value8'],
|
|
|
|
['user4', 'appFetch9', 'keyFetch8', 'value9'],
|
|
|
|
['user5', 'appFetch8', 'keyFetch9', 'value9'],
|
|
|
|
['user6', 'appFetch9', 'keyFetch9', 'value9'],
|
|
|
|
];
|
2014-11-19 14:18:32 +03:00
|
|
|
foreach ($data as $entry) {
|
|
|
|
$this->connection->executeUpdate(
|
|
|
|
'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' .
|
|
|
|
'`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
|
|
|
|
$entry
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$value = $config->getUsersForUserValue('appFetch9', 'keyFetch9', 'value9');
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->assertEquals(['user1', 'user2', 'user6'], $value);
|
2014-11-19 14:18:32 +03:00
|
|
|
|
|
|
|
// cleanup
|
|
|
|
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|