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,37 +2,46 @@
/**
* SessionTest 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.Model.Datasource
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('CakeSession', 'Model/Datasource');
App::uses('DatabaseSession', 'Model/Datasource/Session');
App::uses('CacheSession', 'Model/Datasource/Session');
/**
* TestCakeSession
*
* @package Cake.Test.Case.Model.Datasource
*/
class TestCakeSession extends CakeSession {
public static function setUserAgent($value) {
self::$_userAgent = $value;
static::$_userAgent = $value;
}
public static function setHost($host) {
self::_setHost($host);
static::_setHost($host);
}
}
/**
* TestCacheSession
*
* @package Cake.Test.Case.Model.Datasource
*/
class TestCacheSession extends CacheSession {
protected function _writeSession() {
@ -41,6 +50,11 @@ class TestCacheSession extends CacheSession {
}
/**
* TestDatabaseSession
*
* @package Cake.Test.Case.Model.Datasource
*/
class TestDatabaseSession extends DatabaseSession {
protected function _writeSession() {
@ -72,7 +86,7 @@ class CakeSessionTest extends CakeTestCase {
*/
public static function setupBeforeClass() {
// Make sure garbage colector will be called
self::$_gcDivisor = ini_get('session.gc_divisor');
static::$_gcDivisor = ini_get('session.gc_divisor');
ini_set('session.gc_divisor', '1');
}
@ -83,7 +97,7 @@ class CakeSessionTest extends CakeTestCase {
*/
public static function teardownAfterClass() {
// Revert to the default setting
ini_set('session.gc_divisor', self::$_gcDivisor);
ini_set('session.gc_divisor', static::$_gcDivisor);
}
/**
@ -100,7 +114,6 @@ class CakeSessionTest extends CakeTestCase {
'cookieTimeout' => 120,
'ini' => array(),
));
TestCakeSession::init();
}
/**
@ -108,12 +121,12 @@ class CakeSessionTest extends CakeTestCase {
*
* @return void
*/
public function teardown() {
public function tearDown() {
if (TestCakeSession::started()) {
session_write_close();
}
unset($_SESSION);
parent::teardown();
parent::tearDown();
}
/**
@ -231,7 +244,7 @@ class CakeSessionTest extends CakeTestCase {
TestCakeSession::write('SessionTestCase', 'value');
$this->assertTrue(TestCakeSession::check('SessionTestCase'));
$this->assertFalse(TestCakeSession::check('NotExistingSessionTestCase'), false);
$this->assertFalse(TestCakeSession::check('NotExistingSessionTestCase'));
}
/**
@ -244,7 +257,7 @@ class CakeSessionTest extends CakeTestCase {
$result = TestCakeSession::read('testing');
$this->assertEquals('1,2,3', $result);
TestCakeSession::write('testing', array('1' => 'one', '2' => 'two','3' => 'three'));
TestCakeSession::write('testing', array('1' => 'one', '2' => 'two', '3' => 'three'));
$result = TestCakeSession::read('testing.1');
$this->assertEquals('one', $result);
@ -267,7 +280,7 @@ class CakeSessionTest extends CakeTestCase {
* @return void
*/
public function testReadyEmpty() {
$this->assertFalse(TestCakeSession::read(''));
$this->assertNull(TestCakeSession::read(''));
}
/**
@ -294,9 +307,9 @@ class CakeSessionTest extends CakeTestCase {
* @return void
*/
public function testWriteEmptyKey() {
$this->assertFalse(TestCakeSession::write('', 'graham'));
$this->assertFalse(TestCakeSession::write('', ''));
$this->assertFalse(TestCakeSession::write(''));
$this->assertTrue(TestCakeSession::write('', 'graham'));
$this->assertTrue(TestCakeSession::write('', ''));
$this->assertTrue(TestCakeSession::write(''));
}
/**
@ -315,6 +328,28 @@ class CakeSessionTest extends CakeTestCase {
);
}
/**
* Test consuming session data.
*
* @return void
*/
public function testConsume() {
TestCakeSession::write('Some.string', 'value');
TestCakeSession::write('Some.array', array('key1' => 'value1', 'key2' => 'value2'));
$this->assertEquals('value', TestCakeSession::read('Some.string'));
$value = TestCakeSession::consume('Some.string');
$this->assertEquals('value', $value);
$this->assertFalse(TestCakeSession::check('Some.string'));
$value = TestCakeSession::consume('');
$this->assertNull($value);
$value = TestCakeSession::consume(null);
$this->assertNull($value);
$value = TestCakeSession::consume('Some.array');
$expected = array('key1' => 'value1', 'key2' => 'value2');
$this->assertEquals($expected, $value);
$this->assertFalse(TestCakeSession::check('Some.array'));
}
/**
* testId method
*
@ -346,21 +381,6 @@ class CakeSessionTest extends CakeTestCase {
$this->assertTrue(TestCakeSession::started());
}
/**
* testError method
*
* @return void
*/
public function testError() {
TestCakeSession::read('Does.not.exist');
$result = TestCakeSession::error();
$this->assertEquals("Does.not.exist doesn't exist", $result);
TestCakeSession::delete('Failing.delete');
$result = TestCakeSession::error();
$this->assertEquals("Failing.delete doesn't exist", $result);
}
/**
* testDel method
*
@ -373,11 +393,47 @@ class CakeSessionTest extends CakeTestCase {
$this->assertTrue(TestCakeSession::check('Delete'));
$this->assertTrue(TestCakeSession::write('Clearing.sale', 'everything must go'));
$this->assertFalse(TestCakeSession::delete(''));
$this->assertTrue(TestCakeSession::check('Clearing.sale'));
$this->assertFalse(TestCakeSession::delete(null));
$this->assertTrue(TestCakeSession::check('Clearing.sale'));
$this->assertTrue(TestCakeSession::delete('Clearing'));
$this->assertFalse(TestCakeSession::check('Clearing.sale'));
$this->assertFalse(TestCakeSession::check('Clearing'));
}
/**
* test delete
*
* @return void
*/
public function testDeleteEmptyString() {
TestCakeSession::write('', 'empty string');
$this->assertTrue(TestCakeSession::delete(''));
$this->assertFalse(TestCakeSession::check(''));
}
/**
* testClear method
*
* @return void
*/
public function testClear() {
$this->assertTrue(TestCakeSession::write('Delete.me', 'Clearing out'));
TestCakeSession::clear(false);
$this->assertFalse(TestCakeSession::check('Delete.me'));
$this->assertFalse(TestCakeSession::check('Delete'));
TestCakeSession::write('Some.string', 'value');
TestCakeSession::clear(false);
$this->assertNull(TestCakeSession::read('Some'));
TestCakeSession::write('Some.string.array', array('values'));
TestCakeSession::clear(false);
$this->assertFalse(TestCakeSession::read());
}
/**
* testDestroy method
*
@ -431,7 +487,8 @@ class CakeSessionTest extends CakeTestCase {
* @return void
*/
public function testCheckEmpty() {
$this->assertFalse(TestCakeSession::check());
$this->assertFalse(TestCakeSession::check(''));
$this->assertFalse(TestCakeSession::check(null));
}
/**
@ -442,10 +499,10 @@ class CakeSessionTest extends CakeTestCase {
public function testKeyExploit() {
$key = "a'] = 1; phpinfo(); \$_SESSION['a";
$result = TestCakeSession::write($key, 'haxored');
$this->assertTrue($result);
$this->assertFalse($result);
$result = TestCakeSession::read($key);
$this->assertEquals('haxored', $result);
$this->assertNull($result);
}
/**
@ -454,6 +511,10 @@ class CakeSessionTest extends CakeTestCase {
* @return void
*/
public function testReadingSavedEmpty() {
TestCakeSession::write('', 'empty string');
$this->assertTrue(TestCakeSession::check(''));
$this->assertEquals('empty string', TestCakeSession::read(''));
TestCakeSession::write('SessionTestCase', 0);
$this->assertEquals(0, TestCakeSession::read('SessionTestCase'));
@ -465,7 +526,23 @@ class CakeSessionTest extends CakeTestCase {
$this->assertFalse(TestCakeSession::read('SessionTestCase'));
TestCakeSession::write('SessionTestCase', null);
$this->assertEquals(null, TestCakeSession::read('SessionTestCase'));
$this->assertNull(TestCakeSession::read('SessionTestCase'));
}
/**
* Test te cacheLimiter settings.
*
* @return void
*/
public function testCacheLimiter() {
Configure::write('Session.cacheLimiter', 'public');
TestCakeSession::start();
$this->assertSame('public', session_cache_limiter());
Configure::write('Session.cacheLimiter', 'private');
TestCakeSession::destroy();
TestCakeSession::start();
$this->assertSame('private', session_cache_limiter());
}
/**
@ -547,9 +624,13 @@ class CakeSessionTest extends CakeTestCase {
'engine' => 'TestAppLibSession'
)
));
TestCakeSession::destroy();
TestCakeSession::start();
$this->assertTrue(TestCakeSession::started());
TestCakeSession::destroy();
$this->assertFalse(TestCakeSession::started());
App::build();
}
@ -571,9 +652,12 @@ class CakeSessionTest extends CakeTestCase {
)
));
TestCakeSession::destroy();
TestCakeSession::start();
$this->assertTrue(TestCakeSession::started());
TestCakeSession::destroy();
$this->assertFalse(TestCakeSession::started());
App::build();
}
@ -658,7 +742,7 @@ class CakeSessionTest extends CakeTestCase {
$this->assertEquals($expected, TestCakeSession::id());
TestCakeSession::renew();
$this->assertFalse($expected == TestCakeSession::id());
$this->assertFalse($expected === TestCakeSession::id());
$expected = session_id();
$this->assertEquals($expected, TestCakeSession::id());
@ -751,4 +835,31 @@ class CakeSessionTest extends CakeTestCase {
$this->assertEquals(400, Configure::read('Session.timeout'));
}
/**
* Proves that invalid sessions will be destroyed and re-created
* if invalid
*
* @return void
*/
public function testInvalidSessionRenew() {
TestCakeSession::start();
$this->assertNotEmpty($_SESSION['Config']);
$data = $_SESSION;
session_write_close();
$_SESSION = null;
TestCakeSession::start();
$this->assertEquals($data, $_SESSION);
TestCakeSession::write('Foo', 'Bar');
session_write_close();
$_SESSION = null;
TestCakeSession::userAgent('bogus!');
TestCakeSession::start();
$this->assertNotEquals($data, $_SESSION);
$this->assertEquals('bogus!', $_SESSION['Config']['userAgent']);
}
}