Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-11-22 18:44:59 +0400
committerThomas Müller <thomas.mueller@tmit.eu>2013-11-22 18:44:59 +0400
commit1267dccfe36bb274df6d3fe54f19fa67a3223427 (patch)
tree9ed563b27c11c84f18bc9f160562928231995206 /tests
parente01efd3887400ab26341260de48c23cc27a6eb82 (diff)
parent6eae96b7b03bf804fbbd891533eb4a396b26ee9d (diff)
Merge branch 'stable5' into fixing-4866-stable5
Diffstat (limited to 'tests')
-rw-r--r--tests/enable_all.php1
-rw-r--r--tests/lib/files/cache/updater.php17
-rw-r--r--tests/lib/files/filesystem.php57
-rw-r--r--tests/lib/files/storage/storage.php57
-rw-r--r--tests/lib/files/view.php70
-rw-r--r--tests/lib/helper.php34
-rw-r--r--tests/lib/share/share.php48
7 files changed, 264 insertions, 20 deletions
diff --git a/tests/enable_all.php b/tests/enable_all.php
index 111ed0e1357..43ee16a72f8 100644
--- a/tests/enable_all.php
+++ b/tests/enable_all.php
@@ -8,6 +8,7 @@
require_once __DIR__.'/../lib/base.php';
+OC_App::enable('files_sharing');
OC_App::enable('files_encryption');
OC_App::enable('calendar');
OC_App::enable('contacts');
diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php
index 198d601b1bb..03d061cc444 100644
--- a/tests/lib/files/cache/updater.php
+++ b/tests/lib/files/cache/updater.php
@@ -21,6 +21,8 @@ class Updater extends \PHPUnit_Framework_TestCase {
*/
private $scanner;
+ private $stateFilesEncryption;
+
/**
* @var \OC\Files\Cache\Cache $cache
*/
@@ -29,6 +31,12 @@ class Updater extends \PHPUnit_Framework_TestCase {
private static $user;
public function setUp() {
+
+ // remember files_encryption state
+ $this->stateFilesEncryption = \OC_App::isEnabled('files_encryption');
+ // we want to tests with the encryption app disabled
+ \OC_App::disable('files_encryption');
+
$this->storage = new \OC\Files\Storage\Temporary(array());
$textData = "dummy file data\n";
$imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
@@ -46,6 +54,10 @@ class Updater extends \PHPUnit_Framework_TestCase {
if (!self::$user) {
self::$user = uniqid();
}
+
+ \OC_User::createUser(self::$user, 'password');
+ \OC_User::setUserId(self::$user);
+
\OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files');
Filesystem::clearMounts();
@@ -63,7 +75,12 @@ class Updater extends \PHPUnit_Framework_TestCase {
if ($this->cache) {
$this->cache->clear();
}
+ \OC_User::deleteUser(self::$user);
Filesystem::tearDown();
+ // reset app files_encryption
+ if ($this->stateFilesEncryption) {
+ \OC_App::enable('files_encryption');
+ }
}
public function testWrite() {
diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php
index bef70cc725b..16b9237150a 100644
--- a/tests/lib/files/filesystem.php
+++ b/tests/lib/files/filesystem.php
@@ -66,17 +66,72 @@ class Filesystem extends \PHPUnit_Framework_TestCase {
}
public function testNormalize() {
+ $this->assertEquals('/', \OC\Files\Filesystem::normalizePath(''));
+ $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('/'));
+ $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('/', false));
+ $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('//'));
+ $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('//', false));
$this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('/path/'));
$this->assertEquals('/path/', \OC\Files\Filesystem::normalizePath('/path/', false));
$this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('path'));
- $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('\path'));
$this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo//bar/'));
+ $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('/foo//bar/', false));
$this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo////bar'));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/////bar'));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/bar/.'));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/bar/./'));
+ $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('/foo/bar/./', false));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/bar/./.'));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/bar/././'));
+ $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('/foo/bar/././', false));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/./bar/'));
+ $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('/foo/./bar/', false));
+ $this->assertEquals('/foo/.bar', \OC\Files\Filesystem::normalizePath('/foo/.bar/'));
+ $this->assertEquals('/foo/.bar/', \OC\Files\Filesystem::normalizePath('/foo/.bar/', false));
+ $this->assertEquals('/foo/.bar/tee', \OC\Files\Filesystem::normalizePath('/foo/.bar/tee'));
+
+ // normalize does not resolve '..' (by design)
+ $this->assertEquals('/foo/..', \OC\Files\Filesystem::normalizePath('/foo/../'));
+
if (class_exists('Patchwork\PHP\Shim\Normalizer')) {
$this->assertEquals("/foo/bar\xC3\xBC", \OC\Files\Filesystem::normalizePath("/foo/baru\xCC\x88"));
}
}
+ public function testNormalizeWindowsPaths() {
+ $this->assertEquals('/', \OC\Files\Filesystem::normalizePath(''));
+ $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('\\'));
+ $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('\\', false));
+ $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('\\\\'));
+ $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('\\\\', false));
+ $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('\\path'));
+ $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('\\path', false));
+ $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('\\path\\'));
+ $this->assertEquals('/path/', \OC\Files\Filesystem::normalizePath('\\path\\', false));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\\\bar\\'));
+ $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('\\foo\\\\bar\\', false));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\\\\\\\bar'));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\\\\\\\\\bar'));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.'));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.\\'));
+ $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.\\', false));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.\\.'));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.\\.\\'));
+ $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.\\.\\', false));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\.\\bar\\'));
+ $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('\\foo\\.\\bar\\', false));
+ $this->assertEquals('/foo/.bar', \OC\Files\Filesystem::normalizePath('\\foo\\.bar\\'));
+ $this->assertEquals('/foo/.bar/', \OC\Files\Filesystem::normalizePath('\\foo\\.bar\\', false));
+ $this->assertEquals('/foo/.bar/tee', \OC\Files\Filesystem::normalizePath('\\foo\\.bar\\tee'));
+
+ // normalize does not resolve '..' (by design)
+ $this->assertEquals('/foo/..', \OC\Files\Filesystem::normalizePath('\\foo\\..\\'));
+
+ if (class_exists('Patchwork\PHP\Shim\Normalizer')) {
+ $this->assertEquals("/foo/bar\xC3\xBC", \OC\Files\Filesystem::normalizePath("\\foo\\baru\xCC\x88"));
+ }
+ }
+
public function testHooks() {
if(\OC\Files\Filesystem::getView()){
$user = \OC_User::getUser();
diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php
index 0e22f26ae83..4587a3b2d06 100644
--- a/tests/lib/files/storage/storage.php
+++ b/tests/lib/files/storage/storage.php
@@ -42,18 +42,21 @@ 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'));
+ /**
+ * @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 +65,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 +84,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
*/
@@ -171,8 +182,9 @@ abstract class Storage extends \PHPUnit_Framework_TestCase {
$this->assertTrue($this->instance->hasUpdated('/lorem.txt', $ctimeStart - 1));
$this->assertTrue($this->instance->hasUpdated('/', $ctimeStart - 1));
- $this->assertTrue(($ctimeStart - 1) <= $mTime);
- $this->assertTrue($mTime <= ($ctimeEnd + 1));
+ // check that ($ctimeStart - 1) <= $mTime <= ($ctimeEnd + 1)
+ $this->assertGreaterThanOrEqual(($ctimeStart - 1), $mTime);
+ $this->assertLessThanOrEqual(($ctimeEnd + 1), $mTime);
$this->assertEquals(filesize($textFile), $this->instance->filesize('/lorem.txt'));
$stat = $this->instance->stat('/lorem.txt');
@@ -238,6 +250,17 @@ abstract class Storage extends \PHPUnit_Framework_TestCase {
$this->assertContains('/sub/logo-wide.png', $result);
}
+ 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/files/view.php b/tests/lib/files/view.php
index 1cd07773513..aceb36aa01e 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -7,6 +7,12 @@
namespace Test\Files;
+class TemporaryNoTouch extends \OC\Files\Storage\Temporary {
+ public function touch($path, $mtime = null) {
+ return false;
+ }
+}
+
class View extends \PHPUnit_Framework_TestCase {
/**
* @var \OC\Files\Storage\Storage[] $storages;
@@ -262,12 +268,38 @@ class View extends \PHPUnit_Framework_TestCase {
$this->hookPath = $params['path'];
}
+ function testTouch() {
+ $storage = $this->getTestStorage(true, '\Test\Files\TemporaryNoTouch');
+
+ \OC\Files\Filesystem::mount($storage, array(), '/');
+
+ $rootView = new \OC\Files\View('');
+ $oldCachedData = $rootView->getFileInfo('foo.txt');
+ $newMTime = $oldCachedData['mtime'] + 500;
+
+ $rootView->touch('foo.txt', $newMTime);
+
+ $cachedData = $rootView->getFileInfo('foo.txt');
+ $this->assertEquals($newMTime, $cachedData['mtime']);
+
+ // reset mtime to original to make sure the next file access
+ // gets a higher mtime
+ $rootView->touch('foo.txt', $oldCachedData['mtime']);
+
+ $rootView->file_put_contents('foo.txt', 'asd');
+ $cachedData = $rootView->getFileInfo('foo.txt');
+ $this->assertGreaterThanOrEqual($cachedData['mtime'], $oldCachedData['mtime']);
+ }
+
/**
* @param bool $scan
* @return \OC\Files\Storage\Storage
*/
- private function getTestStorage($scan = true) {
- $storage = new \OC\Files\Storage\Temporary(array());
+ private function getTestStorage($scan = true, $class = '\OC\Files\Storage\Temporary') {
+ /**
+ * @var \OC\Files\Storage\Storage $storage
+ */
+ $storage = new $class(array());
$textData = "dummy file data\n";
$imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
$storage->mkdir('folder');
@@ -282,4 +314,38 @@ class View extends \PHPUnit_Framework_TestCase {
$this->storages[] = $storage;
return $storage;
}
+
+ /**
+ * @dataProvider resolvePathTestProvider
+ */
+ public function testResolvePath($expected, $pathToTest) {
+ $storage1 = $this->getTestStorage();
+ \OC\Files\Filesystem::mount($storage1, array(), '/');
+
+ $view = new \OC\Files\View('');
+
+ $result = $view->resolvePath($pathToTest);
+ $this->assertEquals($expected, $result[1]);
+
+ $exists = $view->file_exists($pathToTest);
+ $this->assertTrue($exists);
+
+ $exists = $view->file_exists($result[1]);
+ $this->assertTrue($exists);
+ }
+
+ function resolvePathTestProvider() {
+ return array(
+ array('foo.txt', 'foo.txt'),
+ array('foo.txt', '/foo.txt'),
+ array('folder', 'folder'),
+ array('folder', '/folder'),
+ array('folder', 'folder/'),
+ array('folder', '/folder/'),
+ array('folder/bar.txt', 'folder/bar.txt'),
+ array('folder/bar.txt', '/folder/bar.txt'),
+ array('', ''),
+ array('', '/'),
+ );
+ }
}
diff --git a/tests/lib/helper.php b/tests/lib/helper.php
index 336e8f8b3c5..7de63b74b49 100644
--- a/tests/lib/helper.php
+++ b/tests/lib/helper.php
@@ -137,4 +137,38 @@ class Test_Helper extends PHPUnit_Framework_TestCase {
$result = OC_Helper::recursiveArraySearch($haystack, "NotFound");
$this->assertFalse($result);
}
+
+ /**
+ * @dataProvider streamCopyDataProvider
+ */
+ public function testStreamCopy($expectedCount, $expectedResult, $source, $target) {
+
+ if (is_string($source)) {
+ $source = fopen($source, 'r');
+ }
+ if (is_string($target)) {
+ $target = fopen($target, 'w');
+ }
+
+ list($count, $result) = \OC_Helper::streamCopy($source, $target);
+
+ if (is_resource($source)) {
+ fclose($source);
+ }
+ if (is_resource($target)) {
+ fclose($target);
+ }
+
+ $this->assertSame($expectedCount, $count);
+ $this->assertSame($expectedResult, $result);
+ }
+
+
+ function streamCopyDataProvider() {
+ return array(
+ array(0, false, false, false),
+ array(0, false, \OC::$SERVERROOT . '/tests/data/lorem.txt', false),
+ array(446, true, \OC::$SERVERROOT . '/tests/data/lorem.txt', \OC::$SERVERROOT . '/tests/data/lorem-copy.txt'),
+ );
+ }
}
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php
index e02b0e4354d..8e9eef65d32 100644
--- a/tests/lib/share/share.php
+++ b/tests/lib/share/share.php
@@ -535,4 +535,52 @@ class Test_Share extends PHPUnit_Framework_TestCase {
'Failed asserting that user 3 still has access to test.txt after expiration date has been set.'
);
}
+
+ protected function getShareByValidToken($token) {
+ $row = OCP\Share::getShareByToken($token);
+ $this->assertInternalType(
+ 'array',
+ $row,
+ "Failed asserting that a share for token $token exists."
+ );
+ return $row;
+ }
+
+ public function testShareItemWithLink() {
+ OC_User::setUserId($this->user1);
+ $token = OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_LINK, null, OCP\PERMISSION_READ);
+ $this->assertInternalType(
+ 'string',
+ $token,
+ 'Failed asserting that user 1 successfully shared text.txt as link with token.'
+ );
+
+ // testGetShareByTokenNoExpiration
+ $row = $this->getShareByValidToken($token);
+ $this->assertEmpty(
+ $row['expiration'],
+ 'Failed asserting that the returned row does not have an expiration date.'
+ );
+
+ // testGetShareByTokenExpirationValid
+ $this->assertTrue(
+ OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInFuture),
+ 'Failed asserting that user 1 successfully set a future expiration date for the test.txt share.'
+ );
+ $row = $this->getShareByValidToken($token);
+ $this->assertNotEmpty(
+ $row['expiration'],
+ 'Failed asserting that the returned row has an expiration date.'
+ );
+
+ // testGetShareByTokenExpirationExpired
+ $this->assertTrue(
+ OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInPast),
+ 'Failed asserting that user 1 successfully set a past expiration date for the test.txt share.'
+ );
+ $this->assertFalse(
+ OCP\Share::getShareByToken($token),
+ 'Failed asserting that an expired share could not be found.'
+ );
+ }
}