diff options
Diffstat (limited to 'tests/lib')
37 files changed, 637 insertions, 96 deletions
diff --git a/tests/lib/api.php b/tests/lib/api.php index 9c4324e63e0..233beebd68a 100644 --- a/tests/lib/api.php +++ b/tests/lib/api.php @@ -9,6 +9,10 @@ class Test_API extends PHPUnit_Framework_TestCase { // Helps build a response variable + + /** + * @param string $message + */ function buildResponse($shipped, $data, $code, $message=null) { return array( 'shipped' => $shipped, @@ -18,6 +22,10 @@ class Test_API extends PHPUnit_Framework_TestCase { } // Validate details of the result + + /** + * @param OC_OCS_Result $result + */ function checkResult($result, $success) { // Check response is of correct type $this->assertInstanceOf('OC_OCS_Result', $result); diff --git a/tests/lib/appconfig.php b/tests/lib/appconfig.php index 23dd2549e32..6ae790a9edd 100644 --- a/tests/lib/appconfig.php +++ b/tests/lib/appconfig.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. @@ -41,6 +42,7 @@ class Test_Appconfig extends PHPUnit_Framework_TestCase { while ($row = $result->fetchRow()) { $expected[] = $row['appid']; } + sort($expected); $apps = \OC_Appconfig::getApps(); $this->assertEquals($expected, $apps); } @@ -52,6 +54,7 @@ class Test_Appconfig extends PHPUnit_Framework_TestCase { while($row = $result->fetchRow()) { $expected[] = $row["configkey"]; } + sort($expected); $keys = \OC_Appconfig::getKeys('testapp'); $this->assertEquals($expected, $keys); } diff --git a/tests/lib/appframework/http/DispatcherTest.php b/tests/lib/appframework/http/DispatcherTest.php index 6cf0da879ff..9841dcaa1f7 100644 --- a/tests/lib/appframework/http/DispatcherTest.php +++ b/tests/lib/appframework/http/DispatcherTest.php @@ -24,7 +24,6 @@ namespace OC\AppFramework\Http; -use OC\AppFramework\Core\API; use OC\AppFramework\Middleware\MiddlewareDispatcher; use OCP\AppFramework\Http; //require_once(__DIR__ . "/../classloader.php"); @@ -78,6 +77,10 @@ class DispatcherTest extends \PHPUnit_Framework_TestCase { } + /** + * @param string $out + * @param string $httpHeaders + */ private function setMiddlewareExpections($out=null, $httpHeaders=null, $responseHeaders=array(), $ex=false, $catchEx=true) { diff --git a/tests/lib/appframework/http/ResponseTest.php b/tests/lib/appframework/http/ResponseTest.php index 1a38c38c1e7..4f21d77a170 100644 --- a/tests/lib/appframework/http/ResponseTest.php +++ b/tests/lib/appframework/http/ResponseTest.php @@ -25,8 +25,8 @@ namespace OC\AppFramework\Http; -use OCP\AppFramework\Http\Response, - OCP\AppFramework\Http; +use OCP\AppFramework\Http\Response; +use OCP\AppFramework\Http; class ResponseTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php b/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php index 95d42e4eb8e..f16b14150c3 100644 --- a/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php +++ b/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php @@ -50,6 +50,9 @@ class TestMiddleware extends Middleware { private $beforeControllerThrowsEx; + /** + * @param boolean $beforeControllerThrowsEx + */ public function __construct($beforeControllerThrowsEx) { self::$beforeControllerCalled = 0; self::$afterControllerCalled = 0; diff --git a/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php b/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php index dae6135dc54..63c48a62829 100644 --- a/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php +++ b/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php @@ -58,6 +58,9 @@ class SecurityMiddlewareTest extends \PHPUnit_Framework_TestCase { } + /** + * @param string $method + */ private function checkNavEntry($method){ $api = $this->getAPI(); @@ -79,6 +82,10 @@ class SecurityMiddlewareTest extends \PHPUnit_Framework_TestCase { } + /** + * @param string $method + * @param string $test + */ private function ajaxExceptionStatus($method, $test, $status) { $api = $this->getAPI(); $api->expects($this->any()) @@ -183,6 +190,10 @@ class SecurityMiddlewareTest extends \PHPUnit_Framework_TestCase { } + /** + * @param string $method + * @param string $expects + */ private function securityCheck($method, $expects, $shouldFail=false){ $api = $this->getAPI(); $api->expects($this->once()) diff --git a/tests/lib/appframework/routing/RoutingTest.php b/tests/lib/appframework/routing/RoutingTest.php index a7aa922db12..d0244cf2511 100644 --- a/tests/lib/appframework/routing/RoutingTest.php +++ b/tests/lib/appframework/routing/RoutingTest.php @@ -78,6 +78,13 @@ class RouteConfigTest extends \PHPUnit_Framework_TestCase $this->assertResource($routes, 'admin_accounts', '/admin/accounts', 'AdminAccountsController', 'adminAccountId'); } + /** + * @param string $name + * @param string $verb + * @param string $url + * @param string $controllerName + * @param string $actionName + */ private function assertSimpleRoute($routes, $name, $verb, $url, $controllerName, $actionName) { // route mocks @@ -100,6 +107,12 @@ class RouteConfigTest extends \PHPUnit_Framework_TestCase $config->register(); } + /** + * @param string $resourceName + * @param string $url + * @param string $controllerName + * @param string $paramName + */ private function assertResource($yaml, $resourceName, $url, $controllerName, $paramName) { // router mock diff --git a/tests/lib/backgroundjob/dummyjoblist.php b/tests/lib/backgroundjob/dummyjoblist.php index e1579c273bb..7801269b27e 100644 --- a/tests/lib/backgroundjob/dummyjoblist.php +++ b/tests/lib/backgroundjob/dummyjoblist.php @@ -21,6 +21,8 @@ class DummyJobList extends \OC\BackgroundJob\JobList { private $last = 0; + public function __construct(){} + /** * @param \OC\BackgroundJob\Job|string $job * @param mixed $argument diff --git a/tests/lib/backgroundjob/job.php b/tests/lib/backgroundjob/job.php index 7d66fa772d2..10a8f46462e 100644 --- a/tests/lib/backgroundjob/job.php +++ b/tests/lib/backgroundjob/job.php @@ -8,31 +8,6 @@ namespace Test\BackgroundJob; - -class TestJob extends \OC\BackgroundJob\Job { - private $testCase; - - /** - * @var callable $callback - */ - private $callback; - - /** - * @param Job $testCase - * @param callable $callback - */ - public function __construct($testCase, $callback) { - $this->testCase = $testCase; - $this->callback = $callback; - } - - public function run($argument) { - $this->testCase->markRun(); - $callback = $this->callback; - $callback($argument); - } -} - class Job extends \PHPUnit_Framework_TestCase { private $run = false; diff --git a/tests/lib/backgroundjob/joblist.php b/tests/lib/backgroundjob/joblist.php new file mode 100644 index 00000000000..c3318f80cb2 --- /dev/null +++ b/tests/lib/backgroundjob/joblist.php @@ -0,0 +1,203 @@ +<?php +/** + * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\BackgroundJob; + +class JobList extends \PHPUnit_Framework_TestCase { + /** + * @var \OC\BackgroundJob\JobList + */ + protected $instance; + + /** + * @var \OCP\IConfig | \PHPUnit_Framework_MockObject_MockObject $config + */ + protected $config; + + public function setUp() { + $conn = \OC::$server->getDatabaseConnection(); + $this->config = $this->getMock('\OCP\IConfig'); + $this->instance = new \OC\BackgroundJob\JobList($conn, $this->config); + } + + public function argumentProvider() { + return array( + array(null), + array(false), + array('foobar'), + array(12), + array(array( + 'asd' => 5, + 'foo' => 'bar' + )) + ); + } + + /** + * @dataProvider argumentProvider + * @param $argument + */ + public function testAddRemove($argument) { + $existingJobs = $this->instance->getAll(); + $job = new TestJob(); + $this->instance->add($job, $argument); + + $jobs = $this->instance->getAll(); + + $this->assertCount(count($existingJobs) + 1, $jobs); + $addedJob = $jobs[count($jobs) - 1]; + $this->assertInstanceOf('\Test\BackgroundJob\TestJob', $addedJob); + $this->assertEquals($argument, $addedJob->getArgument()); + + $this->instance->remove($job, $argument); + + $jobs = $this->instance->getAll(); + $this->assertEquals($existingJobs, $jobs); + } + + /** + * @dataProvider argumentProvider + * @param $argument + */ + public function testRemoveDifferentArgument($argument) { + $existingJobs = $this->instance->getAll(); + $job = new TestJob(); + $this->instance->add($job, $argument); + + $jobs = $this->instance->getAll(); + $this->instance->remove($job, 10); + $jobs2 = $this->instance->getAll(); + + $this->assertEquals($jobs, $jobs2); + + $this->instance->remove($job, $argument); + + $jobs = $this->instance->getAll(); + $this->assertEquals($existingJobs, $jobs); + } + + /** + * @dataProvider argumentProvider + * @param $argument + */ + public function testHas($argument) { + $job = new TestJob(); + $this->assertFalse($this->instance->has($job, $argument)); + $this->instance->add($job, $argument); + + $this->assertTrue($this->instance->has($job, $argument)); + + $this->instance->remove($job, $argument); + + $this->assertFalse($this->instance->has($job, $argument)); + } + + /** + * @dataProvider argumentProvider + * @param $argument + */ + public function testHasDifferentArgument($argument) { + $job = new TestJob(); + $this->instance->add($job, $argument); + + $this->assertFalse($this->instance->has($job, 10)); + + $this->instance->remove($job, $argument); + } + + public function testGetLastJob() { + $this->config->expects($this->once()) + ->method('getAppValue') + ->with('backgroundjob', 'lastjob', 0) + ->will($this->returnValue(15)); + + $this->assertEquals(15, $this->instance->getLastJob()); + } + + public function testGetNext() { + $job = new TestJob(); + $this->instance->add($job, 1); + $this->instance->add($job, 2); + + $jobs = $this->instance->getAll(); + + $savedJob1 = $jobs[count($jobs) - 2]; + $savedJob2 = $jobs[count($jobs) - 1]; + + $this->config->expects($this->once()) + ->method('getAppValue') + ->with('backgroundjob', 'lastjob', 0) + ->will($this->returnValue($savedJob1->getId())); + + $nextJob = $this->instance->getNext(); + + $this->assertEquals($savedJob2, $nextJob); + + $this->instance->remove($job, 1); + $this->instance->remove($job, 2); + } + + public function testGetNextWrapAround() { + $job = new TestJob(); + $this->instance->add($job, 1); + $this->instance->add($job, 2); + + $jobs = $this->instance->getAll(); + + $savedJob2 = $jobs[count($jobs) - 1]; + + $this->config->expects($this->once()) + ->method('getAppValue') + ->with('backgroundjob', 'lastjob', 0) + ->will($this->returnValue($savedJob2->getId())); + + $nextJob = $this->instance->getNext(); + + $this->assertEquals($jobs[0], $nextJob); + + $this->instance->remove($job, 1); + $this->instance->remove($job, 2); + } + + /** + * @dataProvider argumentProvider + * @param $argument + */ + public function testGetById($argument) { + $job = new TestJob(); + $this->instance->add($job, $argument); + + $jobs = $this->instance->getAll(); + + $addedJob = $jobs[count($jobs) - 1]; + + $this->assertEquals($addedJob, $this->instance->getById($addedJob->getId())); + + $this->instance->remove($job, $argument); + } + + public function testSetLastRun() { + $job = new TestJob(); + $this->instance->add($job); + + $jobs = $this->instance->getAll(); + + $addedJob = $jobs[count($jobs) - 1]; + + $timeStart = time(); + $this->instance->setLastRun($addedJob); + $timeEnd = time(); + + $addedJob = $this->instance->getById($addedJob->getId()); + + $this->assertGreaterThanOrEqual($timeStart, $addedJob->getLastRun()); + $this->assertLessThanOrEqual($timeEnd, $addedJob->getLastRun()); + + $this->instance->remove($job); + } +} diff --git a/tests/lib/backgroundjob/testjob.php b/tests/lib/backgroundjob/testjob.php new file mode 100644 index 00000000000..23fc4268d1a --- /dev/null +++ b/tests/lib/backgroundjob/testjob.php @@ -0,0 +1,34 @@ +<?php +/** + * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\BackgroundJob; + + +class TestJob extends \OC\BackgroundJob\Job { + private $testCase; + + /** + * @var callable $callback + */ + private $callback; + + /** + * @param Job $testCase + * @param callable $callback + */ + public function __construct($testCase = null, $callback = null) { + $this->testCase = $testCase; + $this->callback = $callback; + } + + public function run($argument) { + $this->testCase->markRun(); + $callback = $this->callback; + $callback($argument); + } +} diff --git a/tests/lib/connector/sabre/file.php b/tests/lib/connector/sabre/file.php index e1fed0384c6..50b8711a90d 100644 --- a/tests/lib/connector/sabre/file.php +++ b/tests/lib/connector/sabre/file.php @@ -36,6 +36,46 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase { } /** + * @expectedException Sabre_DAV_Exception_BadRequest + */ + public function testSimplePutInvalidChars() { + // setup + $file = new OC_Connector_Sabre_File('/super*star.txt'); + $file->fileView = $this->getMock('\OC\Files\View', array('file_put_contents'), array(), '', FALSE); + $file->fileView->expects($this->any())->method('file_put_contents')->withAnyParameters()->will($this->returnValue(false)); + + // action + $etag = $file->put('test data'); + } + + /** + * Test setting name with setName() + */ + public function testSetName() { + // setup + $file = new OC_Connector_Sabre_File('/test.txt'); + $file->fileView = $this->getMock('\OC\Files\View', array('isUpdatable'), array(), '', FALSE); + $file->fileView->expects($this->any())->method('isUpdatable')->withAnyParameters()->will($this->returnValue(true)); + $etag = $file->put('test data'); + $file->setName('/renamed.txt'); + $this->assertTrue($file->fileView->file_exists('/renamed.txt')); + // clean up + $file->delete(); + } + + /** + * Test setting name with setName() with invalid chars + * @expectedException Sabre_DAV_Exception_BadRequest + */ + public function testSetNameInvalidChars() { + // setup + $file = new OC_Connector_Sabre_File('/test.txt'); + $file->fileView = $this->getMock('\OC\Files\View', array('isUpdatable'), array(), '', FALSE); + $file->fileView->expects($this->any())->method('isUpdatable')->withAnyParameters()->will($this->returnValue(true)); + $file->setName('/super*star.txt'); + } + + /** * @expectedException Sabre_DAV_Exception_Forbidden */ public function testDeleteSharedFails() { diff --git a/tests/lib/connector/sabre/objecttree.php b/tests/lib/connector/sabre/objecttree.php index e32f2365f95..fb50c736edd 100644 --- a/tests/lib/connector/sabre/objecttree.php +++ b/tests/lib/connector/sabre/objecttree.php @@ -52,6 +52,20 @@ class ObjectTree extends PHPUnit_Framework_TestCase { $this->assertTrue(true); } + /** + * @dataProvider moveFailedInvalidCharsProvider + * @expectedException Sabre_DAV_Exception_BadRequest + */ + public function testMoveFailedInvalidChars($source, $dest, $updatables, $deletables) { + $this->moveTest($source, $dest, $updatables, $deletables); + } + + function moveFailedInvalidCharsProvider() { + return array( + array('a/b', 'a/c*', array('a' => false, 'a/b' => true, 'a/c*' => false), array()), + ); + } + function moveFailedProvider() { return array( array('a/b', 'a/c', array('a' => false, 'a/b' => false, 'a/c' => false), array()), @@ -66,6 +80,8 @@ class ObjectTree extends PHPUnit_Framework_TestCase { return array( array('a/b', 'a/c', array('a' => false, 'a/b' => true, 'a/c' => false), array()), array('a/b', 'b/b', array('a' => true, 'a/b' => true, 'b' => true, 'b/b' => false), array('a/b' => true)), + // older files with special chars can still be renamed to valid names + array('a/b*', 'b/b', array('a' => true, 'a/b*' => true, 'b' => true, 'b/b' => false), array('a/b*' => true)), ); } diff --git a/tests/lib/db.php b/tests/lib/db.php index f0b271a36f1..2fca67b5638 100644 --- a/tests/lib/db.php +++ b/tests/lib/db.php @@ -30,7 +30,7 @@ class Test_DB extends PHPUnit_Framework_TestCase { public function setUp() { $dbfile = OC::$SERVERROOT.'/tests/data/db_structure.xml'; - $r = '_'.OC_Util::generateRandomBytes('4').'_'; + $r = '_'.OC_Util::generateRandomBytes(4).'_'; $content = file_get_contents( $dbfile ); $content = str_replace( '*dbprefix*', '*dbprefix*'.$r, $content ); file_put_contents( self::$schema_file, $content ); diff --git a/tests/lib/dbschema.php b/tests/lib/dbschema.php index 4a7b7f7aac0..11e9fcdf4fa 100644 --- a/tests/lib/dbschema.php +++ b/tests/lib/dbschema.php @@ -16,7 +16,7 @@ class Test_DBSchema extends PHPUnit_Framework_TestCase { $dbfile = OC::$SERVERROOT.'/tests/data/db_structure.xml'; $dbfile2 = OC::$SERVERROOT.'/tests/data/db_structure2.xml'; - $r = '_'.OC_Util::generateRandomBytes('4').'_'; + $r = '_'.OC_Util::generateRandomBytes(4).'_'; $content = file_get_contents( $dbfile ); $content = str_replace( '*dbprefix*', '*dbprefix*'.$r, $content ); file_put_contents( $this->schema_file, $content ); @@ -111,10 +111,16 @@ class Test_DBSchema extends PHPUnit_Framework_TestCase { } } + /** + * @param string $table + */ public function assertTableExist($table) { $this->assertTrue($this->tableExist($table), 'Table ' . $table . ' does not exist'); } + /** + * @param string $table + */ public function assertTableNotExist($table) { $type=OC_Config::getValue( "dbtype", "sqlite" ); if( $type == 'sqlite' || $type == 'sqlite3' ) { diff --git a/tests/lib/errorHandler.php b/tests/lib/errorHandler.php index 68b87deccb6..32396eafbea 100644 --- a/tests/lib/errorHandler.php +++ b/tests/lib/errorHandler.php @@ -56,6 +56,10 @@ class Test_ErrorHandler extends \PHPUnit_Framework_TestCase { * @brief dummy class to access protected methods of \OC\Log\ErrorHandler */ class TestableErrorHandler extends \OC\Log\ErrorHandler { + + /** + * @param string $msg + */ public static function testRemovePassword($msg) { return self::removePassword($msg); } diff --git a/tests/lib/files/cache/homecache.php b/tests/lib/files/cache/homecache.php index 87fd0dba4c6..dbcf6e9caa0 100644 --- a/tests/lib/files/cache/homecache.php +++ b/tests/lib/files/cache/homecache.php @@ -19,6 +19,10 @@ class DummyUser extends \OC\User\User { */ private $uid; + /** + * @param string $uid + * @param string $home + */ public function __construct($uid, $home) { $this->home = $home; $this->uid = $uid; diff --git a/tests/lib/files/cache/watcher.php b/tests/lib/files/cache/watcher.php index 1920c276907..7f4f3c5ee98 100644 --- a/tests/lib/files/cache/watcher.php +++ b/tests/lib/files/cache/watcher.php @@ -11,7 +11,7 @@ namespace Test\Files\Cache; class Watcher extends \PHPUnit_Framework_TestCase { /** - * @var \OC\Files\Storage\Storage[] $storages; + * @var \OC\Files\Storage\Storage[] $storages */ private $storages = array(); @@ -105,6 +105,60 @@ class Watcher extends \PHPUnit_Framework_TestCase { $this->assertTrue($cache->inCache('foo.txt/bar.txt')); } + public function testPolicyNever() { + $storage = $this->getTestStorage(); + $cache = $storage->getCache(); + $updater = $storage->getWatcher(); + + //set the mtime to the past so it can detect an mtime change + $cache->put('foo.txt', array('storage_mtime' => 10)); + + $updater->setPolicy(\OC\Files\Cache\Watcher::CHECK_NEVER); + + $storage->file_put_contents('foo.txt', 'q'); + $this->assertFalse($updater->checkUpdate('foo.txt')); + + $cache->put('foo.txt', array('storage_mtime' => 20)); + $storage->file_put_contents('foo.txt', 'w'); + $this->assertFalse($updater->checkUpdate('foo.txt')); + } + + public function testPolicyOnce() { + $storage = $this->getTestStorage(); + $cache = $storage->getCache(); + $updater = $storage->getWatcher(); + + //set the mtime to the past so it can detect an mtime change + $cache->put('foo.txt', array('storage_mtime' => 10)); + + $updater->setPolicy(\OC\Files\Cache\Watcher::CHECK_ONCE); + + $storage->file_put_contents('foo.txt', 'q'); + $this->assertTrue($updater->checkUpdate('foo.txt')); + + $cache->put('foo.txt', array('storage_mtime' => 20)); + $storage->file_put_contents('foo.txt', 'w'); + $this->assertFalse($updater->checkUpdate('foo.txt')); + } + + public function testPolicyAlways() { + $storage = $this->getTestStorage(); + $cache = $storage->getCache(); + $updater = $storage->getWatcher(); + + //set the mtime to the past so it can detect an mtime change + $cache->put('foo.txt', array('storage_mtime' => 10)); + + $updater->setPolicy(\OC\Files\Cache\Watcher::CHECK_ALWAYS); + + $storage->file_put_contents('foo.txt', 'q'); + $this->assertTrue($updater->checkUpdate('foo.txt')); + + $cache->put('foo.txt', array('storage_mtime' => 20)); + $storage->file_put_contents('foo.txt', 'w'); + $this->assertTrue($updater->checkUpdate('foo.txt')); + } + /** * @param bool $scan * @return \OC\Files\Storage\Storage diff --git a/tests/lib/files/etagtest.php b/tests/lib/files/etagtest.php index 6c41413c4df..ce05adb188a 100644 --- a/tests/lib/files/etagtest.php +++ b/tests/lib/files/etagtest.php @@ -68,6 +68,9 @@ class EtagTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($originalEtags, $this->getEtags($files)); } + /** + * @param string[] $files + */ private function getEtags($files) { $etags = array(); foreach ($files as $file) { diff --git a/tests/lib/files/node/integration.php b/tests/lib/files/node/integration.php index 14e1d05853d..319f2f9f5f7 100644 --- a/tests/lib/files/node/integration.php +++ b/tests/lib/files/node/integration.php @@ -9,10 +9,7 @@ namespace Test\Files\Node; use OC\Files\Cache\Cache; -use OC\Files\Mount\Manager; use OC\Files\Node\Root; -use OCP\Files\NotFoundException; -use OCP\Files\NotPermittedException; use OC\Files\Storage\Temporary; use OC\Files\View; use OC\User\User; diff --git a/tests/lib/files/node/root.php b/tests/lib/files/node/root.php index 97eaf7f7162..27f1a937826 100644 --- a/tests/lib/files/node/root.php +++ b/tests/lib/files/node/root.php @@ -8,7 +8,6 @@ namespace Test\Files\Node; -use OC\Files\Cache\Cache; use OCP\Files\NotPermittedException; use OC\Files\Mount\Manager; diff --git a/tests/lib/files/storage/home.php b/tests/lib/files/storage/home.php index 885291e4404..51315a2a556 100644 --- a/tests/lib/files/storage/home.php +++ b/tests/lib/files/storage/home.php @@ -29,6 +29,10 @@ class DummyUser extends User { private $uid; + /** + * @param string $uid + * @param string $home + */ public function __construct($uid, $home) { $this->uid = $uid; $this->home = $home; diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index 182c014d999..f9291758606 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -27,6 +27,17 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { * @var \OC\Files\Storage\Storage instance */ protected $instance; + protected $waitDelay = 0; + + /** + * Sleep for the number of seconds specified in the + * $waitDelay attribute + */ + protected function wait() { + if ($this->waitDelay > 0) { + sleep($this->waitDelay); + } + } /** * the root folder of the storage should always exist, be readable and be recognized as a directory @@ -77,6 +88,7 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertFalse($this->instance->mkdir('/'.$directory)); //cant create existing folders $this->assertTrue($this->instance->rmdir('/'.$directory)); + $this->wait(); $this->assertFalse($this->instance->file_exists('/'.$directory)); $this->assertFalse($this->instance->rmdir('/'.$directory)); //cant remove non existing folders @@ -97,6 +109,8 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { array('folder'), array(' folder'), array('folder '), + array('folder with space'), + array('spéciäl földer'), ); } /** @@ -144,6 +158,7 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertEquals($this->instance->file_get_contents('/source.txt'), $this->instance->file_get_contents('/target.txt')); $this->instance->rename('/source.txt', '/target2.txt'); + $this->wait(); $this->assertTrue($this->instance->file_exists('/target2.txt')); $this->assertFalse($this->instance->file_exists('/source.txt')); $this->assertEquals(file_get_contents($textFile), $this->instance->file_get_contents('/target2.txt')); @@ -225,6 +240,7 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertTrue($this->instance->file_exists('/lorem.txt')); $this->assertTrue($this->instance->unlink('/lorem.txt')); + $this->wait(); $this->assertFalse($this->instance->file_exists('/lorem.txt')); } @@ -259,9 +275,11 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { public function testRecursiveRmdir() { $this->instance->mkdir('folder'); $this->instance->mkdir('folder/bar'); + $this->wait(); $this->instance->file_put_contents('folder/asd.txt', 'foobar'); $this->instance->file_put_contents('folder/bar/foo.txt', 'asd'); $this->assertTrue($this->instance->rmdir('folder')); + $this->wait(); $this->assertFalse($this->instance->file_exists('folder/asd.txt')); $this->assertFalse($this->instance->file_exists('folder/bar/foo.txt')); $this->assertFalse($this->instance->file_exists('folder/bar')); @@ -274,6 +292,7 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->instance->file_put_contents('folder/asd.txt', 'foobar'); $this->instance->file_put_contents('folder/bar/foo.txt', 'asd'); $this->assertTrue($this->instance->unlink('folder')); + $this->wait(); $this->assertFalse($this->instance->file_exists('folder/asd.txt')); $this->assertFalse($this->instance->file_exists('folder/bar/foo.txt')); $this->assertFalse($this->instance->file_exists('folder/bar')); diff --git a/tests/lib/files/storage/wrapper/quota.php b/tests/lib/files/storage/wrapper/quota.php index 87bafb64d41..e1b880255fb 100644 --- a/tests/lib/files/storage/wrapper/quota.php +++ b/tests/lib/files/storage/wrapper/quota.php @@ -27,6 +27,9 @@ class Quota extends \Test\Files\Storage\Storage { \OC_Helper::rmdirr($this->tmpDir); } + /** + * @param integer $limit + */ protected function getLimitedStorage($limit) { $storage = new \OC\Files\Storage\Local(array('datadir' => $this->tmpDir)); $storage->getScanner()->scan(''); diff --git a/tests/lib/files/stream/quota.php b/tests/lib/files/stream/quota.php index b11f0ac74c0..d5edace544d 100644 --- a/tests/lib/files/stream/quota.php +++ b/tests/lib/files/stream/quota.php @@ -13,6 +13,10 @@ class Quota extends \PHPUnit_Framework_TestCase { \OC\Files\Stream\Quota::clear(); } + /** + * @param string $mode + * @param integer $limit + */ protected function getStream($mode, $limit) { $source = fopen('php://temp', $mode); return \OC\Files\Stream\Quota::wrap($source, $limit); diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index 72a2f854cb2..371d1ed1798 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -7,6 +7,8 @@ namespace Test\Files; +use OC\Files\Cache\Watcher; + class TemporaryNoTouch extends \OC\Files\Storage\Temporary { public function touch($path, $mtime = null) { return false; @@ -249,6 +251,7 @@ class View extends \PHPUnit_Framework_TestCase { function testWatcher() { $storage1 = $this->getTestStorage(); \OC\Files\Filesystem::mount($storage1, array(), '/'); + $storage1->getWatcher()->setPolicy(Watcher::CHECK_ALWAYS); $rootView = new \OC\Files\View(''); diff --git a/tests/lib/group/backend.php b/tests/lib/group/backend.php index d308232a78b..2c563ae9ac9 100644 --- a/tests/lib/group/backend.php +++ b/tests/lib/group/backend.php @@ -29,7 +29,7 @@ abstract class Test_Group_Backend extends PHPUnit_Framework_TestCase { /** * get a new unique group name * test cases can override this in order to clean up created groups - * @return array + * @return string */ public function getGroupName() { return uniqid('test_'); @@ -38,7 +38,7 @@ abstract class Test_Group_Backend extends PHPUnit_Framework_TestCase { /** * get a new unique user name * test cases can override this in order to clean up created user - * @return array + * @return string */ public function getUserName() { return uniqid('test_'); diff --git a/tests/lib/group/database.php b/tests/lib/group/database.php index 5278c26f4df..3e05c656061 100644 --- a/tests/lib/group/database.php +++ b/tests/lib/group/database.php @@ -26,7 +26,7 @@ class Test_Group_Database extends Test_Group_Backend { /** * get a new unique group name * test cases can override this in order to clean up created groups - * @return array + * @return string */ public function getGroupName() { $name=uniqid('test_'); @@ -37,7 +37,7 @@ class Test_Group_Database extends Test_Group_Backend { /** * get a new unique user name * test cases can override this in order to clean up created user - * @return array + * @return string */ public function getUserName() { return uniqid('test_'); diff --git a/tests/lib/group/group.php b/tests/lib/group/group.php index f1fda3b9288..3982c00e45f 100644 --- a/tests/lib/group/group.php +++ b/tests/lib/group/group.php @@ -13,7 +13,7 @@ use OC\User\User; class Group extends \PHPUnit_Framework_TestCase { /** - * @return \PHPUnit_Framework_MockObject_MockObject | \OC\User\Manager + * @return \OC\User\Manager | \OC\User\Manager */ protected function getUserManager() { $userManager = $this->getMock('\OC\User\Manager'); diff --git a/tests/lib/group/manager.php b/tests/lib/group/manager.php index 9d3adf51a0c..90f0e1b35e2 100644 --- a/tests/lib/group/manager.php +++ b/tests/lib/group/manager.php @@ -116,16 +116,22 @@ class Manager extends \PHPUnit_Framework_TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend */ + $backendGroupCreated = false; $backend = $this->getMock('\OC_Group_Database'); $backend->expects($this->any()) ->method('groupExists') ->with('group1') - ->will($this->returnValue(false)); + ->will($this->returnCallback(function () use (&$backendGroupCreated) { + return $backendGroupCreated; + })); $backend->expects($this->once()) ->method('implementsActions') ->will($this->returnValue(true)); $backend->expects($this->once()) - ->method('createGroup'); + ->method('createGroup') + ->will($this->returnCallback(function () use (&$backendGroupCreated) { + $backendGroupCreated = true; + }));; /** * @var \OC\User\Manager $userManager @@ -170,6 +176,10 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getGroups') ->with('1') ->will($this->returnValue(array('group1'))); + $backend->expects($this->once()) + ->method('groupExists') + ->with('group1') + ->will($this->returnValue(true)); /** * @var \OC\User\Manager $userManager @@ -193,6 +203,9 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getGroups') ->with('1') ->will($this->returnValue(array('group1'))); + $backend1->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2 @@ -202,6 +215,9 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getGroups') ->with('1') ->will($this->returnValue(array('group12', 'group1'))); + $backend2->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); /** * @var \OC\User\Manager $userManager @@ -228,6 +244,9 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getGroups') ->with('1', 2, 1) ->will($this->returnValue(array('group1'))); + $backend1->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2 @@ -237,6 +256,9 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getGroups') ->with('1', 1, 0) ->will($this->returnValue(array('group12'))); + $backend2->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); /** * @var \OC\User\Manager $userManager @@ -263,6 +285,10 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getUserGroups') ->with('user1') ->will($this->returnValue(array('group1'))); + $backend->expects($this->any()) + ->method('groupExists') + ->with('group1') + ->will($this->returnValue(true)); /** * @var \OC\User\Manager $userManager @@ -286,6 +312,10 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getUserGroups') ->with('user1') ->will($this->returnValue(array('group1'))); + $backend1->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); + /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2 */ @@ -294,6 +324,9 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getUserGroups') ->with('user1') ->will($this->returnValue(array('group1', 'group2'))); + $backend1->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); /** * @var \OC\User\Manager $userManager diff --git a/tests/lib/migrate.php b/tests/lib/migrate.php new file mode 100644 index 00000000000..d438a7a692e --- /dev/null +++ b/tests/lib/migrate.php @@ -0,0 +1,90 @@ +<?php +/** + * Copyright (c) 2014 Tom Needham <tom@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +class Test_Migrate extends PHPUnit_Framework_TestCase { + + public $users; + public $tmpfiles = array(); + + /** + * @brief Generates a test user and sets up their file system + * @return string the test users id + */ + public function generateUser() { + $username = uniqid(); + \OC_User::createUser($username, 'password'); + \OC_Util::tearDownFS(); + \OC_User::setUserId(''); + \OC\Files\Filesystem::tearDown(); + \OC_Util::setupFS($username); + $this->users[] = $username; + return $username; + } + + /** + * @brief validates an export for a user + * @brief checks for existence of export_info.json and file folder + * @param string $exportedUser the user that was exported + * @param string $path the path to the .zip export + * @param string $exportedBy + */ + public function validateUserExport($exportedBy, $exportedUser, $path) { + $this->assertTrue(file_exists($path)); + // Extract + $extract = get_temp_dir() . '/oc_import_' . uniqid(); + //mkdir($extract); + $this->tmpfiles[] = $extract; + $zip = new ZipArchive; + $zip->open($path); + $zip->extractTo($extract); + $zip->close(); + $this->assertTrue(file_exists($extract.'/export_info.json')); + $exportInfo = file_get_contents($extract.'/export_info.json'); + $exportInfo = json_decode($exportInfo); + $this->assertNotNull($exportInfo); + $this->assertEquals($exportedUser, $exportInfo->exporteduser); + $this->assertEquals($exportedBy, $exportInfo->exportedby); + $this->assertTrue(file_exists($extract.'/'.$exportedUser.'/files')); + } + + public function testUserSelfExport() { + // Create a user + $user = $this->generateUser(); + \OC_User::setUserId($user); + $export = \OC_Migrate::export($user); + // Check it succeeded and exists + $this->assertTrue(json_decode($export)->success); + // Validate the export + $this->validateUserExport($user, $user, json_decode($export)->data); + } + + public function testUserOtherExport() { + $user = $this->generateUser(); + $user2 = $this->generateUser(); + \OC_User::setUserId($user2); + $export = \OC_Migrate::export($user); + // Check it succeeded and exists + $this->assertTrue(json_decode($export)->success); + // Validate the export + $this->validateUserExport($user2, $user, json_decode($export)->data); + } + + public function tearDown() { + $u = new OC_User(); + foreach($this->users as $user) { + $u->deleteUser($user); + } + foreach($this->tmpfiles as $file) { + \OC_Helper::rmdirr($file); + } + } + + + + +} diff --git a/tests/lib/ocs/privatedata.php b/tests/lib/ocs/privatedata.php index ea8413734f1..498ab718621 100644 --- a/tests/lib/ocs/privatedata.php +++ b/tests/lib/ocs/privatedata.php @@ -131,6 +131,7 @@ class Test_OC_OCS_Privatedata extends PHPUnit_Framework_TestCase /** * @param \OC_OCS_Result $result + * @param integer $expectedArraySize */ public function assertOcsResult($expectedArraySize, $result) { $this->assertEquals(100, $result->getStatusCode()); diff --git a/tests/lib/preferences.php b/tests/lib/preferences.php index a8236909ded..f1f6ed08003 100644 --- a/tests/lib/preferences.php +++ b/tests/lib/preferences.php @@ -144,58 +144,6 @@ class Test_Preferences_Object extends PHPUnit_Framework_TestCase { $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); diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php index d6acee6c924..a89f100d97a 100644 --- a/tests/lib/share/share.php +++ b/tests/lib/share/share.php @@ -151,6 +151,10 @@ class Test_Share extends PHPUnit_Framework_TestCase { ); } + /** + * @param string $sharer + * @param string $receiver + */ protected function shareUserTestFileWithUser($sharer, $receiver) { OC_User::setUserId($sharer); $this->assertTrue( @@ -558,6 +562,9 @@ class Test_Share extends PHPUnit_Framework_TestCase { ); } + /** + * @param boolean|string $token + */ protected function getShareByValidToken($token) { $row = OCP\Share::getShareByToken($token); $this->assertInternalType( diff --git a/tests/lib/template/resourcelocator.php b/tests/lib/template/resourcelocator.php index d80d222e2c9..619560643fe 100644 --- a/tests/lib/template/resourcelocator.php +++ b/tests/lib/template/resourcelocator.php @@ -7,6 +7,11 @@ */ class Test_ResourceLocator extends PHPUnit_Framework_TestCase { + + /** + * @param string $theme + * @param string $form_factor + */ public function getResourceLocator( $theme, $form_factor, $core_map, $party_map, $appsroots ) { return $this->getMockForAbstractClass('OC\Template\ResourceLocator', array( $theme, $form_factor, $core_map, $party_map, $appsroots ), diff --git a/tests/lib/user.php b/tests/lib/user.php index fdf9e7a08e0..e2c3282a19f 100644 --- a/tests/lib/user.php +++ b/tests/lib/user.php @@ -9,8 +9,6 @@ namespace Test; -use OC\Hooks\PublicEmitter; - class User extends \PHPUnit_Framework_TestCase { /** * @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend diff --git a/tests/lib/util.php b/tests/lib/util.php index bfe68f5f680..ee336aa1118 100644 --- a/tests/lib/util.php +++ b/tests/lib/util.php @@ -170,4 +170,52 @@ class Test_Util extends PHPUnit_Framework_TestCase { array('442aa682de2a64db1e010f50e60fd9c9', 'local::C:\Users\ADMINI~1\AppData\Local\Temp\2/442aa682de2a64db1e010f50e60fd9c9/') ); } + + /** + * @dataProvider filenameValidationProvider + */ + public function testFilenameValidation($file, $valid) { + // private API + $this->assertEquals($valid, \OC_Util::isValidFileName($file)); + // public API + $this->assertEquals($valid, \OCP\Util::isValidFileName($file)); + } + + public function filenameValidationProvider() { + return array( + // valid names + array('boringname', true), + array('something.with.extension', true), + array('now with spaces', true), + array('.a', true), + array('..a', true), + array('.dotfile', true), + array('single\'quote', true), + array(' spaces before', true), + array('spaces after ', true), + array('allowed chars including the crazy ones $%&_-^@!,()[]{}=;#', true), + array('汉字也能用', true), + array('und Ümläüte sind auch willkommen', true), + // disallowed names + array('', false), + array(' ', false), + array('.', false), + array('..', false), + array('back\\slash', false), + array('sl/ash', false), + array('lt<lt', false), + array('gt>gt', false), + array('col:on', false), + array('double"quote', false), + array('pi|pe', false), + array('dont?ask?questions?', false), + array('super*star', false), + array('new\nline', false), + // better disallow these to avoid unexpected trimming to have side effects + array(' ..', false), + array('.. ', false), + array('. ', false), + array(' .', false), + ); + } } |