diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/files/cache/scanner.php | 10 | ||||
-rw-r--r-- | tests/lib/files/view.php | 14 | ||||
-rw-r--r-- | tests/lib/preferences.php | 179 |
3 files changed, 203 insertions, 0 deletions
diff --git a/tests/lib/files/cache/scanner.php b/tests/lib/files/cache/scanner.php index f6deb93a49e..4c90119814a 100644 --- a/tests/lib/files/cache/scanner.php +++ b/tests/lib/files/cache/scanner.php @@ -184,6 +184,16 @@ class Scanner extends \PHPUnit_Framework_TestCase { $this->assertFalse($this->cache->inCache('folder/bar.txt')); } + public function testScanRemovedFile(){ + $this->fillTestFolders(); + + $this->scanner->scan(''); + $this->assertTrue($this->cache->inCache('folder/bar.txt')); + $this->storage->unlink('folder/bar.txt'); + $this->scanner->scanFile('folder/bar.txt'); + $this->assertFalse($this->cache->inCache('folder/bar.txt')); + } + function setUp() { $this->storage = new \OC\Files\Storage\Temporary(array()); $this->scanner = new \OC\Files\Cache\Scanner($this->storage); diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index 0de436f570a..3043f132b73 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -354,8 +354,22 @@ class View extends \PHPUnit_Framework_TestCase { $this->hookPath = $params['path']; } + public function testSearchNotOutsideView() { + $storage1 = $this->getTestStorage(); + \OC\Files\Filesystem::mount($storage1, array(), '/'); + $storage1->rename('folder', 'foo'); + $scanner = $storage1->getScanner(); + $scanner->scan(''); + + $view = new \OC\Files\View('/foo'); + + $result = $view->search('.txt'); + $this->assertCount(1, $result); + } + /** * @param bool $scan + * @param string $class * @return \OC\Files\Storage\Storage */ private function getTestStorage($scan = true, $class = '\OC\Files\Storage\Temporary') { 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'); + } +} |