diff options
author | Andy Scherzinger <info@andy-scherzinger.de> | 2024-09-15 21:29:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-15 21:29:14 +0200 |
commit | 90a6b8257920a5b950c319f9b3af54b66690531e (patch) | |
tree | bdcd299282ceae2b61ea9a87f7d3a5555cb73cc1 /tests/lib | |
parent | fa355386f779428a90c40dbf6467c3d924bff24b (diff) | |
parent | 66a6b442b5543a571ba405d328651677774b699a (diff) | |
download | nextcloud-server-90a6b8257920a5b950c319f9b3af54b66690531e.tar.gz nextcloud-server-90a6b8257920a5b950c319f9b3af54b66690531e.zip |
Merge pull request #47940 from nextcloud/backport/47933/stable30
[stable30] fix(config): Throw PreconditionException always when it didn't match
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/AllConfigTest.php | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/lib/AllConfigTest.php b/tests/lib/AllConfigTest.php index c703c47c94e..48df3416df1 100644 --- a/tests/lib/AllConfigTest.php +++ b/tests/lib/AllConfigTest.php @@ -182,6 +182,42 @@ class AllConfigTest extends \Test\TestCase { $config->deleteUserValue('userPreCond1', 'appPreCond', 'keyPreCond'); } + public function testSetUserValueWithPreConditionFailureWhenResultStillMatches(): void { + $this->expectException(\OCP\PreConditionNotMetException::class); + + $config = $this->getConfig(); + + $selectAllSQL = 'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?'; + + $config->setUserValue('userPreCond1', 'appPreCond', 'keyPreCond', 'valuePreCond'); + + $result = $this->connection->executeQuery($selectAllSQL, ['userPreCond1'])->fetchAll(); + + $this->assertCount(1, $result); + $this->assertEquals([ + 'userid' => 'userPreCond1', + 'appid' => 'appPreCond', + 'configkey' => 'keyPreCond', + 'configvalue' => 'valuePreCond' + ], $result[0]); + + // test if the method throws with invalid precondition when the value is the same + $config->setUserValue('userPreCond1', 'appPreCond', 'keyPreCond', 'valuePreCond', 'valuePreCond3'); + + $result = $this->connection->executeQuery($selectAllSQL, ['userPreCond1'])->fetchAll(); + + $this->assertCount(1, $result); + $this->assertEquals([ + 'userid' => 'userPreCond1', + 'appid' => 'appPreCond', + 'configkey' => 'keyPreCond', + 'configvalue' => 'valuePreCond' + ], $result[0]); + + // cleanup + $config->deleteUserValue('userPreCond1', 'appPreCond', 'keyPreCond'); + } + public function testSetUserValueUnchanged() { // 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'); |