mirror of
https://github.com/brmlab/brmsklad.git
synced 2025-10-30 15:53:59 +01:00
Backup of current cakephp version
This commit is contained in:
parent
b8f82da6f8
commit
5a580df460
925 changed files with 238041 additions and 1 deletions
412
lib/Cake/Test/Case/Cache/CacheTest.php
Normal file
412
lib/Cake/Test/Case/Cache/CacheTest.php
Normal file
|
|
@ -0,0 +1,412 @@
|
|||
<?php
|
||||
/**
|
||||
* CacheTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
||||
* @package Cake.Test.Case.Cache
|
||||
* @since CakePHP(tm) v 1.2.0.5432
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
App::uses('Cache', 'Cache');
|
||||
|
||||
/**
|
||||
* CacheTest class
|
||||
*
|
||||
* @package Cake.Test.Case.Cache
|
||||
*/
|
||||
class CacheTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->_cacheDisable = Configure::read('Cache.disable');
|
||||
Configure::write('Cache.disable', false);
|
||||
|
||||
$this->_defaultCacheConfig = Cache::config('default');
|
||||
Cache::config('default', array('engine' => 'File', 'path' => TMP . 'tests'));
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
Configure::write('Cache.disable', $this->_cacheDisable);
|
||||
Cache::config('default', $this->_defaultCacheConfig['settings']);
|
||||
}
|
||||
|
||||
/**
|
||||
* testConfig method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConfig() {
|
||||
$settings = array('engine' => 'File', 'path' => TMP . 'tests', 'prefix' => 'cake_test_');
|
||||
$results = Cache::config('new', $settings);
|
||||
$this->assertEquals(Cache::config('new'), $results);
|
||||
$this->assertTrue(isset($results['engine']));
|
||||
$this->assertTrue(isset($results['settings']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that no fatal errors are issued doing normal things when Cache.disable is true.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNonFatalErrorsWithCachedisable() {
|
||||
Configure::write('Cache.disable', true);
|
||||
Cache::config('test', array('engine' => 'File', 'path' => TMP, 'prefix' => 'error_test_'));
|
||||
|
||||
Cache::write('no_save', 'Noooo!', 'test');
|
||||
Cache::read('no_save', 'test');
|
||||
Cache::delete('no_save', 'test');
|
||||
Cache::set('duration', '+10 minutes');
|
||||
|
||||
Configure::write('Cache.disable', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* test configuring CacheEngines in App/libs
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConfigWithLibAndPluginEngines() {
|
||||
App::build(array(
|
||||
'Lib' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Lib' . DS),
|
||||
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
||||
), App::RESET);
|
||||
CakePlugin::load('TestPlugin');
|
||||
|
||||
$settings = array('engine' => 'TestAppCache', 'path' => TMP, 'prefix' => 'cake_test_');
|
||||
$result = Cache::config('libEngine', $settings);
|
||||
$this->assertEquals(Cache::config('libEngine'), $result);
|
||||
|
||||
$settings = array('engine' => 'TestPlugin.TestPluginCache', 'path' => TMP, 'prefix' => 'cake_test_');
|
||||
$result = Cache::config('pluginLibEngine', $settings);
|
||||
$this->assertEquals(Cache::config('pluginLibEngine'), $result);
|
||||
|
||||
Cache::drop('libEngine');
|
||||
Cache::drop('pluginLibEngine');
|
||||
|
||||
App::build();
|
||||
CakePlugin::unload();
|
||||
}
|
||||
|
||||
/**
|
||||
* testInvalidConfig method
|
||||
*
|
||||
* Test that the cache class doesn't cause fatal errors with a partial path
|
||||
*
|
||||
* @expectedException PHPUnit_Framework_Error_Warning
|
||||
* @return void
|
||||
*/
|
||||
public function testInvalidConfig() {
|
||||
Cache::config('invalid', array(
|
||||
'engine' => 'File',
|
||||
'duration' => '+1 year',
|
||||
'prefix' => 'testing_invalid_',
|
||||
'path' => 'data/',
|
||||
'serialize' => true,
|
||||
'random' => 'wii'
|
||||
));
|
||||
$read = Cache::read('Test', 'invalid');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test reading from a config that is undefined.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testReadNonExistingConfig() {
|
||||
$this->assertFalse(Cache::read('key', 'totally fake'));
|
||||
$this->assertFalse(Cache::write('key', 'value', 'totally fake'));
|
||||
$this->assertFalse(Cache::increment('key', 1, 'totally fake'));
|
||||
$this->assertFalse(Cache::decrement('key', 1, 'totally fake'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test that trying to configure classes that don't extend CacheEngine fail.
|
||||
*
|
||||
* @expectedException CacheException
|
||||
* @return void
|
||||
*/
|
||||
public function testAttemptingToConfigureANonCacheEngineClass() {
|
||||
$this->getMock('StdClass', array(), array(), 'RubbishEngine');
|
||||
Cache::config('Garbage', array(
|
||||
'engine' => 'Rubbish'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* testConfigChange method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConfigChange() {
|
||||
$_cacheConfigSessions = Cache::config('sessions');
|
||||
$_cacheConfigTests = Cache::config('tests');
|
||||
|
||||
$result = Cache::config('sessions', array('engine' => 'File', 'path' => TMP . 'sessions'));
|
||||
$this->assertEquals(Cache::settings('sessions'), $result['settings']);
|
||||
|
||||
$result = Cache::config('tests', array('engine' => 'File', 'path' => TMP . 'tests'));
|
||||
$this->assertEquals(Cache::settings('tests'), $result['settings']);
|
||||
|
||||
Cache::config('sessions', $_cacheConfigSessions['settings']);
|
||||
Cache::config('tests', $_cacheConfigTests['settings']);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that calling config() sets the 'default' configuration up.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConfigSettingDefaultConfigKey() {
|
||||
Cache::config('test_name', array('engine' => 'File', 'prefix' => 'test_name_'));
|
||||
|
||||
Cache::write('value_one', 'I am cached', 'test_name');
|
||||
$result = Cache::read('value_one', 'test_name');
|
||||
$this->assertEquals('I am cached', $result);
|
||||
|
||||
$result = Cache::read('value_one');
|
||||
$this->assertEquals(null, $result);
|
||||
|
||||
Cache::write('value_one', 'I am in default config!');
|
||||
$result = Cache::read('value_one');
|
||||
$this->assertEquals('I am in default config!', $result);
|
||||
|
||||
$result = Cache::read('value_one', 'test_name');
|
||||
$this->assertEquals('I am cached', $result);
|
||||
|
||||
Cache::delete('value_one', 'test_name');
|
||||
Cache::delete('value_one', 'default');
|
||||
}
|
||||
|
||||
/**
|
||||
* testWritingWithConfig method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testWritingWithConfig() {
|
||||
$_cacheConfigSessions = Cache::config('sessions');
|
||||
|
||||
Cache::write('test_something', 'this is the test data', 'tests');
|
||||
|
||||
$expected = array(
|
||||
'path' => TMP . 'sessions' . DS,
|
||||
'prefix' => 'cake_',
|
||||
'lock' => true,
|
||||
'serialize' => true,
|
||||
'duration' => 3600,
|
||||
'probability' => 100,
|
||||
'engine' => 'File',
|
||||
'isWindows' => DIRECTORY_SEPARATOR == '\\',
|
||||
'mask' => 0664,
|
||||
'groups' => array()
|
||||
);
|
||||
$this->assertEquals($expected, Cache::settings('sessions'));
|
||||
|
||||
Cache::config('sessions', $_cacheConfigSessions['settings']);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that configured returns an array of the currently configured cache
|
||||
* settings
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConfigured() {
|
||||
$result = Cache::configured();
|
||||
$this->assertTrue(in_array('_cake_core_', $result));
|
||||
$this->assertTrue(in_array('default', $result));
|
||||
}
|
||||
|
||||
/**
|
||||
* testInitSettings method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInitSettings() {
|
||||
$initial = Cache::settings();
|
||||
$override = array('engine' => 'File', 'path' => TMP . 'tests');
|
||||
Cache::config('for_test', $override);
|
||||
|
||||
$settings = Cache::settings();
|
||||
$expecting = $override + $initial;
|
||||
$this->assertEquals($settings, $expecting);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that drop removes cache configs, and that further attempts to use that config
|
||||
* do not work.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDrop() {
|
||||
App::build(array(
|
||||
'Lib' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Lib' . DS),
|
||||
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
||||
), App::RESET);
|
||||
|
||||
$result = Cache::drop('some_config_that_does_not_exist');
|
||||
$this->assertFalse($result);
|
||||
|
||||
$_testsConfig = Cache::config('tests');
|
||||
$result = Cache::drop('tests');
|
||||
$this->assertTrue($result);
|
||||
|
||||
Cache::config('unconfigTest', array(
|
||||
'engine' => 'TestAppCache'
|
||||
));
|
||||
$this->assertTrue(Cache::isInitialized('unconfigTest'));
|
||||
|
||||
$this->assertTrue(Cache::drop('unconfigTest'));
|
||||
$this->assertFalse(Cache::isInitialized('TestAppCache'));
|
||||
|
||||
Cache::config('tests', $_testsConfig);
|
||||
App::build();
|
||||
}
|
||||
|
||||
/**
|
||||
* testWriteEmptyValues method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testWriteEmptyValues() {
|
||||
Cache::write('App.falseTest', false);
|
||||
$this->assertSame(Cache::read('App.falseTest'), false);
|
||||
|
||||
Cache::write('App.trueTest', true);
|
||||
$this->assertSame(Cache::read('App.trueTest'), true);
|
||||
|
||||
Cache::write('App.nullTest', null);
|
||||
$this->assertSame(Cache::read('App.nullTest'), null);
|
||||
|
||||
Cache::write('App.zeroTest', 0);
|
||||
$this->assertSame(Cache::read('App.zeroTest'), 0);
|
||||
|
||||
Cache::write('App.zeroTest2', '0');
|
||||
$this->assertSame(Cache::read('App.zeroTest2'), '0');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that failed writes cause errors to be triggered.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testWriteTriggerError() {
|
||||
App::build(array(
|
||||
'Lib' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Lib' . DS),
|
||||
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
||||
), App::RESET);
|
||||
|
||||
Cache::config('test_trigger', array('engine' => 'TestAppCache', 'prefix' => ''));
|
||||
try {
|
||||
Cache::write('fail', 'value', 'test_trigger');
|
||||
$this->fail('No exception thrown');
|
||||
} catch (PHPUnit_Framework_Error $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
Cache::drop('test_trigger');
|
||||
App::build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public 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', 'test_cache_disable_1'));
|
||||
$this->assertSame(Cache::read('key_1', 'test_cache_disable_1'), 'hello');
|
||||
|
||||
Configure::write('Cache.disable', true);
|
||||
|
||||
$this->assertFalse(Cache::write('key_2', 'hello', 'test_cache_disable_1'));
|
||||
$this->assertFalse(Cache::read('key_2', 'test_cache_disable_1'));
|
||||
|
||||
Configure::write('Cache.disable', false);
|
||||
|
||||
$this->assertTrue(Cache::write('key_3', 'hello', 'test_cache_disable_1'));
|
||||
$this->assertSame(Cache::read('key_3', 'test_cache_disable_1'), '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', 'test_cache_disable_2'));
|
||||
$this->assertFalse(Cache::read('key_4', 'test_cache_disable_2'));
|
||||
|
||||
Configure::write('Cache.disable', false);
|
||||
|
||||
$this->assertTrue(Cache::write('key_5', 'hello', 'test_cache_disable_2'));
|
||||
$this->assertSame(Cache::read('key_5', 'test_cache_disable_2'), 'hello');
|
||||
|
||||
Configure::write('Cache.disable', true);
|
||||
|
||||
$this->assertFalse(Cache::write('key_6', 'hello', 'test_cache_disable_2'));
|
||||
$this->assertFalse(Cache::read('key_6', 'test_cache_disable_2'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testSet method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSet() {
|
||||
$_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->assertEquals('this is just a simple test of the cache system', $data);
|
||||
|
||||
Cache::delete('test_cache');
|
||||
|
||||
$global = Cache::settings();
|
||||
|
||||
Cache::set($_cacheSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* test set() parameter handling for user cache configs.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetOnAlternateConfigs() {
|
||||
Cache::config('file_config', array('engine' => 'File', 'prefix' => 'test_file_'));
|
||||
Cache::set(array('duration' => '+1 year'), 'file_config');
|
||||
$settings = Cache::settings('file_config');
|
||||
|
||||
$this->assertEquals('test_file_', $settings['prefix']);
|
||||
$this->assertEquals(strtotime('+1 year') - time(), $settings['duration']);
|
||||
}
|
||||
}
|
||||
273
lib/Cake/Test/Case/Cache/Engine/ApcEngineTest.php
Normal file
273
lib/Cake/Test/Case/Cache/Engine/ApcEngineTest.php
Normal file
|
|
@ -0,0 +1,273 @@
|
|||
<?php
|
||||
/**
|
||||
* ApcEngineTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
||||
* @package Cake.Test.Case.Cache.Engine
|
||||
* @since CakePHP(tm) v 1.2.0.5434
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
App::uses('Cache', 'Cache');
|
||||
|
||||
/**
|
||||
* ApcEngineTest class
|
||||
*
|
||||
* @package Cake.Test.Case.Cache.Engine
|
||||
*/
|
||||
class ApcEngineTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->skipIf(!function_exists('apc_store'), 'Apc is not installed or configured properly.');
|
||||
|
||||
$this->_cacheDisable = Configure::read('Cache.disable');
|
||||
Configure::write('Cache.disable', false);
|
||||
Cache::config('apc', array('engine' => 'Apc', 'prefix' => 'cake_'));
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
Configure::write('Cache.disable', $this->_cacheDisable);
|
||||
Cache::drop('apc');
|
||||
Cache::drop('apc_groups');
|
||||
Cache::config('default');
|
||||
}
|
||||
|
||||
/**
|
||||
* testReadAndWriteCache method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testReadAndWriteCache() {
|
||||
Cache::set(array('duration' => 1), 'apc');
|
||||
|
||||
$result = Cache::read('test', 'apc');
|
||||
$expecting = '';
|
||||
$this->assertEquals($expecting, $result);
|
||||
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('test', $data, 'apc');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = Cache::read('test', 'apc');
|
||||
$expecting = $data;
|
||||
$this->assertEquals($expecting, $result);
|
||||
|
||||
Cache::delete('test', 'apc');
|
||||
}
|
||||
|
||||
/**
|
||||
* Writing cache entries with duration = 0 (forever) should work.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testReadWriteDurationZero() {
|
||||
Cache::config('apc', array('engine' => 'Apc', 'duration' => 0, 'prefix' => 'cake_'));
|
||||
Cache::write('zero', 'Should save', 'apc');
|
||||
sleep(1);
|
||||
|
||||
$result = Cache::read('zero', 'apc');
|
||||
$this->assertEquals('Should save', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testExpiry method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExpiry() {
|
||||
Cache::set(array('duration' => 1), 'apc');
|
||||
|
||||
$result = Cache::read('test', 'apc');
|
||||
$this->assertFalse($result);
|
||||
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('other_test', $data, 'apc');
|
||||
$this->assertTrue($result);
|
||||
|
||||
sleep(2);
|
||||
$result = Cache::read('other_test', 'apc');
|
||||
$this->assertFalse($result);
|
||||
|
||||
Cache::set(array('duration' => 1), 'apc');
|
||||
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('other_test', $data, 'apc');
|
||||
$this->assertTrue($result);
|
||||
|
||||
sleep(2);
|
||||
$result = Cache::read('other_test', 'apc');
|
||||
$this->assertFalse($result);
|
||||
|
||||
sleep(2);
|
||||
$result = Cache::read('other_test', 'apc');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDeleteCache method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeleteCache() {
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('delete_test', $data, 'apc');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = Cache::delete('delete_test', 'apc');
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDecrement method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDecrement() {
|
||||
$this->skipIf(!function_exists('apc_dec'), 'No apc_dec() function, cannot test decrement().');
|
||||
|
||||
$result = Cache::write('test_decrement', 5, 'apc');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = Cache::decrement('test_decrement', 1, 'apc');
|
||||
$this->assertEquals(4, $result);
|
||||
|
||||
$result = Cache::read('test_decrement', 'apc');
|
||||
$this->assertEquals(4, $result);
|
||||
|
||||
$result = Cache::decrement('test_decrement', 2, 'apc');
|
||||
$this->assertEquals(2, $result);
|
||||
|
||||
$result = Cache::read('test_decrement', 'apc');
|
||||
$this->assertEquals(2, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testIncrement method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIncrement() {
|
||||
$this->skipIf(!function_exists('apc_inc'), 'No apc_inc() function, cannot test increment().');
|
||||
|
||||
$result = Cache::write('test_increment', 5, 'apc');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = Cache::increment('test_increment', 1, 'apc');
|
||||
$this->assertEquals(6, $result);
|
||||
|
||||
$result = Cache::read('test_increment', 'apc');
|
||||
$this->assertEquals(6, $result);
|
||||
|
||||
$result = Cache::increment('test_increment', 2, 'apc');
|
||||
$this->assertEquals(8, $result);
|
||||
|
||||
$result = Cache::read('test_increment', 'apc');
|
||||
$this->assertEquals(8, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test the clearing of cache keys
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testClear() {
|
||||
apc_store('not_cake', 'survive');
|
||||
Cache::write('some_value', 'value', 'apc');
|
||||
|
||||
$result = Cache::clear(false, 'apc');
|
||||
$this->assertTrue($result);
|
||||
$this->assertFalse(Cache::read('some_value', 'apc'));
|
||||
$this->assertEquals('survive', apc_fetch('not_cake'));
|
||||
apc_delete('not_cake');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that configuring groups for stored keys return the correct values when read/written
|
||||
* Shows that altering the group value is equivalent to deleting all keys under the same
|
||||
* group
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGroupsReadWrite() {
|
||||
Cache::config('apc_groups', array(
|
||||
'engine' => 'Apc',
|
||||
'duration' => 0,
|
||||
'groups' => array('group_a', 'group_b'),
|
||||
'prefix' => 'test_'
|
||||
));
|
||||
$this->assertTrue(Cache::write('test_groups', 'value', 'apc_groups'));
|
||||
$this->assertEquals('value', Cache::read('test_groups', 'apc_groups'));
|
||||
|
||||
apc_inc('test_group_a');
|
||||
$this->assertFalse(Cache::read('test_groups', 'apc_groups'));
|
||||
$this->assertTrue(Cache::write('test_groups', 'value2', 'apc_groups'));
|
||||
$this->assertEquals('value2', Cache::read('test_groups', 'apc_groups'));
|
||||
|
||||
apc_inc('test_group_b');
|
||||
$this->assertFalse(Cache::read('test_groups', 'apc_groups'));
|
||||
$this->assertTrue(Cache::write('test_groups', 'value3', 'apc_groups'));
|
||||
$this->assertEquals('value3', Cache::read('test_groups', 'apc_groups'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that deleteing from a groups-enabled config is possible
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGroupDelete() {
|
||||
Cache::config('apc_groups', array(
|
||||
'engine' => 'Apc',
|
||||
'duration' => 0,
|
||||
'groups' => array('group_a', 'group_b'),
|
||||
'prefix' => 'test_'
|
||||
));
|
||||
$this->assertTrue(Cache::write('test_groups', 'value', 'apc_groups'));
|
||||
$this->assertEquals('value', Cache::read('test_groups', 'apc_groups'));
|
||||
$this->assertTrue(Cache::delete('test_groups', 'apc_groups'));
|
||||
|
||||
$this->assertFalse(Cache::read('test_groups', 'apc_groups'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test clearing a cache group
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
public function testGroupClear() {
|
||||
Cache::config('apc_groups', array(
|
||||
'engine' => 'Apc',
|
||||
'duration' => 0,
|
||||
'groups' => array('group_a', 'group_b'),
|
||||
'prefix' => 'test_'
|
||||
));
|
||||
|
||||
$this->assertTrue(Cache::write('test_groups', 'value', 'apc_groups'));
|
||||
$this->assertTrue(Cache::clearGroup('group_a', 'apc_groups'));
|
||||
$this->assertFalse(Cache::read('test_groups', 'apc_groups'));
|
||||
|
||||
$this->assertTrue(Cache::write('test_groups', 'value2', 'apc_groups'));
|
||||
$this->assertTrue(Cache::clearGroup('group_b', 'apc_groups'));
|
||||
$this->assertFalse(Cache::read('test_groups', 'apc_groups'));
|
||||
}
|
||||
}
|
||||
455
lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php
Normal file
455
lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php
Normal file
|
|
@ -0,0 +1,455 @@
|
|||
<?php
|
||||
/**
|
||||
* FileEngineTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
||||
* @package Cake.Test.Case.Cache.Engine
|
||||
* @since CakePHP(tm) v 1.2.0.5434
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
App::uses('Cache', 'Cache');
|
||||
|
||||
/**
|
||||
* FileEngineTest class
|
||||
*
|
||||
* @package Cake.Test.Case.Cache.Engine
|
||||
*/
|
||||
class FileEngineTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* config property
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $config = array();
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
Configure::write('Cache.disable', false);
|
||||
Cache::config('file_test', array('engine' => 'File', 'path' => CACHE));
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
Cache::clear(false, 'file_test');
|
||||
Cache::drop('file_test');
|
||||
Cache::drop('file_groups');
|
||||
Cache::drop('file_groups2');
|
||||
Cache::drop('file_groups3');
|
||||
}
|
||||
|
||||
/**
|
||||
* testCacheDirChange method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCacheDirChange() {
|
||||
$result = Cache::config('sessions', array('engine' => 'File', 'path' => TMP . 'sessions'));
|
||||
$this->assertEquals(Cache::settings('sessions'), $result['settings']);
|
||||
|
||||
$result = Cache::config('sessions', array('engine' => 'File', 'path' => TMP . 'tests'));
|
||||
$this->assertEquals(Cache::settings('sessions'), $result['settings']);
|
||||
$this->assertNotEquals(Cache::settings('default'), $result['settings']);
|
||||
}
|
||||
|
||||
/**
|
||||
* testReadAndWriteCache method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testReadAndWriteCache() {
|
||||
Cache::config('default');
|
||||
|
||||
$result = Cache::write(null, 'here', 'file_test');
|
||||
$this->assertFalse($result);
|
||||
|
||||
Cache::set(array('duration' => 1), 'file_test');
|
||||
|
||||
$result = Cache::read('test', 'file_test');
|
||||
$expecting = '';
|
||||
$this->assertEquals($expecting, $result);
|
||||
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('test', $data, 'file_test');
|
||||
$this->assertTrue(file_exists(CACHE . 'cake_test'));
|
||||
|
||||
$result = Cache::read('test', 'file_test');
|
||||
$expecting = $data;
|
||||
$this->assertEquals($expecting, $result);
|
||||
|
||||
Cache::delete('test', 'file_test');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test read/write on the same cache key. Ensures file handles are re-wound.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConsecutiveReadWrite() {
|
||||
Cache::write('rw', 'first write', 'file_test');
|
||||
$result = Cache::read('rw', 'file_test');
|
||||
|
||||
Cache::write('rw', 'second write', 'file_test');
|
||||
$resultB = Cache::read('rw', 'file_test');
|
||||
|
||||
Cache::delete('rw', 'file_test');
|
||||
$this->assertEquals('first write', $result);
|
||||
$this->assertEquals('second write', $resultB);
|
||||
}
|
||||
|
||||
/**
|
||||
* testExpiry method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExpiry() {
|
||||
Cache::set(array('duration' => 1), 'file_test');
|
||||
|
||||
$result = Cache::read('test', 'file_test');
|
||||
$this->assertFalse($result);
|
||||
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('other_test', $data, 'file_test');
|
||||
$this->assertTrue($result);
|
||||
|
||||
sleep(2);
|
||||
$result = Cache::read('other_test', 'file_test');
|
||||
$this->assertFalse($result);
|
||||
|
||||
Cache::set(array('duration' => "+1 second"), 'file_test');
|
||||
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('other_test', $data, 'file_test');
|
||||
$this->assertTrue($result);
|
||||
|
||||
sleep(2);
|
||||
$result = Cache::read('other_test', 'file_test');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDeleteCache method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeleteCache() {
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('delete_test', $data, 'file_test');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = Cache::delete('delete_test', 'file_test');
|
||||
$this->assertTrue($result);
|
||||
$this->assertFalse(file_exists(TMP . 'tests' . DS . 'delete_test'));
|
||||
|
||||
$result = Cache::delete('delete_test', 'file_test');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testSerialize method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSerialize() {
|
||||
Cache::config('file_test', array('engine' => 'File', 'serialize' => true));
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$write = Cache::write('serialize_test', $data, 'file_test');
|
||||
$this->assertTrue($write);
|
||||
|
||||
Cache::config('file_test', array('serialize' => false));
|
||||
$read = Cache::read('serialize_test', 'file_test');
|
||||
|
||||
$newread = Cache::read('serialize_test', 'file_test');
|
||||
|
||||
$delete = Cache::delete('serialize_test', 'file_test');
|
||||
|
||||
$this->assertSame($read, serialize($data));
|
||||
|
||||
$this->assertSame(unserialize($newread), $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* testClear method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testClear() {
|
||||
Cache::config('file_test', array('engine' => 'File', 'duration' => 1));
|
||||
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$write = Cache::write('serialize_test1', $data, 'file_test');
|
||||
$write = Cache::write('serialize_test2', $data, 'file_test');
|
||||
$write = Cache::write('serialize_test3', $data, 'file_test');
|
||||
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test1'));
|
||||
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test2'));
|
||||
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test3'));
|
||||
sleep(2);
|
||||
$result = Cache::clear(true, 'file_test');
|
||||
$this->assertTrue($result);
|
||||
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test1'));
|
||||
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test2'));
|
||||
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test3'));
|
||||
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$write = Cache::write('serialize_test1', $data, 'file_test');
|
||||
$write = Cache::write('serialize_test2', $data, 'file_test');
|
||||
$write = Cache::write('serialize_test3', $data, 'file_test');
|
||||
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test1'));
|
||||
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test2'));
|
||||
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test3'));
|
||||
|
||||
$result = Cache::clear(false, 'file_test');
|
||||
$this->assertTrue($result);
|
||||
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test1'));
|
||||
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test2'));
|
||||
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test3'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test that clear() doesn't wipe files not in the current engine's prefix.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testClearWithPrefixes() {
|
||||
$FileOne = new FileEngine();
|
||||
$FileOne->init(array(
|
||||
'prefix' => 'prefix_one_',
|
||||
'duration' => DAY
|
||||
));
|
||||
$FileTwo = new FileEngine();
|
||||
$FileTwo->init(array(
|
||||
'prefix' => 'prefix_two_',
|
||||
'duration' => DAY
|
||||
));
|
||||
|
||||
$dataOne = $dataTwo = $expected = 'content to cache';
|
||||
$FileOne->write('prefix_one_key_one', $dataOne, DAY);
|
||||
$FileTwo->write('prefix_two_key_two', $dataTwo, DAY);
|
||||
|
||||
$this->assertEquals($expected, $FileOne->read('prefix_one_key_one'));
|
||||
$this->assertEquals($expected, $FileTwo->read('prefix_two_key_two'));
|
||||
|
||||
$FileOne->clear(false);
|
||||
$this->assertEquals($expected, $FileTwo->read('prefix_two_key_two'), 'secondary config was cleared by accident.');
|
||||
$FileTwo->clear(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* testKeyPath method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testKeyPath() {
|
||||
$result = Cache::write('views.countries.something', 'here', 'file_test');
|
||||
$this->assertTrue($result);
|
||||
$this->assertTrue(file_exists(CACHE . 'cake_views_countries_something'));
|
||||
|
||||
$result = Cache::read('views.countries.something', 'file_test');
|
||||
$this->assertEquals('here', $result);
|
||||
|
||||
$result = Cache::clear(false, 'file_test');
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testRemoveWindowsSlashesFromCache method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRemoveWindowsSlashesFromCache() {
|
||||
Cache::config('windows_test', array('engine' => 'File', 'isWindows' => true, 'prefix' => null, 'path' => TMP));
|
||||
|
||||
$expected = array(
|
||||
'C:\dev\prj2\sites\cake\libs' => array(
|
||||
0 => 'C:\dev\prj2\sites\cake\libs', 1 => 'C:\dev\prj2\sites\cake\libs\view',
|
||||
2 => 'C:\dev\prj2\sites\cake\libs\view\scaffolds', 3 => 'C:\dev\prj2\sites\cake\libs\view\pages',
|
||||
4 => 'C:\dev\prj2\sites\cake\libs\view\layouts', 5 => 'C:\dev\prj2\sites\cake\libs\view\layouts\xml',
|
||||
6 => 'C:\dev\prj2\sites\cake\libs\view\layouts\rss', 7 => 'C:\dev\prj2\sites\cake\libs\view\layouts\js',
|
||||
8 => 'C:\dev\prj2\sites\cake\libs\view\layouts\email', 9 => 'C:\dev\prj2\sites\cake\libs\view\layouts\email\text',
|
||||
10 => 'C:\dev\prj2\sites\cake\libs\view\layouts\email\html', 11 => 'C:\dev\prj2\sites\cake\libs\view\helpers',
|
||||
12 => 'C:\dev\prj2\sites\cake\libs\view\errors', 13 => 'C:\dev\prj2\sites\cake\libs\view\elements',
|
||||
14 => 'C:\dev\prj2\sites\cake\libs\view\elements\email', 15 => 'C:\dev\prj2\sites\cake\libs\view\elements\email\text',
|
||||
16 => 'C:\dev\prj2\sites\cake\libs\view\elements\email\html', 17 => 'C:\dev\prj2\sites\cake\libs\model',
|
||||
18 => 'C:\dev\prj2\sites\cake\libs\model\datasources', 19 => 'C:\dev\prj2\sites\cake\libs\model\datasources\dbo',
|
||||
20 => 'C:\dev\prj2\sites\cake\libs\model\behaviors', 21 => 'C:\dev\prj2\sites\cake\libs\controller',
|
||||
22 => 'C:\dev\prj2\sites\cake\libs\controller\components', 23 => 'C:\dev\prj2\sites\cake\libs\cache'),
|
||||
'C:\dev\prj2\sites\main_site\vendors' => array(
|
||||
0 => 'C:\dev\prj2\sites\main_site\vendors', 1 => 'C:\dev\prj2\sites\main_site\vendors\shells',
|
||||
2 => 'C:\dev\prj2\sites\main_site\vendors\shells\templates', 3 => 'C:\dev\prj2\sites\main_site\vendors\shells\templates\cdc_project',
|
||||
4 => 'C:\dev\prj2\sites\main_site\vendors\shells\tasks', 5 => 'C:\dev\prj2\sites\main_site\vendors\js',
|
||||
6 => 'C:\dev\prj2\sites\main_site\vendors\css'),
|
||||
'C:\dev\prj2\sites\vendors' => array(
|
||||
0 => 'C:\dev\prj2\sites\vendors', 1 => 'C:\dev\prj2\sites\vendors\simpletest',
|
||||
2 => 'C:\dev\prj2\sites\vendors\simpletest\test', 3 => 'C:\dev\prj2\sites\vendors\simpletest\test\support',
|
||||
4 => 'C:\dev\prj2\sites\vendors\simpletest\test\support\collector', 5 => 'C:\dev\prj2\sites\vendors\simpletest\extensions',
|
||||
6 => 'C:\dev\prj2\sites\vendors\simpletest\extensions\testdox', 7 => 'C:\dev\prj2\sites\vendors\simpletest\docs',
|
||||
8 => 'C:\dev\prj2\sites\vendors\simpletest\docs\fr', 9 => 'C:\dev\prj2\sites\vendors\simpletest\docs\en'),
|
||||
'C:\dev\prj2\sites\main_site\views\helpers' => array(
|
||||
0 => 'C:\dev\prj2\sites\main_site\views\helpers')
|
||||
);
|
||||
|
||||
Cache::write('test_dir_map', $expected, 'windows_test');
|
||||
$data = Cache::read('test_dir_map', 'windows_test');
|
||||
Cache::delete('test_dir_map', 'windows_test');
|
||||
$this->assertEquals($expected, $data);
|
||||
|
||||
Cache::drop('windows_test');
|
||||
}
|
||||
|
||||
/**
|
||||
* testWriteQuotedString method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testWriteQuotedString() {
|
||||
Cache::config('file_test', array('engine' => 'File', 'path' => TMP . 'tests'));
|
||||
Cache::write('App.doubleQuoteTest', '"this is a quoted string"', 'file_test');
|
||||
$this->assertSame(Cache::read('App.doubleQuoteTest', 'file_test'), '"this is a quoted string"');
|
||||
Cache::write('App.singleQuoteTest', "'this is a quoted string'", 'file_test');
|
||||
$this->assertSame(Cache::read('App.singleQuoteTest', 'file_test'), "'this is a quoted string'");
|
||||
|
||||
Cache::config('file_test', array('isWindows' => true, 'path' => TMP . 'tests'));
|
||||
$this->assertSame(Cache::read('App.doubleQuoteTest', 'file_test'), '"this is a quoted string"');
|
||||
Cache::write('App.singleQuoteTest', "'this is a quoted string'", 'file_test');
|
||||
$this->assertSame(Cache::read('App.singleQuoteTest', 'file_test'), "'this is a quoted string'");
|
||||
Cache::delete('App.singleQuoteTest', 'file_test');
|
||||
Cache::delete('App.doubleQuoteTest', 'file_test');
|
||||
}
|
||||
|
||||
/**
|
||||
* check that FileEngine generates an error when a configured Path does not exist.
|
||||
*
|
||||
* @expectedException PHPUnit_Framework_Error_Warning
|
||||
* @return void
|
||||
*/
|
||||
public function testErrorWhenPathDoesNotExist() {
|
||||
$this->skipIf(is_dir(TMP . 'tests' . DS . 'file_failure'), 'Cannot run test directory exists.');
|
||||
|
||||
Cache::config('failure', array(
|
||||
'engine' => 'File',
|
||||
'path' => TMP . 'tests' . DS . 'file_failure'
|
||||
));
|
||||
|
||||
Cache::drop('failure');
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing the mask setting in FileEngine
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMaskSetting() {
|
||||
if (DS === '\\') {
|
||||
$this->markTestSkipped('File permission testing does not work on Windows.');
|
||||
}
|
||||
Cache::config('mask_test', array('engine' => 'File', 'path' => TMP . 'tests'));
|
||||
$data = 'This is some test content';
|
||||
$write = Cache::write('masking_test', $data, 'mask_test');
|
||||
$result = substr(sprintf('%o',fileperms(TMP . 'tests' . DS . 'cake_masking_test')), -4);
|
||||
$expected = '0664';
|
||||
$this->assertEquals($expected, $result);
|
||||
Cache::delete('masking_test', 'mask_test');
|
||||
Cache::drop('mask_test');
|
||||
|
||||
Cache::config('mask_test', array('engine' => 'File', 'mask' => 0666, 'path' => TMP . 'tests'));
|
||||
$write = Cache::write('masking_test', $data, 'mask_test');
|
||||
$result = substr(sprintf('%o',fileperms(TMP . 'tests' . DS . 'cake_masking_test')), -4);
|
||||
$expected = '0666';
|
||||
$this->assertEquals($expected, $result);
|
||||
Cache::delete('masking_test', 'mask_test');
|
||||
Cache::drop('mask_test');
|
||||
|
||||
Cache::config('mask_test', array('engine' => 'File', 'mask' => 0644, 'path' => TMP . 'tests'));
|
||||
$write = Cache::write('masking_test', $data, 'mask_test');
|
||||
$result = substr(sprintf('%o',fileperms(TMP . 'tests' . DS . 'cake_masking_test')), -4);
|
||||
$expected = '0644';
|
||||
$this->assertEquals($expected, $result);
|
||||
Cache::delete('masking_test', 'mask_test');
|
||||
Cache::drop('mask_test');
|
||||
|
||||
Cache::config('mask_test', array('engine' => 'File', 'mask' => 0640, 'path' => TMP . 'tests'));
|
||||
$write = Cache::write('masking_test', $data, 'mask_test');
|
||||
$result = substr(sprintf('%o',fileperms(TMP . 'tests' . DS . 'cake_masking_test')), -4);
|
||||
$expected = '0640';
|
||||
$this->assertEquals($expected, $result);
|
||||
Cache::delete('masking_test', 'mask_test');
|
||||
Cache::drop('mask_test');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that configuring groups for stored keys return the correct values when read/written
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGroupsReadWrite() {
|
||||
Cache::config('file_groups', array('engine' => 'File', 'duration' => 3600, 'groups' => array('group_a', 'group_b')));
|
||||
$this->assertTrue(Cache::write('test_groups', 'value', 'file_groups'));
|
||||
$this->assertEquals('value', Cache::read('test_groups', 'file_groups'));
|
||||
|
||||
$this->assertTrue(Cache::write('test_groups2', 'value2', 'file_groups'));
|
||||
$this->assertTrue(Cache::write('test_groups3', 'value3', 'file_groups'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that deleteing from a groups-enabled config is possible
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGroupDelete() {
|
||||
Cache::config('file_groups', array('engine' => 'File', 'duration' => 3600, 'groups' => array('group_a', 'group_b')));
|
||||
$this->assertTrue(Cache::write('test_groups', 'value', 'file_groups'));
|
||||
$this->assertEquals('value', Cache::read('test_groups', 'file_groups'));
|
||||
$this->assertTrue(Cache::delete('test_groups', 'file_groups'));
|
||||
|
||||
$this->assertFalse(Cache::read('test_groups', 'file_groups'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test clearing a cache group
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
public function testGroupClear() {
|
||||
Cache::config('file_groups', array('engine' => 'File', 'duration' => 3600, 'groups' => array('group_a', 'group_b')));
|
||||
Cache::config('file_groups2', array('engine' => 'File', 'duration' => 3600, 'groups' => array('group_b')));
|
||||
Cache::config('file_groups3', array('engine' => 'File', 'duration' => 3600, 'groups' => array('group_a')));
|
||||
|
||||
$this->assertTrue(Cache::write('test_groups', 'value', 'file_groups'));
|
||||
$this->assertTrue(Cache::write('test_groups2', 'value', 'file_groups2'));
|
||||
$this->assertTrue(Cache::write('test_groups3', 'value', 'file_groups3'));
|
||||
|
||||
$this->assertTrue(Cache::clearGroup('group_a', 'file_groups'));
|
||||
$this->assertFalse(Cache::read('test_groups', 'file_groups'));
|
||||
$this->assertEquals('value', Cache::read('test_groups2', 'file_groups2'));
|
||||
$this->assertFalse(Cache::read('test_groups3', 'file_groups3'));
|
||||
|
||||
$this->assertTrue(Cache::write('test_groups4', 'value', 'file_groups'));
|
||||
$this->assertTrue(Cache::write('test_groups5', 'value', 'file_groups2'));
|
||||
$this->assertTrue(Cache::write('test_groups6', 'value', 'file_groups3'));
|
||||
|
||||
$this->assertTrue(Cache::clearGroup('group_b', 'file_groups'));
|
||||
$this->assertFalse(Cache::read('test_groups4', 'file_groups'));
|
||||
$this->assertFalse(Cache::read('test_groups5', 'file_groups2'));
|
||||
$this->assertEquals('value', Cache::read('test_groups6', 'file_groups3'));
|
||||
}
|
||||
}
|
||||
479
lib/Cake/Test/Case/Cache/Engine/MemcacheEngineTest.php
Normal file
479
lib/Cake/Test/Case/Cache/Engine/MemcacheEngineTest.php
Normal file
|
|
@ -0,0 +1,479 @@
|
|||
<?php
|
||||
/**
|
||||
* MemcacheEngineTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
||||
* @package Cake.Test.Case.Cache.Engine
|
||||
* @since CakePHP(tm) v 1.2.0.5434
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
App::uses('Cache', 'Cache');
|
||||
App::uses('MemcacheEngine', 'Cache/Engine');
|
||||
|
||||
class TestMemcacheEngine extends MemcacheEngine {
|
||||
|
||||
/**
|
||||
* public accessor to _parseServerString
|
||||
*
|
||||
* @param string $server
|
||||
* @return array
|
||||
*/
|
||||
public function parseServerString($server) {
|
||||
return $this->_parseServerString($server);
|
||||
}
|
||||
|
||||
public function setMemcache($memcache) {
|
||||
$this->_Memcache = $memcache;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* MemcacheEngineTest class
|
||||
*
|
||||
* @package Cake.Test.Case.Cache.Engine
|
||||
*/
|
||||
class MemcacheEngineTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->skipIf(!class_exists('Memcache'), 'Memcache is not installed or configured properly.');
|
||||
|
||||
$this->_cacheDisable = Configure::read('Cache.disable');
|
||||
Configure::write('Cache.disable', false);
|
||||
Cache::config('memcache', array(
|
||||
'engine' => 'Memcache',
|
||||
'prefix' => 'cake_',
|
||||
'duration' => 3600
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
Configure::write('Cache.disable', $this->_cacheDisable);
|
||||
Cache::drop('memcache');
|
||||
Cache::drop('memcache_groups');
|
||||
Cache::drop('memcache_helper');
|
||||
Cache::config('default');
|
||||
}
|
||||
|
||||
/**
|
||||
* testSettings method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSettings() {
|
||||
$settings = Cache::settings('memcache');
|
||||
unset($settings['serialize'], $settings['path']);
|
||||
$expecting = array(
|
||||
'prefix' => 'cake_',
|
||||
'duration' => 3600,
|
||||
'probability' => 100,
|
||||
'servers' => array('127.0.0.1'),
|
||||
'persistent' => true,
|
||||
'compress' => false,
|
||||
'engine' => 'Memcache',
|
||||
'persistent' => true,
|
||||
'groups' => array()
|
||||
);
|
||||
$this->assertEquals($expecting, $settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* testSettings method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMultipleServers() {
|
||||
$servers = array('127.0.0.1:11211', '127.0.0.1:11222');
|
||||
$available = true;
|
||||
$Memcache = new Memcache();
|
||||
|
||||
foreach ($servers as $server) {
|
||||
list($host, $port) = explode(':', $server);
|
||||
//@codingStandardsIgnoreStart
|
||||
if (!@$Memcache->connect($host, $port)) {
|
||||
$available = false;
|
||||
}
|
||||
//@codingStandardsIgnoreEnd
|
||||
}
|
||||
|
||||
$this->skipIf(!$available, 'Need memcache servers at ' . implode(', ', $servers) . ' to run this test.');
|
||||
|
||||
$Memcache = new MemcacheEngine();
|
||||
$Memcache->init(array('engine' => 'Memcache', 'servers' => $servers));
|
||||
|
||||
$settings = $Memcache->settings();
|
||||
$this->assertEquals($settings['servers'], $servers);
|
||||
Cache::drop('dual_server');
|
||||
}
|
||||
|
||||
/**
|
||||
* testConnect method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConnect() {
|
||||
$Memcache = new MemcacheEngine();
|
||||
$Memcache->init(Cache::settings('memcache'));
|
||||
$result = $Memcache->connect('127.0.0.1');
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test connecting to an ipv6 server.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConnectIpv6() {
|
||||
$Memcache = new MemcacheEngine();
|
||||
$result = $Memcache->init(array(
|
||||
'prefix' => 'cake_',
|
||||
'duration' => 200,
|
||||
'engine' => 'Memcache',
|
||||
'servers' => array(
|
||||
'[::1]:11211'
|
||||
)
|
||||
));
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test non latin domains.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testParseServerStringNonLatin() {
|
||||
$Memcache = new TestMemcacheEngine();
|
||||
$result = $Memcache->parseServerString('schülervz.net:13211');
|
||||
$this->assertEquals(array('schülervz.net', '13211'), $result);
|
||||
|
||||
$result = $Memcache->parseServerString('sülül:1111');
|
||||
$this->assertEquals(array('sülül', '1111'), $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test unix sockets.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testParseServerStringUnix() {
|
||||
$Memcache = new TestMemcacheEngine();
|
||||
$result = $Memcache->parseServerString('unix:///path/to/memcached.sock');
|
||||
$this->assertEquals(array('unix:///path/to/memcached.sock', 0), $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testReadAndWriteCache method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testReadAndWriteCache() {
|
||||
Cache::set(array('duration' => 1), null, 'memcache');
|
||||
|
||||
$result = Cache::read('test', 'memcache');
|
||||
$expecting = '';
|
||||
$this->assertEquals($expecting, $result);
|
||||
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('test', $data, 'memcache');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = Cache::read('test', 'memcache');
|
||||
$expecting = $data;
|
||||
$this->assertEquals($expecting, $result);
|
||||
|
||||
Cache::delete('test', 'memcache');
|
||||
}
|
||||
|
||||
/**
|
||||
* testExpiry method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExpiry() {
|
||||
Cache::set(array('duration' => 1), 'memcache');
|
||||
|
||||
$result = Cache::read('test', 'memcache');
|
||||
$this->assertFalse($result);
|
||||
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('other_test', $data, 'memcache');
|
||||
$this->assertTrue($result);
|
||||
|
||||
sleep(2);
|
||||
$result = Cache::read('other_test', 'memcache');
|
||||
$this->assertFalse($result);
|
||||
|
||||
Cache::set(array('duration' => "+1 second"), 'memcache');
|
||||
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('other_test', $data, 'memcache');
|
||||
$this->assertTrue($result);
|
||||
|
||||
sleep(3);
|
||||
$result = Cache::read('other_test', 'memcache');
|
||||
$this->assertFalse($result);
|
||||
|
||||
Cache::config('memcache', array('duration' => '+1 second'));
|
||||
|
||||
$result = Cache::read('other_test', 'memcache');
|
||||
$this->assertFalse($result);
|
||||
|
||||
Cache::config('memcache', array('duration' => '+29 days'));
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('long_expiry_test', $data, 'memcache');
|
||||
$this->assertTrue($result);
|
||||
|
||||
sleep(2);
|
||||
$result = Cache::read('long_expiry_test', 'memcache');
|
||||
$expecting = $data;
|
||||
$this->assertEquals($expecting, $result);
|
||||
|
||||
Cache::config('memcache', array('duration' => 3600));
|
||||
}
|
||||
|
||||
/**
|
||||
* testDeleteCache method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeleteCache() {
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('delete_test', $data, 'memcache');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = Cache::delete('delete_test', 'memcache');
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDecrement method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDecrement() {
|
||||
$result = Cache::write('test_decrement', 5, 'memcache');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = Cache::decrement('test_decrement', 1, 'memcache');
|
||||
$this->assertEquals(4, $result);
|
||||
|
||||
$result = Cache::read('test_decrement', 'memcache');
|
||||
$this->assertEquals(4, $result);
|
||||
|
||||
$result = Cache::decrement('test_decrement', 2, 'memcache');
|
||||
$this->assertEquals(2, $result);
|
||||
|
||||
$result = Cache::read('test_decrement', 'memcache');
|
||||
$this->assertEquals(2, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testIncrement method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIncrement() {
|
||||
$result = Cache::write('test_increment', 5, 'memcache');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = Cache::increment('test_increment', 1, 'memcache');
|
||||
$this->assertEquals(6, $result);
|
||||
|
||||
$result = Cache::read('test_increment', 'memcache');
|
||||
$this->assertEquals(6, $result);
|
||||
|
||||
$result = Cache::increment('test_increment', 2, 'memcache');
|
||||
$this->assertEquals(8, $result);
|
||||
|
||||
$result = Cache::read('test_increment', 'memcache');
|
||||
$this->assertEquals(8, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that configurations don't conflict, when a file engine is declared after a memcache one.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConfigurationConflict() {
|
||||
Cache::config('long_memcache', array(
|
||||
'engine' => 'Memcache',
|
||||
'duration' => '+2 seconds',
|
||||
'servers' => array('127.0.0.1:11211'),
|
||||
));
|
||||
Cache::config('short_memcache', array(
|
||||
'engine' => 'Memcache',
|
||||
'duration' => '+1 seconds',
|
||||
'servers' => array('127.0.0.1:11211'),
|
||||
));
|
||||
Cache::config('some_file', array('engine' => 'File'));
|
||||
|
||||
$this->assertTrue(Cache::write('duration_test', 'yay', 'long_memcache'));
|
||||
$this->assertTrue(Cache::write('short_duration_test', 'boo', 'short_memcache'));
|
||||
|
||||
$this->assertEquals('yay', Cache::read('duration_test', 'long_memcache'), 'Value was not read %s');
|
||||
$this->assertEquals('boo', Cache::read('short_duration_test', 'short_memcache'), 'Value was not read %s');
|
||||
|
||||
sleep(1);
|
||||
$this->assertEquals('yay', Cache::read('duration_test', 'long_memcache'), 'Value was not read %s');
|
||||
|
||||
sleep(2);
|
||||
$this->assertFalse(Cache::read('short_duration_test', 'short_memcache'), 'Cache was not invalidated %s');
|
||||
$this->assertFalse(Cache::read('duration_test', 'long_memcache'), 'Value did not expire %s');
|
||||
|
||||
Cache::delete('duration_test', 'long_memcache');
|
||||
Cache::delete('short_duration_test', 'short_memcache');
|
||||
}
|
||||
|
||||
/**
|
||||
* test clearing memcache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testClear() {
|
||||
Cache::config('memcache2', array(
|
||||
'engine' => 'Memcache',
|
||||
'prefix' => 'cake2_',
|
||||
'duration' => 3600
|
||||
));
|
||||
|
||||
Cache::write('some_value', 'cache1', 'memcache');
|
||||
$result = Cache::clear(true, 'memcache');
|
||||
$this->assertTrue($result);
|
||||
$this->assertEquals('cache1', Cache::read('some_value', 'memcache'));
|
||||
|
||||
Cache::write('some_value', 'cache2', 'memcache2');
|
||||
$result = Cache::clear(false, 'memcache');
|
||||
$this->assertTrue($result);
|
||||
$this->assertFalse(Cache::read('some_value', 'memcache'));
|
||||
$this->assertEquals('cache2', Cache::read('some_value', 'memcache2'));
|
||||
|
||||
Cache::clear(false, 'memcache2');
|
||||
}
|
||||
|
||||
/**
|
||||
* test that a 0 duration can successfully write.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testZeroDuration() {
|
||||
Cache::config('memcache', array('duration' => 0));
|
||||
$result = Cache::write('test_key', 'written!', 'memcache');
|
||||
|
||||
$this->assertTrue($result);
|
||||
$result = Cache::read('test_key', 'memcache');
|
||||
$this->assertEquals('written!', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that durations greater than 30 days never expire
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLongDurationEqualToZero() {
|
||||
$memcache = new TestMemcacheEngine();
|
||||
$memcache->settings['compress'] = false;
|
||||
|
||||
$mock = $this->getMock('Memcache');
|
||||
$memcache->setMemcache($mock);
|
||||
$mock->expects($this->once())
|
||||
->method('set')
|
||||
->with('key', 'value', false, 0);
|
||||
|
||||
$value = 'value';
|
||||
$memcache->write('key', $value, 50 * DAY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that configuring groups for stored keys return the correct values when read/written
|
||||
* Shows that altering the group value is equivalent to deleting all keys under the same
|
||||
* group
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGroupReadWrite() {
|
||||
Cache::config('memcache_groups', array(
|
||||
'engine' => 'Memcache',
|
||||
'duration' => 3600,
|
||||
'groups' => array('group_a', 'group_b'),
|
||||
'prefix' => 'test_'
|
||||
));
|
||||
Cache::config('memcache_helper', array(
|
||||
'engine' => 'Memcache',
|
||||
'duration' => 3600,
|
||||
'prefix' => 'test_'
|
||||
));
|
||||
$this->assertTrue(Cache::write('test_groups', 'value', 'memcache_groups'));
|
||||
$this->assertEquals('value', Cache::read('test_groups', 'memcache_groups'));
|
||||
|
||||
Cache::increment('group_a', 1, 'memcache_helper');
|
||||
$this->assertFalse(Cache::read('test_groups', 'memcache_groups'));
|
||||
$this->assertTrue(Cache::write('test_groups', 'value2', 'memcache_groups'));
|
||||
$this->assertEquals('value2', Cache::read('test_groups', 'memcache_groups'));
|
||||
|
||||
Cache::increment('group_b', 1, 'memcache_helper');
|
||||
$this->assertFalse(Cache::read('test_groups', 'memcache_groups'));
|
||||
$this->assertTrue(Cache::write('test_groups', 'value3', 'memcache_groups'));
|
||||
$this->assertEquals('value3', Cache::read('test_groups', 'memcache_groups'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that deleteing from a groups-enabled config is possible
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGroupDelete() {
|
||||
Cache::config('memcache_groups', array(
|
||||
'engine' => 'Memcache',
|
||||
'duration' => 3600,
|
||||
'groups' => array('group_a', 'group_b')
|
||||
));
|
||||
$this->assertTrue(Cache::write('test_groups', 'value', 'memcache_groups'));
|
||||
$this->assertEquals('value', Cache::read('test_groups', 'memcache_groups'));
|
||||
$this->assertTrue(Cache::delete('test_groups', 'memcache_groups'));
|
||||
|
||||
$this->assertFalse(Cache::read('test_groups', 'memcache_groups'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test clearing a cache group
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
public function testGroupClear() {
|
||||
Cache::config('memcache_groups', array(
|
||||
'engine' => 'Memcache',
|
||||
'duration' => 3600,
|
||||
'groups' => array('group_a', 'group_b')
|
||||
));
|
||||
|
||||
$this->assertTrue(Cache::write('test_groups', 'value', 'memcache_groups'));
|
||||
$this->assertTrue(Cache::clearGroup('group_a', 'memcache_groups'));
|
||||
$this->assertFalse(Cache::read('test_groups', 'memcache_groups'));
|
||||
|
||||
$this->assertTrue(Cache::write('test_groups', 'value2', 'memcache_groups'));
|
||||
$this->assertTrue(Cache::clearGroup('group_b', 'memcache_groups'));
|
||||
$this->assertFalse(Cache::read('test_groups', 'memcache_groups'));
|
||||
}
|
||||
}
|
||||
335
lib/Cake/Test/Case/Cache/Engine/RedisEngineTest.php
Normal file
335
lib/Cake/Test/Case/Cache/Engine/RedisEngineTest.php
Normal file
|
|
@ -0,0 +1,335 @@
|
|||
<?php
|
||||
/**
|
||||
* RedisEngineTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
||||
* @package Cake.Test.Case.Cache.Engine
|
||||
* @since CakePHP(tm) v 2.2
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
App::uses('Cache', 'Cache');
|
||||
App::uses('RedisEngine', 'Cache/Engine');
|
||||
|
||||
/**
|
||||
* RedisEngineTest class
|
||||
*
|
||||
* @package Cake.Test.Case.Cache.Engine
|
||||
*/
|
||||
class RegisEngineTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
$this->skipIf(!class_exists('Redis'), 'Redis is not installed or configured properly.');
|
||||
|
||||
$this->_cacheDisable = Configure::read('Cache.disable');
|
||||
Configure::write('Cache.disable', false);
|
||||
Cache::config('redis', array(
|
||||
'engine' => 'Redis',
|
||||
'prefix' => 'cake_',
|
||||
'duration' => 3600
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
Configure::write('Cache.disable', $this->_cacheDisable);
|
||||
Cache::drop('');
|
||||
Cache::drop('redis_groups');
|
||||
Cache::drop('redis_helper');
|
||||
Cache::config('default');
|
||||
}
|
||||
|
||||
/**
|
||||
* testSettings method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSettings() {
|
||||
$settings = Cache::settings('redis');
|
||||
$expecting = array(
|
||||
'prefix' => 'cake_',
|
||||
'duration' => 3600,
|
||||
'probability' => 100,
|
||||
'groups' => array(),
|
||||
'engine' => 'Redis',
|
||||
'server' => '127.0.0.1',
|
||||
'port' => 6379,
|
||||
'timeout' => 0,
|
||||
'persistent' => true
|
||||
);
|
||||
$this->assertEquals($expecting, $settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* testConnect method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConnect() {
|
||||
$Redis = new RedisEngine();
|
||||
$this->assertTrue($Redis->init(Cache::settings('redis')));
|
||||
}
|
||||
|
||||
/**
|
||||
* testReadAndWriteCache method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testReadAndWriteCache() {
|
||||
Cache::set(array('duration' => 1), null, 'redis');
|
||||
|
||||
$result = Cache::read('test', 'redis');
|
||||
$expecting = '';
|
||||
$this->assertEquals($expecting, $result);
|
||||
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('test', $data, 'redis');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = Cache::read('test', 'redis');
|
||||
$expecting = $data;
|
||||
$this->assertEquals($expecting, $result);
|
||||
|
||||
$data = array(1, 2, 3);
|
||||
$this->assertTrue(Cache::write('array_data', $data, 'redis'));
|
||||
$this->assertEquals($data, Cache::read('array_data', 'redis'));
|
||||
|
||||
Cache::delete('test', 'redis');
|
||||
}
|
||||
|
||||
/**
|
||||
* testExpiry method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExpiry() {
|
||||
Cache::set(array('duration' => 1), 'redis');
|
||||
|
||||
$result = Cache::read('test', 'redis');
|
||||
$this->assertFalse($result);
|
||||
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('other_test', $data, 'redis');
|
||||
$this->assertTrue($result);
|
||||
|
||||
sleep(2);
|
||||
$result = Cache::read('other_test', 'redis');
|
||||
$this->assertFalse($result);
|
||||
|
||||
Cache::set(array('duration' => "+1 second"), 'redis');
|
||||
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('other_test', $data, 'redis');
|
||||
$this->assertTrue($result);
|
||||
|
||||
sleep(2);
|
||||
$result = Cache::read('other_test', 'redis');
|
||||
$this->assertFalse($result);
|
||||
|
||||
Cache::config('redis', array('duration' => '+1 second'));
|
||||
sleep(2);
|
||||
|
||||
$result = Cache::read('other_test', 'redis');
|
||||
$this->assertFalse($result);
|
||||
|
||||
Cache::config('redis', array('duration' => '+29 days'));
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('long_expiry_test', $data, 'redis');
|
||||
$this->assertTrue($result);
|
||||
|
||||
sleep(2);
|
||||
$result = Cache::read('long_expiry_test', 'redis');
|
||||
$expecting = $data;
|
||||
$this->assertEquals($expecting, $result);
|
||||
|
||||
Cache::config('redis', array('duration' => 3600));
|
||||
}
|
||||
|
||||
/**
|
||||
* testDeleteCache method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeleteCache() {
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('delete_test', $data, 'redis');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = Cache::delete('delete_test', 'redis');
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDecrement method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDecrement() {
|
||||
Cache::delete('test_decrement', 'redis');
|
||||
$result = Cache::write('test_decrement', 5, 'redis');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = Cache::decrement('test_decrement', 1, 'redis');
|
||||
$this->assertEquals(4, $result);
|
||||
|
||||
$result = Cache::read('test_decrement', 'redis');
|
||||
$this->assertEquals(4, $result);
|
||||
|
||||
$result = Cache::decrement('test_decrement', 2, 'redis');
|
||||
$this->assertEquals(2, $result);
|
||||
|
||||
$result = Cache::read('test_decrement', 'redis');
|
||||
$this->assertEquals(2, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testIncrement method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIncrement() {
|
||||
Cache::delete('test_increment', 'redis');
|
||||
$result = Cache::increment('test_increment', 1, 'redis');
|
||||
$this->assertEquals(1, $result);
|
||||
|
||||
$result = Cache::read('test_increment', 'redis');
|
||||
$this->assertEquals(1, $result);
|
||||
|
||||
$result = Cache::increment('test_increment', 2, 'redis');
|
||||
$this->assertEquals(3, $result);
|
||||
|
||||
$result = Cache::read('test_increment', 'redis');
|
||||
$this->assertEquals(3, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test clearing redis.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testClear() {
|
||||
Cache::config('redis2', array(
|
||||
'engine' => 'Redis',
|
||||
'prefix' => 'cake2_',
|
||||
'duration' => 3600
|
||||
));
|
||||
|
||||
Cache::write('some_value', 'cache1', 'redis');
|
||||
$result = Cache::clear(true, 'redis');
|
||||
$this->assertTrue($result);
|
||||
$this->assertEquals('cache1', Cache::read('some_value', 'redis'));
|
||||
|
||||
Cache::write('some_value', 'cache2', 'redis2');
|
||||
$result = Cache::clear(false, 'redis');
|
||||
$this->assertTrue($result);
|
||||
$this->assertFalse(Cache::read('some_value', 'redis'));
|
||||
$this->assertEquals('cache2', Cache::read('some_value', 'redis2'));
|
||||
|
||||
Cache::clear(false, 'redis2');
|
||||
}
|
||||
|
||||
/**
|
||||
* test that a 0 duration can successfully write.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testZeroDuration() {
|
||||
Cache::config('redis', array('duration' => 0));
|
||||
$result = Cache::write('test_key', 'written!', 'redis');
|
||||
|
||||
$this->assertTrue($result);
|
||||
$result = Cache::read('test_key', 'redis');
|
||||
$this->assertEquals('written!', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that configuring groups for stored keys return the correct values when read/written
|
||||
* Shows that altering the group value is equivalent to deleting all keys under the same
|
||||
* group
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGroupReadWrite() {
|
||||
Cache::config('redis_groups', array(
|
||||
'engine' => 'Redis',
|
||||
'duration' => 3600,
|
||||
'groups' => array('group_a', 'group_b'),
|
||||
'prefix' => 'test_'
|
||||
));
|
||||
Cache::config('redis_helper', array(
|
||||
'engine' => 'Redis',
|
||||
'duration' => 3600,
|
||||
'prefix' => 'test_'
|
||||
));
|
||||
$this->assertTrue(Cache::write('test_groups', 'value', 'redis_groups'));
|
||||
$this->assertEquals('value', Cache::read('test_groups', 'redis_groups'));
|
||||
|
||||
Cache::increment('group_a', 1, 'redis_helper');
|
||||
$this->assertFalse(Cache::read('test_groups', 'redis_groups'));
|
||||
$this->assertTrue(Cache::write('test_groups', 'value2', 'redis_groups'));
|
||||
$this->assertEquals('value2', Cache::read('test_groups', 'redis_groups'));
|
||||
|
||||
Cache::increment('group_b', 1, 'redis_helper');
|
||||
$this->assertFalse(Cache::read('test_groups', 'redis_groups'));
|
||||
$this->assertTrue(Cache::write('test_groups', 'value3', 'redis_groups'));
|
||||
$this->assertEquals('value3', Cache::read('test_groups', 'redis_groups'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that deleteing from a groups-enabled config is possible
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGroupDelete() {
|
||||
Cache::config('redis_groups', array(
|
||||
'engine' => 'Redis',
|
||||
'duration' => 3600,
|
||||
'groups' => array('group_a', 'group_b')
|
||||
));
|
||||
$this->assertTrue(Cache::write('test_groups', 'value', 'redis_groups'));
|
||||
$this->assertEquals('value', Cache::read('test_groups', 'redis_groups'));
|
||||
$this->assertTrue(Cache::delete('test_groups', 'redis_groups'));
|
||||
|
||||
$this->assertFalse(Cache::read('test_groups', 'redis_groups'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test clearing a cache group
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
public function testGroupClear() {
|
||||
Cache::config('redis_groups', array(
|
||||
'engine' => 'Redis',
|
||||
'duration' => 3600,
|
||||
'groups' => array('group_a', 'group_b')
|
||||
));
|
||||
|
||||
$this->assertTrue(Cache::write('test_groups', 'value', 'redis_groups'));
|
||||
$this->assertTrue(Cache::clearGroup('group_a', 'redis_groups'));
|
||||
$this->assertFalse(Cache::read('test_groups', 'redis_groups'));
|
||||
|
||||
$this->assertTrue(Cache::write('test_groups', 'value2', 'redis_groups'));
|
||||
$this->assertTrue(Cache::clearGroup('group_b', 'redis_groups'));
|
||||
$this->assertFalse(Cache::read('test_groups', 'redis_groups'));
|
||||
}
|
||||
|
||||
}
|
||||
263
lib/Cake/Test/Case/Cache/Engine/WincacheEngineTest.php
Normal file
263
lib/Cake/Test/Case/Cache/Engine/WincacheEngineTest.php
Normal file
|
|
@ -0,0 +1,263 @@
|
|||
<?php
|
||||
/**
|
||||
* WincacheEngineTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
||||
* @package Cake.Test.Case.Cache.Engine
|
||||
* @since CakePHP(tm) v 1.2.0.5434
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
App::uses('Cache', 'Cache');
|
||||
|
||||
/**
|
||||
* WincacheEngineTest class
|
||||
*
|
||||
* @package Cake.Test.Case.Cache.Engine
|
||||
*/
|
||||
class WincacheEngineTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->skipIf(!function_exists('wincache_ucache_set'), 'Wincache is not installed or configured properly.');
|
||||
$this->_cacheDisable = Configure::read('Cache.disable');
|
||||
Configure::write('Cache.disable', false);
|
||||
Cache::config('wincache', array('engine' => 'Wincache', 'prefix' => 'cake_'));
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
Configure::write('Cache.disable', $this->_cacheDisable);
|
||||
Cache::drop('wincache');
|
||||
Cache::drop('wincache_groups');
|
||||
Cache::config('default');
|
||||
}
|
||||
|
||||
/**
|
||||
* testReadAndWriteCache method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testReadAndWriteCache() {
|
||||
Cache::set(array('duration' => 1), 'wincache');
|
||||
|
||||
$result = Cache::read('test', 'wincache');
|
||||
$expecting = '';
|
||||
$this->assertEquals($expecting, $result);
|
||||
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('test', $data, 'wincache');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = Cache::read('test', 'wincache');
|
||||
$expecting = $data;
|
||||
$this->assertEquals($expecting, $result);
|
||||
|
||||
Cache::delete('test', 'wincache');
|
||||
}
|
||||
|
||||
/**
|
||||
* testExpiry method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExpiry() {
|
||||
Cache::set(array('duration' => 1), 'wincache');
|
||||
|
||||
$result = Cache::read('test', 'wincache');
|
||||
$this->assertFalse($result);
|
||||
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('other_test', $data, 'wincache');
|
||||
$this->assertTrue($result);
|
||||
|
||||
sleep(2);
|
||||
$result = Cache::read('other_test', 'wincache');
|
||||
$this->assertFalse($result);
|
||||
|
||||
Cache::set(array('duration' => 1), 'wincache');
|
||||
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('other_test', $data, 'wincache');
|
||||
$this->assertTrue($result);
|
||||
|
||||
sleep(2);
|
||||
$result = Cache::read('other_test', 'wincache');
|
||||
$this->assertFalse($result);
|
||||
|
||||
sleep(2);
|
||||
$result = Cache::read('other_test', 'wincache');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDeleteCache method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeleteCache() {
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('delete_test', $data, 'wincache');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = Cache::delete('delete_test', 'wincache');
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDecrement method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDecrement() {
|
||||
$this->skipIf(
|
||||
!function_exists('wincache_ucache_dec'),
|
||||
'No wincache_ucache_dec() function, cannot test decrement().'
|
||||
);
|
||||
|
||||
$result = Cache::write('test_decrement', 5, 'wincache');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = Cache::decrement('test_decrement', 1, 'wincache');
|
||||
$this->assertEquals(4, $result);
|
||||
|
||||
$result = Cache::read('test_decrement', 'wincache');
|
||||
$this->assertEquals(4, $result);
|
||||
|
||||
$result = Cache::decrement('test_decrement', 2, 'wincache');
|
||||
$this->assertEquals(2, $result);
|
||||
|
||||
$result = Cache::read('test_decrement', 'wincache');
|
||||
$this->assertEquals(2, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testIncrement method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIncrement() {
|
||||
$this->skipIf(
|
||||
!function_exists('wincache_ucache_inc'),
|
||||
'No wincache_inc() function, cannot test increment().'
|
||||
);
|
||||
|
||||
$result = Cache::write('test_increment', 5, 'wincache');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = Cache::increment('test_increment', 1, 'wincache');
|
||||
$this->assertEquals(6, $result);
|
||||
|
||||
$result = Cache::read('test_increment', 'wincache');
|
||||
$this->assertEquals(6, $result);
|
||||
|
||||
$result = Cache::increment('test_increment', 2, 'wincache');
|
||||
$this->assertEquals(8, $result);
|
||||
|
||||
$result = Cache::read('test_increment', 'wincache');
|
||||
$this->assertEquals(8, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test the clearing of cache keys
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testClear() {
|
||||
wincache_ucache_set('not_cake', 'safe');
|
||||
Cache::write('some_value', 'value', 'wincache');
|
||||
|
||||
$result = Cache::clear(false, 'wincache');
|
||||
$this->assertTrue($result);
|
||||
$this->assertFalse(Cache::read('some_value', 'wincache'));
|
||||
$this->assertEquals('safe', wincache_ucache_get('not_cake'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that configuring groups for stored keys return the correct values when read/written
|
||||
* Shows that altering the group value is equivalent to deleting all keys under the same
|
||||
* group
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGroupsReadWrite() {
|
||||
Cache::config('wincache_groups', array(
|
||||
'engine' => 'Wincache',
|
||||
'duration' => 0,
|
||||
'groups' => array('group_a', 'group_b'),
|
||||
'prefix' => 'test_'
|
||||
));
|
||||
$this->assertTrue(Cache::write('test_groups', 'value', 'wincache_groups'));
|
||||
$this->assertEquals('value', Cache::read('test_groups', 'wincache_groups'));
|
||||
|
||||
wincache_ucache_inc('test_group_a');
|
||||
$this->assertFalse(Cache::read('test_groups', 'wincache_groups'));
|
||||
$this->assertTrue(Cache::write('test_groups', 'value2', 'wincache_groups'));
|
||||
$this->assertEquals('value2', Cache::read('test_groups', 'wincache_groups'));
|
||||
|
||||
wincache_ucache_inc('test_group_b');
|
||||
$this->assertFalse(Cache::read('test_groups', 'wincache_groups'));
|
||||
$this->assertTrue(Cache::write('test_groups', 'value3', 'wincache_groups'));
|
||||
$this->assertEquals('value3', Cache::read('test_groups', 'wincache_groups'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that deleteing from a groups-enabled config is possible
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGroupDelete() {
|
||||
Cache::config('wincache_groups', array(
|
||||
'engine' => 'Wincache',
|
||||
'duration' => 0,
|
||||
'groups' => array('group_a', 'group_b'),
|
||||
'prefix' => 'test_'
|
||||
));
|
||||
$this->assertTrue(Cache::write('test_groups', 'value', 'wincache_groups'));
|
||||
$this->assertEquals('value', Cache::read('test_groups', 'wincache_groups'));
|
||||
$this->assertTrue(Cache::delete('test_groups', 'wincache_groups'));
|
||||
|
||||
$this->assertFalse(Cache::read('test_groups', 'wincache_groups'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test clearing a cache group
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
public function testGroupClear() {
|
||||
Cache::config('wincache_groups', array(
|
||||
'engine' => 'Wincache',
|
||||
'duration' => 0,
|
||||
'groups' => array('group_a', 'group_b'),
|
||||
'prefix' => 'test_'
|
||||
));
|
||||
|
||||
$this->assertTrue(Cache::write('test_groups', 'value', 'wincache_groups'));
|
||||
$this->assertTrue(Cache::clearGroup('group_a', 'wincache_groups'));
|
||||
$this->assertFalse(Cache::read('test_groups', 'wincache_groups'));
|
||||
|
||||
$this->assertTrue(Cache::write('test_groups', 'value2', 'wincache_groups'));
|
||||
$this->assertTrue(Cache::clearGroup('group_b', 'wincache_groups'));
|
||||
$this->assertFalse(Cache::read('test_groups', 'wincache_groups'));
|
||||
}
|
||||
}
|
||||
272
lib/Cake/Test/Case/Cache/Engine/XcacheEngineTest.php
Normal file
272
lib/Cake/Test/Case/Cache/Engine/XcacheEngineTest.php
Normal file
|
|
@ -0,0 +1,272 @@
|
|||
<?php
|
||||
/**
|
||||
* XcacheEngineTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
||||
* @package Cake.Test.Case.Cache.Engine
|
||||
* @since CakePHP(tm) v 1.2.0.5434
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
App::uses('Cache', 'Cache');
|
||||
|
||||
/**
|
||||
* XcacheEngineTest class
|
||||
*
|
||||
* @package Cake.Test.Case.Cache.Engine
|
||||
*/
|
||||
class XcacheEngineTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
if (!function_exists('xcache_set')) {
|
||||
$this->markTestSkipped('Xcache is not installed or configured properly');
|
||||
}
|
||||
$this->_cacheDisable = Configure::read('Cache.disable');
|
||||
Configure::write('Cache.disable', false);
|
||||
Cache::config('xcache', array('engine' => 'Xcache', 'prefix' => 'cake_'));
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
Configure::write('Cache.disable', $this->_cacheDisable);
|
||||
Cache::drop('xcache');
|
||||
Cache::drop('xcache_groups');
|
||||
Cache::config('default');
|
||||
}
|
||||
|
||||
/**
|
||||
* testSettings method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSettings() {
|
||||
$settings = Cache::settings();
|
||||
$expecting = array(
|
||||
'prefix' => 'cake_',
|
||||
'duration' => 3600,
|
||||
'probability' => 100,
|
||||
'engine' => 'Xcache',
|
||||
);
|
||||
$this->assertTrue(isset($settings['PHP_AUTH_USER']));
|
||||
$this->assertTrue(isset($settings['PHP_AUTH_PW']));
|
||||
|
||||
unset($settings['PHP_AUTH_USER'], $settings['PHP_AUTH_PW']);
|
||||
$this->assertEquals($settings, $expecting);
|
||||
}
|
||||
|
||||
/**
|
||||
* testReadAndWriteCache method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testReadAndWriteCache() {
|
||||
Cache::set(array('duration' => 1));
|
||||
|
||||
$result = Cache::read('test');
|
||||
$expecting = '';
|
||||
$this->assertEquals($expecting, $result);
|
||||
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('test', $data);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = Cache::read('test');
|
||||
$expecting = $data;
|
||||
$this->assertEquals($expecting, $result);
|
||||
|
||||
Cache::delete('test');
|
||||
}
|
||||
|
||||
/**
|
||||
* testExpiry method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExpiry() {
|
||||
Cache::set(array('duration' => 1));
|
||||
$result = Cache::read('test');
|
||||
$this->assertFalse($result);
|
||||
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('other_test', $data);
|
||||
$this->assertTrue($result);
|
||||
|
||||
sleep(2);
|
||||
$result = Cache::read('other_test');
|
||||
$this->assertFalse($result);
|
||||
|
||||
Cache::set(array('duration' => "+1 second"));
|
||||
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('other_test', $data);
|
||||
$this->assertTrue($result);
|
||||
|
||||
sleep(2);
|
||||
$result = Cache::read('other_test');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDeleteCache method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeleteCache() {
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('delete_test', $data);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = Cache::delete('delete_test');
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testClearCache method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testClearCache() {
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('clear_test_1', $data);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = Cache::write('clear_test_2', $data);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = Cache::clear();
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDecrement method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDecrement() {
|
||||
$result = Cache::write('test_decrement', 5);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = Cache::decrement('test_decrement');
|
||||
$this->assertEquals(4, $result);
|
||||
|
||||
$result = Cache::read('test_decrement');
|
||||
$this->assertEquals(4, $result);
|
||||
|
||||
$result = Cache::decrement('test_decrement', 2);
|
||||
$this->assertEquals(2, $result);
|
||||
|
||||
$result = Cache::read('test_decrement');
|
||||
$this->assertEquals(2, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testIncrement method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIncrement() {
|
||||
$result = Cache::write('test_increment', 5);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = Cache::increment('test_increment');
|
||||
$this->assertEquals(6, $result);
|
||||
|
||||
$result = Cache::read('test_increment');
|
||||
$this->assertEquals(6, $result);
|
||||
|
||||
$result = Cache::increment('test_increment', 2);
|
||||
$this->assertEquals(8, $result);
|
||||
|
||||
$result = Cache::read('test_increment');
|
||||
$this->assertEquals(8, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that configuring groups for stored keys return the correct values when read/written
|
||||
* Shows that altering the group value is equivalent to deleting all keys under the same
|
||||
* group
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGroupsReadWrite() {
|
||||
Cache::config('xcache_groups', array(
|
||||
'engine' => 'Xcache',
|
||||
'duration' => 0,
|
||||
'groups' => array('group_a', 'group_b'),
|
||||
'prefix' => 'test_'
|
||||
));
|
||||
$this->assertTrue(Cache::write('test_groups', 'value', 'xcache_groups'));
|
||||
$this->assertEquals('value', Cache::read('test_groups', 'xcache_groups'));
|
||||
|
||||
xcache_inc('test_group_a', 1);
|
||||
$this->assertFalse(Cache::read('test_groups', 'xcache_groups'));
|
||||
$this->assertTrue(Cache::write('test_groups', 'value2', 'xcache_groups'));
|
||||
$this->assertEquals('value2', Cache::read('test_groups', 'xcache_groups'));
|
||||
|
||||
xcache_inc('test_group_b', 1);
|
||||
$this->assertFalse(Cache::read('test_groups', 'xcache_groups'));
|
||||
$this->assertTrue(Cache::write('test_groups', 'value3', 'xcache_groups'));
|
||||
$this->assertEquals('value3', Cache::read('test_groups', 'xcache_groups'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that deleteing from a groups-enabled config is possible
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGroupDelete() {
|
||||
Cache::config('xcache_groups', array(
|
||||
'engine' => 'Xcache',
|
||||
'duration' => 0,
|
||||
'groups' => array('group_a', 'group_b'),
|
||||
'prefix' => 'test_'
|
||||
));
|
||||
$this->assertTrue(Cache::write('test_groups', 'value', 'xcache_groups'));
|
||||
$this->assertEquals('value', Cache::read('test_groups', 'xcache_groups'));
|
||||
$this->assertTrue(Cache::delete('test_groups', 'xcache_groups'));
|
||||
|
||||
$this->assertFalse(Cache::read('test_groups', 'xcache_groups'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test clearing a cache group
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
public function testGroupClear() {
|
||||
Cache::config('xcache_groups', array(
|
||||
'engine' => 'Xcache',
|
||||
'duration' => 0,
|
||||
'groups' => array('group_a', 'group_b'),
|
||||
'prefix' => 'test_'
|
||||
));
|
||||
|
||||
$this->assertTrue(Cache::write('test_groups', 'value', 'xcache_groups'));
|
||||
$this->assertTrue(Cache::clearGroup('group_a', 'xcache_groups'));
|
||||
$this->assertFalse(Cache::read('test_groups', 'xcache_groups'));
|
||||
|
||||
$this->assertTrue(Cache::write('test_groups', 'value2', 'xcache_groups'));
|
||||
$this->assertTrue(Cache::clearGroup('group_b', 'xcache_groups'));
|
||||
$this->assertFalse(Cache::read('test_groups', 'xcache_groups'));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue