Location: PHPKode > projects > Xyster Framework > xyster-02build01/xyster-02build01/tests/Xyster/Controller/Plugin/CacheTest.php
<?php
/**
 * Xyster Framework
 *
 * 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://www.opensource.org/licenses/bsd-license.php
 *
 * @category  Xyster
 * @package   Xyster_Controller
 * @subpackage   UnitTests
 * @copyright Copyright LibreWorks, LLC (http://libreworks.net)
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @version   $Id: CacheTest.php 418 2010-10-18 21:40:08Z jonathanhawk $
 */
namespace XysterTest\Controller\Plugin;
use Xyster\Controller\Plugin\Cache;
/**
 * Test class for Xyster_Controller_Plugin_Cache.
 * Generated by PHPUnit on 2007-09-11 at 19:39:03.
 */
class CacheTest extends \PHPUnit_Framework_TestCase
{
    /**
     * Request object
     * @var \Zend_Controller_Request_Http
     */
    public $request;

    /**
     * Response object
     * @var \Zend_Controller_Response_Http
     */
    public $response;

    /**
     * Error handler plugin
     * @var Cache
     */
    public $plugin;

    /**
     * Sets up the fixture, for example, opens a network connection.
     * This method is called before a test is executed.
     *
     */
    protected function setUp()
    {
        \Zend_Controller_Front::getInstance()->resetInstance();
        $this->request  = new \Zend_Controller_Request_Http();
        $this->response = new \Zend_Controller_Response_Cli();
        $this->plugin   = new Cache();

        $this->plugin->setRequest($this->request);
        $this->plugin->setResponse($this->response);
    }
    
    /**
     * Tests proper default behavior
     *  
     */
    public function testDispatchLoopShutdownWithNoHeaders()
    {
        $body = str_repeat('x', 345);
        $this->response->setBody($body);
        $this->plugin->dispatchLoopShutdown();
        $date = gmdate('D, d M Y H:i:s', strtotime('-20 years'));

        $headers = $this->response->getRawHeaders();
        $this->assertContains('Cache-Control: no-store, no-cache, must-revalidate, max-age=0, pre-check=0', $headers);
        $this->assertContains('Pragma: no-cache', $headers);
        $this->assertContains('Expires: ' . $date . ' GMT', $headers);
        $this->assertContains('Content-Length: ' . strlen($body), $headers);
    }
    
    /**
     * Checks a redirect doesn't have any cache headers
     *
     */
    public function testDispatchLoopShutdownWithRedirect()
    {
        $this->response->setRedirect('somewhere.html');
        
        $this->plugin->dispatchLoopShutdown();
        $date = gmdate('D, d M Y H:i:s', strtotime('-20 years'));

        $headers = $this->response->getRawHeaders();
        $this->assertNotContains('Cache-Control: no-store, no-cache, must-revalidate, max-age=0, pre-check=0', $headers);
        $this->assertNotContains('Pragma: no-cache', $headers);
        $this->assertNotContains('Expires: ' . $date . ' GMT', $headers);
        $this->assertNotContains('Content-Length: 0', $headers);
    }
    
    /**
     * Tests just a content-type header sends nothing
     *
     */
    public function testDispatchLoopShutdownWithType()
    {
        $this->response->setHeader('Content-Type', 'text/plain');

        $body = str_repeat('x', 345);
        $this->response->setBody($body);
        $this->plugin->dispatchLoopShutdown();
        $date = gmdate('D, d M Y H:i:s', strtotime('-20 years'));

        $headers = $this->response->getRawHeaders();
        $this->assertNotContains('Cache-Control: no-store, no-cache, must-revalidate, max-age=0, pre-check=0', $headers);
        $this->assertNotContains('Pragma: no-cache', $headers);
        $this->assertNotContains('Expires: ' . $date . ' GMT', $headers);
        $this->assertNotContains('Content-Length: ' . strlen($body), $headers);
    }
        
    /**
     * Tests just an etag header sends the body length, nothing else
     *
     */
    public function testDispatchLoopShutdownWithEtag()
    {
        $this->response->setHeader('Etag', md5(time()));

        $body = str_repeat('x', 345);
        $this->response->setBody($body);
        $this->plugin->dispatchLoopShutdown();
        $date = gmdate('D, d M Y H:i:s', strtotime('-20 years'));

        $headers = $this->response->getRawHeaders();
        $this->assertNotContains('Cache-Control: no-store, no-cache, must-revalidate, max-age=0, pre-check=0', $headers);
        $this->assertNotContains('Pragma: no-cache', $headers);
        $this->assertNotContains('Expires: ' . $date . ' GMT', $headers);
        $this->assertContains('Content-Length: ' . strlen($body), $headers);
    }
}
Return current item: Xyster Framework