mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-16 03:48:24 +00:00
91a1cf81f3
Conflicts: app/Config/acl.ini.php app/config/database.php.default app/webroot/css.php app/webroot/css/cake.generic.css cake/basics.php cake/bootstrap.php cake/config/paths.php cake/console/cake.php cake/console/error.php cake/console/libs/acl.php cake/console/libs/bake.php cake/console/libs/i18n.php cake/console/libs/shell.php cake/console/libs/tasks/extract.php cake/console/libs/tasks/plugin.php cake/console/libs/tasks/project.php cake/console/libs/testsuite.php cake/console/templates/default/classes/test.ctp cake/console/templates/default/views/home.ctp cake/console/templates/default/views/view.ctp cake/console/templates/skel/config/database.php.default cake/console/templates/skel/views/elements/email/text/default.ctp cake/console/templates/skel/webroot/css.php cake/dispatcher.php cake/libs/cache.php cake/libs/cake_session.php cake/libs/configure.php cake/libs/controller/component.php cake/libs/controller/components/auth.php cake/libs/controller/components/email.php cake/libs/controller/components/request_handler.php cake/libs/controller/components/security.php cake/libs/controller/controller.php cake/libs/controller/scaffold.php cake/libs/error.php cake/libs/magic_db.php cake/libs/model/behaviors/acl.php cake/libs/model/connection_manager.php cake/libs/model/datasources/dbo/dbo_mysqli.php cake/libs/model/model_behavior.php cake/libs/overloadable.php cake/libs/overloadable_php4.php cake/libs/overloadable_php5.php cake/libs/router.php cake/libs/view/errors/missing_action.ctp cake/libs/view/errors/missing_behavior_class.ctp cake/libs/view/errors/missing_behavior_file.ctp cake/libs/view/errors/missing_component_class.ctp cake/libs/view/errors/missing_component_file.ctp cake/libs/view/errors/missing_connection.ctp cake/libs/view/errors/missing_controller.ctp cake/libs/view/errors/missing_helper_class.ctp cake/libs/view/errors/missing_helper_file.ctp cake/libs/view/errors/missing_layout.ctp cake/libs/view/errors/missing_model.ctp cake/libs/view/errors/missing_scaffolddb.ctp cake/libs/view/errors/missing_table.ctp cake/libs/view/errors/missing_view.ctp cake/libs/view/errors/private_action.ctp cake/libs/view/errors/scaffold_error.ctp cake/libs/view/helpers/ajax.php cake/libs/view/helpers/javascript.php cake/libs/view/helpers/js.php cake/libs/view/helpers/session.php cake/libs/view/helpers/xml.php cake/libs/view/media.php cake/libs/view/pages/home.ctp cake/libs/view/scaffolds/edit.ctp cake/libs/view/scaffolds/index.ctp cake/libs/view/scaffolds/view.ctp cake/libs/view/view.php cake/libs/xml.php cake/tests/cases/console/cake.test.php cake/tests/cases/console/libs/acl.test.php cake/tests/cases/console/libs/api.test.php cake/tests/cases/console/libs/bake.test.php cake/tests/cases/console/libs/shell.test.php cake/tests/cases/console/libs/tasks/controller.test.php cake/tests/cases/console/libs/tasks/db_config.test.php cake/tests/cases/console/libs/tasks/fixture.test.php cake/tests/cases/console/libs/tasks/model.test.php cake/tests/cases/console/libs/tasks/plugin.test.php cake/tests/cases/console/libs/tasks/project.test.php cake/tests/cases/console/libs/tasks/test.test.php cake/tests/cases/console/libs/tasks/view.test.php cake/tests/cases/dispatcher.test.php cake/tests/cases/libs/cache/apc.test.php cake/tests/cases/libs/cake_session.test.php cake/tests/cases/libs/cake_test_case.test.php cake/tests/cases/libs/code_coverage_manager.test.php cake/tests/cases/libs/configure.test.php cake/tests/cases/libs/controller/component.test.php cake/tests/cases/libs/controller/components/auth.test.php cake/tests/cases/libs/controller/components/cookie.test.php cake/tests/cases/libs/controller/components/request_handler.test.php cake/tests/cases/libs/controller/components/session.test.php cake/tests/cases/libs/controller/controller.test.php cake/tests/cases/libs/controller/pages_controller.test.php cake/tests/cases/libs/error.test.php cake/tests/cases/libs/http_socket.test.php cake/tests/cases/libs/magic_db.test.php cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php cake/tests/cases/libs/model/datasources/dbo_source.test.php cake/tests/cases/libs/model/models.php cake/tests/cases/libs/overloadable.test.php cake/tests/cases/libs/test_manager.test.php cake/tests/cases/libs/view/helpers/ajax.test.php cake/tests/cases/libs/view/helpers/javascript.test.php cake/tests/cases/libs/view/helpers/session.test.php cake/tests/cases/libs/view/helpers/xml.test.php cake/tests/cases/libs/view/media.test.php cake/tests/cases/libs/view/theme.test.php cake/tests/cases/libs/xml.test.php cake/tests/fixtures/aco_fixture.php cake/tests/fixtures/translate_fixture.php cake/tests/groups/acl.group.php cake/tests/groups/bake.group.php cake/tests/groups/behaviors.group.php cake/tests/groups/cache.group.php cake/tests/groups/components.group.php cake/tests/groups/configure.group.php cake/tests/groups/console.group.php cake/tests/groups/controller.group.php cake/tests/groups/database.group.php cake/tests/groups/helpers.group.php cake/tests/groups/i18n.group.php cake/tests/groups/javascript.group.php cake/tests/groups/lib.group.php cake/tests/groups/model.group.php cake/tests/groups/no_cross_contamination.group.php cake/tests/groups/routing_system.group.php cake/tests/groups/socket.group.php cake/tests/groups/test_suite.group.php cake/tests/groups/view.group.php cake/tests/groups/xml.group.php cake/tests/lib/cake_test_case.php cake/tests/lib/cake_test_model.php cake/tests/lib/cake_test_suite_dispatcher.php cake/tests/lib/cake_web_test_case.php cake/tests/lib/code_coverage_manager.php cake/tests/lib/reporter/cake_base_reporter.php cake/tests/lib/reporter/cake_cli_reporter.php cake/tests/lib/reporter/cake_text_reporter.php cake/tests/lib/templates/menu.php cake/tests/lib/templates/simpletest.php cake/tests/lib/test_manager.php cake/tests/test_app/controllers/tests_apps_controller.php cake/tests/test_app/libs/cache/test_app_cache.php cake/tests/test_app/libs/library.php cake/tests/test_app/libs/log/test_app_log.php cake/tests/test_app/plugins/test_plugin/config/load.php cake/tests/test_app/plugins/test_plugin/config/more.load.php cake/tests/test_app/plugins/test_plugin/controllers/components/other_component.php cake/tests/test_app/plugins/test_plugin/controllers/components/plugins_component.php cake/tests/test_app/plugins/test_plugin/controllers/components/test_plugin_component.php cake/tests/test_app/plugins/test_plugin/controllers/components/test_plugin_other_component.php cake/tests/test_app/plugins/test_plugin/controllers/test_plugin_controller.php cake/tests/test_app/plugins/test_plugin/controllers/tests_controller.php cake/tests/test_app/plugins/test_plugin/libs/cache/test_plugin_cache.php cake/tests/test_app/plugins/test_plugin/libs/log/test_plugin_log.php cake/tests/test_app/plugins/test_plugin/libs/test_plugin_library.php cake/tests/test_app/plugins/test_plugin/test_plugin_app_controller.php cake/tests/test_app/plugins/test_plugin/test_plugin_app_model.php cake/tests/test_app/plugins/test_plugin/vendors/sample/sample_plugin.php cake/tests/test_app/plugins/test_plugin/vendors/welcome.php cake/tests/test_app/plugins/test_plugin/views/helpers/other_helper.php cake/tests/test_app/plugins/test_plugin/views/helpers/plugged_helper.php cake/tests/test_app/vendors/Test/MyTest.php cake/tests/test_app/vendors/Test/hello.php cake/tests/test_app/vendors/sample/configure_test_vendor_sample.php cake/tests/test_app/vendors/shells/sample.php cake/tests/test_app/vendors/somename/some.name.php cake/tests/test_app/vendors/welcome.php cake/tests/test_app/views/elements/email/text/default.ctp cake/tests/test_app/views/layouts/default.ctp cake/tests/test_app/views/posts/test_nocache_tags.ctp lib/Cake/Cache/Engine/MemcacheEngine.php lib/Cake/Config/config.php lib/Cake/Console/Command/Task/ModelTask.php lib/Cake/Console/Templates/skel/webroot/css/cake.generic.css lib/Cake/Console/Templates/skel/webroot/test.php lib/Cake/Console/cake.bat lib/Cake/Controller/Component/CookieComponent.php lib/Cake/Log/CakeLog.php lib/Cake/Model/CakeSchema.php lib/Cake/Test/Case/Log/Engine/FileLog.php lib/Cake/Test/Case/View/Helper/FormHelperTest.php lib/Cake/Test/test_app/View/Emails/html/custom.ctp lib/Cake/Test/test_app/View/Emails/text/custom.ctp lib/Cake/TestSuite/templates/header.php lib/Cake/Utility/Sanitize.php lib/Cake/Utility/Validation.php lib/Cake/VERSION.txt lib/Cake/View/Helper/FormHelper.php
386 lines
9.7 KiB
PHP
386 lines
9.7 KiB
PHP
<?php
|
|
/**
|
|
* MemcacheEngineTest file
|
|
*
|
|
* PHP 5
|
|
*
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
|
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
*
|
|
* Licensed under The MIT License
|
|
* Redistributions of files must retain the above copyright notice
|
|
*
|
|
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
|
* @package cake.tests.cases.libs.cache
|
|
* @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.tests.cases.libs.cache
|
|
*/
|
|
class MemcacheEngineTest extends CakeTestCase {
|
|
|
|
/**
|
|
* setUp method
|
|
*
|
|
* @access public
|
|
* @return void
|
|
*/
|
|
public function 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
|
|
*
|
|
* @access public
|
|
* @return void
|
|
*/
|
|
public function tearDown() {
|
|
Configure::write('Cache.disable', $this->_cacheDisable);
|
|
Cache::drop('memcache');
|
|
Cache::config('default');
|
|
}
|
|
|
|
/**
|
|
* testSettings method
|
|
*
|
|
* @access public
|
|
* @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,
|
|
);
|
|
$this->assertEqual($settings, $expecting);
|
|
}
|
|
|
|
/**
|
|
* testSettings method
|
|
*
|
|
* @access public
|
|
* @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);
|
|
if (!@$Memcache->connect($host, $port)) {
|
|
$available = false;
|
|
}
|
|
}
|
|
|
|
$this->skipIf(!$available, 'Need memcache servers at ' . implode(', ', $servers) . ' to run this test.');
|
|
|
|
$Memcache = new MemcacheEngine();
|
|
$Memcache->init(array('engine' => 'Memcache', 'servers' => $servers));
|
|
|
|
$servers = array_keys($Memcache->__Memcache->getExtendedStats());
|
|
$settings = $Memcache->settings();
|
|
$this->assertEqual($servers, $settings['servers']);
|
|
Cache::drop('dual_server');
|
|
}
|
|
|
|
/**
|
|
* testConnect method
|
|
*
|
|
* @access public
|
|
* @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->assertEqual($result, array('schülervz.net', '13211'));
|
|
|
|
$result = $Memcache->parseServerString('sülül:1111');
|
|
$this->assertEqual($result, array('sülül', '1111'));
|
|
}
|
|
|
|
/**
|
|
* testReadAndWriteCache method
|
|
*
|
|
* @access public
|
|
* @return void
|
|
*/
|
|
public function testReadAndWriteCache() {
|
|
Cache::set(array('duration' => 1), null, 'memcache');
|
|
|
|
$result = Cache::read('test', 'memcache');
|
|
$expecting = '';
|
|
$this->assertEqual($result, $expecting);
|
|
|
|
$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->assertEqual($result, $expecting);
|
|
|
|
Cache::delete('test', 'memcache');
|
|
}
|
|
|
|
/**
|
|
* testExpiry method
|
|
*
|
|
* @access public
|
|
* @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(2);
|
|
$result = Cache::read('other_test', 'memcache');
|
|
$this->assertFalse($result);
|
|
|
|
Cache::config('memcache', array('duration' => '+1 second'));
|
|
sleep(2);
|
|
|
|
$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->assertEqual($result, $expecting);
|
|
|
|
Cache::config('memcache', array('duration' => 3600));
|
|
}
|
|
|
|
/**
|
|
* testDeleteCache method
|
|
*
|
|
* @access public
|
|
* @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
|
|
*
|
|
* @access public
|
|
* @return void
|
|
*/
|
|
public function testDecrement() {
|
|
$result = Cache::write('test_decrement', 5, 'memcache');
|
|
$this->assertTrue($result);
|
|
|
|
$result = Cache::decrement('test_decrement', 1, 'memcache');
|
|
$this->assertEqual(4, $result);
|
|
|
|
$result = Cache::read('test_decrement', 'memcache');
|
|
$this->assertEqual(4, $result);
|
|
|
|
$result = Cache::decrement('test_decrement', 2, 'memcache');
|
|
$this->assertEqual(2, $result);
|
|
|
|
$result = Cache::read('test_decrement', 'memcache');
|
|
$this->assertEqual(2, $result);
|
|
}
|
|
|
|
/**
|
|
* testIncrement method
|
|
*
|
|
* @access public
|
|
* @return void
|
|
*/
|
|
public function testIncrement() {
|
|
$result = Cache::write('test_increment', 5, 'memcache');
|
|
$this->assertTrue($result);
|
|
|
|
$result = Cache::increment('test_increment', 1, 'memcache');
|
|
$this->assertEqual(6, $result);
|
|
|
|
$result = Cache::read('test_increment', 'memcache');
|
|
$this->assertEqual(6, $result);
|
|
|
|
$result = Cache::increment('test_increment', 2, 'memcache');
|
|
$this->assertEqual(8, $result);
|
|
|
|
$result = Cache::read('test_increment', 'memcache');
|
|
$this->assertEqual(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->assertEqual(Cache::read('duration_test', 'long_memcache'), 'yay', 'Value was not read %s');
|
|
$this->assertEqual(Cache::read('short_duration_test', 'short_memcache'), 'boo', 'Value was not read %s');
|
|
|
|
sleep(1);
|
|
$this->assertEqual(Cache::read('duration_test', 'long_memcache'), 'yay', '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::write('some_value', 'value', 'memcache');
|
|
|
|
$result = Cache::clear(false, 'memcache');
|
|
$this->assertTrue($result);
|
|
$this->assertFalse(Cache::read('some_value', 'memcache'));
|
|
}
|
|
/**
|
|
* test that a 0 duration can succesfully write.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testZeroDuration() {
|
|
Cache::config('memcache', array('duration' => 0));
|
|
$result = Cache::write('test_key', 'written!', 'memcache');
|
|
|
|
$this->assertTrue($result, 'Could not write with duration 0');
|
|
$result = Cache::read('test_key', 'memcache');
|
|
$this->assertEqual($result, 'written!');
|
|
}
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
|
|
}
|