Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <[email protected]>
  • Loading branch information
ArtificialOwl committed Dec 7, 2023
1 parent 662161f commit 4e0783a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
4 changes: 2 additions & 2 deletions core/Migrations/Version29000Date20231126110901.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
return null;
}

$table->addColumn('lazy_group', Types::STRING, ['length' => 32, 'default' => '']);
$table->addColumn('sensitive', Types::SMALLINT, ['length' => 1, 'default' => '0']);
$table->addColumn('lazy_group', Types::STRING, ['length' => 32, 'notnull' => true, 'default' => '']);
$table->addColumn('sensitive', Types::SMALLINT, ['length' => 1, 'notnull' => true, 'default' => '0']);

if ($table->hasIndex('appconfig_config_key_index')) {
$table->dropIndex('appconfig_config_key_index');
Expand Down
28 changes: 16 additions & 12 deletions tests/lib/AppConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

use OC\AppConfig;
use OC\DB\Connection;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IAppConfig;
use OCP\IConfig;

/**
Expand Down Expand Up @@ -52,6 +54,8 @@ protected function setUp(): void {
'appid' => $sql->createParameter('appid'),
'configkey' => $sql->createParameter('configkey'),
'configvalue' => $sql->createParameter('configvalue'),
'lazy_group' => $sql->createNamedParameter(''),
'sensitive' => $sql->createNamedParameter(0, IQueryBuilder::PARAM_INT),
]);

$sql->setParameters([
Expand Down Expand Up @@ -139,7 +143,7 @@ protected function tearDown(): void {
}

public function testGetApps() {
$config = new \OC\AppConfig(\OC::$server->get(Connection::class));
$config = \OCP\Server::get(IAppConfig::class);

$this->assertEqualsCanonicalizing([
'anotherapp',
Expand All @@ -150,7 +154,7 @@ public function testGetApps() {
}

public function testGetKeys() {
$config = new \OC\AppConfig(\OC::$server->get(Connection::class));
$config = \OCP\Server::get(IAppConfig::class);

$keys = $config->getKeys('testapp');
$this->assertEqualsCanonicalizing([
Expand All @@ -163,7 +167,7 @@ public function testGetKeys() {
}

public function testGetValue() {
$config = new \OC\AppConfig(\OC::$server->get(Connection::class));
$config = \OCP\Server::get(IAppConfig::class);

$value = $config->getValue('testapp', 'installed_version');
$this->assertConfigKey('testapp', 'installed_version', $value);
Expand All @@ -176,15 +180,15 @@ public function testGetValue() {
}

public function testHasKey() {
$config = new \OC\AppConfig(\OC::$server->get(Connection::class));
$config = \OCP\Server::get(IAppConfig::class);

$this->assertTrue($config->hasKey('testapp', 'installed_version'));
$this->assertFalse($config->hasKey('testapp', 'nonexistant'));
$this->assertFalse($config->hasKey('nonexistant', 'nonexistant'));
}

public function testSetValueUpdate() {
$config = new \OC\AppConfig(\OC::$server->get(Connection::class));
$config = \OCP\Server::get(IAppConfig::class);

$this->assertEquals('1.2.3', $config->getValue('testapp', 'installed_version'));
$this->assertConfigKey('testapp', 'installed_version', '1.2.3');
Expand All @@ -208,7 +212,7 @@ public function testSetValueUpdate() {
}

public function testSetValueInsert() {
$config = new \OC\AppConfig(\OC::$server->get(Connection::class));
$config = \OCP\Server::get(IAppConfig::class);

$this->assertFalse($config->hasKey('someapp', 'somekey'));
$this->assertNull($config->getValue('someapp', 'somekey'));
Expand All @@ -226,7 +230,7 @@ public function testSetValueInsert() {
}

public function testDeleteKey() {
$config = new \OC\AppConfig(\OC::$server->get(Connection::class));
$config = \OCP\Server::get(IAppConfig::class);

$this->assertTrue($config->hasKey('testapp', 'deletethis'));

Expand All @@ -248,7 +252,7 @@ public function testDeleteKey() {
}

public function testDeleteApp() {
$config = new \OC\AppConfig(\OC::$server->get(Connection::class));
$config = \OCP\Server::get(IAppConfig::class);

$this->assertTrue($config->hasKey('someapp', 'otherkey'));

Expand All @@ -268,15 +272,15 @@ public function testDeleteApp() {
}

public function testGetValuesNotAllowed() {
$config = new \OC\AppConfig(\OC::$server->get(Connection::class));
$config = \OCP\Server::get(IAppConfig::class);

$this->assertFalse($config->getValues('testapp', 'enabled'));

$this->assertFalse($config->getValues(false, false));
}

public function testGetValues() {
$config = new \OC\AppConfig(\OC::$server->get(Connection::class));
$config = \OCP\Server::get(IAppConfig::class);

$sql = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$sql->select(['configkey', 'configvalue'])
Expand Down Expand Up @@ -334,8 +338,8 @@ public function testGetFilteredValues() {
}

public function testSettingConfigParallel() {
$appConfig1 = new \OC\AppConfig(\OC::$server->get(Connection::class));
$appConfig2 = new \OC\AppConfig(\OC::$server->get(Connection::class));
$appConfig1 = \OCP\Server::get(IAppConfig::class);
$appConfig2 = \OCP\Server::get(IAppConfig::class);
$appConfig1->getValue('testapp', 'foo', 'v1');
$appConfig2->getValue('testapp', 'foo', 'v1');

Expand Down
2 changes: 2 additions & 0 deletions tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ protected function createConfig($appId, $key, $value) {
'appid' => $query->createNamedParameter($appId),
'configkey' => $query->createNamedParameter((string) $key),
'configvalue' => $query->createNamedParameter((string) $value),
'lazy_group' => $query->createNamedParameter(''),
'sensitive' => $query->createNamedParameter(0, IQueryBuilder::PARAM_INT),
])
->execute();
}
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/DB/QueryBuilder/ExpressionBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ protected function createConfig($appId, $key, $value) {
'appid' => $query->createNamedParameter($appId),
'configkey' => $query->createNamedParameter((string) $key),
'configvalue' => $query->createNamedParameter((string) $value),
'lazy_group' => $query->createNamedParameter(''),
'sensitive' => $query->createNamedParameter(0, IQueryBuilder::PARAM_INT),
])
->execute();
}
Expand Down
6 changes: 5 additions & 1 deletion tests/lib/DB/QueryBuilder/FunctionBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ protected function addDummyData(): void {
$insert->insert('appconfig')
->setValue('appid', $insert->createNamedParameter('group_concat'))
->setValue('configvalue', $insert->createNamedParameter('unittest'))
->setValue('configkey', $insert->createParameter('value'));
->setValue('configkey', $insert->createParameter('value'))
->setValue('lazy_group', $insert->createParameter(''))
->setValue('sensitive', $insert->createParameter(0, IQueryBuilder::PARAM_INT));

$insert->setParameter('value', '1');
$insert->executeStatement();
Expand Down Expand Up @@ -394,6 +396,8 @@ private function setUpMinMax($value) {
'appid' => $query->createNamedParameter('minmax'),
'configkey' => $query->createNamedParameter(uniqid()),
'configvalue' => $query->createNamedParameter((string)$value),
'lazy_group' => $query->createNamedParameter(''),
'sensitive' => $query->createNamedParameter(0, IQueryBuilder::PARAM_INT),
]);
$query->execute();
}
Expand Down

0 comments on commit 4e0783a

Please sign in to comment.