diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/avatar.php | 15 | ||||
-rw-r--r-- | tests/lib/files/storage/storage.php | 16 | ||||
-rw-r--r-- | tests/lib/request.php | 68 | ||||
-rw-r--r-- | tests/lib/util.php | 49 |
4 files changed, 146 insertions, 2 deletions
diff --git a/tests/lib/avatar.php b/tests/lib/avatar.php index 6e6faed2d2c..9cc14865a29 100644 --- a/tests/lib/avatar.php +++ b/tests/lib/avatar.php @@ -22,4 +22,19 @@ class Test_Avatar extends PHPUnit_Framework_TestCase { $avatar->remove(); $this->assertEquals(false, $avatar->get()); } + + public function testAvatarApi() { + $avatarManager = \OC::$server->getAvatarManager(); + $avatar = $avatarManager->getAvatar(\OC_User::getUser()); + + $this->assertEquals(false, $avatar->get()); + + $expected = new OC_Image(\OC::$SERVERROOT.'/tests/data/testavatar.png'); + $expected->resize(64); + $avatar->set($expected->data()); + $this->assertEquals($expected->data(), $avatar->get()->data()); + + $avatar->remove(); + $this->assertEquals(false, $avatar->get()); + } } diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index f72a5276db5..6c433e95475 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -182,8 +182,9 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $ctimeStart - 5)); $this->assertTrue($this->instance->hasUpdated('/', $ctimeStart - 5)); - $this->assertTrue(($ctimeStart - 5) <= $mTime); - $this->assertTrue($mTime <= ($ctimeEnd + 1)); + // check that ($ctimeStart - 5) <= $mTime <= ($ctimeEnd + 1) + $this->assertGreaterThanOrEqual(($ctimeStart - 5), $mTime); + $this->assertLessThanOrEqual(($ctimeEnd + 1), $mTime); $this->assertEquals(filesize($textFile), $this->instance->filesize('/lorem.txt')); $stat = $this->instance->stat('/lorem.txt'); @@ -202,6 +203,17 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 5)); } + public function testUnlink() { + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; + $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); + + $this->assertTrue($this->instance->file_exists('/lorem.txt')); + + $this->assertTrue($this->instance->unlink('/lorem.txt')); + + $this->assertFalse($this->instance->file_exists('/lorem.txt')); + } + public function testFOpen() { $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; diff --git a/tests/lib/request.php b/tests/lib/request.php new file mode 100644 index 00000000000..a740751f060 --- /dev/null +++ b/tests/lib/request.php @@ -0,0 +1,68 @@ +<?php +/** + * Copyright (c) 2013 Thomas Müller <thomas.mueller@tmit.eu> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +class Test_Request extends PHPUnit_Framework_TestCase { + + public function setUp() { + OC_Config::setValue('overwritewebroot', '/domain.tld/ownCloud'); + } + + public function tearDown() { + OC_Config::setValue('overwritewebroot', ''); + } + + public function testScriptNameOverWrite() { + $_SERVER['REMOTE_ADDR'] = '10.0.0.1'; + $_SERVER["SCRIPT_FILENAME"] = __FILE__; + + $scriptName = OC_Request::scriptName(); + $this->assertEquals('/domain.tld/ownCloud/tests/lib/request.php', $scriptName); + } + + /** + * @dataProvider rawPathInfoProvider + * @param $expected + * @param $requestUri + * @param $scriptName + */ + public function testRawPathInfo($expected, $requestUri, $scriptName) { + $_SERVER['REQUEST_URI'] = $requestUri; + $_SERVER['SCRIPT_NAME'] = $scriptName; + $rawPathInfo = OC_Request::getRawPathInfo(); + $this->assertEquals($expected, $rawPathInfo); + } + + function rawPathInfoProvider() { + return array( + array('/core/ajax/translations.php', 'index.php/core/ajax/translations.php', 'index.php'), + array('/core/ajax/translations.php', '/index.php/core/ajax/translations.php', '/index.php'), + array('/core/ajax/translations.php', '//index.php/core/ajax/translations.php', '/index.php'), + ); + } + + /** + * @dataProvider rawPathInfoThrowsExceptionProvider + * @expectedException Exception + * + * @param $requestUri + * @param $scriptName + */ + public function testRawPathInfoThrowsException($requestUri, $scriptName) { + $_SERVER['REQUEST_URI'] = $requestUri; + $_SERVER['SCRIPT_NAME'] = $scriptName; + OC_Request::getRawPathInfo(); + } + + function rawPathInfoThrowsExceptionProvider() { + return array( + array('core/ajax/translations.php', '/index.php'), + array('/core/ajax/translations.php', '/index.php'), + array('//core/ajax/translations.php', '/index.php'), + ); + } +} diff --git a/tests/lib/util.php b/tests/lib/util.php index d607a3e7725..852caaeccc3 100644 --- a/tests/lib/util.php +++ b/tests/lib/util.php @@ -94,6 +94,55 @@ class Test_Util extends PHPUnit_Framework_TestCase { } /** + * Tests that the home storage is not wrapped when no quota exists. + */ + function testHomeStorageWrapperWithoutQuota() { + $user1 = uniqid(); + \OC_User::createUser($user1, 'test'); + OC_Preferences::setValue($user1, 'files', 'quota', 'none'); + \OC_User::setUserId($user1); + + \OC_Util::setupFS($user1); + + $userMount = \OC\Files\Filesystem::getMountManager()->find('/' . $user1 . '/'); + $this->assertNotNull($userMount); + $this->assertNotInstanceOf('\OC\Files\Storage\Wrapper\Quota', $userMount->getStorage()); + + // clean up + \OC_User::setUserId(''); + \OC_User::deleteUser($user1); + OC_Preferences::deleteUser($user1); + \OC_Util::tearDownFS(); + } + + /** + * Tests that the home storage is not wrapped when no quota exists. + */ + function testHomeStorageWrapperWithQuota() { + $user1 = uniqid(); + \OC_User::createUser($user1, 'test'); + OC_Preferences::setValue($user1, 'files', 'quota', '1024'); + \OC_User::setUserId($user1); + + \OC_Util::setupFS($user1); + + $userMount = \OC\Files\Filesystem::getMountManager()->find('/' . $user1 . '/'); + $this->assertNotNull($userMount); + $this->assertInstanceOf('\OC\Files\Storage\Wrapper\Quota', $userMount->getStorage()); + + // ensure that root wasn't wrapped + $rootMount = \OC\Files\Filesystem::getMountManager()->find('/'); + $this->assertNotNull($rootMount); + $this->assertNotInstanceOf('\OC\Files\Storage\Wrapper\Quota', $rootMount->getStorage()); + + // clean up + \OC_User::setUserId(''); + \OC_User::deleteUser($user1); + OC_Preferences::deleteUser($user1); + \OC_Util::tearDownFS(); + } + + /** * @dataProvider baseNameProvider */ public function testBaseName($expected, $file) |