move filesystem test case

This commit is contained in:
Robin Appelman 2012-10-26 18:07:01 +02:00
parent 286fd78865
commit 7ad8bf3156
3 changed files with 120 additions and 122 deletions

View File

@ -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
}
}

View File

@ -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);

View File

@ -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
}
}