Pārlūkot izejas kodu

[TESTS] Fixed failing tests in Zend_Controller_Action_Helper_Cache

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20681 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 16 gadi atpakaļ
vecāks
revīzija
b96bb48315

+ 9 - 5
library/Zend/Controller/Action/Helper/Cache.php

@@ -114,13 +114,17 @@ class Zend_Controller_Action_Helper_Cache
      */
     public function removePage($relativeUrl, $recursive = false)
     {
+        $cache = $this->getCache(Zend_Cache_Manager::PAGECACHE);
         if ($recursive) {
-            return $this->getCache(Zend_Cache_Manager::PAGECACHE)
-                ->getBackend()->removeRecursive($relativeUrl);
-        } else {
-            return $this->getCache(Zend_Cache_Manager::PAGECACHE)
-                ->getBackend()->remove($relativeUrl);
+            $backend = $cache->getBackend();
+            if (($backend instanceof Zend_Cache_Backend)
+                && method_exists($backend, 'removeRecursively')
+            ) {
+                return $backend->removeRecursively($relativeUrl);
+            }
         }
+
+        return $cache->remove($relativeUrl);
     }
 
     /**

+ 24 - 11
tests/Zend/Controller/Action/Helper/CacheTest.php

@@ -15,6 +15,7 @@ require_once 'Zend/Controller/Request/Http.php';
 require_once 'Zend/Controller/Response/Http.php';
 require_once 'Zend/Cache.php';
 require_once 'Zend/Cache/Core.php';
+require_once 'Zend/Cache/Backend.php';
 
 /**
  * Test class for Zend_Controller_Action_Helper_Cache
@@ -110,7 +111,9 @@ class Zend_Controller_Action_Helper_CacheTest extends PHPUnit_Framework_TestCase
     public function testRemovePageCallsPageCacheRemoveRecursiveMethodCorrectly()
     {
         $helper = new Zend_Controller_Action_Helper_Cache;
-        $cache = new Mock_Zend_Cache_Page_2;
+        $cache = new Mock_Zend_Cache_Page_1;
+        $backend = new Mock_Zend_Cache_Page_2;
+        $cache->setBackend($backend);
         $helper->setCache('page', $cache);
         $this->assertEquals('verified', $helper->removePage('/foo', true));
     }
@@ -130,7 +133,7 @@ class Zend_Controller_Action_Helper_CacheTest extends PHPUnit_Framework_TestCase
         $helper->setCache('page', $cache);
         $helper->direct(array('baz'));
         $helper->preDispatch();
-        $this->assertEquals('verified', $cache->res);
+        $this->assertEquals('verified', $cache->ranStart);
     }
 
     public function testPreDispatchCallsCachesStartMethodWithTags()
@@ -140,7 +143,7 @@ class Zend_Controller_Action_Helper_CacheTest extends PHPUnit_Framework_TestCase
         $helper->setCache('page', $cache);
         $helper->direct(array('baz'), array('tag1','tag2'));
         $helper->preDispatch();
-        $this->assertEquals('verified', $cache->res);
+        $this->assertEquals('verified', $cache->ranStart);
     }
 
     public function testPreDispatchDoesNotCallCachesStartMethodWithBadAction()
@@ -183,9 +186,9 @@ class Mock_Zend_Cache_Page_1 extends Zend_Cache_Core
         if ($id == '/foo') {return 'verified';}
     }
 }
-class Mock_Zend_Cache_Page_2 extends Zend_Cache_Core
+class Mock_Zend_Cache_Page_2 extends Zend_Cache_Backend
 {
-    public function removeRecursive($id)
+    public function removeRecursively($id)
     {
         if ($id == '/foo') {return 'verified';}
     }
@@ -201,16 +204,26 @@ class Mock_Zend_Cache_Page_3 extends Zend_Cache_Core
 class Mock_Zend_Cache_Page_4 extends Zend_Cache_Core
 {
     public $res;
-    public function start($id, array $tags = array()) {if ($id == '/foo') {
-        $this->res = 'verified';
-    }}
+    public $ranStart;
+    public function start($id, array $tags = array()) 
+    {
+        $this->ranStart = 'verified';
+        if ($id == '/foo') {
+            $this->res = 'verified';
+        }
+    }
 }
 class Mock_Zend_Cache_Page_6 extends Zend_Cache_Core
 {
     public $res;
-    public function start($id, array $tags = array()) {if ($id == '/foo' && $tags == array('tag1','tag2')) {
-        $this->res = 'verified';
-    }}
+    public $ranStart;
+    public function start($id, array $tags = array()) 
+    {
+        $this->ranStart = 'verified';
+        if ($id == '/foo' && $tags == array('tag1','tag2')) {
+            $this->res = 'verified';
+        }
+    }
 }
 
 /**class Mock_Zend_Cache_Page_5 extends Zend_Cache_Core