Selaa lähdekoodia

[REVIEW] Merging cache-manager-related resources/helpers to trunk

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19839 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 16 vuotta sitten
vanhempi
commit
3257bc29d8

+ 77 - 0
library/Zend/Application/Resource/CacheManager.php

@@ -0,0 +1,77 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Application
+ * @subpackage Resource
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once 'Zend/Application/Resource/ResourceAbstract.php';
+
+/**
+ * Cache Manager resource
+ *
+ * @category   Zend
+ * @package    Zend_Application
+ * @subpackage Resource
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Application_Resource_CacheManager extends Zend_Application_Resource_ResourceAbstract
+{
+    /**
+     * @var Zend_Cache_Manager
+     */
+    protected $_manager = null;
+
+    /**
+     * Initialize Cache_Manager
+     *
+     * @return Zend_Cache_Manager
+     */
+    public function init()
+    {
+        $manager = $this->getCacheManager();
+
+        foreach ($this->getOptions() as $key => $value) {
+            if ($manager->hasCacheTemplate($key)) {
+                $manager->setTemplateOptions($key, $value);
+            } else {
+                $manager->setCacheTemplate($key, $value);
+            }
+        }
+
+        if (null !== ($bootstrap = $this->getBootstrap())) {
+            $this->getBootstrap()->cacheManager = $manager;
+        }
+
+        return $manager;
+    }
+
+    /**
+     * Retrieve front controller instance
+     *
+     * @return Zend_Controller_Front
+     */
+    public function getCacheManager()
+    {
+        if (null === $this->_manager) {
+            $this->_manager = new Zend_Cache_Manager;
+        }
+        return $this->_manager;
+    }
+}

+ 239 - 0
library/Zend/Controller/Action/Helper/Cache.php

@@ -0,0 +1,239 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Controller
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see Zend_Controller_Action_Helper_Abstract
+ */
+require_once 'Zend/Controller/Action/Helper/Abstract.php';
+
+/**
+ * @see Zend_Controller_Action_Exception
+ */
+require_once 'Zend/Controller/Action/Exception.php';
+
+/**
+ * @see Zend_Cache_Manager
+ */
+require_once 'Zend/Cache/Manager.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Controller
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Controller_Action_Helper_Cache
+    extends Zend_Controller_Action_Helper_Abstract
+{
+
+    /**
+     * Local Cache Manager object used by Helper
+     *
+     * @var Zend_Cache_Manager
+     */
+    protected $_manager = null;
+
+    /**
+     * Indexed map of Actions to attempt Page caching on by Controller
+     *
+     * @var array
+     */
+    protected $_caching = array();
+
+    /**
+     * Indexed map of Tags by Controller and Action
+     *
+     * @var array
+     */
+    protected $_tags = array();
+
+    /**
+     * Track output buffering condition
+     */
+    protected $_obStarted = false;
+
+    /**
+     * Tell the helper which actions are cacheable and under which
+     * tags (if applicable) they should be recorded with
+     *
+     * @param array $actions
+     * @param array $tags
+     * @return void
+     */
+    public function direct(array $actions, array $tags = array())
+    {
+        $controller = $this->getRequest()->getControllerName();
+        $actions = array_unique($actions);
+        if (!isset($this->_caching[$controller])) {
+            $this->_caching[$controller] = array();
+        }
+        if (!empty($tags)) {
+            $tags = array_unique($tags);
+            if (!isset($this->_tags[$controller])) {
+                $this->_tags[$controller] = array();
+            }
+        }
+        foreach ($actions as $action) {
+            $this->_caching[$controller][] = $action;
+            if (!empty($tags)) {
+                $this->_tags[$controller][$action] = array();
+                foreach ($tags as $tag) {
+                    $this->_tags[$controller][$action][] = $tag;
+                }
+            }
+        }
+    }
+
+    /**
+     * Remove a specific page cache static file based on its
+     * relative URL from the application's public directory.
+     * The file extension is not required here; usually matches
+     * the original REQUEST_URI that was cached.
+     *
+     * @param string $relativeUrl
+     * @param bool $recursive
+     * @return mixed
+     */
+    public function removePage($relativeUrl, $recursive = false)
+    {
+        if ($recursive) {
+            return $this->getCache('page')->removeRecursive($relativeUrl);
+        } else {
+            return $this->getCache('page')->remove($relativeUrl);
+        }
+    }
+
+    /**
+     * Remove a specific page cache static file based on its
+     * relative URL from the application's public directory.
+     * The file extension is not required here; usually matches
+     * the original REQUEST_URI that was cached.
+     *
+     * @param array $tags
+     * @return mixed
+     */
+    public function removePagesTagged(array $tags)
+    {
+        return $this->getCache('page')
+            ->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, $tags);
+    }
+
+    /**
+     * Commence page caching for any cacheable actions
+     *
+     * @return void
+     */
+    public function preDispatch()
+    {
+        $controller = $this->getRequest()->getControllerName();
+        $action = $this->getRequest()->getActionName();
+        $stats = ob_get_status(true);
+        foreach ($stats as $status) {
+            if ($status['name'] == 'Zend_Cache_Frontend_Page::_flush'
+            || $status['name'] == 'Zend_Cache_Frontend_Capture::_flush') {
+                $obStarted = true;
+            }
+        }
+        if (!isset($obStarted) && isset($this->_caching[$controller]) &&
+        in_array($action, $this->_caching[$controller])) {
+            $reqUri = $this->getRequest()->getRequestUri();
+            $tags = array();
+            if (isset($this->_tags[$controller][$action])
+            && !empty($this->_tags[$controller][$action])) {
+                $tags = array_unique($this->_tags[$controller][$action]);
+            }
+            $this->getCache('page')->start($reqUri, $tags);
+        }
+    }
+
+    /**
+     * Set an instance of the Cache Manager for this helper
+     *
+     * @param Zend_Cache_Manager $manager
+     * @return void
+     */
+    public function setManager(Zend_Cache_Manager $manager)
+    {
+        $this->_manager = $manager;
+    }
+
+    /**
+     * Get the Cache Manager instance or instantiate the object if not
+     * exists. Attempts to load from bootstrap if available.
+     *
+     * @return Zend_Cache_Manager
+     */
+    public function getManager()
+    {
+        if (!is_null($this->_manager)) {
+            return $this->_manager;
+        }
+        $front = Zend_Controller_Front::getInstance();
+        if ($front->getParam('bootstrap')
+        && $front->getParam('bootstrap')->getResource('CacheManager')) {
+            return $front->getParam('bootstrap')
+                ->getResource('CacheManager');
+        }
+        $this->_manager = new Zend_Cache_Manager;
+        return $this->_manager;
+    }
+
+    /**
+     * Return a list of actions for the current Controller marked for
+     * caching
+     *
+     * @return array
+     */
+    public function getCacheableActions()
+    {
+        return $this->_caching;
+    }
+
+    /**
+     * Return a list of tags set for all cacheable actions
+     *
+     * @return array
+     */
+    public function getCacheableTags()
+    {
+        return $this->_tags;
+    }
+
+    /**
+     * Proxy non-matched methods back to Zend_Cache_Manager where
+     * appropriate
+     *
+     * @param string $method
+     * @param array $args
+     * @return mixed
+     */
+    public function __call($method, $args)
+    {
+        if (method_exists($this->getManager(), $method)) {
+            return call_user_func_array(
+                array($this->getManager(), $method), $args
+            );
+        }
+        throw new Zend_Controller_Action_Exception('Method does not exist:'
+            . $method);
+    }
+
+}

+ 2 - 0
tests/Zend/Application/Resource/AllTests.php

@@ -27,6 +27,7 @@ if (!defined('PHPUnit_MAIN_METHOD')) {
 }
 
 require_once 'Zend/Application/Resource/ResourceAbstractTest.php';
+require_once 'Zend/Application/Resource/CacheManagerTest.php';
 require_once 'Zend/Application/Resource/DbTest.php';
 require_once 'Zend/Application/Resource/DojoTest.php';
 require_once 'Zend/Application/Resource/FrontcontrollerTest.php';
@@ -59,6 +60,7 @@ class Zend_Application_Resource_AllTests
         $suite = new PHPUnit_Framework_TestSuite('Zend Framework - Zend_Application_Resource');
 
         $suite->addTestSuite('Zend_Application_Resource_ResourceAbstractTest');
+        $suite->addTestSuite('Zend_Application_Resource_CacheManagerTest');
         $suite->addTestSuite('Zend_Application_Resource_DbTest');
         $suite->addTestSuite('Zend_Application_Resource_DojoTest');
         $suite->addTestSuite('Zend_Application_Resource_FrontcontrollerTest');

+ 161 - 0
tests/Zend/Application/Resource/CacheManagerTest.php

@@ -0,0 +1,161 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Application
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+if (!defined('PHPUnit_MAIN_METHOD')) {
+    define('PHPUnit_MAIN_METHOD', 'Zend_Application_Resource_CacheManagerTest::main');
+}
+
+/**
+ * Test helper
+ */
+require_once dirname(__FILE__) . '/../../../TestHelper.php';
+
+/**
+ * Zend_Loader_Autoloader
+ */
+require_once 'Zend/Loader/Autoloader.php';
+
+/**
+ * Zend_Controller_Front
+ */
+require_once 'Zend/Controller/Front.php';
+
+/**
+ * Zend_Application_Resource_CacheManager
+ */
+require_once 'Zend/Application/Resource/CacheManager.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Application
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @group      Zend_Application
+ */
+class Zend_Application_Resource_CacheManagerTest extends PHPUnit_Framework_TestCase
+{
+    public static function main()
+    {
+        $suite  = new PHPUnit_Framework_TestSuite(__CLASS__);
+        $result = PHPUnit_TextUI_TestRunner::run($suite);
+    }
+
+    public function setUp()
+    {
+        // Store original autoloaders
+        $this->loaders = spl_autoload_functions();
+        if (!is_array($this->loaders)) {
+            // spl_autoload_functions does not return empty array when no
+            // autoloaders registered...
+            $this->loaders = array();
+        }
+
+        Zend_Loader_Autoloader::resetInstance();
+        $this->autoloader = Zend_Loader_Autoloader::getInstance();
+
+        $this->application = new Zend_Application('testing');
+
+        require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
+        $this->bootstrap = new ZfAppBootstrap($this->application);
+    }
+
+    public function tearDown()
+    {
+        // Restore original autoloaders
+        $loaders = spl_autoload_functions();
+        foreach ($loaders as $loader) {
+            spl_autoload_unregister($loader);
+        }
+
+        foreach ($this->loaders as $loader) {
+            spl_autoload_register($loader);
+        }
+
+        Zend_Controller_Front::getInstance()->resetInstance();
+
+        // Reset autoloader instance so it doesn't affect other tests
+        Zend_Loader_Autoloader::resetInstance();
+    }
+
+    public function testInitializationCreatesCacheManagerInstance()
+    {
+
+        $resource = new Zend_Application_Resource_CacheManager(array());
+        $resource->init();
+        $this->assertTrue($resource->getCacheManager() instanceof Zend_Cache_Manager);
+    }
+
+    public function testInitializationPushesCacheManagerToBootstrapWhenPresent()
+    {
+        $resource = new Zend_Application_Resource_CacheManager(array());
+        $resource->setBootstrap($this->bootstrap);
+        $resource->init();
+        $this->assertSame($resource->getCacheManager(), $this->bootstrap->cacheManager);
+    }
+
+    public function testShouldReturnCacheManagerWhenComplete()
+    {
+        $resource = new Zend_Application_Resource_CacheManager(array());
+        $manager = $resource->init();
+        $this->assertTrue($manager instanceof Zend_Cache_Manager);
+    }
+
+    public function testShouldMergeConfigsIfOptionsPassedForDefaultCacheTemplate()
+    {
+        $options = array(
+            'page' => array(
+                'backend' => array(
+                    'options' => array(
+                        'cache_dir' => '/foo'
+                    )
+                )
+            )
+        );
+        $resource = new Zend_Application_Resource_CacheManager($options);
+        $manager = $resource->init();
+        $cacheTemplate = $manager->getCacheTemplate('page');
+        $this->assertEquals('/foo', $cacheTemplate['backend']['options']['cache_dir']);
+
+    }
+    public function testShouldCreateNewCacheTemplateIfConfigNotMatchesADefaultTemplate()
+    {
+        $options = array(
+            'foo' => array(
+                'backend' => array(
+                    'options' => array(
+                        'cache_dir' => '/foo'
+                    )
+                )
+            )
+        );
+        $resource = new Zend_Application_Resource_CacheManager($options);
+        $manager = $resource->init();
+        $cacheTemplate = $manager->getCacheTemplate('foo');
+        $this->assertSame($options['foo'], $cacheTemplate);
+    }
+
+}
+
+if (PHPUnit_MAIN_METHOD == 'Zend_Application_Resource_CacheManagerTest::main') {
+    Zend_Application_Resource_CacheManagerTest::main();
+}

+ 2 - 0
tests/Zend/Controller/Action/Helper/AllTests.php

@@ -29,6 +29,7 @@ if (!defined('PHPUnit_MAIN_METHOD')) {
 require_once 'Zend/Controller/Action/Helper/ActionStackTest.php';
 require_once 'Zend/Controller/Action/Helper/AjaxContextTest.php';
 require_once 'Zend/Controller/Action/Helper/AutoCompleteTest.php';
+require_once 'Zend/Controller/Action/Helper/CacheTest.php';
 require_once 'Zend/Controller/Action/Helper/ContextSwitchTest.php';
 require_once 'Zend/Controller/Action/Helper/FlashMessengerTest.php';
 require_once 'Zend/Controller/Action/Helper/JsonTest.php';
@@ -59,6 +60,7 @@ class Zend_Controller_Action_Helper_AllTests
 
         $suite->addTestSuite('Zend_Controller_Action_Helper_ActionStackTest');
         $suite->addTestSuite('Zend_Controller_Action_Helper_AutoCompleteTest');
+        $suite->addTestSuite('Zend_Controller_Action_Helper_CacheTest');
         $suite->addTestSuite('Zend_Controller_Action_Helper_ContextSwitchTest');
         $suite->addTestSuite('Zend_Controller_Action_Helper_AjaxContextTest');
         $suite->addTestSuite('Zend_Controller_Action_Helper_FlashMessengerTest');

+ 225 - 0
tests/Zend/Controller/Action/Helper/CacheTest.php

@@ -0,0 +1,225 @@
+<?php
+
+if (!defined("PHPUnit_MAIN_METHOD")) {
+    define("PHPUnit_MAIN_METHOD", "Zend_Controller_Action_Helper_CacheTest::main");
+}
+
+require_once dirname(__FILE__) . '/../../../../TestHelper.php';
+require_once "PHPUnit/Framework/TestCase.php";
+require_once "PHPUnit/Framework/TestSuite.php";
+
+require_once 'Zend/Controller/Action/Helper/Cache.php';
+require_once 'Zend/Controller/Action/HelperBroker.php';
+require_once 'Zend/Controller/Front.php';
+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';
+
+/**
+ * Test class for Zend_Controller_Action_Helper_Cache
+ */
+class Zend_Controller_Action_Helper_CacheTest extends PHPUnit_Framework_TestCase
+{
+
+    protected $_requestUriOld;
+
+    /**
+     * Runs the test methods of this class.
+     *
+     * @return void
+     */
+    public static function main()
+    {
+        require_once "PHPUnit/TextUI/TestRunner.php";
+        $suite  = new PHPUnit_Framework_TestSuite("Zend_Controller_Action_Helper_CacheTest");
+        $result = PHPUnit_TextUI_TestRunner::run($suite);
+    }
+
+    public function setUp()
+    {
+        $this->_requestUriOld =
+            isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null;
+        $_SERVER['REQUEST_URI'] = '/foo';
+        $this->front = Zend_Controller_Front::getInstance();
+        $this->front->resetInstance();
+        $this->request = new Zend_Controller_Request_Http();
+        $this->request->setModuleName('foo')
+                ->setControllerName('bar')
+                ->setActionName('baz');
+        $this->front->setRequest($this->request);
+    }
+
+    public function tearDown()
+    {
+        $_SERVER['REQUEST_URI'] = $this->_requestUriOld;
+    }
+
+    public function testGetterInstantiatesManager()
+    {
+        $helper = new Zend_Controller_Action_Helper_Cache;
+        $this->assertTrue($helper->getManager() instanceof Zend_Cache_Manager);
+    }
+
+    public function testMethodsProxyToManager()
+    {
+        $helper = new Zend_Controller_Action_Helper_Cache;
+        $this->assertTrue($helper->hasCache('page'));
+    }
+
+    public function testCacheableActionsStoredAtInit()
+    {
+        $helper = new Zend_Controller_Action_Helper_Cache;
+        $helper->direct(array('action1'));
+        $cacheable = $helper->getCacheableActions();
+        $this->assertEquals('action1', $cacheable['bar'][0]);
+    }
+
+    public function testCacheableActionTagsStoredAtInit()
+    {
+        $helper = new Zend_Controller_Action_Helper_Cache;
+        $helper->direct(array('action1'), array('tag1','tag2'));
+        $cacheable = $helper->getCacheableTags();
+        $this->assertSame(array('tag1','tag2'), $cacheable['bar']['action1']);
+    }
+
+    public function testCacheableActionsNeverDuplicated()
+    {
+        $helper = new Zend_Controller_Action_Helper_Cache;
+        $helper->direct(array('action1','action1'));
+        $cacheable = $helper->getCacheableActions();
+        $this->assertEquals('action1', $cacheable['bar'][0]);
+    }
+
+    public function testCacheableActionTagsNeverDuplicated()
+    {
+        $helper = new Zend_Controller_Action_Helper_Cache;
+        $helper->direct(array('action1'), array('tag1','tag1','tag2','tag2'));
+        $cacheable = $helper->getCacheableTags();
+        $this->assertSame(array('tag1','tag2'), $cacheable['bar']['action1']);
+    }
+
+    public function testRemovePageCallsPageCacheRemoveMethodCorrectly()
+    {
+        $helper = new Zend_Controller_Action_Helper_Cache;
+        $cache = new Mock_Zend_Cache_Page_1;
+        $helper->setCache('page', $cache);
+        $this->assertEquals('verified', $helper->removePage('/foo'));
+    }
+
+    public function testRemovePageCallsPageCacheRemoveRecursiveMethodCorrectly()
+    {
+        $helper = new Zend_Controller_Action_Helper_Cache;
+        $cache = new Mock_Zend_Cache_Page_2;
+        $helper->setCache('page', $cache);
+        $this->assertEquals('verified', $helper->removePage('/foo', true));
+    }
+
+    public function testRemovePagesTaggedCallsPageCacheCleanMethodCorrectly()
+    {
+        $helper = new Zend_Controller_Action_Helper_Cache;
+        $cache = new Mock_Zend_Cache_Page_3;
+        $helper->setCache('page', $cache);
+        $this->assertEquals('verified', $helper->removePagesTagged(array('tag1')));
+    }
+
+    public function testPreDispatchCallsCachesStartMethod()
+    {
+        $helper = new Zend_Controller_Action_Helper_Cache;
+        $cache = new Mock_Zend_Cache_Page_4;
+        $helper->setCache('page', $cache);
+        $helper->direct(array('baz'));
+        $helper->preDispatch();
+        $this->assertEquals('verified', $cache->res);
+    }
+
+    public function testPreDispatchCallsCachesStartMethodWithTags()
+    {
+        $helper = new Zend_Controller_Action_Helper_Cache;
+        $cache = new Mock_Zend_Cache_Page_6;
+        $helper->setCache('page', $cache);
+        $helper->direct(array('baz'), array('tag1','tag2'));
+        $helper->preDispatch();
+        $this->assertEquals('verified', $cache->res);
+    }
+
+    public function testPreDispatchDoesNotCallCachesStartMethodWithBadAction()
+    {
+        $helper = new Zend_Controller_Action_Helper_Cache;
+        $cache = new Mock_Zend_Cache_Page_4;
+        $helper->setCache('page', $cache);
+        $helper->preDispatch();
+        $this->assertNotEquals('verified', $cache->res);
+    }
+
+    /**public function testPostDispatchEndsOutputBufferPageCaching()
+    {
+        $helper = new Zend_Controller_Action_Helper_Cache;
+        $cache = new Mock_Zend_Cache_Page_5;
+        $helper->setCache('page', $cache);
+        $helper->direct(array('baz'));
+        $helper->preDispatch();
+        $helper->postDispatch();
+        $this->assertEquals('verified', $cache->res);
+    }
+
+    public function testPostDispatchNotEndsOutputBufferPageCachingWithBadAction()
+    {
+        $helper = new Zend_Controller_Action_Helper_Cache;
+        $cache = new Mock_Zend_Cache_Page_5;
+        $helper->setCache('page', $cache);
+        $helper->direct(array('action1'));
+        $helper->preDispatch();
+        $helper->postDispatch();
+        $this->assertNotEquals('verified', $cache->res);
+    }**/
+
+}
+
+class Mock_Zend_Cache_Page_1 extends Zend_Cache_Core
+{
+    public function remove($id)
+    {
+        if ($id == '/foo') {return 'verified';}
+    }
+}
+class Mock_Zend_Cache_Page_2 extends Zend_Cache_Core
+{
+    public function removeRecursive($id)
+    {
+        if ($id == '/foo') {return 'verified';}
+    }
+}
+class Mock_Zend_Cache_Page_3 extends Zend_Cache_Core
+{
+    public function clean($mode = 'all', $tags = array())
+    {
+        if ($mode == 'matchingAnyTag' && $tags == array('tag1'))
+        {return 'verified';}
+    }
+}
+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';
+    }}
+}
+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';
+    }}
+}
+
+/**class Mock_Zend_Cache_Page_5 extends Zend_Cache_Core
+{
+    public $res;
+    public function start() {}
+    public function end() {$this->res = 'verified';}
+}**/
+
+if (PHPUnit_MAIN_METHOD == "Zend_Controller_Action_Helper_CacheTest::main") {
+    Zend_Controller_Action_Helper_CacheTest::main();
+}