Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch '1.3-cache' into 1.3-misc

  • Loading branch information...
commit a729fc4d620222385f8b433f5bdc82066e92abee 2 parents c115094 + d37dd4c
@markstory markstory authored
View
293 cake/libs/cache.php
@@ -28,15 +28,9 @@
class Cache {
/**
- * Cache engine to use
- *
- * @var CacheEngine
- * @access protected
- */
- var $_Engine = null;
-
-/**
* Cache configuration stack
+ * Keeps the permanent/default settings for each cache engine.
+ * These settings are used to reset the engines after temporary modification.
*
* @var array
* @access private
@@ -44,7 +38,7 @@ class Cache {
var $__config = array();
/**
- * Holds name of the current configuration being used
+ * Holds name of the current configuration name being used.
*
* @var array
* @access private
@@ -52,7 +46,7 @@ class Cache {
var $__name = 'default';
/**
- * whether to reset the settings with the next call to self::set();
+ * Whether to reset the settings with the next call to Cache::set();
*
* @var array
* @access private
@@ -60,6 +54,13 @@ class Cache {
var $__reset = false;
/**
+ * Engine instances keyed by configuration name.
+ *
+ * @var array
+ */
+ var $_engines = array();
+
+/**
* Returns a singleton instance
*
* @return object
@@ -75,7 +76,18 @@ function &getInstance() {
}
/**
- * 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
* @param string $name Name of the configuration
@@ -85,51 +97,74 @@ function &getInstance() {
* @static
*/
function config($name = null, $settings = array()) {
- $_this =& Cache::getInstance();
+ $self =& Cache::getInstance();
if (is_array($name)) {
$settings = $name;
}
if ($name === null || !is_string($name)) {
- $name = $_this->__name;
+ $name = $self->__name;
}
$current = array();
- if (isset($_this->__config[$name])) {
- $current = $_this->__config[$name];
+ if (isset($self->__config[$name])) {
+ $current = $self->__config[$name];
}
if (!empty($settings)) {
- $_this->__name = null;
- $_this->__config[$name] = array_merge($current, $settings);
+ $self->__config[$name] = array_merge($current, $settings);
}
- if (empty($_this->__config[$name]['engine'])) {
+ if (empty($self->__config[$name]['engine'])) {
return false;
}
- $_this->__name = $name;
- $engine = $_this->__config[$name]['engine'];
+ $self->__name = $name;
+ $engine = $self->__config[$name]['engine'];
- if (!$_this->isInitialized($engine)) {
- if ($_this->engine($engine, $_this->__config[$name]) === false) {
- return false;
- }
- $settings = $_this->__config[$name] = $_this->settings($engine);
- } else if ($settings = $_this->set($_this->__config[$name])) {
- $_this->__config[$name] = $settings;
+ if (!isset($this->_engines[$name])) {
+ $self->_buildEngine($name);
+ $settings = $self->__config[$name] = $self->settings($name);
+ } elseif ($settings = $self->set($self->__config[$name])) {
+ var_dump($settings);
+ $self->__config[$name] = $settings;
}
return compact('engine', 'settings');
}
/**
+ * Finds and builds the instance of the required engine class.
+ *
+ * @param string $name Name of the config array that needs an engine instance built
+ * @return void
+ * @access protected
+ */
+ function _buildEngine($name) {
+ $config = $this->__config[$name];
+
+ list($plugin, $class) = pluginSplit($config['engine']);
+ if ($this->__loadEngine($class, $plugin) === false) {
+ return false;
+ }
+ $cacheClass = $class . 'Engine';
+ $this->_engines[$name] =& new $cacheClass();
+ if ($this->_engines[$name]->init($config)) {
+ if (time() % $this->_engines[$name]->settings['probability'] === 0) {
+ $this->_engines[$name]->gc();
+ }
+ return true;
+ }
+ return false;
+ }
+
+/**
* Returns an array containing the currently configured Cache settings.
*
* @return array
*/
function configured() {
- $_this = Cache::getInstance();
- return array_keys($_this->__config);
+ $self = Cache::getInstance();
+ return array_keys($self->__config);
}
/**
@@ -141,57 +176,16 @@ function configured() {
* @return boolen success of the removal, returns false when the config does not exist.
*/
function drop($name) {
- $_this = Cache::getInstance();
- if (!isset($_this->__config[$name])) {
+ $self = Cache::getInstance();
+ if (!isset($self->__config[$name])) {
return false;
}
- $last = true;
- $engine = $_this->__config[$name]['engine'];
- unset($_this->__config[$name]);
- foreach ($_this->__config as $name => $settings) {
- if ($settings['engine'] == $engine) {
- $last = false;
- break;
- }
- }
- if ($last) {
- unset($_this->_Engine[$engine]);
- }
+ unset($self->__config[$name]);
+ unset($self->_engines[$name]);
return true;
}
/**
- * Set the cache engine to use or modify settings for one instance
- *
- * @param string $name Name of the engine (without 'Engine')
- * @param array $settings Optional associative array of settings passed to the engine
- * @return boolean True on success, false on failure
- * @access public
- * @static
- */
- function engine($name = 'File', $settings = array()) {
- $class = $name;
- list($plugin, $class) = pluginSplit($name);
- $cacheClass = $class . 'Engine';
- $_this =& Cache::getInstance();
- if (!isset($_this->_Engine[$name])) {
- if ($_this->__loadEngine($class, $plugin) === false) {
- return false;
- }
- $_this->_Engine[$name] =& new $cacheClass();
- }
-
- if ($_this->_Engine[$name]->init($settings)) {
- if (time() % $_this->_Engine[$name]->settings['probability'] === 0) {
- $_this->_Engine[$name]->gc();
- }
- return true;
- }
- $_this->_Engine[$name] = null;
- return false;
- }
-
-/**
* Tries to find and include a file for a cache engine and returns object instance
*
* @param $name Name of the engine (without 'Engine')
@@ -210,7 +204,6 @@ function __loadEngine($name, $plugin = null) {
}
}
-
/**
* Temporarily change settings to current config options. if no params are passed, resets settings if needed
* Cache::write() will reset the configuration changes made
@@ -222,30 +215,32 @@ function __loadEngine($name, $plugin = null) {
* @static
*/
function set($settings = array(), $value = null) {
- $_this =& Cache::getInstance();
- if (!isset($_this->__config[$_this->__name])) {
+ $self =& Cache::getInstance();
+ if (!isset($self->__config[$self->__name])) {
return false;
}
- $engine = $_this->__config[$_this->__name]['engine'];
+ $name = $self->__name;
if (!empty($settings)) {
- $_this->__reset = true;
+ $self->__reset = true;
}
- if ($_this->__reset === true) {
+ if ($self->__reset === true) {
if (empty($settings)) {
- $_this->__reset = false;
- $settings = $_this->__config[$_this->__name];
+ $self->__reset = false;
+ $settings = $self->__config[$name];
} else {
if (is_string($settings) && $value !== null) {
$settings = array($settings => $value);
}
- $settings = array_merge($_this->__config[$_this->__name], $settings);
+ $settings = array_merge($self->__config[$self->__name], $settings);
+ if (isset($settings['duration']) && !is_numeric($settings['duration'])) {
+ $settings['duration'] = strtotime($settings['duration']) - time();
+ }
}
- $_this->engine($engine, $settings);
+ $self->_engines[$name]->settings = $settings;
}
-
- return $_this->settings($engine);
+ return $self->settings($name);
}
/**
@@ -258,9 +253,8 @@ function set($settings = array(), $value = null) {
* @static
*/
function gc() {
- $_this =& Cache::getInstance();
- $config = $_this->config();
- $_this->_Engine[$config['engine']]->gc();
+ $self =& Cache::getInstance();
+ $self->_engines[$self->__name]->gc();
}
/**
@@ -274,37 +268,27 @@ function gc() {
* @static
*/
function write($key, $value, $config = null) {
- $_this =& Cache::getInstance();
+ $self =& Cache::getInstance();
- if ($config && isset($_this->__config[$config])) {
- $settings = $_this->set($_this->__config[$config]);
- } else {
- $settings = $_this->settings();
+ if (!$config) {
+ $config = $self->__name;
}
+ $settings = $self->settings($config);
if (empty($settings)) {
return null;
}
- extract($settings);
-
- if (!$_this->isInitialized($engine)) {
- return false;
- }
-
- if (!$key = $_this->_Engine[$engine]->key($key)) {
- return false;
- }
-
- if (is_resource($value)) {
+ if (!$self->isInitialized($config)) {
return false;
}
+ $key = $self->_engines[$config]->key($key);
- if ($duration < 1) {
+ if (!$key || is_resource($value) || $settings['duration'] < 1) {
return false;
}
- $success = $_this->_Engine[$engine]->write($settings['prefix'] . $key, $value, $duration);
- $settings = $_this->set();
+ $success = $self->_engines[$config]->write($settings['prefix'] . $key, $value, $settings['duration']);
+ $self->set();
return $success;
}
@@ -318,29 +302,27 @@ function write($key, $value, $config = null) {
* @static
*/
function read($key, $config = null) {
- $_this =& Cache::getInstance();
+ $self =& Cache::getInstance();
- if (isset($_this->__config[$config])) {
- $settings = $_this->set($_this->__config[$config]);
- } else {
- $settings = $_this->settings();
+ if (!$config) {
+ $config = $self->__name;
}
+ $settings = $self->settings($config);
if (empty($settings)) {
return null;
}
- extract($settings);
-
- if (!$_this->isInitialized($engine)) {
+ if (!$self->isInitialized($config)) {
return false;
}
- if (!$key = $_this->_Engine[$engine]->key($key)) {
+ $key = $self->_engines[$config]->key($key);
+ if (!$key) {
return false;
}
- $success = $_this->_Engine[$engine]->read($settings['prefix'] . $key);
+ $success = $self->_engines[$config]->read($settings['prefix'] . $key);
- if ($config !== null && $config !== $_this->__name) {
- $settings = $_this->set();
+ if ($config !== null && $config !== $self->__name) {
+ $self->set();
}
return $success;
}
@@ -355,28 +337,25 @@ function read($key, $config = null) {
* @static
*/
function delete($key, $config = null) {
- $_this =& Cache::getInstance();
- if (isset($_this->__config[$config])) {
- $settings = $_this->set($_this->__config[$config]);
- } else {
- $settings = $_this->settings();
+ $self =& Cache::getInstance();
+ if (!$config) {
+ $config = $self->__name;
}
+ $settings = $self->settings($config);
if (empty($settings)) {
return null;
}
- extract($settings);
-
- if (!$_this->isInitialized($engine)) {
+ if (!$self->isInitialized($config)) {
return false;
}
-
- if (!$key = $_this->_Engine[$engine]->key($key)) {
+ $key = $self->_engines[$config]->key($key);
+ if (!$key) {
return false;
}
- $success = $_this->_Engine[$engine]->delete($settings['prefix'] . $key);
- $settings = $_this->set();
+ $success = $self->_engines[$config]->delete($settings['prefix'] . $key);
+ $self->set();
return $success;
}
@@ -390,28 +369,26 @@ function delete($key, $config = null) {
* @static
*/
function clear($check = false, $config = null) {
- $_this =& Cache::getInstance();
- if (isset($_this->__config[$config])) {
- $settings = $_this->set($_this->__config[$config]);
- } else {
- $settings = $_this->settings();
+ $self =& Cache::getInstance();
+ if (!$config) {
+ $config = $self->__name;
}
+ $settings = $self->settings($config);
if (empty($settings)) {
return null;
}
- extract($settings);
- if (isset($engine) && !$_this->isInitialized($engine)) {
+ if (!$self->isInitialized($config)) {
return false;
}
- $success = $_this->_Engine[$engine]->clear($check);
- $settings = $_this->set();
+ $success = $self->_engines[$config]->clear($check);
+ $self->set();
return $success;
}
/**
- * Check if Cache has initialized a working storage engine
+ * Check if Cache has initialized a working config for the given name.
*
* @param string $engine Name of the engine
* @param string $config Name of the configuration setting
@@ -419,33 +396,35 @@ function clear($check = false, $config = null) {
* @access public
* @static
*/
- function isInitialized($engine = null) {
+ function isInitialized($name = null) {
if (Configure::read('Cache.disable')) {
return false;
}
- $_this =& Cache::getInstance();
- if (!$engine && isset($_this->__config[$_this->__name]['engine'])) {
- $engine = $_this->__config[$_this->__name]['engine'];
+ $self =& Cache::getInstance();
+ if (!$name && isset($self->__config[$self->__name])) {
+ $name = $self->__name;
}
- return isset($_this->_Engine[$engine]);
+ return isset($self->_engines[$name]);
}
/**
- * Return the settings for current cache engine
+ * Return the settings for current cache engine. If no name is supplied the settings
+ * for the 'active default' configuration will be returned. To set the 'active default'
+ * configuration use `Cache::config()`
*
- * @param string $engine Name of the engine
+ * @param string $engine Name of the configuration to get settings for.
* @return array list of settings for this engine
+ * @see Cache::config()
* @access public
* @static
*/
- function settings($engine = null) {
- $_this =& Cache::getInstance();
- if (!$engine && isset($_this->__config[$_this->__name]['engine'])) {
- $engine = $_this->__config[$_this->__name]['engine'];
+ function settings($name = null) {
+ $self =& Cache::getInstance();
+ if (!$name && isset($self->__config[$self->__name])) {
+ $name = $self->__name;
}
-
- if (isset($_this->_Engine[$engine]) && !is_null($_this->_Engine[$engine])) {
- return $_this->_Engine[$engine]->settings();
+ if (!empty($self->_engines[$name])) {
+ return $self->_engines[$name]->settings();
}
return array();
}
@@ -468,7 +447,7 @@ class CacheEngine {
var $settings = array();
/**
- * Iitialize the cache engine
+ * Initialize the cache engine
*
* Called automatically by the cache frontend
*
View
11 cake/libs/cache/file.php
@@ -37,11 +37,12 @@ class FileEngine extends CacheEngine {
var $__File = null;
/**
- * settings
- * path = absolute path to cache directory, default => CACHE
- * prefix = string prefix for filename, default => cake_
- * lock = enable file locking on write, default => false
- * serialize = serialize the data, default => true
+ * Settings
+ *
+ * - path = absolute path to cache directory, default => CACHE
+ * - prefix = string prefix for filename, default => cake_
+ * - lock = enable file locking on write, default => false
+ * - serialize = serialize the data, default => true
*
* @var array
* @see CacheEngine::__defaults
View
12 cake/libs/cache/xcache.php
@@ -2,7 +2,6 @@
/**
* Xcache storage engine for cache.
*
- *
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
@@ -29,9 +28,10 @@
class XcacheEngine extends CacheEngine {
/**
- * settings
- * PHP_AUTH_USER = xcache.admin.user, default cake
- * PHP_AUTH_PW = xcache.admin.password, default cake
+ * Settings
+ *
+ * - PHP_AUTH_USER = xcache.admin.user, default cake
+ * - PHP_AUTH_PW = xcache.admin.password, default cake
*
* @var array
* @access public
@@ -67,7 +67,7 @@ function init($settings) {
*/
function write($key, &$value, $duration) {
$expires = time() + $duration;
- xcache_set($key.'_expires', $expires, $duration);
+ xcache_set($key . '_expires', $expires, $duration);
return xcache_set($key, $value, $duration);
}
@@ -81,7 +81,7 @@ function write($key, &$value, $duration) {
function read($key) {
if (xcache_isset($key)) {
$time = time();
- $cachetime = intval(xcache_get($key.'_expires'));
+ $cachetime = intval(xcache_get($key . '_expires'));
if ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime) {
return false;
}
View
5 cake/libs/log/file_log.php
@@ -2,7 +2,6 @@
/**
* File Storage stream for Logging
*
- *
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
@@ -18,7 +17,9 @@
* @since CakePHP(tm) v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
-
+if (!class_exists('File')) {
+ require LIBS . 'file.php';
+}
/**
* File Storage stream for Logging
*
View
2  cake/libs/model/datasources/dbo/dbo_mssql.php
@@ -426,7 +426,7 @@ function update(&$model, $fields = array(), $values = null, $conditions = null)
* @return string Error message with error number
*/
function lastError() {
- $error = mssql_get_last_message($this->connection);
+ $error = mssql_get_last_message();
if ($error) {
if (!preg_match('/contexto de la base de datos a|contesto di database|changed database|datenbankkontext/i', $error)) {
View
1  cake/libs/router.php
@@ -183,6 +183,7 @@ function __setPrefixes() {
$this->__prefixes = array_merge($this->__prefixes, (array)$routing['prefixes']);
}
}
+
/**
* Gets a reference to the Router object instance
*
View
4 cake/libs/view/helpers/paginator.php
@@ -302,9 +302,7 @@ function sort($title, $key = null, $options = array()) {
$isSorted = ($sortKey === $key || $sortKey === $this->defaultModel() . '.' . $key);
if ($isSorted) {
- if ($this->sortDir($options['model']) === 'asc') {
- $dir = 'desc';
- }
+ $dir = $this->sortDir($options['model']) === 'asc' ? 'desc' : 'asc';
$class = $dir === 'asc' ? 'desc' : 'asc';
if (!empty($options['class'])) {
$options['class'] .= $class;
View
50 cake/tests/cases/libs/cache.test.php
@@ -43,8 +43,6 @@ function setUp() {
$this->_defaultCacheConfig = Cache::config('default');
Cache::config('default', array('engine' => 'File', 'path' => TMP . 'tests'));
-
- Cache::engine('File', array('path' => TMP . 'tests'));
}
/**
@@ -56,7 +54,6 @@ function setUp() {
function tearDown() {
Configure::write('Cache.disable', $this->_cacheDisable);
Cache::config('default', $this->_defaultCacheConfig['settings']);
- Cache::engine('File');
}
/**
@@ -127,16 +124,46 @@ function testConfigChange() {
$_cacheConfigTests = Cache::config('tests');
$result = Cache::config('sessions', array('engine'=> 'File', 'path' => TMP . 'sessions'));
- $this->assertEqual($result['settings'], Cache::settings('File'));
+ $this->assertEqual($result['settings'], Cache::settings('sessions'));
$result = Cache::config('tests', array('engine'=> 'File', 'path' => TMP . 'tests'));
- $this->assertEqual($result['settings'], Cache::settings('File'));
+ $this->assertEqual($result['settings'], Cache::settings('tests'));
Cache::config('sessions', $_cacheConfigSessions['settings']);
Cache::config('tests', $_cacheConfigTests['settings']);
}
/**
+ * test that calling config() sets the 'default' configuration up.
+ *
+ * @return void
+ */
+ function testConfigSettingDefaultConfigKey() {
+ 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
*
* @access public
@@ -157,7 +184,7 @@ function testWritingWithConfig() {
'engine' => 'File',
'isWindows' => DIRECTORY_SEPARATOR == '\\'
);
- $this->assertEqual($expected, Cache::settings('File'));
+ $this->assertEqual($expected, Cache::settings('sessions'));
Cache::config('sessions', $_cacheConfigSessions['settings']);
}
@@ -181,7 +208,7 @@ function testConfigured() {
* @return void
*/
function testInitSettings() {
- Cache::engine('File', array('path' => TMP . 'tests'));
+ Cache::config('default', array('engine' => 'File', 'path' => TMP . 'tests'));
$settings = Cache::settings();
$expecting = array(
@@ -195,17 +222,15 @@ function testInitSettings() {
'isWindows' => DIRECTORY_SEPARATOR == '\\'
);
$this->assertEqual($settings, $expecting);
-
- Cache::engine('File');
}
/**
- * 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.
*
* @return void
*/
- function testUnconfig() {
+ function testDrop() {
App::build(array(
'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)
@@ -221,7 +246,7 @@ function testUnconfig() {
Cache::config('unconfigTest', array(
'engine' => 'TestAppCache'
));
- $this->assertTrue(Cache::isInitialized('TestAppCache'));
+ $this->assertTrue(Cache::isInitialized('unconfigTest'));
$this->assertTrue(Cache::drop('unconfigTest'));
$this->assertFalse(Cache::isInitialized('TestAppCache'));
@@ -324,5 +349,6 @@ function testSet() {
Cache::set($_cacheSet);
}
+
}
?>
View
5 cake/tests/cases/libs/cache/apc.test.php
@@ -39,7 +39,7 @@ class ApcEngineTest extends UnitTestCase {
*/
function skip() {
$skip = true;
- if (Cache::engine('Apc')) {
+ if (function_exists('apc_store')) {
$skip = false;
}
$this->skipIf($skip, '%s Apc is not installed or configured properly');
@@ -65,6 +65,7 @@ function setUp() {
*/
function tearDown() {
Configure::write('Cache.disable', $this->_cacheDisable);
+ Cache::drop('apc');
Cache::config('default');
}
@@ -112,7 +113,7 @@ function testExpiry() {
$result = Cache::read('other_test');
$this->assertFalse($result);
- Cache::set(array('duration' => "+1 second"));
+ Cache::set(array('duration' => 1));
$data = 'this is a test of the emergency broadcasting system';
$result = Cache::write('other_test', $data);
View
97 cake/tests/cases/libs/cache/file.test.php
@@ -2,8 +2,6 @@
/**
* FileEngineTest file
*
- * Long description for file
- *
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
@@ -22,9 +20,6 @@
if (!class_exists('Cache')) {
require LIBS . 'cache.php';
}
-if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
- define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
-}
/**
* FileEngineTest class
@@ -74,12 +69,11 @@ function endCase() {
*/
function testCacheDirChange() {
$result = Cache::config('sessions', array('engine'=> 'File', 'path' => TMP . 'sessions'));
- $this->assertEqual($result['settings'], Cache::settings('File'));
- $this->assertNotEqual($result, Cache::settings('File'));
+ $this->assertEqual($result['settings'], Cache::settings('sessions'));
- $result = Cache::config('tests', array('engine'=> 'File', 'path' => TMP . 'tests'));
- $this->assertEqual($result['settings'], Cache::settings('File'));
- $this->assertNotEqual($result, Cache::settings('File'));
+ $result = Cache::config('sessions', array('engine'=> 'File', 'path' => TMP . 'tests'));
+ $this->assertEqual($result['settings'], Cache::settings('sessions'));
+ $this->assertNotEqual($result['settings'], Cache::settings('default'));
}
/**
@@ -159,7 +153,6 @@ function testDeleteCache() {
$result = Cache::delete('delete_test');
$this->assertFalse($result);
-
}
/**
@@ -169,12 +162,12 @@ function testDeleteCache() {
* @return void
*/
function testSerialize() {
- Cache::engine('File', array('serialize' => true));
+ Cache::config('default', array('engine' => 'File', 'serialize' => true));
$data = 'this is a test of the emergency broadcasting system';
- $write = Cache::write('serialize_test', $data, 1);
+ $write = Cache::write('serialize_test', $data);
$this->assertTrue($write);
- Cache::engine('File', array('serialize' => false));
+ Cache::config('default', array('serialize' => false));
$read = Cache::read('serialize_test');
$newread = Cache::read('serialize_test');
@@ -184,7 +177,6 @@ function testSerialize() {
$this->assertIdentical($read, serialize($data));
$this->assertIdentical(unserialize($newread), $data);
-
}
/**
@@ -194,7 +186,7 @@ function testSerialize() {
* @return void
*/
function testClear() {
- Cache::engine('File', array('duration' => 1));
+ Cache::config('default', array('engine' => 'File', 'duration' => 1));
$data = 'this is a test of the emergency broadcasting system';
$write = Cache::write('serialize_test1', $data);
$write = Cache::write('serialize_test2', $data);
@@ -223,7 +215,7 @@ function testClear() {
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test2'));
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test3'));
- $result = Cache::engine('File', array('path' => CACHE . 'views'));
+ Cache::config('default', array('engine' => 'File', 'path' => CACHE . 'views'));
$data = 'this is a test of the emergency broadcasting system';
$write = Cache::write('controller_view_1', $data);
@@ -278,7 +270,7 @@ function testClear() {
clearCache('controller_view');
- Cache::engine('File', array('path' => CACHE));
+ Cache::config('default', array('engine' => 'File', 'path' => CACHE));
}
/**
@@ -306,40 +298,43 @@ function testKeyPath() {
* @return void
*/
function testRemoveWindowsSlashesFromCache() {
- Cache::engine('File', array('isWindows' => true, 'prefix' => null, 'path' => TMP));
+ 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'));
-
- $data = Cache::write('test_dir_map', $expected);
- $data = Cache::read('test_dir_map');
- Cache::delete('test_dir_map');
+ '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->assertEqual($expected, $data);
+
+ Cache::drop('windows_test');
}
/**
@@ -349,13 +344,13 @@ function testRemoveWindowsSlashesFromCache() {
* @return void
*/
function testWriteQuotedString() {
- Cache::engine('File', array('path' => TMP . 'tests'));
+ Cache::config('default', array('engine' => 'File', 'path' => TMP . 'tests'));
Cache::write('App.doubleQuoteTest', '"this is a quoted string"');
$this->assertIdentical(Cache::read('App.doubleQuoteTest'), '"this is a quoted string"');
Cache::write('App.singleQuoteTest', "'this is a quoted string'");
$this->assertIdentical(Cache::read('App.singleQuoteTest'), "'this is a quoted string'");
- Cache::engine('File', array('isWindows' => true, 'path' => TMP . 'tests'));
+ Cache::config('default', array('isWindows' => true, 'path' => TMP . 'tests'));
$this->assertIdentical(Cache::read('App.doubleQuoteTest'), '"this is a quoted string"');
Cache::write('App.singleQuoteTest', "'this is a quoted string'");
$this->assertIdentical(Cache::read('App.singleQuoteTest'), "'this is a quoted string'");
View
43 cake/tests/cases/libs/cache/memcache.test.php
@@ -2,8 +2,6 @@
/**
* MemcacheEngineTest file
*
- * Long description for file
- *
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
@@ -29,13 +27,6 @@
* @package cake
* @subpackage cake.tests.cases.libs.cache
*/
-
-/**
- * MemcacheEngineTest class
- *
- * @package cake
- * @subpackage cake.tests.cases.libs.cache
- */
class MemcacheEngineTest extends CakeTestCase {
/**
@@ -46,10 +37,10 @@ class MemcacheEngineTest extends CakeTestCase {
*/
function skip() {
$skip = true;
- if (Cache::engine('Memcache')) {
+ if (class_exists('Memcache')) {
$skip = false;
}
- $this->skipIf($skip, '%s Memcache is not installed or configured properly');
+ $this->skipIf($skip, '%s Memcache is not installed or configured properly.');
}
/**
@@ -72,6 +63,7 @@ function setUp() {
*/
function tearDown() {
Configure::write('Cache.disable', $this->_cacheDisable);
+ Cache::drop('memcache');
Cache::config('default');
}
@@ -103,14 +95,12 @@ function testSettings() {
*/
function testMultipleServers() {
$servers = array('127.0.0.1:11211', '127.0.0.1:11222');
-
- $Cache =& Cache::getInstance();
- $MemCache =& $Cache->_Engine['Memcache'];
-
$available = true;
+ $Memcache =& new Memcache();
+
foreach($servers as $server) {
list($host, $port) = explode(':', $server);
- if (!@$MemCache->__Memcache->connect($host, $port)) {
+ if (!$Memcache->addServer($host, $port)) {
$available = false;
}
}
@@ -118,13 +108,13 @@ function testMultipleServers() {
if ($this->skipIf(!$available, '%s Need memcache servers at ' . implode(', ', $servers) . ' to run this test')) {
return;
}
+ $Memcache =& new MemcacheEngine();
+ $Memcache->init(array('engine' => 'Memcache', 'servers' => $servers));
- unset($MemCache->__Memcache);
- $MemCache->init(array('engine' => 'Memcache', 'servers' => $servers));
-
- $servers = array_keys($MemCache->__Memcache->getExtendedStats());
- $settings = Cache::settings();
+ $servers = array_keys($Memcache->__Memcache->getExtendedStats());
+ $settings = $Memcache->settings();
$this->assertEqual($servers, $settings['servers']);
+ Cache::drop('dual_server');
}
/**
@@ -134,8 +124,9 @@ function testMultipleServers() {
* @return void
*/
function testConnect() {
- $Cache =& Cache::getInstance();
- $result = $Cache->_Engine['Memcache']->connect('127.0.0.1');
+ $Memcache =& new MemcacheEngine();
+ $Memcache->init(Cache::settings('memcache'));
+ $result = $Memcache->connect('127.0.0.1');
$this->assertTrue($result);
}
@@ -193,13 +184,13 @@ function testExpiry() {
$result = Cache::read('other_test');
$this->assertFalse($result);
- Cache::engine('Memcache', array('duration' => '+1 second'));
+ Cache::config('memcache', array('duration' => '+1 second'));
sleep(2);
$result = Cache::read('other_test');
$this->assertFalse($result);
- Cache::engine('Memcache', array('duration' => '+31 day'));
+ Cache::config('memcache', array('duration' => '+31 day'));
$data = 'this is a test of the emergency broadcasting system';
$result = Cache::write('long_expiry_test', $data);
$this->assertTrue($result);
@@ -212,7 +203,7 @@ function testExpiry() {
$result = Cache::read('long_expiry_test');
$this->assertTrue($result);
- Cache::engine('Memcache', array('duration' => 3600));
+ Cache::config('memcache', array('duration' => 3600));
}
/**
View
19 cake/tests/cases/libs/cache/xcache.test.php
@@ -39,7 +39,7 @@ class XcacheEngineTest extends UnitTestCase {
*/
function skip() {
$skip = true;
- if ($result = Cache::engine('Xcache')) {
+ if (function_exists('xcache_set')) {
$skip = false;
}
$this->skipIf($skip, '%s Xcache is not installed or configured properly');
@@ -76,13 +76,16 @@ function tearDown() {
*/
function testSettings() {
$settings = Cache::settings();
- $expecting = array('prefix' => 'cake_',
- 'duration'=> 3600,
- 'probability' => 100,
- 'engine' => 'Xcache',
- 'PHP_AUTH_USER' => 'user',
- 'PHP_AUTH_PW' => 'password',
- );
+ $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->assertEqual($settings, $expecting);
}
View
23 cake/tests/cases/libs/view/helpers/paginator.test.php
@@ -195,6 +195,29 @@ function testSortLinks() {
$this->Paginator->params['paging']['Article']['options']['sort'] = null;
$result = $this->Paginator->sort('title');
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result);
+
+ $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
+ $this->Paginator->params['paging']['Article']['options']['sort'] = null;
+ $result = $this->Paginator->sort('Title', 'title', array('direction' => 'desc'));
+ $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc" class="desc">Title<\/a>$/', $result);
+
+
+ $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
+ $this->Paginator->params['paging']['Article']['options']['sort'] = null;
+ $result = $this->Paginator->sort('Title', 'title', array('direction' => 'asc'));
+ $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc" class="desc">Title<\/a>$/', $result);
+
+
+ $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
+ $this->Paginator->params['paging']['Article']['options']['sort'] = null;
+ $result = $this->Paginator->sort('Title', 'title', array('direction' => 'asc'));
+ $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result);
+
+
+ $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
+ $this->Paginator->params['paging']['Article']['options']['sort'] = null;
+ $result = $this->Paginator->sort('Title', 'title', array('direction' => 'desc'));
+ $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result);
}
Please sign in to comment.
Something went wrong with that request. Please try again.