From a675271ad71b7713d1b33bdba3c51b2b04813229 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 15 Nov 2015 12:50:33 -0500 Subject: Rewrite of session management --- tests/units/Core/Session/FlashMessageTest.php | 23 +++++++++++++++ tests/units/Core/Session/SessionStorageTest.php | 38 +++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 tests/units/Core/Session/FlashMessageTest.php create mode 100644 tests/units/Core/Session/SessionStorageTest.php (limited to 'tests/units/Core/Session') diff --git a/tests/units/Core/Session/FlashMessageTest.php b/tests/units/Core/Session/FlashMessageTest.php new file mode 100644 index 00000000..25361343 --- /dev/null +++ b/tests/units/Core/Session/FlashMessageTest.php @@ -0,0 +1,23 @@ +container); + + $flash->success('my message'); + $this->assertEquals('my message', $flash->getMessage('success')); + $this->assertEmpty($flash->getMessage('success')); + + $flash->failure('my error message'); + $this->assertEquals('my error message', $flash->getMessage('failure')); + $this->assertEmpty($flash->getMessage('failure')); + + $this->assertEmpty($flash->getMessage('not found')); + } +} diff --git a/tests/units/Core/Session/SessionStorageTest.php b/tests/units/Core/Session/SessionStorageTest.php new file mode 100644 index 00000000..62495e5e --- /dev/null +++ b/tests/units/Core/Session/SessionStorageTest.php @@ -0,0 +1,38 @@ +something = array('a' => 'b'); + $this->assertEquals(array('a' => 'b'), $storage->something); + $this->assertTrue(isset($storage->something)); + $this->assertFalse(isset($storage->something->x)); + $this->assertFalse(isset($storage->notFound)); + $this->assertFalse(isset($storage->notFound->x)); + $this->assertFalse(isset($storage->notFound['x'])); + } + + public function testPersistentStorage() + { + $session = array('d' => 'e'); + + $storage = new SessionStorage(); + $storage->setStorage($session); + $storage->something = array('a' => 'b'); + + $this->assertEquals(array('a' => 'b'), $storage->something); + $this->assertEquals('e', $storage->d); + + $storage->something['a'] = 'c'; + $this->assertEquals('c', $storage->something['a']); + + $storage = null; + $this->assertEquals(array('something' => array('a' => 'c'), 'd' => 'e'), $session); + } +} -- cgit v1.2.3 From d0e809a32cd58c0d89b2425aeb245e04a94df7d6 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 6 Dec 2015 08:23:53 -0500 Subject: Add new method to flush session variables --- app/Core/Security/AuthenticationManager.php | 2 +- app/Core/Session/SessionStorage.php | 15 +++++++++++++++ tests/units/Core/Session/SessionStorageTest.php | 22 ++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) (limited to 'tests/units/Core/Session') diff --git a/app/Core/Security/AuthenticationManager.php b/app/Core/Security/AuthenticationManager.php index dbc41b09..8e5f76be 100644 --- a/app/Core/Security/AuthenticationManager.php +++ b/app/Core/Security/AuthenticationManager.php @@ -71,7 +71,7 @@ class AuthenticationManager extends Base if ($this->userSession->isLogged() ) { foreach ($this->filterProviders('SessionCheckProviderInterface') as $provider) { if (! $provider->isValidSession()) { - unset($this->sessionStorage->user); + $this->sessionStorage->flush(); $this->preAuthentication(); return false; } diff --git a/app/Core/Session/SessionStorage.php b/app/Core/Session/SessionStorage.php index 11230793..f55a7ee3 100644 --- a/app/Core/Session/SessionStorage.php +++ b/app/Core/Session/SessionStorage.php @@ -61,6 +61,21 @@ class SessionStorage return $session; } + /** + * Flush session data + * + * @access public + */ + public function flush() + { + $session = get_object_vars($this); + unset($session['storage']); + + foreach (array_keys($session) as $property) { + unset($this->$property); + } + } + /** * Copy class properties to external storage * diff --git a/tests/units/Core/Session/SessionStorageTest.php b/tests/units/Core/Session/SessionStorageTest.php index 62495e5e..dd0040d5 100644 --- a/tests/units/Core/Session/SessionStorageTest.php +++ b/tests/units/Core/Session/SessionStorageTest.php @@ -35,4 +35,26 @@ class SessionStorageTest extends Base $storage = null; $this->assertEquals(array('something' => array('a' => 'c'), 'd' => 'e'), $session); } + + public function testFlush() + { + $session = array('d' => 'e'); + + $storage = new SessionStorage(); + $storage->setStorage($session); + $storage->something = array('a' => 'b'); + + $this->assertEquals(array('a' => 'b'), $storage->something); + $this->assertEquals('e', $storage->d); + + $storage->flush(); + + $this->assertFalse(isset($storage->d)); + $this->assertFalse(isset($storage->something)); + + $storage->foo = 'bar'; + + $storage = null; + $this->assertEquals(array('foo' => 'bar'), $session); + } } -- cgit v1.2.3