From b7c29cd84514e0e7a19c9e55af4e87ec101d6d30 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sat, 16 Nov 2013 21:48:48 +0530 Subject: [PATCH] Use model alias instead of full class name for `Session.handler.model` --- Cake/Network/Session/DatabaseSession.php | 16 ++++++---------- .../Network/Session/DatabaseSessionTest.php | 18 +++++++----------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/Cake/Network/Session/DatabaseSession.php b/Cake/Network/Session/DatabaseSession.php index 7b220663e99..34c3a265e74 100644 --- a/Cake/Network/Session/DatabaseSession.php +++ b/Cake/Network/Session/DatabaseSession.php @@ -50,20 +50,16 @@ class DatabaseSession implements SessionHandlerInterface { * */ public function __construct() { - $modelName = Configure::read('Session.handler.model'); + $modelAlias = Configure::read('Session.handler.model'); - if (empty($modelName)) { - $settings = array( - 'alias' => 'Sessions', + if (empty($modelAlias)) { + $this->_table = TableRegistry::get('Sessions', [ 'table' => 'cake_sessions', - ); + ]); } else { - $settings = array( - 'className' => $modelName, - 'alias' => 'Sessions', - ); + $this->_table = TableRegistry::get($modelAlias); } - $this->_table = TableRegistry::get('Sessions', $settings); + $this->_timeout = Configure::read('Session.timeout') * 60; } diff --git a/Cake/Test/TestCase/Network/Session/DatabaseSessionTest.php b/Cake/Test/TestCase/Network/Session/DatabaseSessionTest.php index 64595accc84..fa9108ccbfc 100644 --- a/Cake/Test/TestCase/Network/Session/DatabaseSessionTest.php +++ b/Cake/Test/TestCase/Network/Session/DatabaseSessionTest.php @@ -27,21 +27,16 @@ use Cake\TestSuite\TestCase; /** - * Class SessionTestModel + * Database session test. * */ -class SessionTestTable extends Table { - - protected $_table = 'sessions'; - -} +class DatabaseSessionTest extends TestCase { /** - * Database session test. + * sessionBackup * + * @var array */ -class DatabaseSessionTest extends TestCase { - protected static $_sessionBackup; /** @@ -58,8 +53,9 @@ class DatabaseSessionTest extends TestCase { */ public static function setupBeforeClass() { static::$_sessionBackup = Configure::read('Session'); + Configure::write('Session.handler', array( - 'model' => __NAMESPACE__ . '\SessionTestTable' + 'model' => 'Sessions' )); Configure::write('Session.timeout', 100); } @@ -105,7 +101,7 @@ public function testConstructionSettings() { new DatabaseSession(); $session = TableRegistry::get('Sessions'); - $this->assertInstanceOf(__NAMESPACE__ . '\SessionTestTable', $session); + $this->assertInstanceOf('Cake\ORM\Table', $session); $this->assertEquals('Sessions', $session->alias()); $this->assertEquals(ConnectionManager::get('test'), $session->connection()); $this->assertEquals('sessions', $session->table());