Extend testing and fix first bug.
authorGunnar Wrobel <p@rdus.de>
Mon, 29 Nov 2010 15:48:00 +0000 (16:48 +0100)
committerGunnar Wrobel <p@rdus.de>
Mon, 29 Nov 2010 15:48:00 +0000 (16:48 +0100)
framework/Prefs/lib/Horde/Prefs/Storage/File.php
framework/Prefs/test/Horde/Prefs/Unit/Storage/FileTest.php

index 7518c11..5c61c65 100644 (file)
@@ -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';
     }
 
     /**
index 310326d..d0b047b 100644 (file)
@@ -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