Skip to content

Commit

Permalink
Adding tests for CacheHelper callback methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 7, 2010
1 parent f7f9c3f commit 4739d7f
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions cake/tests/cases/libs/view/helpers/cache.test.php
Expand Up @@ -75,11 +75,11 @@ function skip() {
* @return void
*/
function setUp() {
parent::setUp();
$request = new CakeRequest();
$this->Controller = new CacheTestController($request);
$View = new View($this->Controller);
$this->Cache = new CacheHelper($View);
$this->_cacheSettings = Configure::read('Cache');
Configure::write('Cache.check', true);
Configure::write('Cache.disable', false);
App::build(array(
Expand All @@ -96,8 +96,7 @@ function setUp() {
function tearDown() {
clearCache();
unset($this->Cache);
Configure::write('Cache', $this->_cacheSettings);
App::build();
parent::tearDown();
}

/**
Expand Down Expand Up @@ -470,6 +469,54 @@ function testCacheBaseNameControllerName() {
@unlink($filename);
}

/**
* test that afterRender checks the conditions correctly.
*
* @return void
*/
function testAfterRenderConditions() {
Configure::write('Cache.check', true);
$View = new View($this->Controller);
$View->cacheAction = '+1 day';
$View->output = 'test';

$Cache = $this->getMock('CacheHelper', array('cache'), array($View));
$Cache->expects($this->once())->method('cache')
->with('posts/index', $View->output, false);
$Cache->afterRender('posts/index');

Configure::write('Cache.check', false);
$Cache->afterRender('posts/index');

Configure::write('Cache.check', true);
$View->cacheAction = false;
$Cache->afterRender('posts/index');
}

/**
* test that afterRender checks the conditions correctly.
*
* @return void
*/
function testAfterLayoutConditions() {
Configure::write('Cache.check', true);
$View = new View($this->Controller);
$View->cacheAction = '+1 day';
$View->output = 'test';

$Cache = $this->getMock('CacheHelper', array('cache'), array($View));
$Cache->expects($this->once())->method('cache')
->with('posts/index', $View->output, true);
$Cache->afterLayout('posts/index');

Configure::write('Cache.check', false);
$Cache->afterLayout('posts/index');

Configure::write('Cache.check', true);
$View->cacheAction = false;
$Cache->afterLayout('posts/index');
}

/**
* testCacheEmptySections method
*
Expand Down

0 comments on commit 4739d7f

Please sign in to comment.