Skip to content
Snippets Groups Projects
Commit 7ad8bf31 authored by Robin Appelman's avatar Robin Appelman
Browse files

move filesystem test case

parent 286fd788
No related branches found
No related tags found
No related merge requests found
...@@ -20,9 +20,9 @@ ...@@ -20,9 +20,9 @@
* *
*/ */
use \OC\Files\Filesystem as Filesystem; namespace Test\Files;
class Test_Filesystem extends UnitTestCase { class Filesystem extends \PHPUnit_Framework_TestCase {
/** /**
* @var array tmpDirs * @var array tmpDirs
*/ */
...@@ -32,79 +32,79 @@ class Test_Filesystem extends UnitTestCase { ...@@ -32,79 +32,79 @@ class Test_Filesystem extends UnitTestCase {
* @return array * @return array
*/ */
private function getStorageData() { private function getStorageData() {
$dir = OC_Helper::tmpFolder(); $dir = \OC_Helper::tmpFolder();
$this->tmpDirs[] = $dir; $this->tmpDirs[] = $dir;
return array('datadir' => $dir); return array('datadir' => $dir);
} }
public function tearDown() { public function tearDown() {
foreach ($this->tmpDirs as $dir) { foreach ($this->tmpDirs as $dir) {
OC_Helper::rmdirr($dir); \OC_Helper::rmdirr($dir);
} }
} }
public function setUp() { public function setUp() {
Filesystem::clearMounts(); \OC\Files\Filesystem::clearMounts();
} }
public function testMount() { public function testMount() {
Filesystem::mount('\OC\Files\Storage\Local',self::getStorageData(),'/'); \OC\Files\Filesystem::mount('\OC\Files\Storage\Local',self::getStorageData(),'/');
$this->assertEqual('/',Filesystem::getMountPoint('/')); $this->assertEquals('/',\OC\Files\Filesystem::getMountPoint('/'));
$this->assertEqual('/',Filesystem::getMountPoint('/some/folder')); $this->assertEquals('/',\OC\Files\Filesystem::getMountPoint('/some/folder'));
list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/'); list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/');
$this->assertEqual('',$internalPath); $this->assertEquals('',$internalPath);
list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/some/folder'); list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/some/folder');
$this->assertEqual('some/folder',$internalPath); $this->assertEquals('some/folder',$internalPath);
Filesystem::mount('\OC\Files\Storage\Local',self::getStorageData(),'/some'); \OC\Files\Filesystem::mount('\OC\Files\Storage\Local',self::getStorageData(),'/some');
$this->assertEqual('/',Filesystem::getMountPoint('/')); $this->assertEquals('/',\OC\Files\Filesystem::getMountPoint('/'));
$this->assertEqual('/some/',Filesystem::getMountPoint('/some/folder')); $this->assertEquals('/some/',\OC\Files\Filesystem::getMountPoint('/some/folder'));
$this->assertEqual('/some/',Filesystem::getMountPoint('/some/')); $this->assertEquals('/some/',\OC\Files\Filesystem::getMountPoint('/some/'));
$this->assertEqual('/',Filesystem::getMountPoint('/some')); $this->assertEquals('/',\OC\Files\Filesystem::getMountPoint('/some'));
list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/some/folder'); list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/some/folder');
$this->assertEqual('folder',$internalPath); $this->assertEquals('folder',$internalPath);
} }
public function testNormalize() { public function testNormalize() {
$this->assertEqual('/path', Filesystem::normalizePath('/path/')); $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('/path/'));
$this->assertEqual('/path/', Filesystem::normalizePath('/path/', false)); $this->assertEquals('/path/', \OC\Files\Filesystem::normalizePath('/path/', false));
$this->assertEqual('/path', Filesystem::normalizePath('path')); $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('path'));
$this->assertEqual('/path', Filesystem::normalizePath('\path')); $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('\path'));
$this->assertEqual('/foo/bar', Filesystem::normalizePath('/foo//bar/')); $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo//bar/'));
$this->assertEqual('/foo/bar', Filesystem::normalizePath('/foo////bar')); $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo////bar'));
if (class_exists('Normalizer')) { if (class_exists('Normalizer')) {
$this->assertEqual("/foo/bar\xC3\xBC", Filesystem::normalizePath("/foo/baru\xCC\x88")); $this->assertEquals("/foo/bar\xC3\xBC", \OC\Files\Filesystem::normalizePath("/foo/baru\xCC\x88"));
} }
} }
public function testHooks() { public function testHooks() {
if(Filesystem::getView()){ if(\OC\Files\Filesystem::getView()){
$user = OC_User::getUser(); $user = \OC_User::getUser();
}else{ }else{
$user=uniqid(); $user=uniqid();
Filesystem::init('/'.$user.'/files'); \OC\Files\Filesystem::init('/'.$user.'/files');
} }
OC_Hook::clear('OC_Filesystem'); \OC_Hook::clear('OC_Filesystem');
OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook'); \OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
Filesystem::mount('OC\Files\Storage\Temporary', array(), '/'); \OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', array(), '/');
$rootView=new \OC\Files\View(''); $rootView=new \OC\Files\View('');
$rootView->mkdir('/'.$user); $rootView->mkdir('/'.$user);
$rootView->mkdir('/'.$user.'/files'); $rootView->mkdir('/'.$user.'/files');
Filesystem::file_put_contents('/foo', 'foo'); \OC\Files\Filesystem::file_put_contents('/foo', 'foo');
Filesystem::mkdir('/bar'); \OC\Files\Filesystem::mkdir('/bar');
Filesystem::file_put_contents('/bar//foo', 'foo'); \OC\Files\Filesystem::file_put_contents('/bar//foo', 'foo');
$tmpFile = OC_Helper::tmpFile(); $tmpFile = \OC_Helper::tmpFile();
file_put_contents($tmpFile, 'foo'); file_put_contents($tmpFile, 'foo');
$fh = fopen($tmpFile, 'r'); $fh = fopen($tmpFile, 'r');
Filesystem::file_put_contents('/bar//foo', $fh); \OC\Files\Filesystem::file_put_contents('/bar//foo', $fh);
} }
public function dummyHook($arguments) { public function dummyHook($arguments) {
$path = $arguments['path']; $path = $arguments['path'];
$this->assertEqual($path, Filesystem::normalizePath($path)); //the path passed to the hook should already be normalized $this->assertEquals($path, \OC\Files\Filesystem::normalizePath($path)); //the path passed to the hook should already be normalized
} }
} }
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
namespace Test\Files; namespace Test\Files;
use \OC\Files\Filesystem as Filesystem;
class View extends \PHPUnit_Framework_TestCase { class View extends \PHPUnit_Framework_TestCase {
/** /**
* @var \OC\Files\Storage\Storage[] $storages; * @var \OC\Files\Storage\Storage[] $storages;
...@@ -16,7 +14,7 @@ class View extends \PHPUnit_Framework_TestCase { ...@@ -16,7 +14,7 @@ class View extends \PHPUnit_Framework_TestCase {
private $storages = array(); private $storages = array();
public function setUp() { public function setUp() {
Filesystem::clearMounts(); \OC\Files\Filesystem::clearMounts();
} }
public function tearDown() { public function tearDown() {
...@@ -30,9 +28,9 @@ class View extends \PHPUnit_Framework_TestCase { ...@@ -30,9 +28,9 @@ class View extends \PHPUnit_Framework_TestCase {
$storage1 = $this->getTestStorage(); $storage1 = $this->getTestStorage();
$storage2 = $this->getTestStorage(); $storage2 = $this->getTestStorage();
$storage3 = $this->getTestStorage(); $storage3 = $this->getTestStorage();
Filesystem::mount($storage1, array(), '/'); \OC\Files\Filesystem::mount($storage1, array(), '/');
Filesystem::mount($storage2, array(), '/substorage'); \OC\Files\Filesystem::mount($storage2, array(), '/substorage');
Filesystem::mount($storage3, array(), '/folder/anotherstorage'); \OC\Files\Filesystem::mount($storage3, array(), '/folder/anotherstorage');
$textSize = strlen("dummy file data\n"); $textSize = strlen("dummy file data\n");
$imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png'); $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png');
$storageSize = $textSize * 2 + $imageSize; $storageSize = $textSize * 2 + $imageSize;
...@@ -84,8 +82,8 @@ class View extends \PHPUnit_Framework_TestCase { ...@@ -84,8 +82,8 @@ class View extends \PHPUnit_Framework_TestCase {
public function testAutoScan() { public function testAutoScan() {
$storage1 = $this->getTestStorage(false); $storage1 = $this->getTestStorage(false);
$storage2 = $this->getTestStorage(false); $storage2 = $this->getTestStorage(false);
Filesystem::mount($storage1, array(), '/'); \OC\Files\Filesystem::mount($storage1, array(), '/');
Filesystem::mount($storage2, array(), '/substorage'); \OC\Files\Filesystem::mount($storage2, array(), '/substorage');
$textSize = strlen("dummy file data\n"); $textSize = strlen("dummy file data\n");
$rootView = new \OC\Files\View(''); $rootView = new \OC\Files\View('');
...@@ -103,9 +101,9 @@ class View extends \PHPUnit_Framework_TestCase { ...@@ -103,9 +101,9 @@ class View extends \PHPUnit_Framework_TestCase {
$storage1 = $this->getTestStorage(); $storage1 = $this->getTestStorage();
$storage2 = $this->getTestStorage(); $storage2 = $this->getTestStorage();
$storage3 = $this->getTestStorage(); $storage3 = $this->getTestStorage();
Filesystem::mount($storage1, array(), '/'); \OC\Files\Filesystem::mount($storage1, array(), '/');
Filesystem::mount($storage2, array(), '/substorage'); \OC\Files\Filesystem::mount($storage2, array(), '/substorage');
Filesystem::mount($storage3, array(), '/folder/anotherstorage'); \OC\Files\Filesystem::mount($storage3, array(), '/folder/anotherstorage');
$rootView = new \OC\Files\View(''); $rootView = new \OC\Files\View('');
...@@ -113,7 +111,7 @@ class View extends \PHPUnit_Framework_TestCase { ...@@ -113,7 +111,7 @@ class View extends \PHPUnit_Framework_TestCase {
$this->assertEquals(6, count($results)); $this->assertEquals(6, count($results));
$paths = array(); $paths = array();
foreach ($results as $result) { 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']; $paths[] = $result['path'];
} }
$this->assertContains('/foo.txt', $paths); $this->assertContains('/foo.txt', $paths);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment