diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2014-06-05 18:54:25 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2014-06-05 18:54:25 +0200 |
commit | 70e0ae063739b9749883bd184fee0a80f184685b (patch) | |
tree | 2280ca2140e53bb1706af64312ae7ba5b363964b /tests | |
parent | 1c598085176e4bef12f5fbcd221ef6b832b734bb (diff) | |
parent | e9011a8c5525678c1574d59d243af17fca16e9ae (diff) | |
download | nextcloud-server-70e0ae063739b9749883bd184fee0a80f184685b.tar.gz nextcloud-server-70e0ae063739b9749883bd184fee0a80f184685b.zip |
Merge pull request #8483 from owncloud/encryption_use_oc_preferences
[encryption] use oc preferences
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/preferences.php | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/tests/lib/preferences.php b/tests/lib/preferences.php index 93c9704f6c6..d31b0257bad 100644 --- a/tests/lib/preferences.php +++ b/tests/lib/preferences.php @@ -97,6 +97,42 @@ class Test_Preferences extends PHPUnit_Framework_TestCase { $this->assertEquals('othervalue', $value); } + public function testSetValueWithPreCondition() { + // remove existing key + $this->assertTrue(\OC_Preferences::deleteKey('Someuser', 'setvalueapp', 'newkey')); + + // add new preference with pre-condition should fails + $this->assertFalse(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'newvalue', 'preCondition')); + $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'); + $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey')); + $row = $result->fetchRow(); + $this->assertFalse($row); + + // add new preference without pre-condition should insert the new value + $this->assertTrue(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'newvalue')); + $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'); + $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey')); + $row = $result->fetchRow(); + $value = $row['configvalue']; + $this->assertEquals('newvalue', $value); + + // wrong pre-condition, value should stay the same + $this->assertFalse(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'othervalue', 'preCondition')); + $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'); + $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey')); + $row = $result->fetchRow(); + $value = $row['configvalue']; + $this->assertEquals('newvalue', $value); + + // correct pre-condition, value should change + $this->assertTrue(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'othervalue', 'newvalue')); + $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'); + $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey')); + $row = $result->fetchRow(); + $value = $row['configvalue']; + $this->assertEquals('othervalue', $value); + } + public function testDeleteKey() { $this->assertTrue(\OC_Preferences::deleteKey('Deleteuser', 'deleteapp', 'deletekey')); $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'); @@ -165,19 +201,11 @@ class Test_Preferences_Object extends PHPUnit_Framework_TestCase { ) )); $connectionMock->expects($this->once()) - ->method('update') - ->with($this->equalTo('*PREFIX*preferences'), - $this->equalTo( - array( - 'configvalue' => 'v2', - )), - $this->equalTo( - array( - 'userid' => 'grg', - 'appid' => 'bar', - 'configkey' => 'foo', - ) - )); + ->method('executeUpdate') + ->with($this->equalTo("UPDATE `*PREFIX*preferences` SET `configvalue` = ?" + . " WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?"), + $this->equalTo(array('v2', 'grg', 'bar', 'foo')) + ); $preferences = new OC\Preferences($connectionMock); $preferences->setValue('grg', 'bar', 'foo', 'v1'); |