summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-10-26 18:07:01 +0200
committerRobin Appelman <icewind@owncloud.com>2012-10-26 18:07:01 +0200
commit7ad8bf3156a794e47ee223efd2e1cf9191cc8a97 (patch)
treee767b9481d56439f6fad71eb90449b8359a1700c /tests/lib
parent286fd78865c6a0267bf11d9e50e72e23932b3f23 (diff)
downloadnextcloud-server-7ad8bf3156a794e47ee223efd2e1cf9191cc8a97.tar.gz
nextcloud-server-7ad8bf3156a794e47ee223efd2e1cf9191cc8a97.zip
move filesystem test case
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/files/filesystem.php110
-rw-r--r--tests/lib/files/view.php22
-rw-r--r--tests/lib/filesystem.php110
3 files changed, 120 insertions, 122 deletions
diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php
new file mode 100644
index 00000000000..363426511bd
--- /dev/null
+++ b/tests/lib/files/filesystem.php
@@ -0,0 +1,110 @@
+<?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;
+
+class Filesystem extends \PHPUnit_Framework_TestCase {
+ /**
+ * @var array tmpDirs
+ */
+ private $tmpDirs=array();
+
+ /**
+ * @return array
+ */
+ private function getStorageData() {
+ $dir = \OC_Helper::tmpFolder();
+ $this->tmpDirs[] = $dir;
+ return array('datadir' => $dir);
+ }
+
+ public function tearDown() {
+ foreach ($this->tmpDirs as $dir) {
+ \OC_Helper::rmdirr($dir);
+ }
+ }
+
+ public function setUp() {
+ \OC\Files\Filesystem::clearMounts();
+ }
+
+ public function testMount() {
+ \OC\Files\Filesystem::mount('\OC\Files\Storage\Local',self::getStorageData(),'/');
+ $this->assertEquals('/',\OC\Files\Filesystem::getMountPoint('/'));
+ $this->assertEquals('/',\OC\Files\Filesystem::getMountPoint('/some/folder'));
+ list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/');
+ $this->assertEquals('',$internalPath);
+ list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/some/folder');
+ $this->assertEquals('some/folder',$internalPath);
+
+ \OC\Files\Filesystem::mount('\OC\Files\Storage\Local',self::getStorageData(),'/some');
+ $this->assertEquals('/',\OC\Files\Filesystem::getMountPoint('/'));
+ $this->assertEquals('/some/',\OC\Files\Filesystem::getMountPoint('/some/folder'));
+ $this->assertEquals('/some/',\OC\Files\Filesystem::getMountPoint('/some/'));
+ $this->assertEquals('/',\OC\Files\Filesystem::getMountPoint('/some'));
+ list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/some/folder');
+ $this->assertEquals('folder',$internalPath);
+ }
+
+ public function testNormalize() {
+ $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'));
+ if (class_exists('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();
+ }else{
+ $user=uniqid();
+ \OC\Files\Filesystem::init('/'.$user.'/files');
+ }
+ \OC_Hook::clear('OC_Filesystem');
+ \OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
+
+ \OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', array(), '/');
+
+ $rootView=new \OC\Files\View('');
+ $rootView->mkdir('/'.$user);
+ $rootView->mkdir('/'.$user.'/files');
+
+ \OC\Files\Filesystem::file_put_contents('/foo', 'foo');
+ \OC\Files\Filesystem::mkdir('/bar');
+ \OC\Files\Filesystem::file_put_contents('/bar//foo', 'foo');
+
+ $tmpFile = \OC_Helper::tmpFile();
+ file_put_contents($tmpFile, 'foo');
+ $fh = fopen($tmpFile, 'r');
+ \OC\Files\Filesystem::file_put_contents('/bar//foo', $fh);
+ }
+
+ public function dummyHook($arguments) {
+ $path = $arguments['path'];
+ $this->assertEquals($path, \OC\Files\Filesystem::normalizePath($path)); //the path passed to the hook should already be normalized
+ }
+}
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index fc872ea5e27..980c5298fb4 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -7,8 +7,6 @@
namespace Test\Files;
-use \OC\Files\Filesystem as Filesystem;
-
class View extends \PHPUnit_Framework_TestCase {
/**
* @var \OC\Files\Storage\Storage[] $storages;
@@ -16,7 +14,7 @@ class View extends \PHPUnit_Framework_TestCase {
private $storages = array();
public function setUp() {
- Filesystem::clearMounts();
+ \OC\Files\Filesystem::clearMounts();
}
public function tearDown() {
@@ -30,9 +28,9 @@ class View extends \PHPUnit_Framework_TestCase {
$storage1 = $this->getTestStorage();
$storage2 = $this->getTestStorage();
$storage3 = $this->getTestStorage();
- Filesystem::mount($storage1, array(), '/');
- Filesystem::mount($storage2, array(), '/substorage');
- Filesystem::mount($storage3, array(), '/folder/anotherstorage');
+ \OC\Files\Filesystem::mount($storage1, array(), '/');
+ \OC\Files\Filesystem::mount($storage2, array(), '/substorage');
+ \OC\Files\Filesystem::mount($storage3, array(), '/folder/anotherstorage');
$textSize = strlen("dummy file data\n");
$imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png');
$storageSize = $textSize * 2 + $imageSize;
@@ -84,8 +82,8 @@ class View extends \PHPUnit_Framework_TestCase {
public function testAutoScan() {
$storage1 = $this->getTestStorage(false);
$storage2 = $this->getTestStorage(false);
- Filesystem::mount($storage1, array(), '/');
- Filesystem::mount($storage2, array(), '/substorage');
+ \OC\Files\Filesystem::mount($storage1, array(), '/');
+ \OC\Files\Filesystem::mount($storage2, array(), '/substorage');
$textSize = strlen("dummy file data\n");
$rootView = new \OC\Files\View('');
@@ -103,9 +101,9 @@ class View extends \PHPUnit_Framework_TestCase {
$storage1 = $this->getTestStorage();
$storage2 = $this->getTestStorage();
$storage3 = $this->getTestStorage();
- Filesystem::mount($storage1, array(), '/');
- Filesystem::mount($storage2, array(), '/substorage');
- Filesystem::mount($storage3, array(), '/folder/anotherstorage');
+ \OC\Files\Filesystem::mount($storage1, array(), '/');
+ \OC\Files\Filesystem::mount($storage2, array(), '/substorage');
+ \OC\Files\Filesystem::mount($storage3, array(), '/folder/anotherstorage');
$rootView = new \OC\Files\View('');
@@ -113,7 +111,7 @@ class View extends \PHPUnit_Framework_TestCase {
$this->assertEquals(6, count($results));
$paths = array();
foreach ($results as $result) {
- $this->assertEquals($result['path'], Filesystem::normalizePath($result['path']));
+ $this->assertEquals($result['path'], \OC\Files\Filesystem::normalizePath($result['path']));
$paths[] = $result['path'];
}
$this->assertContains('/foo.txt', $paths);
diff --git a/tests/lib/filesystem.php b/tests/lib/filesystem.php
deleted file mode 100644
index 6e7b4fb781f..00000000000
--- a/tests/lib/filesystem.php
+++ /dev/null
@@ -1,110 +0,0 @@
-<?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/>.
- *
- */
-
-use \OC\Files\Filesystem as Filesystem;
-
-class Test_Filesystem extends UnitTestCase {
- /**
- * @var array tmpDirs
- */
- private $tmpDirs=array();
-
- /**
- * @return array
- */
- private function getStorageData() {
- $dir = OC_Helper::tmpFolder();
- $this->tmpDirs[] = $dir;
- return array('datadir' => $dir);
- }
-
- public function tearDown() {
- foreach ($this->tmpDirs as $dir) {
- OC_Helper::rmdirr($dir);
- }
- }
-
- public function setUp() {
- Filesystem::clearMounts();
- }
-
- public function testMount() {
- Filesystem::mount('\OC\Files\Storage\Local',self::getStorageData(),'/');
- $this->assertEqual('/',Filesystem::getMountPoint('/'));
- $this->assertEqual('/',Filesystem::getMountPoint('/some/folder'));
- list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/');
- $this->assertEqual('',$internalPath);
- list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/some/folder');
- $this->assertEqual('some/folder',$internalPath);
-
- Filesystem::mount('\OC\Files\Storage\Local',self::getStorageData(),'/some');
- $this->assertEqual('/',Filesystem::getMountPoint('/'));
- $this->assertEqual('/some/',Filesystem::getMountPoint('/some/folder'));
- $this->assertEqual('/some/',Filesystem::getMountPoint('/some/'));
- $this->assertEqual('/',Filesystem::getMountPoint('/some'));
- list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/some/folder');
- $this->assertEqual('folder',$internalPath);
- }
-
- public function testNormalize() {
- $this->assertEqual('/path', Filesystem::normalizePath('/path/'));
- $this->assertEqual('/path/', Filesystem::normalizePath('/path/', false));
- $this->assertEqual('/path', Filesystem::normalizePath('path'));
- $this->assertEqual('/path', Filesystem::normalizePath('\path'));
- $this->assertEqual('/foo/bar', Filesystem::normalizePath('/foo//bar/'));
- $this->assertEqual('/foo/bar', Filesystem::normalizePath('/foo////bar'));
- if (class_exists('Normalizer')) {
- $this->assertEqual("/foo/bar\xC3\xBC", Filesystem::normalizePath("/foo/baru\xCC\x88"));
- }
- }
-
- public function testHooks() {
- if(Filesystem::getView()){
- $user = OC_User::getUser();
- }else{
- $user=uniqid();
- Filesystem::init('/'.$user.'/files');
- }
- OC_Hook::clear('OC_Filesystem');
- OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
-
- Filesystem::mount('OC\Files\Storage\Temporary', array(), '/');
-
- $rootView=new \OC\Files\View('');
- $rootView->mkdir('/'.$user);
- $rootView->mkdir('/'.$user.'/files');
-
- Filesystem::file_put_contents('/foo', 'foo');
- Filesystem::mkdir('/bar');
- Filesystem::file_put_contents('/bar//foo', 'foo');
-
- $tmpFile = OC_Helper::tmpFile();
- file_put_contents($tmpFile, 'foo');
- $fh = fopen($tmpFile, 'r');
- Filesystem::file_put_contents('/bar//foo', $fh);
- }
-
- public function dummyHook($arguments) {
- $path = $arguments['path'];
- $this->assertEqual($path, Filesystem::normalizePath($path)); //the path passed to the hook should already be normalized
- }
-}