diff options
author | Andreas Fischer <bantu@owncloud.com> | 2013-09-23 12:44:11 +0200 |
---|---|---|
committer | Andreas Fischer <bantu@owncloud.com> | 2013-09-23 12:44:11 +0200 |
commit | 4a9f1cc74d7323b43983023c2b5b28e550e8c85d (patch) | |
tree | 13b09a7b9bc56eaffa3872de0260896b2916ca30 /tests | |
parent | 2a17025d537c41b9366c9592c985b911d9394337 (diff) | |
parent | 9851f0f4f2a97dc6ac1382bcd533eb23feffa4e0 (diff) | |
download | nextcloud-server-4a9f1cc74d7323b43983023c2b5b28e550e8c85d.tar.gz nextcloud-server-4a9f1cc74d7323b43983023c2b5b28e550e8c85d.zip |
Merge remote-tracking branch 'owncloud/master' into fixing-4866-master
* owncloud/master: (98 commits)
[tx-robot] updated from transifex
files: when filtering search results, ensure results are children of the fakeroot not just path starting the same
setting a default on filecache column unencrypted_size
[tx-robot] updated from transifex
remove unneccessary lib in namespace
namespaces use upcasefirst parts when _ is left in namespace and files are named after their classes the autoloader will also find classes in the lib folder of an app its magic!
initialize variable
calculate correct permissions while toggle the password protection
make sure that both $permissions and $oldPermissions have the same type
Add copyright, remove starting blank line
update inherit docs comment
Fix insert/update/delete helper functions for oracle
Add missing return true statements to legacy preferences functions
Add missing static
Convert OC_Preference to object interface
fix race condition in lazy preview loading
use {count} instead of 'One' for more versatile translation
fix double translation of error message
use n to translate title
fixing typos and l10n
...
Conflicts:
tests/lib/files/cache/scanner.php
Diffstat (limited to 'tests')
-rw-r--r-- | tests/data/db_structure.xml | 21 | ||||
-rw-r--r-- | tests/data/db_structure2.xml | 21 | ||||
-rw-r--r-- | tests/lib/db.php | 38 | ||||
-rw-r--r-- | tests/lib/files/cache/scanner.php | 11 | ||||
-rw-r--r-- | tests/lib/files/view.php | 14 | ||||
-rw-r--r-- | tests/lib/preferences.php | 179 | ||||
-rw-r--r-- | tests/lib/share/share.php | 145 |
7 files changed, 418 insertions, 11 deletions
diff --git a/tests/data/db_structure.xml b/tests/data/db_structure.xml index 8f6dc5e2ecd..2e83bbb78c7 100644 --- a/tests/data/db_structure.xml +++ b/tests/data/db_structure.xml @@ -178,4 +178,25 @@ </declaration> </table> + <table> + <name>*dbprefix*timestamp</name> + <declaration> + <field> + <name>id</name> + <autoincrement>1</autoincrement> + <type>integer</type> + <default>0</default> + <notnull>true</notnull> + <length>4</length> + </field> + + <field> + <name>timestamptest</name> + <type>timestamp</type> + <default></default> + <notnull>false</notnull> + </field> + </declaration> + </table> + </database> diff --git a/tests/data/db_structure2.xml b/tests/data/db_structure2.xml index 6f12f81f477..bbfb24985cb 100644 --- a/tests/data/db_structure2.xml +++ b/tests/data/db_structure2.xml @@ -75,4 +75,25 @@ </table> + <table> + <name>*dbprefix*timestamp</name> + <declaration> + <field> + <name>id</name> + <autoincrement>1</autoincrement> + <type>integer</type> + <default>0</default> + <notnull>true</notnull> + <length>4</length> + </field> + + <field> + <name>timestamptest</name> + <type>timestamp</type> + <default></default> + <notnull>false</notnull> + </field> + </declaration> + </table> + </database> diff --git a/tests/lib/db.php b/tests/lib/db.php index 1977025cf12..c87bee4ab99 100644 --- a/tests/lib/db.php +++ b/tests/lib/db.php @@ -145,4 +145,42 @@ class Test_DB extends PHPUnit_Framework_TestCase { $this->assertEquals(1, $result->numRows()); } + + /** + * Tests whether the database is configured so it accepts and returns dates + * in the expected format. + */ + public function testTimestampDateFormat() { + $table = '*PREFIX*'.$this->test_prefix.'timestamp'; + $column = 'timestamptest'; + + $expectedFormat = 'Y-m-d H:i:s'; + $expected = new \DateTime; + + $query = OC_DB::prepare("INSERT INTO `$table` (`$column`) VALUES (?)"); + $result = $query->execute(array($expected->format($expectedFormat))); + $this->assertEquals( + 1, + $result, + "Database failed to accept dates in the format '$expectedFormat'." + ); + + $id = OC_DB::insertid($table); + $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `id` = ?"); + $result = $query->execute(array($id)); + $row = $result->fetchRow(); + + $actual = \DateTime::createFromFormat($expectedFormat, $row[$column]); + $this->assertInstanceOf( + '\DateTime', + $actual, + "Database failed to return dates in the format '$expectedFormat'." + ); + + $this->assertEquals( + $expected, + $actual, + 'Failed asserting that the returned date is the same as the inserted.' + ); + } } diff --git a/tests/lib/files/cache/scanner.php b/tests/lib/files/cache/scanner.php index b137799bbcf..6956e7aa948 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')); + } + public function testETagRecreation() { $this->fillTestFolders(); @@ -207,7 +217,6 @@ class Scanner extends \PHPUnit_Framework_TestCase { $this->assertNotEmpty($newData0['etag']); $this->assertNotEquals($data1['etag'], $newData1['etag']); $this->assertNotEquals($data2['etag'], $newData2['etag']); - } function setUp() { 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'); + } +} diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php index e7d441a7e78..e02b0e4354d 100644 --- a/tests/lib/share/share.php +++ b/tests/lib/share/share.php @@ -29,6 +29,8 @@ class Test_Share extends PHPUnit_Framework_TestCase { protected $group1; protected $group2; protected $resharing; + protected $dateInFuture; + protected $dateInPast; public function setUp() { OC_User::clearBackends(); @@ -58,6 +60,12 @@ class Test_Share extends PHPUnit_Framework_TestCase { OC::registerShareHooks(); $this->resharing = OC_Appconfig::getValue('core', 'shareapi_allow_resharing', 'yes'); OC_Appconfig::setValue('core', 'shareapi_allow_resharing', 'yes'); + + // 20 Minutes in the past, 20 minutes in the future. + $now = time(); + $dateFormat = 'Y-m-d H:i:s'; + $this->dateInPast = date($dateFormat, $now - 20 * 60); + $this->dateInFuture = date($dateFormat, $now + 20 * 60); } public function tearDown() { @@ -121,6 +129,26 @@ class Test_Share extends PHPUnit_Framework_TestCase { } } + protected function shareUserOneTestFileWithUserTwo() { + OC_User::setUserId($this->user1); + $this->assertTrue( + OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ), + 'Failed asserting that user 1 successfully shared text.txt with user 2.' + ); + $this->assertEquals( + array('test.txt'), + OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that test.txt is a shared file of user 1.' + ); + + OC_User::setUserId($this->user2); + $this->assertEquals( + array('test.txt'), + OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that user 2 has access to test.txt after initial sharing.' + ); + } + public function testShareWithUser() { // Invalid shares $message = 'Sharing test.txt failed, because the user '.$this->user1.' is the item owner'; @@ -146,10 +174,7 @@ class Test_Share extends PHPUnit_Framework_TestCase { } // Valid share - $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ)); - $this->assertEquals(array('test.txt'), OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE)); - OC_User::setUserId($this->user2); - $this->assertEquals(array('test.txt'), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE)); + $this->shareUserOneTestFileWithUserTwo(); // Attempt to share again OC_User::setUserId($this->user1); @@ -264,6 +289,66 @@ class Test_Share extends PHPUnit_Framework_TestCase { $this->assertEquals(array('test1.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET)); } + public function testShareWithUserExpirationExpired() { + $this->shareUserOneTestFileWithUserTwo(); + + OC_User::setUserId($this->user1); + $this->assertTrue( + OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInPast), + 'Failed asserting that user 1 successfully set an expiration date for the test.txt share.' + ); + + OC_User::setUserId($this->user2); + $this->assertFalse( + OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that user 2 no longer has access to test.txt after expiration.' + ); + } + + public function testShareWithUserExpirationValid() { + $this->shareUserOneTestFileWithUserTwo(); + + OC_User::setUserId($this->user1); + $this->assertTrue( + OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInFuture), + 'Failed asserting that user 1 successfully set an expiration date for the test.txt share.' + ); + + OC_User::setUserId($this->user2); + $this->assertEquals( + array('test.txt'), + OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that user 2 still has access to test.txt after expiration date has been set.' + ); + } + + protected function shareUserOneTestFileWithGroupOne() { + OC_User::setUserId($this->user1); + $this->assertTrue( + OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\PERMISSION_READ), + 'Failed asserting that user 1 successfully shared text.txt with group 1.' + ); + $this->assertEquals( + array('test.txt'), + OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that test.txt is a shared file of user 1.' + ); + + OC_User::setUserId($this->user2); + $this->assertEquals( + array('test.txt'), + OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that user 2 has access to test.txt after initial sharing.' + ); + + OC_User::setUserId($this->user3); + $this->assertEquals( + array('test.txt'), + OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that user 3 has access to test.txt after initial sharing.' + ); + } + public function testShareWithGroup() { // Invalid shares $message = 'Sharing test.txt failed, because the group foobar does not exist'; @@ -285,12 +370,7 @@ class Test_Share extends PHPUnit_Framework_TestCase { OC_Appconfig::setValue('core', 'shareapi_share_policy', $policy); // Valid share - $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\PERMISSION_READ)); - $this->assertEquals(array('test.txt'), OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE)); - OC_User::setUserId($this->user2); - $this->assertEquals(array('test.txt'), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE)); - OC_User::setUserId($this->user3); - $this->assertEquals(array('test.txt'), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE)); + $this->shareUserOneTestFileWithGroupOne(); // Attempt to share again OC_User::setUserId($this->user1); @@ -410,4 +490,49 @@ class Test_Share extends PHPUnit_Framework_TestCase { $this->assertEquals(array(), OCP\Share::getItemsShared('test')); } + public function testShareWithGroupExpirationExpired() { + $this->shareUserOneTestFileWithGroupOne(); + + OC_User::setUserId($this->user1); + $this->assertTrue( + OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInPast), + 'Failed asserting that user 1 successfully set an expiration date for the test.txt share.' + ); + + OC_User::setUserId($this->user2); + $this->assertFalse( + OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that user 2 no longer has access to test.txt after expiration.' + ); + + OC_User::setUserId($this->user3); + $this->assertFalse( + OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that user 3 no longer has access to test.txt after expiration.' + ); + } + + public function testShareWithGroupExpirationValid() { + $this->shareUserOneTestFileWithGroupOne(); + + OC_User::setUserId($this->user1); + $this->assertTrue( + OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInFuture), + 'Failed asserting that user 1 successfully set an expiration date for the test.txt share.' + ); + + OC_User::setUserId($this->user2); + $this->assertEquals( + array('test.txt'), + OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that user 2 still has access to test.txt after expiration date has been set.' + ); + + OC_User::setUserId($this->user3); + $this->assertEquals( + array('test.txt'), + OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that user 3 still has access to test.txt after expiration date has been set.' + ); + } } |