diff options
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/files/cache/updater.php | 8 | ||||
-rw-r--r-- | tests/lib/files/storage/storage.php | 27 | ||||
-rw-r--r-- | tests/lib/request.php | 11 | ||||
-rw-r--r-- | tests/lib/user/avataruserdummy.php | 27 | ||||
-rw-r--r-- | tests/lib/user/user.php | 69 |
5 files changed, 136 insertions, 6 deletions
diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php index e3d3aae818d..91e384e12af 100644 --- a/tests/lib/files/cache/updater.php +++ b/tests/lib/files/cache/updater.php @@ -202,6 +202,14 @@ class Updater extends \PHPUnit_Framework_TestCase { $this->assertNotEquals($rootCachedData['etag'], $cachedData['etag']); } + public function testRenameExtension() { + $fooCachedData = $this->cache->get('foo.txt'); + $this->assertEquals('text/plain', $fooCachedData['mimetype']); + Filesystem::rename('foo.txt', 'foo.abcd'); + $fooCachedData = $this->cache->get('foo.abcd'); + $this->assertEquals('application/octet-stream', $fooCachedData['mimetype']); + } + public function testRenameWithMountPoints() { $storage2 = new \OC\Files\Storage\Temporary(array()); $cache2 = $storage2->getCache(); diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index 6c433e95475..5a0581665a2 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -139,7 +139,15 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->instance->rename('/source.txt', '/target2.txt'); $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('/target.txt')); + $this->assertEquals(file_get_contents($textFile), $this->instance->file_get_contents('/target2.txt')); + + // move to overwrite + $testContents = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $this->instance->file_put_contents('/target3.txt', $testContents); + $this->instance->rename('/target2.txt', '/target3.txt'); + $this->assertTrue($this->instance->file_exists('/target3.txt')); + $this->assertFalse($this->instance->file_exists('/target2.txt')); + $this->assertEquals(file_get_contents($textFile), $this->instance->file_get_contents('/target3.txt')); } public function testLocal() { @@ -236,7 +244,8 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { public function testTouchCreateFile() { $this->assertFalse($this->instance->file_exists('foo')); - $this->instance->touch('foo'); + // returns true on success + $this->assertTrue($this->instance->touch('foo')); $this->assertTrue($this->instance->file_exists('foo')); } @@ -245,7 +254,19 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->instance->mkdir('folder/bar'); $this->instance->file_put_contents('folder/asd.txt', 'foobar'); $this->instance->file_put_contents('folder/bar/foo.txt', 'asd'); - $this->instance->rmdir('folder'); + $this->assertTrue($this->instance->rmdir('folder')); + $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')); + $this->assertFalse($this->instance->file_exists('folder')); + } + + public function testRecursiveUnlink() { + $this->instance->mkdir('folder'); + $this->instance->mkdir('folder/bar'); + $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->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/request.php b/tests/lib/request.php index a740751f060..090cebc9231 100644 --- a/tests/lib/request.php +++ b/tests/lib/request.php @@ -42,6 +42,13 @@ class Test_Request extends PHPUnit_Framework_TestCase { 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'), + array('', '/oc/core', '/oc/core/index.php'), + array('', '/oc/core/', '/oc/core/index.php'), + array('', '/oc/core/index.php', '/oc/core/index.php'), + array('/core/ajax/translations.php', '/core/ajax/translations.php', 'index.php'), + array('/core/ajax/translations.php', '//core/ajax/translations.php', '/index.php'), + array('/core/ajax/translations.php', '/oc/core/ajax/translations.php', '/oc/index.php'), + array('/1', '/oc/core/1', '/oc/core/index.php'), ); } @@ -60,9 +67,7 @@ class Test_Request extends PHPUnit_Framework_TestCase { 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'), + array('/oc/core1', '/oc/core/index.php'), ); } } diff --git a/tests/lib/user/avataruserdummy.php b/tests/lib/user/avataruserdummy.php new file mode 100644 index 00000000000..738b10492ea --- /dev/null +++ b/tests/lib/user/avataruserdummy.php @@ -0,0 +1,27 @@ +<?php +/** +* ownCloud +* +* @author Arthur Schiwon +* @copyright 2013 Arthur Schiwon blizzz@owncloud.com +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ + +class Avatar_User_Dummy extends \OC_User_Dummy { + public function canChangeAvatar($uid) { + return true; + } +}
\ No newline at end of file diff --git a/tests/lib/user/user.php b/tests/lib/user/user.php index de5ccbf38c1..0bbcda013ce 100644 --- a/tests/lib/user/user.php +++ b/tests/lib/user/user.php @@ -87,6 +87,75 @@ class User extends \PHPUnit_Framework_TestCase { $this->assertFalse($user->setPassword('bar','')); } + public function testChangeAvatarSupportedYes() { + /** + * @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend + */ + require_once 'avataruserdummy.php'; + $backend = $this->getMock('Avatar_User_Dummy'); + $backend->expects($this->once()) + ->method('canChangeAvatar') + ->with($this->equalTo('foo')) + ->will($this->returnValue(true)); + + $backend->expects($this->any()) + ->method('implementsActions') + ->will($this->returnCallback(function ($actions) { + if ($actions === \OC_USER_BACKEND_PROVIDE_AVATAR) { + return true; + } else { + return false; + } + })); + + $user = new \OC\User\User('foo', $backend); + $this->assertTrue($user->canChangeAvatar()); + } + + public function testChangeAvatarSupportedNo() { + /** + * @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend + */ + require_once 'avataruserdummy.php'; + $backend = $this->getMock('Avatar_User_Dummy'); + $backend->expects($this->once()) + ->method('canChangeAvatar') + ->with($this->equalTo('foo')) + ->will($this->returnValue(false)); + + $backend->expects($this->any()) + ->method('implementsActions') + ->will($this->returnCallback(function ($actions) { + if ($actions === \OC_USER_BACKEND_PROVIDE_AVATAR) { + return true; + } else { + return false; + } + })); + + $user = new \OC\User\User('foo', $backend); + $this->assertFalse($user->canChangeAvatar()); + } + + public function testChangeAvatarNotSupported() { + /** + * @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend + */ + require_once 'avataruserdummy.php'; + $backend = $this->getMock('Avatar_User_Dummy'); + $backend->expects($this->never()) + ->method('canChangeAvatar'); + + $backend->expects($this->any()) + ->method('implementsActions') + ->will($this->returnCallback(function ($actions) { + return false; + })); + + $user = new \OC\User\User('foo', $backend); + $this->assertTrue($user->canChangeAvatar()); + } + public function testDelete() { /** * @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend |