diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2025-06-20 15:52:56 +0200 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2025-06-25 19:46:53 +0200 |
commit | ba11c713c05b66fc9466844b305c33bec67e33c9 (patch) | |
tree | a52f41f650a891ab4c73e806266d1562c4a6cfb5 /tests | |
parent | 0f94ceace12e96f2ffffba029cdb3d69dea46e14 (diff) | |
download | nextcloud-server-feat/noid/lexicon-events.tar.gz nextcloud-server-feat/noid/lexicon-events.zip |
feat(lexicon): events onSet() and initialize()feat/noid/lexicon-events
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Config/LexiconTest.php | 29 | ||||
-rw-r--r-- | tests/lib/Config/TestConfigLexicon_I.php | 49 |
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'; + } + ), ]; } |