aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/AppConfigTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/AppConfigTest.php')
-rw-r--r--tests/lib/AppConfigTest.php63
1 files changed, 39 insertions, 24 deletions
diff --git a/tests/lib/AppConfigTest.php b/tests/lib/AppConfigTest.php
index 518d7909d70..b7878c42c83 100644
--- a/tests/lib/AppConfigTest.php
+++ b/tests/lib/AppConfigTest.php
@@ -14,6 +14,7 @@ use OCP\Exceptions\AppConfigUnknownKeyException;
use OCP\IAppConfig;
use OCP\IDBConnection;
use OCP\Security\ICrypto;
+use OCP\Server;
use Psr\Log\LoggerInterface;
/**
@@ -32,13 +33,13 @@ class AppConfigTest extends TestCase {
private array $originalConfig;
/**
- * @var array<string, array<array<string, string, int, bool, bool>>>
- * [appId => [configKey, configValue, valueType, lazy, sensitive]]
+ * @var array<string, array<string, array<string, string, int, bool, bool>>>
+ * [appId => [configKey, configValue, valueType, lazy, sensitive]]
*/
- private array $baseStruct =
+ private static array $baseStruct =
[
'testapp' => [
- 'enabled' => ['enabled', 'true'],
+ 'enabled' => ['enabled', 'yes'],
'installed_version' => ['installed_version', '1.2.3'],
'depends_on' => ['depends_on', 'someapp'],
'deletethis' => ['deletethis', 'deletethis'],
@@ -49,11 +50,12 @@ class AppConfigTest extends TestCase {
'otherkey' => ['otherkey', 'othervalue']
],
'123456' => [
- 'enabled' => ['enabled', 'true'],
+ 'enabled' => ['enabled', 'yes'],
'key' => ['key', 'value']
],
'anotherapp' => [
- 'enabled' => ['enabled', 'false'],
+ 'enabled' => ['enabled', 'no'],
+ 'installed_version' => ['installed_version', '3.2.1'],
'key' => ['key', 'value']
],
'non-sensitive-app' => [
@@ -86,9 +88,9 @@ class AppConfigTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $this->connection = \OCP\Server::get(IDBConnection::class);
- $this->logger = \OCP\Server::get(LoggerInterface::class);
- $this->crypto = \OCP\Server::get(ICrypto::class);
+ $this->connection = Server::get(IDBConnection::class);
+ $this->logger = Server::get(LoggerInterface::class);
+ $this->crypto = Server::get(ICrypto::class);
// storing current config and emptying the data table
$sql = $this->connection->getQueryBuilder();
@@ -114,14 +116,14 @@ class AppConfigTest extends TestCase {
]
);
- foreach ($this->baseStruct as $appId => $appData) {
+ foreach (self::$baseStruct as $appId => $appData) {
foreach ($appData as $key => $row) {
$value = $row[1];
$type = $row[2] ?? IAppConfig::VALUE_MIXED;
if (($row[4] ?? false) === true) {
$type |= IAppConfig::VALUE_SENSITIVE;
$value = self::invokePrivate(AppConfig::class, 'ENCRYPTION_PREFIX') . $this->crypto->encrypt($value);
- $this->baseStruct[$appId][$key]['encrypted'] = $value;
+ self::$baseStruct[$appId][$key]['encrypted'] = $value;
}
$sql->setParameters(
@@ -175,7 +177,7 @@ class AppConfigTest extends TestCase {
*/
private function generateAppConfig(bool $preLoading = true): IAppConfig {
/** @var AppConfig $config */
- $config = new \OC\AppConfig(
+ $config = new AppConfig(
$this->connection,
$this->logger,
$this->crypto,
@@ -197,7 +199,7 @@ class AppConfigTest extends TestCase {
$this->assertSame(true, $status['fastLoaded'], $msg);
$this->assertSame(false, $status['lazyLoaded'], $msg);
- $apps = array_values(array_diff(array_keys($this->baseStruct), ['only-lazy']));
+ $apps = array_values(array_diff(array_keys(self::$baseStruct), ['only-lazy']));
$this->assertEqualsCanonicalizing($apps, array_keys($status['fastCache']), $msg);
$this->assertSame([], array_keys($status['lazyCache']), $msg);
}
@@ -208,7 +210,20 @@ class AppConfigTest extends TestCase {
public function testGetApps(): void {
$config = $this->generateAppConfig(false);
- $this->assertEqualsCanonicalizing(array_keys($this->baseStruct), $config->getApps());
+ $this->assertEqualsCanonicalizing(array_keys(self::$baseStruct), $config->getApps());
+ }
+
+ public function testGetAppInstalledVersions(): void {
+ $config = $this->generateAppConfig(false);
+
+ $this->assertEquals(
+ ['testapp' => '1.2.3', 'anotherapp' => '3.2.1'],
+ $config->getAppInstalledVersions(false)
+ );
+ $this->assertEquals(
+ ['testapp' => '1.2.3'],
+ $config->getAppInstalledVersions(true)
+ );
}
/**
@@ -217,9 +232,9 @@ class AppConfigTest extends TestCase {
* @return array<string, string[]> ['appId' => ['key1', 'key2', ]]
* @see testGetKeys
*/
- public function providerGetAppKeys(): array {
+ public static function providerGetAppKeys(): array {
$appKeys = [];
- foreach ($this->baseStruct as $appId => $appData) {
+ foreach (self::$baseStruct as $appId => $appData) {
$keys = [];
foreach ($appData as $row) {
$keys[] = $row[0];
@@ -238,9 +253,9 @@ class AppConfigTest extends TestCase {
* @see testIsLazy
* @see testGetKeys
*/
- public function providerGetKeys(): array {
+ public static function providerGetKeys(): array {
$appKeys = [];
- foreach ($this->baseStruct as $appId => $appData) {
+ foreach (self::$baseStruct as $appId => $appData) {
foreach ($appData as $row) {
$appKeys[] = [
(string)$appId, $row[0], $row[1], $row[2] ?? IAppConfig::VALUE_MIXED, $row[3] ?? false,
@@ -283,7 +298,7 @@ class AppConfigTest extends TestCase {
public function testHasKeyOnNonExistentKeyReturnsFalse(): void {
$config = $this->generateAppConfig();
- $this->assertEquals(false, $config->hasKey(array_keys($this->baseStruct)[0], 'inexistant-key'));
+ $this->assertEquals(false, $config->hasKey(array_keys(self::$baseStruct)[0], 'inexistant-key'));
}
public function testHasKeyOnUnknownAppReturnsFalse(): void {
@@ -319,7 +334,7 @@ class AppConfigTest extends TestCase {
public function testIsSensitiveOnNonExistentKeyThrowsException(): void {
$config = $this->generateAppConfig();
$this->expectException(AppConfigUnknownKeyException::class);
- $config->isSensitive(array_keys($this->baseStruct)[0], 'inexistant-key');
+ $config->isSensitive(array_keys(self::$baseStruct)[0], 'inexistant-key');
}
public function testIsSensitiveOnUnknownAppThrowsException(): void {
@@ -362,7 +377,7 @@ class AppConfigTest extends TestCase {
public function testIsLazyOnNonExistentKeyThrowsException(): void {
$config = $this->generateAppConfig();
$this->expectException(AppConfigUnknownKeyException::class);
- $config->isLazy(array_keys($this->baseStruct)[0], 'inexistant-key');
+ $config->isLazy(array_keys(self::$baseStruct)[0], 'inexistant-key');
}
public function testIsLazyOnUnknownAppThrowsException(): void {
@@ -410,7 +425,7 @@ class AppConfigTest extends TestCase {
public function testSearchValues(): void {
$config = $this->generateAppConfig();
- $this->assertEqualsCanonicalizing(['testapp' => 'true', '123456' => 'true', 'anotherapp' => 'false'], $config->searchValues('enabled'));
+ $this->assertEqualsCanonicalizing(['testapp' => 'yes', '123456' => 'yes', 'anotherapp' => 'no'], $config->searchValues('enabled'));
}
public function testGetValueString(): void {
@@ -530,7 +545,7 @@ class AppConfigTest extends TestCase {
*
* @see testGetValueMixed
*/
- public function providerGetValueMixed(): array {
+ public static function providerGetValueMixed(): array {
return [
// key, value, type
['mixed', 'mix', IAppConfig::VALUE_MIXED],
@@ -1322,7 +1337,7 @@ class AppConfigTest extends TestCase {
$config = $this->generateAppConfig();
$config->deleteKey('anotherapp', 'key');
$status = $config->statusCache();
- $this->assertEqualsCanonicalizing(['enabled' => 'false'], $status['fastCache']['anotherapp']);
+ $this->assertEqualsCanonicalizing(['enabled' => 'no', 'installed_version' => '3.2.1'], $status['fastCache']['anotherapp']);
}
public function testDeleteKeyDatabase(): void {