mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge remote-tracking branch 'origin/2.0' into 2.0-class-loading
This commit is contained in:
commit
0cd51de827
9 changed files with 169 additions and 167 deletions
|
@ -1,9 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* This file is loaded automatically by the app/webroot/index.php file after the core bootstrap.php
|
* This file is loaded automatically by the app/webroot/index.php file after core.php
|
||||||
*
|
*
|
||||||
* This is an application wide file to load any function that is not used within a class
|
* This file should load/create any application wide configuration settings, such as
|
||||||
* define. You can also use this to include or require any files in your application.
|
* Caching, Logging, loading additional configuration files.
|
||||||
|
*
|
||||||
|
* You should also use this file to include any files that provide global functions/constants
|
||||||
|
* that your application uses.
|
||||||
*
|
*
|
||||||
* PHP 5
|
* PHP 5
|
||||||
*
|
*
|
||||||
|
@ -20,6 +23,9 @@
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Setup a 'default' cache configuration for use in the application.
|
||||||
|
Cache::config('default', array('engine' => 'File'));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The settings below can be used to set additional paths to models, views and controllers.
|
* The settings below can be used to set additional paths to models, views and controllers.
|
||||||
* This is related to Ticket #470 (https://trac.cakephp.org/ticket/470)
|
* This is related to Ticket #470 (https://trac.cakephp.org/ticket/470)
|
||||||
|
|
|
@ -283,4 +283,40 @@
|
||||||
* ));
|
* ));
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Cache::config('default', array('engine' => 'File'));
|
|
||||||
|
// Pick the caching engine to use. If APC is enabled use it.
|
||||||
|
$engine = 'File';
|
||||||
|
if (extension_loaded('apc')) {
|
||||||
|
$engine = 'Apc';
|
||||||
|
}
|
||||||
|
|
||||||
|
// In development mode, caches should expire quickly.
|
||||||
|
$duration = '+999 days';
|
||||||
|
if (Configure::read('debug') >= 1) {
|
||||||
|
$duration = '+10 seconds';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure the cache used for general framework caching. Path information,
|
||||||
|
* object listings, and translation cache files are stored with this configuration.
|
||||||
|
*/
|
||||||
|
Cache::config('_cake_core_', array(
|
||||||
|
'engine' => $engine,
|
||||||
|
'prefix' => 'cake_core_',
|
||||||
|
'path' => CACHE . 'persistent' . DS,
|
||||||
|
'serialize' => ($engine === 'File'),
|
||||||
|
'duration' => $duration
|
||||||
|
));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure the cache for model, and datasource caches. This cache configuration
|
||||||
|
* is used to store schema descriptions, and table listings in connections.
|
||||||
|
*/
|
||||||
|
Cache::config('_cake_model_', array(
|
||||||
|
'engine' => $engine,
|
||||||
|
'prefix' => 'cake_model_',
|
||||||
|
'path' => CACHE . 'models' . DS,
|
||||||
|
'serialize' => ($engine === 'File'),
|
||||||
|
'duration' => $duration
|
||||||
|
));
|
||||||
|
|
||||||
|
|
|
@ -73,14 +73,24 @@ class Cache {
|
||||||
* both create new configurations, return the settings for already configured
|
* both create new configurations, return the settings for already configured
|
||||||
* configurations.
|
* configurations.
|
||||||
*
|
*
|
||||||
* To create a new configuration:
|
* To create a new configuration, or to modify an existing configuration permanently:
|
||||||
*
|
*
|
||||||
* `Cache::config('my_config', array('engine' => 'File', 'path' => TMP));`
|
* `Cache::config('my_config', array('engine' => 'File', 'path' => TMP));`
|
||||||
*
|
*
|
||||||
* To get the settings for a configuration, and set it as the currently selected configuration
|
* If you need to modify a configuration temporarily, use Cache::set().
|
||||||
|
* To get the settings for a configuration:
|
||||||
*
|
*
|
||||||
* `Cache::config('default');`
|
* `Cache::config('default');`
|
||||||
*
|
*
|
||||||
|
* There are 4 built-in caching engines:
|
||||||
|
*
|
||||||
|
* - `FileEngine` - Uses simple files to store content. Poor performance, but good for
|
||||||
|
* storing large objects, or things that are not IO sensitive.
|
||||||
|
* - `ApcEngine` - Uses the APC object cache, one of the fastest caching engines.
|
||||||
|
* - `MemcacheEngine` - Uses the PECL::Memcache extension and Memcached for storage.
|
||||||
|
* Fast reads/writes, and benefits from memcache being distributed.
|
||||||
|
* - `XcacheEngine` - Uses the Xcache extension, an alternative to APC.
|
||||||
|
*
|
||||||
* @see app/config/core.php for configuration settings
|
* @see app/config/core.php for configuration settings
|
||||||
* @param string $name Name of the configuration
|
* @param string $name Name of the configuration
|
||||||
* @param array $settings Optional associative array of settings passed to the engine
|
* @param array $settings Optional associative array of settings passed to the engine
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* File Storage engine for cache
|
* File Storage engine for cache. Filestorage is the slowest cache storage
|
||||||
|
* to read and write. However, it is good for servers that don't have other storage
|
||||||
|
* engine available, or have content which is not performance sensitive.
|
||||||
*
|
*
|
||||||
|
* You can configure a FileEngine cache, using Cache::config()
|
||||||
*
|
*
|
||||||
* PHP 5
|
* PHP 5
|
||||||
*
|
*
|
||||||
|
@ -13,7 +16,6 @@
|
||||||
*
|
*
|
||||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
* @link http://cakephp.org CakePHP(tm) Project
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
* @package cake.libs.cache
|
|
||||||
* @since CakePHP(tm) v 1.2.0.4933
|
* @since CakePHP(tm) v 1.2.0.4933
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
|
@ -21,7 +23,6 @@
|
||||||
/**
|
/**
|
||||||
* File Storage engine for cache
|
* File Storage engine for cache
|
||||||
*
|
*
|
||||||
* @todo use the File and Folder classes (if it's not a too big performance hit)
|
|
||||||
* @package cake.libs.cache
|
* @package cake.libs.cache
|
||||||
*/
|
*/
|
||||||
class FileEngine extends CacheEngine {
|
class FileEngine extends CacheEngine {
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* This file is loaded automatically by the app/webroot/index.php file after the core bootstrap.php
|
* This file is loaded automatically by the app/webroot/index.php file after core.php
|
||||||
*
|
*
|
||||||
* This is an application wide file to load any function that is not used within a class
|
* This file should load/create any application wide configuration settings, such as
|
||||||
* define. You can also use this to include or require any files in your application.
|
* Caching, Logging, loading additional configuration files.
|
||||||
|
*
|
||||||
|
* You should also use this file to include any files that provide global functions/constants
|
||||||
|
* that your application uses.
|
||||||
*
|
*
|
||||||
* PHP 5
|
* PHP 5
|
||||||
*
|
*
|
||||||
|
@ -20,6 +23,9 @@
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Setup a 'default' cache configuration for use in the application.
|
||||||
|
Cache::config('default', array('engine' => 'File'));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The settings below can be used to set additional paths to models, views and controllers.
|
* The settings below can be used to set additional paths to models, views and controllers.
|
||||||
* This is related to Ticket #470 (https://trac.cakephp.org/ticket/470)
|
* This is related to Ticket #470 (https://trac.cakephp.org/ticket/470)
|
||||||
|
@ -28,7 +34,7 @@
|
||||||
* 'plugins' => array('/full/path/to/plugins/', '/next/full/path/to/plugins/'),
|
* 'plugins' => array('/full/path/to/plugins/', '/next/full/path/to/plugins/'),
|
||||||
* 'models' => array('/full/path/to/models/', '/next/full/path/to/models/'),
|
* 'models' => array('/full/path/to/models/', '/next/full/path/to/models/'),
|
||||||
* 'views' => array('/full/path/to/views/', '/next/full/path/to/views/'),
|
* 'views' => array('/full/path/to/views/', '/next/full/path/to/views/'),
|
||||||
* 'controllers' => array(/full/path/to/controllers/', '/next/full/path/to/controllers/'),
|
* 'controllers' => array('/full/path/to/controllers/', '/next/full/path/to/controllers/'),
|
||||||
* 'datasources' => array('/full/path/to/datasources/', '/next/full/path/to/datasources/'),
|
* 'datasources' => array('/full/path/to/datasources/', '/next/full/path/to/datasources/'),
|
||||||
* 'behaviors' => array('/full/path/to/behaviors/', '/next/full/path/to/behaviors/'),
|
* 'behaviors' => array('/full/path/to/behaviors/', '/next/full/path/to/behaviors/'),
|
||||||
* 'components' => array('/full/path/to/components/', '/next/full/path/to/components/'),
|
* 'components' => array('/full/path/to/components/', '/next/full/path/to/components/'),
|
||||||
|
|
|
@ -283,4 +283,40 @@
|
||||||
* ));
|
* ));
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Cache::config('default', array('engine' => 'File'));
|
|
||||||
|
// Pick the caching engine to use. If APC is enabled use it.
|
||||||
|
$engine = 'File';
|
||||||
|
if (extension_loaded('apc')) {
|
||||||
|
$engine = 'Apc';
|
||||||
|
}
|
||||||
|
|
||||||
|
// In development mode, caches should expire quickly.
|
||||||
|
$duration = '+999 days';
|
||||||
|
if (Configure::read('debug') >= 1) {
|
||||||
|
$duration = '+10 seconds';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure the cache used for general framework caching. Path information,
|
||||||
|
* object listings, and translation cache files are stored with this configuration.
|
||||||
|
*/
|
||||||
|
Cache::config('_cake_core_', array(
|
||||||
|
'engine' => $engine,
|
||||||
|
'prefix' => 'cake_core_',
|
||||||
|
'path' => CACHE . 'persistent' . DS,
|
||||||
|
'serialize' => ($engine === 'File'),
|
||||||
|
'duration' => $duration
|
||||||
|
));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure the cache for model, and datasource caches. This cache configuration
|
||||||
|
* is used to store schema descriptions, and table listings in connections.
|
||||||
|
*/
|
||||||
|
Cache::config('_cake_model_', array(
|
||||||
|
'engine' => $engine,
|
||||||
|
'prefix' => 'cake_model_',
|
||||||
|
'path' => CACHE . 'models' . DS,
|
||||||
|
'serialize' => ($engine === 'File'),
|
||||||
|
'duration' => $duration
|
||||||
|
));
|
||||||
|
|
||||||
|
|
|
@ -186,7 +186,7 @@ class SecurityComponent extends Component {
|
||||||
*/
|
*/
|
||||||
public function startup($controller) {
|
public function startup($controller) {
|
||||||
$this->request = $controller->request;
|
$this->request = $controller->request;
|
||||||
$this->_action = strtolower($this->request->params['action']);
|
$this->_action = $this->request->params['action'];
|
||||||
$this->_methodsRequired($controller);
|
$this->_methodsRequired($controller);
|
||||||
$this->_secureRequired($controller);
|
$this->_secureRequired($controller);
|
||||||
$this->_authRequired($controller);
|
$this->_authRequired($controller);
|
||||||
|
@ -321,10 +321,10 @@ class SecurityComponent extends Component {
|
||||||
foreach (array('Post', 'Get', 'Put', 'Delete') as $method) {
|
foreach (array('Post', 'Get', 'Put', 'Delete') as $method) {
|
||||||
$property = 'require' . $method;
|
$property = 'require' . $method;
|
||||||
if (is_array($this->$property) && !empty($this->$property)) {
|
if (is_array($this->$property) && !empty($this->$property)) {
|
||||||
$require = array_map('strtolower', $this->$property);
|
$require = $this->$property;
|
||||||
if (in_array($this->_action, $require) || $this->$property == array('*')) {
|
if (in_array($this->_action, $require) || $this->$property == array('*')) {
|
||||||
if (!$this->request->is(strtolower($method))) {
|
if (!$this->request->is($method)) {
|
||||||
if (!$this->blackHole($controller, strtolower($method))) {
|
if (!$this->blackHole($controller, $method)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -342,7 +342,7 @@ class SecurityComponent extends Component {
|
||||||
*/
|
*/
|
||||||
protected function _secureRequired($controller) {
|
protected function _secureRequired($controller) {
|
||||||
if (is_array($this->requireSecure) && !empty($this->requireSecure)) {
|
if (is_array($this->requireSecure) && !empty($this->requireSecure)) {
|
||||||
$requireSecure = array_map('strtolower', $this->requireSecure);
|
$requireSecure = $this->requireSecure;
|
||||||
|
|
||||||
if (in_array($this->_action, $requireSecure) || $this->requireSecure == array('*')) {
|
if (in_array($this->_action, $requireSecure) || $this->requireSecure == array('*')) {
|
||||||
if (!$this->request->is('ssl')) {
|
if (!$this->request->is('ssl')) {
|
||||||
|
@ -363,7 +363,7 @@ class SecurityComponent extends Component {
|
||||||
*/
|
*/
|
||||||
protected function _authRequired($controller) {
|
protected function _authRequired($controller) {
|
||||||
if (is_array($this->requireAuth) && !empty($this->requireAuth) && !empty($this->request->data)) {
|
if (is_array($this->requireAuth) && !empty($this->requireAuth) && !empty($this->request->data)) {
|
||||||
$requireAuth = array_map('strtolower', $this->requireAuth);
|
$requireAuth = $this->requireAuth;
|
||||||
|
|
||||||
if (in_array($this->request->params['action'], $requireAuth) || $this->requireAuth == array('*')) {
|
if (in_array($this->request->params['action'], $requireAuth) || $this->requireAuth == array('*')) {
|
||||||
if (!isset($controller->request->data['_Token'] )) {
|
if (!isset($controller->request->data['_Token'] )) {
|
||||||
|
|
|
@ -73,43 +73,6 @@ class Configure {
|
||||||
trigger_error(__("Can't find application core file. Please create %score.php, and make sure it is readable by PHP.", CONFIGS), E_USER_ERROR);
|
trigger_error(__("Can't find application core file. Please create %score.php, and make sure it is readable by PHP.", CONFIGS), E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty(self::$_values['Cache']['disable'])) {
|
|
||||||
$cache = Cache::config('default');
|
|
||||||
|
|
||||||
if (empty($cache['settings'])) {
|
|
||||||
trigger_error(__('Cache not configured properly. Please check Cache::config(); in APP/config/core.php'), E_USER_WARNING);
|
|
||||||
$cache = Cache::config('default', array('engine' => 'File'));
|
|
||||||
}
|
|
||||||
$path = $prefix = $duration = null;
|
|
||||||
|
|
||||||
if (!empty($cache['settings']['path'])) {
|
|
||||||
$path = realpath($cache['settings']['path']);
|
|
||||||
} else {
|
|
||||||
$prefix = $cache['settings']['prefix'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self::$_values['debug'] >= 1) {
|
|
||||||
$duration = '+10 seconds';
|
|
||||||
} else {
|
|
||||||
$duration = '+999 days';
|
|
||||||
}
|
|
||||||
$cacheConfigs = Cache::configured();
|
|
||||||
|
|
||||||
if (!in_array('_cake_core_', $cacheConfigs)) {
|
|
||||||
Cache::config('_cake_core_', array_merge((array)$cache['settings'], array(
|
|
||||||
'prefix' => $prefix . 'cake_core_', 'path' => $path . DS . 'persistent' . DS,
|
|
||||||
'serialize' => true, 'duration' => $duration
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!in_array('_cake_model_', $cacheConfigs)) {
|
|
||||||
Cache::config('_cake_model_', array_merge((array)$cache['settings'], array(
|
|
||||||
'prefix' => $prefix . 'cake_model_', 'path' => $path . DS . 'models' . DS,
|
|
||||||
'serialize' => true, 'duration' => $duration
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
App::init();
|
App::init();
|
||||||
App::build();
|
App::build();
|
||||||
if (!include(CONFIGS . 'bootstrap.php')) {
|
if (!include(CONFIGS . 'bootstrap.php')) {
|
||||||
|
|
164
lib/Cake/tests/cases/libs/cache/file.test.php
vendored
164
lib/Cake/tests/cases/libs/cache/file.test.php
vendored
|
@ -41,10 +41,9 @@ class FileEngineTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function setUp() {
|
function setUp() {
|
||||||
$this->_cacheDisable = Configure::read('Cache.disable');
|
parent::setUp();
|
||||||
$this->_cacheConfig = Cache::config('default');
|
|
||||||
Configure::write('Cache.disable', false);
|
Configure::write('Cache.disable', false);
|
||||||
Cache::config('default', array('engine' => 'File', 'path' => CACHE));
|
Cache::config('file_test', array('engine' => 'File', 'path' => CACHE));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,9 +53,9 @@ class FileEngineTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function tearDown() {
|
function tearDown() {
|
||||||
Cache::clear(false, 'default');
|
parent::tearDown();
|
||||||
Configure::write('Cache.disable', $this->_cacheDisable);
|
Cache::clear(false, 'file_test');
|
||||||
Cache::config('default', $this->_cacheConfig['settings']);
|
Cache::drop('file_test');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,24 +82,24 @@ class FileEngineTest extends CakeTestCase {
|
||||||
function testReadAndWriteCache() {
|
function testReadAndWriteCache() {
|
||||||
Cache::config('default');
|
Cache::config('default');
|
||||||
|
|
||||||
$result = Cache::write(null, 'here');
|
$result = Cache::write(null, 'here', 'file_test');
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
|
|
||||||
Cache::set(array('duration' => 1));
|
Cache::set(array('duration' => 1), 'file_test');
|
||||||
|
|
||||||
$result = Cache::read('test');
|
$result = Cache::read('test', 'file_test');
|
||||||
$expecting = '';
|
$expecting = '';
|
||||||
$this->assertEqual($result, $expecting);
|
$this->assertEqual($result, $expecting);
|
||||||
|
|
||||||
$data = 'this is a test of the emergency broadcasting system';
|
$data = 'this is a test of the emergency broadcasting system';
|
||||||
$result = Cache::write('test', $data);
|
$result = Cache::write('test', $data, 'file_test');
|
||||||
$this->assertTrue(file_exists(CACHE . 'cake_test'));
|
$this->assertTrue(file_exists(CACHE . 'cake_test'));
|
||||||
|
|
||||||
$result = Cache::read('test');
|
$result = Cache::read('test', 'file_test');
|
||||||
$expecting = $data;
|
$expecting = $data;
|
||||||
$this->assertEqual($result, $expecting);
|
$this->assertEqual($result, $expecting);
|
||||||
|
|
||||||
Cache::delete('test');
|
Cache::delete('test', 'file_test');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -110,27 +109,27 @@ class FileEngineTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testExpiry() {
|
function testExpiry() {
|
||||||
Cache::set(array('duration' => 1));
|
Cache::set(array('duration' => 1), 'file_test');
|
||||||
|
|
||||||
$result = Cache::read('test');
|
$result = Cache::read('test', 'file_test');
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
|
|
||||||
$data = 'this is a test of the emergency broadcasting system';
|
$data = 'this is a test of the emergency broadcasting system';
|
||||||
$result = Cache::write('other_test', $data);
|
$result = Cache::write('other_test', $data, 'file_test');
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
sleep(2);
|
sleep(2);
|
||||||
$result = Cache::read('other_test');
|
$result = Cache::read('other_test', 'file_test');
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
|
|
||||||
Cache::set(array('duration' => "+1 second"));
|
Cache::set(array('duration' => "+1 second"), 'file_test');
|
||||||
|
|
||||||
$data = 'this is a test of the emergency broadcasting system';
|
$data = 'this is a test of the emergency broadcasting system';
|
||||||
$result = Cache::write('other_test', $data);
|
$result = Cache::write('other_test', $data, 'file_test');
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
sleep(2);
|
sleep(2);
|
||||||
$result = Cache::read('other_test');
|
$result = Cache::read('other_test', 'file_test');
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,14 +141,14 @@ class FileEngineTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testDeleteCache() {
|
function testDeleteCache() {
|
||||||
$data = 'this is a test of the emergency broadcasting system';
|
$data = 'this is a test of the emergency broadcasting system';
|
||||||
$result = Cache::write('delete_test', $data);
|
$result = Cache::write('delete_test', $data, 'file_test');
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
$result = Cache::delete('delete_test');
|
$result = Cache::delete('delete_test', 'file_test');
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertFalse(file_exists(TMP . 'tests' . DS . 'delete_test'));
|
$this->assertFalse(file_exists(TMP . 'tests' . DS . 'delete_test'));
|
||||||
|
|
||||||
$result = Cache::delete('delete_test');
|
$result = Cache::delete('delete_test', 'file_test');
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,17 +159,17 @@ class FileEngineTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testSerialize() {
|
function testSerialize() {
|
||||||
Cache::config('default', array('engine' => 'File', 'serialize' => true));
|
Cache::config('file_test', array('engine' => 'File', 'serialize' => true));
|
||||||
$data = 'this is a test of the emergency broadcasting system';
|
$data = 'this is a test of the emergency broadcasting system';
|
||||||
$write = Cache::write('serialize_test', $data);
|
$write = Cache::write('serialize_test', $data, 'file_test');
|
||||||
$this->assertTrue($write);
|
$this->assertTrue($write);
|
||||||
|
|
||||||
Cache::config('default', array('serialize' => false));
|
Cache::config('file_test', array('serialize' => false));
|
||||||
$read = Cache::read('serialize_test');
|
$read = Cache::read('serialize_test', 'file_test');
|
||||||
|
|
||||||
$newread = Cache::read('serialize_test');
|
$newread = Cache::read('serialize_test', 'file_test');
|
||||||
|
|
||||||
$delete = Cache::delete('serialize_test');
|
$delete = Cache::delete('serialize_test', 'file_test');
|
||||||
|
|
||||||
$this->assertIdentical($read, serialize($data));
|
$this->assertIdentical($read, serialize($data));
|
||||||
|
|
||||||
|
@ -184,91 +183,35 @@ class FileEngineTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testClear() {
|
function testClear() {
|
||||||
Cache::config('default', array('engine' => 'File', 'duration' => 1));
|
Cache::config('file_test', array('engine' => 'File', 'duration' => 1));
|
||||||
|
|
||||||
$data = 'this is a test of the emergency broadcasting system';
|
$data = 'this is a test of the emergency broadcasting system';
|
||||||
$write = Cache::write('serialize_test1', $data);
|
$write = Cache::write('serialize_test1', $data, 'file_test');
|
||||||
$write = Cache::write('serialize_test2', $data);
|
$write = Cache::write('serialize_test2', $data, 'file_test');
|
||||||
$write = Cache::write('serialize_test3', $data);
|
$write = Cache::write('serialize_test3', $data, 'file_test');
|
||||||
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test1'));
|
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test1'));
|
||||||
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test2'));
|
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test2'));
|
||||||
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test3'));
|
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test3'));
|
||||||
sleep(2);
|
sleep(2);
|
||||||
$result = Cache::clear(true);
|
$result = Cache::clear(true, 'file_test');
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test1'));
|
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test1'));
|
||||||
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test2'));
|
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test2'));
|
||||||
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test3'));
|
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test3'));
|
||||||
|
|
||||||
$data = 'this is a test of the emergency broadcasting system';
|
$data = 'this is a test of the emergency broadcasting system';
|
||||||
$write = Cache::write('serialize_test1', $data);
|
$write = Cache::write('serialize_test1', $data, 'file_test');
|
||||||
$write = Cache::write('serialize_test2', $data);
|
$write = Cache::write('serialize_test2', $data, 'file_test');
|
||||||
$write = Cache::write('serialize_test3', $data);
|
$write = Cache::write('serialize_test3', $data, 'file_test');
|
||||||
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test1'));
|
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test1'));
|
||||||
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test2'));
|
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test2'));
|
||||||
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test3'));
|
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test3'));
|
||||||
|
|
||||||
$result = Cache::clear();
|
$result = Cache::clear(false, 'file_test');
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test1'));
|
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test1'));
|
||||||
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test2'));
|
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test2'));
|
||||||
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test3'));
|
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test3'));
|
||||||
|
|
||||||
Cache::config('default', array('engine' => 'File', 'path' => CACHE . 'views' . DS));
|
|
||||||
|
|
||||||
$data = 'this is a test of the emergency broadcasting system';
|
|
||||||
$write = Cache::write('controller_view_1', $data);
|
|
||||||
$write = Cache::write('controller_view_2', $data);
|
|
||||||
$write = Cache::write('controller_view_3', $data);
|
|
||||||
$write = Cache::write('controller_view_10', $data);
|
|
||||||
$write = Cache::write('controller_view_11', $data);
|
|
||||||
$write = Cache::write('controller_view_12', $data);
|
|
||||||
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_1'));
|
|
||||||
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_2'));
|
|
||||||
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_3'));
|
|
||||||
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_10'));
|
|
||||||
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_11'));
|
|
||||||
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_12'));
|
|
||||||
|
|
||||||
clearCache('controller_view_1', 'views', '');
|
|
||||||
$this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_1'));
|
|
||||||
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_2'));
|
|
||||||
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_3'));
|
|
||||||
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_10'));
|
|
||||||
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_11'));
|
|
||||||
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_12'));
|
|
||||||
|
|
||||||
clearCache('controller_view', 'views', '');
|
|
||||||
$this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_1'));
|
|
||||||
$this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_2'));
|
|
||||||
$this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_3'));
|
|
||||||
$this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_10'));
|
|
||||||
$this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_11'));
|
|
||||||
$this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_12'));
|
|
||||||
|
|
||||||
$write = Cache::write('controller_view_1', $data);
|
|
||||||
$write = Cache::write('controller_view_2', $data);
|
|
||||||
$write = Cache::write('controller_view_3', $data);
|
|
||||||
$write = Cache::write('controller_view_10', $data);
|
|
||||||
$write = Cache::write('controller_view_11', $data);
|
|
||||||
$write = Cache::write('controller_view_12', $data);
|
|
||||||
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_1'));
|
|
||||||
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_2'));
|
|
||||||
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_3'));
|
|
||||||
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_10'));
|
|
||||||
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_11'));
|
|
||||||
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_12'));
|
|
||||||
|
|
||||||
clearCache(array('controller_view_2', 'controller_view_11', 'controller_view_12'), 'views', '');
|
|
||||||
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_1'));
|
|
||||||
$this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_2'));
|
|
||||||
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_3'));
|
|
||||||
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_10'));
|
|
||||||
$this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_11'));
|
|
||||||
$this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_12'));
|
|
||||||
|
|
||||||
clearCache('controller_view');
|
|
||||||
|
|
||||||
Cache::config('default', array('engine' => 'File', 'path' => CACHE));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -289,14 +232,15 @@ class FileEngineTest extends CakeTestCase {
|
||||||
));
|
));
|
||||||
|
|
||||||
$data1 = $data2 = $expected = 'content to cache';
|
$data1 = $data2 = $expected = 'content to cache';
|
||||||
$FileOne->write('key_one', $data1, DAY);
|
$FileOne->write('prefix_one_key_one', $data1, DAY);
|
||||||
$FileTwo->write('key_two', $data2, DAY);
|
$FileTwo->write('prefix_two_key_two', $data2, DAY);
|
||||||
|
|
||||||
$this->assertEqual($FileOne->read('key_one'), $expected);
|
$this->assertEqual($FileOne->read('prefix_one_key_one'), $expected);
|
||||||
$this->assertEqual($FileTwo->read('key_two'), $expected);
|
$this->assertEqual($FileTwo->read('prefix_two_key_two'), $expected);
|
||||||
|
|
||||||
$FileOne->clear(false);
|
$FileOne->clear(false);
|
||||||
$this->assertEqual($FileTwo->read('key_two'), $expected, 'secondary config was cleared by accident.');
|
$this->assertEqual($FileTwo->read('prefix_two_key_two'), $expected, 'secondary config was cleared by accident.');
|
||||||
|
$FileTwo->clear(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -306,11 +250,11 @@ class FileEngineTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testKeyPath() {
|
function testKeyPath() {
|
||||||
$result = Cache::write('views.countries.something', 'here');
|
$result = Cache::write('views.countries.something', 'here', 'file_test');
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertTrue(file_exists(CACHE . 'cake_views_countries_something'));
|
$this->assertTrue(file_exists(CACHE . 'cake_views_countries_something'));
|
||||||
|
|
||||||
$result = Cache::read('views.countries.something');
|
$result = Cache::read('views.countries.something', 'file_test');
|
||||||
$this->assertEqual($result, 'here');
|
$this->assertEqual($result, 'here');
|
||||||
|
|
||||||
$result = Cache::clear();
|
$result = Cache::clear();
|
||||||
|
@ -370,16 +314,16 @@ class FileEngineTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testWriteQuotedString() {
|
function testWriteQuotedString() {
|
||||||
Cache::config('default', array('engine' => 'File', 'path' => TMP . 'tests'));
|
Cache::config('file_test', array('engine' => 'File', 'path' => TMP . 'tests'));
|
||||||
Cache::write('App.doubleQuoteTest', '"this is a quoted string"');
|
Cache::write('App.doubleQuoteTest', '"this is a quoted string"', 'file_test');
|
||||||
$this->assertIdentical(Cache::read('App.doubleQuoteTest'), '"this is a quoted string"');
|
$this->assertIdentical(Cache::read('App.doubleQuoteTest', 'file_test'), '"this is a quoted string"');
|
||||||
Cache::write('App.singleQuoteTest', "'this is a quoted string'");
|
Cache::write('App.singleQuoteTest', "'this is a quoted string'", 'file_test');
|
||||||
$this->assertIdentical(Cache::read('App.singleQuoteTest'), "'this is a quoted string'");
|
$this->assertIdentical(Cache::read('App.singleQuoteTest', 'file_test'), "'this is a quoted string'");
|
||||||
|
|
||||||
Cache::config('default', array('isWindows' => true, 'path' => TMP . 'tests'));
|
Cache::config('file_test', array('isWindows' => true, 'path' => TMP . 'tests'));
|
||||||
$this->assertIdentical(Cache::read('App.doubleQuoteTest'), '"this is a quoted string"');
|
$this->assertIdentical(Cache::read('App.doubleQuoteTest', 'file_test'), '"this is a quoted string"');
|
||||||
Cache::write('App.singleQuoteTest', "'this is a quoted string'");
|
Cache::write('App.singleQuoteTest', "'this is a quoted string'", 'file_test');
|
||||||
$this->assertIdentical(Cache::read('App.singleQuoteTest'), "'this is a quoted string'");
|
$this->assertIdentical(Cache::read('App.singleQuoteTest', 'file_test'), "'this is a quoted string'");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue