Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -2,19 +2,18 @@
/**
* 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)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) 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)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Cache', 'Cache');
@ -26,6 +25,8 @@ App::uses('Cache', 'Cache');
*/
class CacheTest extends CakeTestCase {
protected $_count = 0;
/**
* setUp method
*
@ -47,6 +48,9 @@ class CacheTest extends CakeTestCase {
*/
public function tearDown() {
parent::tearDown();
Cache::drop('latest');
Cache::drop('page');
Cache::drop('archive');
Configure::write('Cache.disable', $this->_cacheDisable);
Cache::config('default', $this->_defaultCacheConfig['settings']);
}
@ -64,6 +68,17 @@ class CacheTest extends CakeTestCase {
$this->assertTrue(isset($results['settings']));
}
/**
* testConfigInvalidEngine method
*
* @expectedException CacheException
* @return void
*/
public function testConfigInvalidEngine() {
$settings = array('engine' => 'Imaginary');
Cache::config('imaginary', $settings);
}
/**
* Check that no fatal errors are issued doing normal things when Cache.disable is true.
*
@ -117,6 +132,10 @@ class CacheTest extends CakeTestCase {
* @return void
*/
public function testInvalidConfig() {
// In debug mode it would auto create the folder.
$debug = Configure::read('debug');
Configure::write('debug', 0);
Cache::config('invalid', array(
'engine' => 'File',
'duration' => '+1 year',
@ -125,7 +144,9 @@ class CacheTest extends CakeTestCase {
'serialize' => true,
'random' => 'wii'
));
$read = Cache::read('Test', 'invalid');
Cache::read('Test', 'invalid');
Configure::write('debug', $debug);
}
/**
@ -216,7 +237,7 @@ class CacheTest extends CakeTestCase {
'duration' => 3600,
'probability' => 100,
'engine' => 'File',
'isWindows' => DIRECTORY_SEPARATOR == '\\',
'isWindows' => DIRECTORY_SEPARATOR === '\\',
'mask' => 0664,
'groups' => array()
);
@ -225,6 +246,71 @@ class CacheTest extends CakeTestCase {
Cache::config('sessions', $_cacheConfigSessions['settings']);
}
/**
* testGroupConfigs method
*
* @return void
*/
public function testGroupConfigs() {
Cache::config('latest', array(
'duration' => 300,
'engine' => 'File',
'groups' => array(
'posts', 'comments',
),
));
$expected = array(
'posts' => array('latest'),
'comments' => array('latest'),
);
$result = Cache::groupConfigs();
$this->assertEquals($expected, $result);
$result = Cache::groupConfigs('posts');
$this->assertEquals(array('posts' => array('latest')), $result);
Cache::config('page', array(
'duration' => 86400,
'engine' => 'File',
'groups' => array(
'posts', 'archive'
),
));
$result = Cache::groupConfigs();
$expected = array(
'posts' => array('latest', 'page'),
'comments' => array('latest'),
'archive' => array('page'),
);
$this->assertEquals($expected, $result);
$result = Cache::groupConfigs('archive');
$this->assertEquals(array('archive' => array('page')), $result);
Cache::config('archive', array(
'duration' => 86400 * 30,
'engine' => 'File',
'groups' => array(
'posts', 'archive', 'comments',
),
));
$result = Cache::groupConfigs('archive');
$this->assertEquals(array('archive' => array('archive', 'page')), $result);
}
/**
* testGroupConfigsThrowsException method
*
* @expectedException CacheException
* @return void
*/
public function testGroupConfigsThrowsException() {
Cache::groupConfigs('bogus');
}
/**
* test that configured returns an array of the currently configured cache
* settings
@ -290,13 +376,13 @@ class CacheTest extends CakeTestCase {
*/
public function testWriteEmptyValues() {
Cache::write('App.falseTest', false);
$this->assertSame(Cache::read('App.falseTest'), false);
$this->assertFalse(Cache::read('App.falseTest'));
Cache::write('App.trueTest', true);
$this->assertSame(Cache::read('App.trueTest'), true);
$this->assertTrue(Cache::read('App.trueTest'));
Cache::write('App.nullTest', null);
$this->assertSame(Cache::read('App.nullTest'), null);
$this->assertNull(Cache::read('App.nullTest'));
Cache::write('App.zeroTest', 0);
$this->assertSame(Cache::read('App.zeroTest'), 0);
@ -391,7 +477,7 @@ class CacheTest extends CakeTestCase {
Cache::delete('test_cache');
$global = Cache::settings();
Cache::settings();
Cache::set($_cacheSet);
}
@ -409,4 +495,108 @@ class CacheTest extends CakeTestCase {
$this->assertEquals('test_file_', $settings['prefix']);
$this->assertEquals(strtotime('+1 year') - time(), $settings['duration']);
}
/**
* test remember method.
*
* @return void
*/
public function testRemember() {
$expected = 'This is some data 0';
$result = Cache::remember('test_key', array($this, 'cacher'), 'default');
$this->assertEquals($expected, $result);
$this->_count = 1;
$result = Cache::remember('test_key', array($this, 'cacher'), 'default');
$this->assertEquals($expected, $result);
}
/**
* Method for testing Cache::remember()
*
* @return string
*/
public function cacher() {
return 'This is some data ' . $this->_count;
}
/**
* Test add method.
*
* @return void
*/
public function testAdd() {
Cache::delete('test_add_key', 'default');
$result = Cache::add('test_add_key', 'test data', 'default');
$this->assertTrue($result);
$expected = 'test data';
$result = Cache::read('test_add_key', 'default');
$this->assertEquals($expected, $result);
$result = Cache::add('test_add_key', 'test data 2', 'default');
$this->assertFalse($result);
}
/**
* Test engine method.
*
* Success, default engine.
*
* @return void
*/
public function testEngineSuccess() {
$actual = Cache::engine();
$this->assertInstanceOf('CacheEngine', $actual);
$actual = Cache::engine('default');
$this->assertInstanceOf('CacheEngine', $actual);
}
/**
* Test engine method.
*
* Success, memcached engine.
*
* @return void
*/
public function testEngineSuccessMemcached() {
$this->skipIf(!class_exists('Memcached'), 'Memcached is not installed or configured properly.');
// @codingStandardsIgnoreStart
$socket = @fsockopen('127.0.0.1', 11211, $errno, $errstr, 1);
// @codingStandardsIgnoreEnd
$this->skipIf(!$socket, 'Memcached is not running.');
fclose($socket);
Cache::config('memcached', array(
'engine' => 'Memcached',
'prefix' => 'cake_',
'duration' => 3600
));
$actual = Cache::engine('memcached');
$this->assertInstanceOf('MemcachedEngine', $actual);
$this->assertTrue($actual->add('test_add_key', 'test data', 10));
$this->assertFalse($actual->add('test_add_key', 'test data', 10));
$this->assertTrue($actual->delete('test_add_key'));
}
/**
* Test engine method.
*
* Failure.
*
* @return void
*/
public function testEngineFailure() {
$actual = Cache::engine('some_config_that_does_not_exist');
$this->assertNull($actual);
Configure::write('Cache.disable', true);
$actual = Cache::engine();
$this->assertNull($actual);
}
}