Adding documentation to Cache::config().

Adding tests for default configuration manipulation of config().
This commit is contained in:
mark_story 2009-11-16 21:58:27 -05:00
parent d1066bfeaf
commit 3404f1ed39
2 changed files with 48 additions and 4 deletions

View file

@ -75,7 +75,18 @@ class Cache {
} }
/** /**
* Set the cache configuration to use * Set the cache configuration to use. config() can
* both create new configurations, return the settings for already configured
* configurations. It also sets the 'default' configuration to use for subsequent
* operations.
*
* To create a new configuration:
*
* `Cache::config('my_config', array('engine' => 'File', 'path' => TMP));`
*
* To get the settings for a configuration, and set it as the currently selected configuration
*
* `Cache::config('default');`
* *
* @see app/config/core.php for configuration settings * @see app/config/core.php for configuration settings
* @param string $name Name of the configuration * @param string $name Name of the configuration

View file

@ -22,7 +22,7 @@
if (!class_exists('Cache')) { if (!class_exists('Cache')) {
require LIBS . 'cache.php'; require LIBS . 'cache.php';
} }
Configure::write('debug', 0);
/** /**
* CacheTest class * CacheTest class
* *
@ -136,6 +136,37 @@ class CacheTest extends CakeTestCase {
Cache::config('tests', $_cacheConfigTests['settings']); Cache::config('tests', $_cacheConfigTests['settings']);
} }
/**
* test that calling config() sets the 'default' configuration up.
*
* @return void
*/
function testConfigSettingDefaultConfigKey() {
Configure::write('debug', 2);
Cache::config('test_name', array('engine' => 'File', 'prefix' => 'test_name_'));
Cache::config('test_name');
Cache::write('value_one', 'I am cached');
$result = Cache::read('value_one');
$this->assertEqual($result, 'I am cached');
Cache::config('default');
$result = Cache::read('value_one');
$this->assertEqual($result, null);
Cache::write('value_one', 'I am in another cache config!');
$result = Cache::read('value_one');
$this->assertEqual($result, 'I am in another cache config!');
Cache::config('test_name');
$result = Cache::read('value_one');
$this->assertEqual($result, 'I am cached');
Cache::delete('value_one');
Cache::config('default');
Cache::delete('value_one');
}
/** /**
* testWritingWithConfig method * testWritingWithConfig method
* *
@ -200,12 +231,12 @@ class CacheTest extends CakeTestCase {
} }
/** /**
* test that unconfig removes cache configs, and that further attempts to use that config * test that drop removes cache configs, and that further attempts to use that config
* do not work. * do not work.
* *
* @return void * @return void
*/ */
function testUnconfig() { function testDrop() {
App::build(array( App::build(array(
'libs' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'libs' . DS), 'libs' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'libs' . DS),
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS) 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
@ -324,5 +355,7 @@ class CacheTest extends CakeTestCase {
Cache::set($_cacheSet); Cache::set($_cacheSet);
} }
} }
?> ?>