Explorar o código

[ZF-10558] Zend_Cache

- Fixed undefined variable in Zend_Cache_Backend_Static::removeRecursively().

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23605 44c647ce-9c0f-0410-b52a-842ac1e357ba
ramon %!s(int64=15) %!d(string=hai) anos
pai
achega
239854e552
Modificáronse 2 ficheiros con 29 adicións e 8 borrados
  1. 11 6
      library/Zend/Cache/Backend/Static.php
  2. 18 2
      tests/Zend/Cache/StaticBackendTest.php

+ 11 - 6
library/Zend/Cache/Backend/Static.php

@@ -343,14 +343,16 @@ class Zend_Cache_Backend_Static
             if (!is_writable($directory)) {
                 return false;
             }
-            foreach (new DirectoryIterator($directory) as $file) {
-                if (true === $file->isFile()) {
-                    if (false === unlink($file->getPathName())) {
-                        return false;
+            if (is_dir($directory)) {
+                foreach (new DirectoryIterator($directory) as $file) {
+                    if (true === $file->isFile()) {
+                        if (false === unlink($file->getPathName())) {
+                            return false;
+                        }
                     }
                 }
             }
-            rmdir(dirname($path));
+            rmdir($directory);
         }
         if (file_exists($file)) {
             if (!is_writable($file)) {
@@ -551,9 +553,12 @@ class Zend_Cache_Backend_Static
 
     /**
      * Decode a request URI from the provided ID
+     *
+     * @param string $id
+     * @return string
      */
     protected function _decodeId($id)
     {
-        return pack('H*', $id);;
+        return pack('H*', $id);
     }
 }

+ 18 - 2
tests/Zend/Cache/StaticBackendTest.php

@@ -112,7 +112,7 @@ class Zend_Cache_StaticBackendTest extends Zend_Cache_CommonBackendTest {
         $res = $this->_instance->save('data to cache', bin2hex('/foo'), array('tag1', 'tag2'), 10);
         $this->assertTrue($res);
     }
-    
+
     public function testSaveWithSpecificExtension()
     {
         $res = $this->_instance->save(serialize(array('data to cache', 'xml')), bin2hex('/foo2'));
@@ -150,7 +150,7 @@ class Zend_Cache_StaticBackendTest extends Zend_Cache_CommonBackendTest {
         $this->assertTrue($this->_instance->test(bin2hex('/foo')));
         unlink($this->_instance->getOption('public_dir') . '/foo.xml');
     }
-    
+
     public function testRemovalWithSpecificExtension()
     {
         $res = $this->_instance->save(serialize(array('data to cache', 'xml')), bin2hex('/foo3'), array('tag1'));
@@ -242,6 +242,22 @@ class Zend_Cache_StaticBackendTest extends Zend_Cache_CommonBackendTest {
         $this->assertFalse($this->_instance->test(bin2hex('bar2')));
     }
 
+    /**
+     * @group ZF-10558
+     */
+    public function testRemoveRecursively()
+    {
+        @mkdir($this->_cache_dir . '/issues/zf10558', 0777, true);
+        $id = '/issues/zf10558';
+        $pathFile = $this->_cache_dir . $id . '/index.html';
+        file_put_contents($pathFile, '<strong>foo</strong>');
+
+        $this->_instance->removeRecursively($id);
+        $this->assertFileNotExists($pathFile);
+        $this->assertFileNotExists(dirname($pathFile));
+        rmdir($this->_cache_dir . '/issues/');
+    }
+
 
     // Irrelevant Tests (from common tests)