summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2013-03-03 12:04:29 +0100
committerBart Visscher <bartv@thisnet.nl>2013-09-19 18:13:06 +0200
commit445d34a2a90295c11ace24171c20a93991ebfa87 (patch)
treefb830ec0cba28fb024c5fabdbde725d400bb391e /tests
parent2e79aab0ce7ec9fa88ccbafd01e82574b93514f9 (diff)
downloadnextcloud-server-445d34a2a90295c11ace24171c20a93991ebfa87.tar.gz
nextcloud-server-445d34a2a90295c11ace24171c20a93991ebfa87.zip
Convert OC_Preference to object interface
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/preferences.php179
1 files changed, 179 insertions, 0 deletions
diff --git a/tests/lib/preferences.php b/tests/lib/preferences.php
index 612cc81926b..68b794e9ea9 100644
--- a/tests/lib/preferences.php
+++ b/tests/lib/preferences.php
@@ -1,6 +1,7 @@
<?php
/**
* Copyright (c) 2013 Christopher Schäpers <christopher@schaepers.it>
+ * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
@@ -124,3 +125,181 @@ class Test_Preferences extends PHPUnit_Framework_TestCase {
$this->assertEquals(0, $result->numRows());
}
}
+
+class Test_Preferences_Object extends PHPUnit_Framework_TestCase {
+ public function testGetUsers()
+ {
+ $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false);
+ $statementMock->expects($this->exactly(2))
+ ->method('fetchColumn')
+ ->will($this->onConsecutiveCalls('foo', false));
+ $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
+ $connectionMock->expects($this->once())
+ ->method('executeQuery')
+ ->with($this->equalTo('SELECT DISTINCT `userid` FROM `*PREFIX*preferences`'))
+ ->will($this->returnValue($statementMock));
+
+ $preferences = new OC\Preferences($connectionMock);
+ $apps = $preferences->getUsers();
+ $this->assertEquals(array('foo'), $apps);
+ }
+
+ public function testGetApps()
+ {
+ $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false);
+ $statementMock->expects($this->exactly(2))
+ ->method('fetchColumn')
+ ->will($this->onConsecutiveCalls('foo', false));
+ $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
+ $connectionMock->expects($this->once())
+ ->method('executeQuery')
+ ->with($this->equalTo('SELECT DISTINCT `appid` FROM `*PREFIX*preferences` WHERE `userid` = ?'),
+ $this->equalTo(array('bar')))
+ ->will($this->returnValue($statementMock));
+
+ $preferences = new OC\Preferences($connectionMock);
+ $apps = $preferences->getApps('bar');
+ $this->assertEquals(array('foo'), $apps);
+ }
+
+ public function testGetKeys()
+ {
+ $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false);
+ $statementMock->expects($this->exactly(2))
+ ->method('fetchColumn')
+ ->will($this->onConsecutiveCalls('foo', false));
+ $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
+ $connectionMock->expects($this->once())
+ ->method('executeQuery')
+ ->with($this->equalTo('SELECT `configkey` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ?'),
+ $this->equalTo(array('bar', 'moo')))
+ ->will($this->returnValue($statementMock));
+
+ $preferences = new OC\Preferences($connectionMock);
+ $keys = $preferences->getKeys('bar', 'moo');
+ $this->assertEquals(array('foo'), $keys);
+ }
+
+ public function testGetValue()
+ {
+ $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
+ $connectionMock->expects($this->exactly(2))
+ ->method('fetchAssoc')
+ ->with($this->equalTo('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'),
+ $this->equalTo(array('grg', 'bar', 'red')))
+ ->will($this->onConsecutiveCalls(array('configvalue'=>'foo'), null));
+
+ $preferences = new OC\Preferences($connectionMock);
+ $value = $preferences->getValue('grg', 'bar', 'red');
+ $this->assertEquals('foo', $value);
+ $value = $preferences->getValue('grg', 'bar', 'red', 'def');
+ $this->assertEquals('def', $value);
+ }
+
+ public function testSetValue()
+ {
+ $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
+ $connectionMock->expects($this->exactly(2))
+ ->method('fetchColumn')
+ ->with($this->equalTo('SELECT COUNT(*) FROM `*PREFIX*preferences`'
+ .' WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'),
+ $this->equalTo(array('grg', 'bar', 'foo')))
+ ->will($this->onConsecutiveCalls(0, 1));
+ $connectionMock->expects($this->once())
+ ->method('insert')
+ ->with($this->equalTo('*PREFIX*preferences'),
+ $this->equalTo(
+ array(
+ 'userid' => 'grg',
+ 'appid' => 'bar',
+ 'configkey' => 'foo',
+ 'configvalue' => 'v1',
+ )
+ ));
+ $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',
+ )
+ ));
+
+ $preferences = new OC\Preferences($connectionMock);
+ $preferences->setValue('grg', 'bar', 'foo', 'v1');
+ $preferences->setValue('grg', 'bar', 'foo', 'v2');
+ }
+
+ public function testDeleteKey()
+ {
+ $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
+ $connectionMock->expects($this->once())
+ ->method('delete')
+ ->with($this->equalTo('*PREFIX*preferences'),
+ $this->equalTo(
+ array(
+ 'userid' => 'grg',
+ 'appid' => 'bar',
+ 'configkey' => 'foo',
+ )
+ ));
+
+ $preferences = new OC\Preferences($connectionMock);
+ $preferences->deleteKey('grg', 'bar', 'foo');
+ }
+
+ public function testDeleteApp()
+ {
+ $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
+ $connectionMock->expects($this->once())
+ ->method('delete')
+ ->with($this->equalTo('*PREFIX*preferences'),
+ $this->equalTo(
+ array(
+ 'userid' => 'grg',
+ 'appid' => 'bar',
+ )
+ ));
+
+ $preferences = new OC\Preferences($connectionMock);
+ $preferences->deleteApp('grg', 'bar');
+ }
+
+ public function testDeleteUser()
+ {
+ $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
+ $connectionMock->expects($this->once())
+ ->method('delete')
+ ->with($this->equalTo('*PREFIX*preferences'),
+ $this->equalTo(
+ array(
+ 'userid' => 'grg',
+ )
+ ));
+
+ $preferences = new OC\Preferences($connectionMock);
+ $preferences->deleteUser('grg');
+ }
+
+ public function testDeleteAppFromAllUsers()
+ {
+ $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
+ $connectionMock->expects($this->once())
+ ->method('delete')
+ ->with($this->equalTo('*PREFIX*preferences'),
+ $this->equalTo(
+ array(
+ 'appid' => 'bar',
+ )
+ ));
+
+ $preferences = new OC\Preferences($connectionMock);
+ $preferences->deleteAppFromAllUsers('bar');
+ }
+}