Skip to content
Browse files

returning the correct value in the memory session adapter, merging co…

…okie integration test and session integration tests. they all should pass now correctly.
  • Loading branch information...
1 parent bbe99c8 commit 73be5eab8eb4b0fa31dba6d2a7c7c7834d910d4e @daschl daschl committed Aug 4, 2011
View
1 storage/session/adapter/Memory.php
@@ -107,6 +107,7 @@ public function delete($key, array $options = array()) {
return function($self, $params) use (&$session) {
extract($params);
unset($session[$key]);
+ return !isset($session[$key]);
};
}
View
149 tests/integration/storage/CookieTest.php
@@ -1,149 +0,0 @@
-<?php
-/**
- * Lithium: the most rad php framework
- *
- * @copyright Copyright 2011, Union of RAD (http://union-of-rad.org)
- * @license http://opensource.org/licenses/bsd-license.php The BSD License
- */
-
-namespace lithium\tests\integration\storage;
-
-use lithium\storage\Session;
-
-class CookieTest extends \lithium\test\Integration {
-
- public function setUp() {
- Session::reset();
- $cookies = array_keys($_COOKIE);
-
- foreach ($cookies as $cookie) {
- setcookie($cookie, "", time()-1);
- }
- }
-
- public function tearDown() {
- Session::reset();
- $cookies = array_keys($_COOKIE);
-
- foreach ($cookies as $cookie) {
- setcookie($cookie, "", time()-1);
- }
- }
-
- public function skip() {
- $this->skipIf(PHP_SAPI == 'cli', 'No cookie support in cli SAPI');
- }
-
- public function testCookieWriteReadDelete() {
- Session::config(array(
- 'li3' => array(
- 'adapter' => 'Cookie',
- 'expiry' => '+1 day'
- )
- ));
-
- Session::write('ns.testkey1', 'value1', array('name' => 'li3'));
- Session::write('ns.testkey2', 'value2', array('name' => 'li3'));
- Session::write('ns.testkey3', 'value3', array('name' => 'li3'));
-
- $this->assertCookie(
- array('key' => 'ns.testkey1', 'value' => 'value1')
- );
- $this->assertCookie(
- array('key' => 'ns.testkey2', 'value' => 'value2')
- );
- $this->assertCookie(
- array('key' => 'ns.testkey3', 'value' => 'value3')
- );
-
- Session::delete('ns.testkey1', array('name' => 'li3'));
- Session::delete('ns.testkey2', array('name' => 'li3'));
- Session::delete('ns.testkey3', array('name' => 'li3'));
-
- $params = array('exires' => '-1 second', 'path' => '/');
-
- $this->assertNoCookie(array('key' => 'ns.testkey1'));
- $this->assertNoCookie(array('key' => 'ns.testkey2'));
- $this->assertNoCookie(array('key' => 'ns.testkey3'));
- }
-
- public function testStrategiesPhpAdapter() {
- Session::config(array(
- 'strategy' => array(
- 'adapter' => 'Php',
- 'strategies' => array('Hmac' => array('secret' => 'somesecretkey'))
- )
- ));
-
- $key = 'test';
- $value = 'value';
-
- Session::write($key, $value, array('name' => 'strategy'));
- $result = Session::read($key, array('name' => 'strategy'));
-
- $this->assertEqual($value, $result);
- $this->assertTrue(Session::delete($key, array('name' => 'strategy')));
- $result = Session::read($key, array('name' => 'strategy'));
- $this->assertNull($result);
-
- Session::write($key, $value, array('name' => 'strategy'));
- $result = Session::read($key, array('name' => 'strategy'));
- $this->assertEqual($value, $result);
-
- $cache = $_SESSION;
- $_SESSION['injectedkey'] = 'hax0r';
- $this->expectException('/Possible data tampering - HMAC signature does not match data./');
- $result = Session::read($key, array('name' => 'strategy'));
- $_SESSION = $cache;
- }
-
- public function testStrategiesCookieAdapter() {
- $key = 'test_key';
- $value = 'test_value';
-
- Session::config(array(
- 'default' => array(
- 'adapter' => 'Cookie',
- 'strategies' => array('Hmac' => array('secret' => 'somesecretkey'))
- )
- ));
-
- $result = Session::write($key, $value);
- $this->assertTrue($result);
-
- $result = Session::read($key);
- $this->assertEqual($value, $result);
-
- $this->assertTrue(Session::delete($key));
-
- $result = Session::read($key);
- $this->assertNull($result);
-
- Session::write($key, $value);
- $result = Session::read($key);
- $this->assertEqual($value, $result);
- $this->assertTrue(Session::delete($key));
- }
-
- public function testHmacStrategy() {
- $key = 'test';
- $value = 'value';
- $name = 'hmac_test';
-
- Session::config(array(
- 'default' => array(
- 'adapter' => 'Cookie',
- 'strategies' => array('Hmac' => array('secret' => 'somesecretkey')),
- 'name' => $name
- )
- ));
-
- $cache = $_COOKIE;
- $_COOKIE[$name]['injectedkey'] = 'hax0r';
- $this->expectException('/Possible data tampering - HMAC signature does not match data./');
- $result = Session::read($key, array('name' => 'hmac'));
- $_COOKIE = $cache;
- }
-}
-
-?>
View
219 tests/integration/storage/SessionTest.php
@@ -12,172 +12,139 @@
class SessionTest extends \lithium\test\Integration {
- public function setUp() {
- Session::reset();
- $cookies = array_keys($_COOKIE);
-
- foreach ($cookies as $cookie) {
- setcookie($cookie, "", time()-1);
- }
- }
-
- public function tearDown() {
- Session::reset();
- $cookies = array_keys($_COOKIE);
-
- foreach ($cookies as $cookie) {
- setcookie($cookie, "", time()-1);
- }
- }
-
public function skip() {
$this->skipIf(PHP_SAPI == 'cli', 'No session support in cli SAPI');
}
- public function testWriteAndRead() {
+ public function testPhpReadWriteDelete() {
+ $config = array('name' => 'phpInt');
+
Session::config(array(
- 'default' => array('adapter' => 'Php')
+ $config['name'] => array(
+ 'adapter' => 'Php'
+ )
));
- $key = 'write_key';
- $value = 'write_value';
+ Session::clear($config);
- Session::write($key, $value);
- $result = Session::read($key);
- $this->assertEqual($value, $result);
+ $key1 = 'key_one';
+ $value1 = 'value_one';
+ $key2 = 'key_two';
+ $value2 = 'value_two';
- $key2 = 'write_key_2';
- $value2 = 'write_value_2';
- Session::write($key2, $value2);
- $result = Session::read($key2);
- $this->assertEqual($value2, $result);
+ $this->assertNull(Session::read($key1, $config));
+ $this->assertTrue(Session::write($key1, $value1, $config));
+ $this->assertEqual($value1, Session::read($key1, $config));
+ $this->assertNull(Session::read($key2, $config));
+ $this->assertTrue(Session::delete($key1, $config));
+ $this->assertNull(Session::read($key1, $config));
+ }
- $this->assertTrue(Session::delete($key));
- $this->assertTrue(Session::delete($key2));
+ public function testCookieReadWriteDelete() {
+ $config = array('name' => 'cookieInt');
- $result = Session::read($key);
- $result2 = Session::read($key2);
+ Session::config(array(
+ $config['name'] => array(
+ 'adapter' => 'Cookie'
+ )
+ ));
- $this->assertNull($result);
- $this->assertNull($result2);
+ Session::clear($config);
+
+ $key1 = 'key_one';
+ $value1 = 'value_one';
+ $key2 = 'key_two';
+ $value2 = 'value_two';
+
+ $this->assertNull(Session::read($key1, $config));
+ $this->assertTrue(Session::write($key1, $value1, $config));
+ $this->assertCookie(array('key' => $key1, 'value' => $value1));
+ $this->assertNull(Session::read($key2, $config));
+ $this->assertTrue(Session::delete($key1, $config));
+ $this->assertCookie(array('key' => $key1, 'value' => 'deleted'));
+ $this->assertNoCookie(array('key' => $key2, 'value' => $value2));
+ $this->assertNull(Session::read($key1, $config));
}
- public function testWriteReadDelete() {
+ public function testMemoryReadWriteDelete() {
+ $config = array('name' => 'memoryInt');
+
Session::config(array(
- 'default' => array('adapter' => 'Php')
+ $config['name'] => array(
+ 'adapter' => 'Memory'
+ )
));
- $key = 'test';
- $value = 'value';
-
- Session::write($key, $value);
- $result = Session::read($key);
+ Session::clear($config);
- $this->assertEqual($value, $result);
- $this->assertTrue(Session::delete($key));
+ $key1 = 'key_one';
+ $value1 = 'value_one';
+ $key2 = 'key_two';
+ $value2 = 'value_two';
- $result = Session::read($key);
- $this->assertNull($result);
+ $this->assertNull(Session::read($key1, $config));
+ $this->assertTrue(Session::write($key1, $value1, $config));
+ $this->assertEqual($value1, Session::read($key1, $config));
+ $this->assertNull(Session::read($key2, $config));
+ $this->assertTrue(Session::delete($key1, $config));
+ $this->assertNull(Session::read($key1, $config));
}
- public function testNamespaces() {
+ public function testNamespacesWithPhpAdapter() {
+ $config = array('name' => 'namespaceInt');
+
Session::config(array(
- 'test' => array('adapter' => 'Php')
+ $config['name'] => array(
+ 'adapter' => 'Php'
+ )
));
- $value = 'second value';
- Session::write('first.second', $value);
- $result = Session::read('first.second');
- $this->assertEqual($value, $result);
- $this->assertTrue(isset($_SESSION['first']));
- $this->assertTrue(isset($_SESSION['first']['second']));
- $this->assertEqual($value, $_SESSION['first']['second']);
-
- $result = Session::read('first');
- $expected = array('second' => 'second value');
- $this->assertEqual($expected, $result);
- $this->assertTrue(isset($_SESSION['first']));
- $this->assertEqual($_SESSION['first'], $result);
-
- $value = 'another value';
- Session::write('first.sibling', $value);
- $result = Session::read('first.sibling');
- $this->assertEqual($value, $result);
- $this->assertEqual($_SESSION['first']['sibling'], $value);
-
- $result = Session::delete('first.sibling');
- $this->assertEqual(true, $result);
- $this->assertFalse(isset($_SESSION['first']['sibling']));
- $this->assertTrue(isset($_SESSION['first']['second']));
-
- $result = Session::delete('first');
- $this->assertEqual(true, $result);
- $this->assertFalse(isset($_SESSION['first']));
- }
+ Session::clear($config);
- public function testCookieWriteReadDelete() {
- Session::config(array(
- 'li3' => array('adapter' => 'Cookie', 'expiry' => '+1 day')
- ));
+ $key1 = 'really.deep.nested.key';
+ $value1 = 'nested_val';
+ $key2 = 'shallow.key';
+ $value2 = 'shallow_val';
- Session::write('testkey1', 'value1', array('name' => 'li3'));
- Session::write('testkey2', 'value2', array('name' => 'li3'));
- Session::write('testkey3', 'value3', array('name' => 'li3'));
-
- $this->assertCookie(
- array('key' => 'testkey1', 'value' => 'value1')
- );
- $this->assertCookie(
- array('key' => 'testkey2', 'value' => 'value2')
- );
- $this->assertCookie(
- array('key' => 'testkey3', 'value' => 'value3')
- );
-
- Session::delete('testkey1', array('name' => 'li3'));
- Session::delete('testkey2', array('name' => 'li3'));
- Session::delete('testkey3', array('name' => 'li3'));
-
- $params = array('exires' => '-1 second', 'path' => '/');
-
- $this->assertCookie(
- array('key' => 'testkey1', 'value' => 'deleted')
- );
- $this->assertCookie(
- array('key' => 'testkey2', 'value' => 'deleted')
- );
- $this->assertCookie(
- array('key' => 'testkey3', 'value' => 'deleted')
- );
+ $this->assertTrue(Session::write($key1, $value1, $config));
+ $this->assertTrue(Session::write($key2, $value2, $config));
+ $this->assertEqual($value1, Session::read($key1, $config));
+ $this->assertEqual($value2, Session::read($key2, $config));
+ $expected = array('nested' => array('key' => $value1));
+ $this->assertEqual($expected, Session::read('really.deep', $config));
}
- public function testStrategiesPhpAdapter() {
+ public function testHmacStrategyWithPhpAdapter() {
+ $config = array('name' => 'hmacInt');
+
Session::config(array(
- 'strategy' => array(
+ $config['name'] => array(
'adapter' => 'Php',
- 'strategies' => array('Hmac' => array('secret' => 'somesecretkey'))
+ 'strategies' => array(
+ 'Hmac' => array(
+ 'secret' => 's3cr3t'
+ )
+ )
)
));
+ Session::clear($config);
+
$key = 'test';
$value = 'value';
- Session::write($key, $value, array('name' => 'strategy'));
- $result = Session::read($key, array('name' => 'strategy'));
-
- $this->assertEqual($value, $result);
- $this->assertTrue(Session::delete($key, array('name' => 'strategy')));
- $result = Session::read($key, array('name' => 'strategy'));
- $this->assertNull($result);
+ $this->assertTrue(Session::write($key, $value, $config));
+ $this->assertEqual($value, Session::read($key, $config));
+ $this->assertTrue(Session::delete($key, $config));
+ $this->assertNull(Session::read($key, $config));
- Session::write($key, $value, array('name' => 'strategy'));
- $result = Session::read($key, array('name' => 'strategy'));
- $this->assertEqual($value, $result);
+ $this->assertTrue(Session::write($key, $value, $config));
+ $this->assertEqual($value, Session::read($key, $config));
$cache = $_SESSION;
$_SESSION['injectedkey'] = 'hax0r';
- $this->expectException('/Possible data tampering - HMAC signature does not match data./');
- $result = Session::read($key, array('name' => 'strategy'));
+ $this->expectException('/Possible data tampering: HMAC signature does not match data./');
+ Session::read($key, $config);
$_SESSION = $cache;
}
}

0 comments on commit 73be5ea

Please sign in to comment.
Something went wrong with that request. Please try again.