From 0466437fa7878fa1681ee01651d7d41cdef7454a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 12 Apr 2012 15:55:56 +0200 Subject: [PATCH] tests for oc_filesystem --- lib/filesystem.php | 8 +++++ tests/lib/filestorage/local.php | 5 +-- tests/lib/filesystem.php | 64 +++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 tests/lib/filesystem.php diff --git a/lib/filesystem.php b/lib/filesystem.php index b6909f5acd..dc678fba74 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -248,6 +248,14 @@ class OC_Filesystem{ return self::$defaultInstance->getRoot(); } + /** + * clear all mounts and storage backends + */ + public static function clearMounts(){ + self::$mounts=array(); + self::$storages=array(); + } + /** * mount an OC_Filestorage in our virtual filesystem * @param OC_Filestorage storage diff --git a/tests/lib/filestorage/local.php b/tests/lib/filestorage/local.php index 0a2d46c5eb..692f05f9fc 100644 --- a/tests/lib/filestorage/local.php +++ b/tests/lib/filestorage/local.php @@ -26,10 +26,7 @@ class Test_Filestorage_Local extends Test_FileStorage { */ private $tmpDir; public function setUp(){ - $this->tmpDir=get_temp_dir().'/filestoragelocal'; - if(!file_exists($this->tmpDir)){ - mkdir($this->tmpDir); - } + $this->tmpDir=OC_Helper::tmpFolder(); $this->instance=new OC_Filestorage_Local(array('datadir'=>$this->tmpDir)); } diff --git a/tests/lib/filesystem.php b/tests/lib/filesystem.php new file mode 100644 index 0000000000..3e28d8c06e --- /dev/null +++ b/tests/lib/filesystem.php @@ -0,0 +1,64 @@ +. +* +*/ + +class Test_Filesystem extends UnitTestCase{ + /** + * @var array tmpDirs + */ + private $tmpDirs; + + /** + * @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_Filesystem::clearMounts(); + } + + public function testMount(){ + OC_Filesystem::mount('OC_Filestorage_Local',self::getStorageData(),'/'); + $this->assertEqual('/',OC_Filesystem::getMountPoint('/')); + $this->assertEqual('/',OC_Filesystem::getMountPoint('/some/folder')); + $this->assertEqual('',OC_Filesystem::getInternalPath('/')); + $this->assertEqual('some/folder',OC_Filesystem::getInternalPath('/some/folder')); + + OC_Filesystem::mount('OC_Filestorage_Local',self::getStorageData(),'/some'); + $this->assertEqual('/',OC_Filesystem::getMountPoint('/')); + $this->assertEqual('/some/',OC_Filesystem::getMountPoint('/some/folder')); + $this->assertEqual('/some/',OC_Filesystem::getMountPoint('/some/')); + $this->assertEqual('/',OC_Filesystem::getMountPoint('/some')); + $this->assertEqual('folder',OC_Filesystem::getInternalPath('/some/folder')); + } +} + +?> \ No newline at end of file