From 527ff3537e50bdd3c19c1f715e18221e357f230f Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel
Date: Mon, 29 Nov 2010 16:48:00 +0100 Subject: [PATCH] Extend testing and fix first bug. --- framework/Prefs/lib/Horde/Prefs/Storage/File.php | 2 +- .../test/Horde/Prefs/Unit/Storage/FileTest.php | 46 ++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/framework/Prefs/lib/Horde/Prefs/Storage/File.php b/framework/Prefs/lib/Horde/Prefs/Storage/File.php index 7518c110a..5c61c65a0 100644 --- a/framework/Prefs/lib/Horde/Prefs/Storage/File.php +++ b/framework/Prefs/lib/Horde/Prefs/Storage/File.php @@ -54,7 +54,7 @@ class Horde_Prefs_Storage_File extends Horde_Prefs_Storage_Base parent::__construct($user, $params); - $this->_fullpath = $this->params['directory'] . '/' . basename($this->_params['user']) . '.prefs'; + $this->_fullpath = $this->_params['directory'] . '/' . basename($this->_params['user']) . '.prefs'; } /** diff --git a/framework/Prefs/test/Horde/Prefs/Unit/Storage/FileTest.php b/framework/Prefs/test/Horde/Prefs/Unit/Storage/FileTest.php index 310326dc0..d0b047b42 100644 --- a/framework/Prefs/test/Horde/Prefs/Unit/Storage/FileTest.php +++ b/framework/Prefs/test/Horde/Prefs/Unit/Storage/FileTest.php @@ -32,6 +32,13 @@ require_once dirname(__FILE__) . '/../../Autoload.php'; */ class Horde_Prefs_Unit_Storage_FileTest extends PHPUnit_Framework_TestCase { + public function tearDown() + { + if (!empty($this->_temp_dir)) { + $this->_rrmdir($this->_temp_dir); + } + } + /** * @expectedException InvalidArgumentException */ @@ -39,4 +46,43 @@ class Horde_Prefs_Unit_Storage_FileTest extends PHPUnit_Framework_TestCase { $b = new Horde_Prefs_Storage_File('nobody'); } + + /** + * @expectedException InvalidArgumentException + */ + public function testInvalidDirectory() + { + $b = new Horde_Prefs_Storage_File('nobody', array('directory' => dirname(__FILE__) . '/DOES_NOT_EXIST')); + } + + public function testConstruction() + { + $b = new Horde_Prefs_Storage_File('nobody', array('directory' => $this->_getTemporaryDirectory())); + } + + private function _getTemporaryDirectory() + { + $this->_temp_dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR + . 'Horde_Prefs_' . mt_rand(); + mkdir($this->_temp_dir); + return $this->_temp_dir; + } + + private function _rrmdir($dir) + { + if (is_dir($dir)) { + $objects = scandir($dir); + foreach ($objects as $object) { + if ($object != '.' && $object != '..') { + if (filetype($dir . DIRECTORY_SEPARATOR . $object) == 'dir') { + $this->_rrmdir($dir . DIRECTORY_SEPARATOR . $object); + } else { + unlink($dir . DIRECTORY_SEPARATOR . $object); + } + } + } + reset($objects); + rmdir($dir); + } + } } \ No newline at end of file -- 2.11.0