@@ -182,6 +182,42 @@ public function testSetUserValueWithPreConditionFailure() {
182182 $ config ->deleteUserValue ('userPreCond1 ' , 'appPreCond ' , 'keyPreCond ' );
183183 }
184184
185+ public function testSetUserValueWithPreConditionFailureWhenResultStillMatches (): void {
186+ $ this ->expectException (\OCP \PreConditionNotMetException::class);
187+
188+ $ config = $ this ->getConfig ();
189+
190+ $ selectAllSQL = 'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? ' ;
191+
192+ $ config ->setUserValue ('userPreCond1 ' , 'appPreCond ' , 'keyPreCond ' , 'valuePreCond ' );
193+
194+ $ result = $ this ->connection ->executeQuery ($ selectAllSQL , ['userPreCond1 ' ])->fetchAll ();
195+
196+ $ this ->assertCount (1 , $ result );
197+ $ this ->assertEquals ([
198+ 'userid ' => 'userPreCond1 ' ,
199+ 'appid ' => 'appPreCond ' ,
200+ 'configkey ' => 'keyPreCond ' ,
201+ 'configvalue ' => 'valuePreCond '
202+ ], $ result [0 ]);
203+
204+ // test if the method throws with invalid precondition when the value is the same
205+ $ config ->setUserValue ('userPreCond1 ' , 'appPreCond ' , 'keyPreCond ' , 'valuePreCond ' , 'valuePreCond3 ' );
206+
207+ $ result = $ this ->connection ->executeQuery ($ selectAllSQL , ['userPreCond1 ' ])->fetchAll ();
208+
209+ $ this ->assertCount (1 , $ result );
210+ $ this ->assertEquals ([
211+ 'userid ' => 'userPreCond1 ' ,
212+ 'appid ' => 'appPreCond ' ,
213+ 'configkey ' => 'keyPreCond ' ,
214+ 'configvalue ' => 'valuePreCond '
215+ ], $ result [0 ]);
216+
217+ // cleanup
218+ $ config ->deleteUserValue ('userPreCond1 ' , 'appPreCond ' , 'keyPreCond ' );
219+ }
220+
185221 public function testSetUserValueUnchanged () {
186222 // TODO - FIXME until the dependency injection is handled properly (in AllConfig)
187223 $ this ->markTestSkipped ('Skipped because this is just testable if database connection can be injected ' );
0 commit comments