diff options
author | Robin Appelman <icewind@owncloud.com> | 2014-02-07 13:42:18 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2014-02-07 13:45:59 +0100 |
commit | b537d90e58913be203fd96f31b624559be00abeb (patch) | |
tree | 9af6c432b3b503303f1315f82f602844664f837d /tests/lib/files/storage | |
parent | b35b22977cfc9412278ae70b49c402a95efca19e (diff) | |
parent | b9e724d4ae7635435b3cc7793237c3ab9fe2a1c0 (diff) | |
download | nextcloud-server-b537d90e58913be203fd96f31b624559be00abeb.tar.gz nextcloud-server-b537d90e58913be203fd96f31b624559be00abeb.zip |
use the 'new' server container for appconfig
Diffstat (limited to 'tests/lib/files/storage')
-rw-r--r-- | tests/lib/files/storage/home.php | 96 | ||||
-rw-r--r-- | tests/lib/files/storage/storage.php | 91 | ||||
-rw-r--r-- | tests/lib/files/storage/wrapper/quota.php | 41 |
3 files changed, 208 insertions, 20 deletions
diff --git a/tests/lib/files/storage/home.php b/tests/lib/files/storage/home.php new file mode 100644 index 00000000000..885291e4404 --- /dev/null +++ b/tests/lib/files/storage/home.php @@ -0,0 +1,96 @@ +<?php +/** + * ownCloud + * + * @author Robin Appelman + * @copyright 2012 Robin Appelman icewind@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/>. + * + */ + +namespace Test\Files\Storage; + +use OC\User\User; + +class DummyUser extends User { + private $home; + + private $uid; + + public function __construct($uid, $home) { + $this->uid = $uid; + $this->home = $home; + } + + public function getHome() { + return $this->home; + } + + public function getUID() { + return $this->uid; + } +} + +class Home extends Storage { + /** + * @var string tmpDir + */ + private $tmpDir; + + /** + * @var \OC\User\User $user + */ + private $user; + + public function setUp() { + $this->tmpDir = \OC_Helper::tmpFolder(); + $this->userId = uniqid('user_'); + $this->user = new DummyUser($this->userId, $this->tmpDir); + $this->instance = new \OC\Files\Storage\Home(array('user' => $this->user)); + } + + public function tearDown() { + \OC_Helper::rmdirr($this->tmpDir); + } + + /** + * Tests that the root path matches the data dir + */ + public function testRoot() { + $this->assertEquals($this->tmpDir, $this->instance->getLocalFolder('')); + } + + /** + * Tests that the home id is in the format home::user1 + */ + public function testId() { + $this->assertEquals('home::' . $this->userId, $this->instance->getId()); + } + + /** + * Tests that the legacy home id is in the format local::/path/to/datadir/user1/ + */ + public function testLegacyId() { + $this->instance = new \OC\Files\Storage\Home(array('user' => $this->user, 'legacy' => true)); + $this->assertEquals('local::' . $this->tmpDir . '/', $this->instance->getId()); + } + + /** + * Tests that getCache() returns an instance of HomeCache + */ + public function testGetCacheReturnsHomeCache() { + $this->assertInstanceOf('\OC\Files\Cache\HomeCache', $this->instance->getCache()); + } +} diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index 3f339a10016..182c014d999 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -42,18 +42,28 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertTrue($this->instance->isUpdatable('/'), 'Root folder is not writable'); } - public function testDirectories() { - $this->assertFalse($this->instance->file_exists('/folder')); + /** + * Check that the test() function works + */ + public function testTestFunction() { + $this->assertTrue($this->instance->test()); + } + + /** + * @dataProvider directoryProvider + */ + public function testDirectories($directory) { + $this->assertFalse($this->instance->file_exists('/'.$directory)); - $this->assertTrue($this->instance->mkdir('/folder')); + $this->assertTrue($this->instance->mkdir('/'.$directory)); - $this->assertTrue($this->instance->file_exists('/folder')); - $this->assertTrue($this->instance->is_dir('/folder')); - $this->assertFalse($this->instance->is_file('/folder')); - $this->assertEquals('dir', $this->instance->filetype('/folder')); - $this->assertEquals(0, $this->instance->filesize('/folder')); - $this->assertTrue($this->instance->isReadable('/folder')); - $this->assertTrue($this->instance->isUpdatable('/folder')); + $this->assertTrue($this->instance->file_exists('/'.$directory)); + $this->assertTrue($this->instance->is_dir('/'.$directory)); + $this->assertFalse($this->instance->is_file('/'.$directory)); + $this->assertEquals('dir', $this->instance->filetype('/'.$directory)); + $this->assertEquals(0, $this->instance->filesize('/'.$directory)); + $this->assertTrue($this->instance->isReadable('/'.$directory)); + $this->assertTrue($this->instance->isUpdatable('/'.$directory)); $dh = $this->instance->opendir('/'); $content = array(); @@ -62,14 +72,14 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $content[] = $file; } } - $this->assertEquals(array('folder'), $content); + $this->assertEquals(array($directory), $content); - $this->assertFalse($this->instance->mkdir('/folder')); //cant create existing folders - $this->assertTrue($this->instance->rmdir('/folder')); + $this->assertFalse($this->instance->mkdir('/'.$directory)); //cant create existing folders + $this->assertTrue($this->instance->rmdir('/'.$directory)); - $this->assertFalse($this->instance->file_exists('/folder')); + $this->assertFalse($this->instance->file_exists('/'.$directory)); - $this->assertFalse($this->instance->rmdir('/folder')); //cant remove non existing folders + $this->assertFalse($this->instance->rmdir('/'.$directory)); //cant remove non existing folders $dh = $this->instance->opendir('/'); $content = array(); @@ -81,6 +91,14 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertEquals(array(), $content); } + public function directoryProvider() + { + return array( + array('folder'), + array(' folder'), + array('folder '), + ); + } /** * test the various uses of file_get_contents and file_put_contents */ @@ -128,7 +146,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() { @@ -171,8 +197,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'); @@ -191,6 +218,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'; @@ -213,7 +251,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')); } @@ -222,7 +261,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/files/storage/wrapper/quota.php b/tests/lib/files/storage/wrapper/quota.php index 3702f8154f5..87bafb64d41 100644 --- a/tests/lib/files/storage/wrapper/quota.php +++ b/tests/lib/files/storage/wrapper/quota.php @@ -58,4 +58,45 @@ class Quota extends \Test\Files\Storage\Storage { fclose($stream); $this->assertEquals('foobarqwe', $instance->file_get_contents('foo')); } + + public function testReturnFalseWhenFopenFailed(){ + $failStorage = $this->getMock( + '\OC\Files\Storage\Local', + array('fopen'), + array(array('datadir' => $this->tmpDir))); + $failStorage->expects($this->any()) + ->method('fopen') + ->will($this->returnValue(false)); + + $instance = new \OC\Files\Storage\Wrapper\Quota(array('storage' => $failStorage, 'quota' => 1000)); + + $this->assertFalse($instance->fopen('failedfopen', 'r')); + } + + public function testReturnRegularStreamOnRead(){ + $instance = $this->getLimitedStorage(9); + + // create test file first + $stream = $instance->fopen('foo', 'w+'); + fwrite($stream, 'blablacontent'); + fclose($stream); + + $stream = $instance->fopen('foo', 'r'); + $meta = stream_get_meta_data($stream); + $this->assertEquals('plainfile', $meta['wrapper_type']); + fclose($stream); + + $stream = $instance->fopen('foo', 'rb'); + $meta = stream_get_meta_data($stream); + $this->assertEquals('plainfile', $meta['wrapper_type']); + fclose($stream); + } + + public function testReturnQuotaStreamOnWrite(){ + $instance = $this->getLimitedStorage(9); + $stream = $instance->fopen('foo', 'w+'); + $meta = stream_get_meta_data($stream); + $this->assertEquals('user-space', $meta['wrapper_type']); + fclose($stream); + } } |