aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Config/LexiconTest.php29
-rw-r--r--tests/lib/Config/TestConfigLexicon_I.php49
2 files changed, 76 insertions, 2 deletions
diff --git a/tests/lib/Config/LexiconTest.php b/tests/lib/Config/LexiconTest.php
index 530767a7416..068984a56f3 100644
--- a/tests/lib/Config/LexiconTest.php
+++ b/tests/lib/Config/LexiconTest.php
@@ -203,4 +203,33 @@ class LexiconTest extends TestCase {
$this->configManager->migrateConfigLexiconKeys(TestConfigLexicon_I::APPID);
$this->assertSame(false, $this->appConfig->getValueBool(TestConfigLexicon_I::APPID, 'key4'));
}
+
+ public function testAppConfigOnSetEdit() {
+ $this->appConfig->setValueInt(TestConfigLexicon_I::APPID, 'key5', 42);
+ $this->assertSame(52, $this->appConfig->getValueInt(TestConfigLexicon_I::APPID, 'key5'));
+ }
+
+ public function testAppConfigOnSetIgnore() {
+ $this->appConfig->setValueInt(TestConfigLexicon_I::APPID, 'key5', 142);
+ $this->assertSame(12, $this->appConfig->getValueInt(TestConfigLexicon_I::APPID, 'key5'));
+ }
+
+ public function testUserConfigOnSetEdit() {
+ $this->userConfig->setValueInt('user1', TestConfigLexicon_I::APPID, 'key5', 42);
+ $this->assertSame(32, $this->userConfig->getValueInt('user1', TestConfigLexicon_I::APPID, 'key5'));
+ }
+
+ public function testUserConfigOnSetIgnore() {
+ $this->userConfig->setValueInt('user1', TestConfigLexicon_I::APPID, 'key5', 142);
+ $this->assertSame(12, $this->userConfig->getValueInt('user1', TestConfigLexicon_I::APPID, 'key5'));
+ }
+
+ public function testAppConfigInitialize() {
+ $this->assertSame('random_string', $this->appConfig->getValueString(TestConfigLexicon_I::APPID, 'key6'));
+ }
+
+ public function testUserConfigInitialize() {
+ $this->assertSame('random_string', $this->userConfig->getValueString('user1', TestConfigLexicon_I::APPID, 'key6'));
+ }
+
}
diff --git a/tests/lib/Config/TestConfigLexicon_I.php b/tests/lib/Config/TestConfigLexicon_I.php
index 6fb7921b6e6..b9917e6a087 100644
--- a/tests/lib/Config/TestConfigLexicon_I.php
+++ b/tests/lib/Config/TestConfigLexicon_I.php
@@ -27,14 +27,59 @@ class TestConfigLexicon_I implements IConfigLexicon {
new ConfigLexiconEntry('key1', ValueType::STRING, 'abcde', 'test key', true, IAppConfig::FLAG_SENSITIVE),
new ConfigLexiconEntry('key2', ValueType::INT, 12345, 'test key', false),
new ConfigLexiconEntry('key3', ValueType::INT, 12345, 'test key', true, rename: 'old_key3'),
- new ConfigLexiconEntry('key4', ValueType::BOOL, 12345, 'test key', true, rename: 'old_key4', options: ConfigLexiconEntry::RENAME_INVERT_BOOLEAN),
+ new ConfigLexiconEntry(
+ 'key4', ValueType::BOOL, 12345, 'test key', true, rename: 'old_key4',
+ options: ConfigLexiconEntry::RENAME_INVERT_BOOLEAN
+ ),
+ (new ConfigLexiconEntry('key5', ValueType::INT, 12, 'test key', true))->onSet(
+ function (string &$v): bool {
+ $i = (int)$v;
+ if ($i > 100) {
+ return false;
+ }
+ $v = (string)($i + 10);
+
+ return true;
+ }
+ ),
+ (new ConfigLexiconEntry('key6', ValueType::STRING, '', 'test key'))->initialize(
+ function (string &$d): void {
+ $d = 'random_string';
+ }
+ ),
+ (new ConfigLexiconEntry('key6', ValueType::STRING, '', 'test key'))->initialize(
+ function (string &$d): void {
+ $d = 'random_string';
+ }
+ ),
+ (new ConfigLexiconEntry('email', ValueType::STRING, '', 'email'))->onSet(
+ function (string &$value): void {
+ $value = strtolower($value);
+ }
+ ),
];
}
public function getUserConfigs(): array {
return [
new ConfigLexiconEntry('key1', ValueType::STRING, 'abcde', 'test key', true, IUserConfig::FLAG_SENSITIVE),
- new ConfigLexiconEntry('key2', ValueType::INT, 12345, 'test key', false)
+ new ConfigLexiconEntry('key2', ValueType::INT, 12345, 'test key', false),
+ (new ConfigLexiconEntry('key5', ValueType::INT, 12, 'test key', true))->onSet(
+ function (string &$v): bool {
+ $i = (int)$v;
+ if ($i > 100) {
+ return false;
+ }
+ $v = (string)($i - 10);
+
+ return true;
+ }
+ ),
+ (new ConfigLexiconEntry('key6', ValueType::STRING, '', 'test key'))->initialize(
+ function (string &$d): void {
+ $d = 'random_string';
+ }
+ ),
];
}