From c1b932d36010121dc08b726f5b0547150ece4eae Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Wed, 5 Oct 2016 20:26:56 +0900 Subject: [PATCH] Add unit tests for Session::checkStart() --- common/framework/session.php | 2 +- tests/unit/framework/SessionTest.php | 33 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/common/framework/session.php b/common/framework/session.php index c3901186f..74426de7a 100644 --- a/common/framework/session.php +++ b/common/framework/session.php @@ -317,7 +317,7 @@ class Session self::$_started = false; self::$_member_info = false; self::_setKeys(); - session_destroy(); + @session_destroy(); return true; } diff --git a/tests/unit/framework/SessionTest.php b/tests/unit/framework/SessionTest.php index 3a901faf5..9e248b9c0 100644 --- a/tests/unit/framework/SessionTest.php +++ b/tests/unit/framework/SessionTest.php @@ -4,6 +4,7 @@ class SessionTest extends \Codeception\TestCase\Test { public function _before() { + Rhymix\Framework\Config::set('session.delay', false); Rhymix\Framework\Session::close(); session_id('rhymix-test-session'); $_SESSION = array(); @@ -12,6 +13,7 @@ class SessionTest extends \Codeception\TestCase\Test public function _after() { + Rhymix\Framework\Config::set('session.delay', false); Rhymix\Framework\Session::close(); session_id('rhymix-test-session'); $_SESSION = array(); @@ -20,6 +22,7 @@ class SessionTest extends \Codeception\TestCase\Test public function _failed() { + Rhymix\Framework\Config::set('session.delay', false); Rhymix\Framework\Session::close(); session_id('rhymix-test-session'); $_SESSION = array(); @@ -96,6 +99,36 @@ class SessionTest extends \Codeception\TestCase\Test Rhymix\Framework\Session::close(); } + public function testCheckStart() + { + Rhymix\Framework\Config::set('session.delay', true); + + $_SESSION = array(); + unset($_COOKIE['PHPSESSID']); + $this->assertFalse(Rhymix\Framework\Session::start()); + $this->assertFalse(Rhymix\Framework\Session::isStarted()); + $this->assertFalse(Rhymix\Framework\Session::checkStart()); + $this->assertFalse(Rhymix\Framework\Session::isStarted()); + + $_SESSION['foo'] = 'bar'; + $this->assertTrue(Rhymix\Framework\Session::checkStart()); + $this->assertTrue(Rhymix\Framework\Session::isStarted()); + $this->assertEquals('bar', $_SESSION['foo']); + $this->assertEquals('bar', Rhymix\Framework\Session::get('foo')); + Rhymix\Framework\Session::close(); + + $_SESSION = array(); + unset($_COOKIE['PHPSESSID']); + $this->assertTrue(Rhymix\Framework\Session::checkStart(true)); + $this->assertTrue(Rhymix\Framework\Session::isStarted()); + Rhymix\Framework\Session::close(); + + $_SESSION = array(); + unset($_COOKIE['PHPSESSID']); + $this->assertTrue(Rhymix\Framework\Session::start(true)); + $this->assertTrue(Rhymix\Framework\Session::isStarted()); + } + public function testRefresh() { Rhymix\Framework\Session::start();