Skip to content

Commit

Permalink
Adding tests to disprove #6236. Closes #6236.
Browse files Browse the repository at this point in the history
Removing return from testWriteEmptyValues method to enable the test.
Updating CacheTest to revert settings changed in the tests.



git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8131 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
mariuswilms committed Mar 26, 2009
1 parent 9f0cbb0 commit 5d23f46
Showing 1 changed file with 70 additions and 13 deletions.
83 changes: 70 additions & 13 deletions cake/tests/cases/libs/cache.test.php
Expand Up @@ -41,20 +41,24 @@ class CacheTest extends CakeTestCase {
* @return void
*/
function setUp() {
if (!isset($this->config)) {
$this->config = Cache::config('default');
}
$this->_cacheDisable = Configure::read('Cache.disable');
Configure::write('Cache.disable', false);

Cache::config('default', array('engine'=> 'File', 'path' => CACHE));
$this->_defaultCacheConfig = Cache::config('default');
Cache::config('default', array('engine' => 'File', 'path' => TMP . 'tests'));

Cache::engine('File', array('path' => TMP . 'tests'));
}
/**
* end method
* tearDown method
*
* @access public
* @return void
*/
function end() {
Cache::config('default', $this->config['settings']);
function tearDown() {
Configure::write('Cache.disable', $this->_cacheDisable);
Cache::config('default', $this->_defaultCacheConfig['settings']);
Cache::engine('File');
}
/**
* testConfig method
Expand All @@ -74,11 +78,17 @@ function testConfig() {
* @return void
*/
function testConfigChange() {
$_cacheConfigSessions = Cache::config('sessions');
$_cacheConfigTests = Cache::config('tests');

$result = Cache::config('sessions', array('engine'=> 'File', 'path' => TMP . 'sessions'));
$this->assertEqual($result['settings'], Cache::settings('File'));

$result = Cache::config('tests', array('engine'=> 'File', 'path' => TMP . 'tests'));
$this->assertEqual($result['settings'], Cache::settings('File'));

Cache::config('sessions', $_cacheConfigSessions['settings']);
Cache::config('tests', $_cacheConfigTests['settings']);
}
/**
* testWritingWithConfig method
Expand All @@ -87,7 +97,8 @@ function testConfigChange() {
* @return void
*/
function testWritingWithConfig() {
Cache::config('sessions');
$_cacheConfigSessions = Cache::config('sessions');

Cache::write('test_somthing', 'this is the test data', 'tests');

$expected = array(
Expand All @@ -101,6 +112,8 @@ function testWritingWithConfig() {
'isWindows' => DIRECTORY_SEPARATOR == '\\'
);
$this->assertEqual($expected, Cache::settings('File'));

Cache::config('sessions', $_cacheConfigSessions['settings']);
}
/**
* testInitSettings method
Expand All @@ -110,6 +123,7 @@ function testWritingWithConfig() {
*/
function testInitSettings() {
Cache::engine('File', array('path' => TMP . 'tests'));

$settings = Cache::settings();
$expecting = array(
'engine' => 'File',
Expand All @@ -122,6 +136,8 @@ function testInitSettings() {
'isWindows' => DIRECTORY_SEPARATOR == '\\'
);
$this->assertEqual($settings, $expecting);

Cache::engine('File');
}
/**
* testWriteEmptyValues method
Expand All @@ -130,8 +146,6 @@ function testInitSettings() {
* @return void
*/
function testWriteEmptyValues() {
return;
Cache::engine('File', array('path' => TMP . 'tests'));
Cache::write('App.falseTest', false);
$this->assertIdentical(Cache::read('App.falseTest'), false);

Expand All @@ -147,32 +161,75 @@ function testWriteEmptyValues() {
Cache::write('App.zeroTest2', '0');
$this->assertIdentical(Cache::read('App.zeroTest2'), '0');
}
/**
* testCacheDisable method
*
* Check that the "Cache.disable" configuration and a change to it
* (even after a cache config has been setup) is taken into account.
*
* @link https://trac.cakephp.org/ticket/6236
* @access public
* @return void
*/
function testCacheDisable() {
Configure::write('Cache.disable', false);
Cache::config('test_cache_disable_1', array('engine'=> 'File', 'path' => TMP . 'tests'));

$this->assertTrue(Cache::write('key_1', 'hello'));
$this->assertIdentical(Cache::read('key_1'), 'hello');

Configure::write('Cache.disable', true);

$this->assertFalse(Cache::write('key_2', 'hello'));
$this->assertFalse(Cache::read('key_2'));

Configure::write('Cache.disable', false);

$this->assertTrue(Cache::write('key_3', 'hello'));
$this->assertIdentical(Cache::read('key_3'), 'hello');

Configure::write('Cache.disable', true);
Cache::config('test_cache_disable_2', array('engine'=> 'File', 'path' => TMP . 'tests'));

$this->assertFalse(Cache::write('key_4', 'hello'));
$this->assertFalse(Cache::read('key_4'));

Configure::write('Cache.disable', false);

$this->assertTrue(Cache::write('key_5', 'hello'));
$this->assertIdentical(Cache::read('key_5'), 'hello');

Configure::write('Cache.disable', true);

$this->assertFalse(Cache::write('key_6', 'hello'));
$this->assertFalse(Cache::read('key_6'));
}
/**
* testSet method
*
* @access public
* @return void
*/
function testSet() {
$write = false;
$_cacheSet = Cache::set();

Cache::set(array('duration' => '+1 year'));
$data = Cache::read('test_cache');
$this->assertFalse($data);

$data = 'this is just a simple test of the cache system';
$write = Cache::write('test_cache', $data);

$this->assertTrue($write);

Cache::set(array('duration' => '+1 year'));
$data = Cache::read('test_cache');

$this->assertEqual($data, 'this is just a simple test of the cache system');

Cache::delete('test_cache');

$global = Cache::settings();

Cache::set($_cacheSet);
}
}
?>

0 comments on commit 5d23f46

Please sign in to comment.