Location: PHPKode > projects > Xyster Framework > xyster-02build01/xyster-02build01/tests/Xyster/Controller/Action/Helper/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\Action\Helper;
use Xyster\Controller\Action\Helper\Cache;
require_once dirname(dirname(dirname(__FILE__))) . '/_files/HelperCacheController.php';

/**
 * Test class for Xyster_Controller_Action_Helper_Cache.
 * Generated by PHPUnit on 2007-09-11 at 19:28:58.
 */
class CacheTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var \Zend_Controller_Action
     */
    public $controller;
    
    /**
     * @var \Zend_Controller_Front
     */
    public $front;

    /**
     * @var \Xyster\Controller\Action\Helper\Cache
     */
    public $helper;

    /**
     * @var \Zend_Controller_Request_Http
     */
    public $request;

    /**
     * @var \Zend_Controller_Response_Cli
     */
    public $response;
    
    /**
     * Sets up the fixture, for example, opens a network connection.
     * This method is called before a test is executed.
     *
     */
    protected function setUp()
    {
        $this->front      = \Zend_Controller_Front::getInstance();
        $this->front->resetInstance();
        $this->front->returnResponse(true);
        $this->front->setControllerDirectory(dirname(dirname(dirname(__FILE__))) . '/_files');
        $this->request    = new \Zend_Controller_Request_Http();
        $this->response   = new \Zend_Controller_Response_Cli();
        $this->controller = new \XysterTest\Controller\HelperCacheController($this->request, $this->response, array());
        $this->helper     = new Cache();
        $this->helper->setActionController($this->controller);
    }
    
    /**
     * Tests the checkModifiedSince/direct method
     */
    public function testDirectNotModified()
    {
        $time = strtotime('-2 hours');
        $date = gmdate('D, d M Y H:i:s', $time) . ' GMT';
        $_SERVER['HTTP_IF_MODIFIED_SINCE'] = $date;
        
        $return = $this->helper->direct($time);
        
        $headers = $this->response->getHeaders();
        $rawHeaders = $this->response->getRawHeaders();
        
        $this->assertTrue($return);
        $this->assertContains('Status: 304 Not Modified', $rawHeaders);
        $this->assertContains(array('name'=>'Content-Length', 'value'=>'0', 'replace'=>true), $headers);
        $this->assertEquals(304, $this->response->getHttpResponseCode());
        $this->assertTrue($this->front->getParam('noViewRenderer'));
    }
    
    /**
     * Tests the checkModifiedSince/direct method if modified
     *
     */
    public function testDirectModified()
    {
        $oldTime = strtotime('-2 hours');
        $oldDate = gmdate('D, d M Y H:i:s', $oldTime) . ' GMT';
        $_SERVER['HTTP_IF_MODIFIED_SINCE'] = $oldDate;
        
        $newTime = time();
        $newDate = gmdate('D, d M Y H:i:s', $newTime) . ' GMT';
        
        $return = $this->helper->direct($newTime);
        
        $headers = $this->response->getHeaders();
        $rawHeaders = $this->response->getRawHeaders();
        
        $this->assertFalse($return);
        $this->assertContains(Cache::CACHE_CONTROL_HEADER, $rawHeaders);
        $this->assertContains('Last-Modified: ' . $newDate, $rawHeaders);
        $this->assertContains(array('name'=>'Etag','value'=>md5($newDate), 'replace'=>false), $headers);
        $this->assertNotEquals(304, $this->response->getHttpResponseCode());
        $this->assertNotEquals(true, $this->front->getParam('noViewRenderer'));
    }
}
Return current item: Xyster Framework