From 57486009573a86d9e286a49c92216ba17aae0d5a Mon Sep 17 00:00:00 2001 From: dchill42 Date: Tue, 31 Jul 2012 09:39:53 -0400 Subject: Added Session driver library unit tests and added driver library autoloading to test framework --- tests/codeigniter/libraries/Session_test.php | 304 +++++++++++++++++++++++++++ 1 file changed, 304 insertions(+) create mode 100644 tests/codeigniter/libraries/Session_test.php (limited to 'tests/codeigniter/libraries/Session_test.php') diff --git a/tests/codeigniter/libraries/Session_test.php b/tests/codeigniter/libraries/Session_test.php new file mode 100644 index 000000000..db7efb6b7 --- /dev/null +++ b/tests/codeigniter/libraries/Session_test.php @@ -0,0 +1,304 @@ + 0, 'use_only_cookies' => 0, 'cache_limiter' => false); + protected $setting_vals = array(); + protected $cookie_vals; + protected $session; + + /** + * Set up test framework + */ + public function set_up() + { + // Override settings + foreach ($this->settings as $name => $value) { + $this->setting_vals[$name] = ini_get('session.'.$name); + ini_set('session.'.$name, $value); + } + + // Start with clean environment + $this->cookie_vals = $_COOKIE; + $_COOKIE = array(); + + // Establish necessary support classes + $obj = new stdClass; + foreach (array('config' => 'cfg', 'load' => 'load', 'input' => 'in') as $name => $abbr) { + $class = $this->ci_core_class($abbr); + $obj->$name = new $class; + } + $this->ci_instance($obj); + + // Attach session instance locally + $config = array('sess_encrypt_cookie' => FALSE, 'sess_use_database' => FALSE, 'sess_table_name' => '', + 'sess_expiration' => 7200, 'sess_expire_on_close' => FALSE, 'sess_match_ip' => FALSE, + 'sess_match_useragent' => TRUE, 'sess_cookie_name' => 'ci_session', 'cookie_path' => '', + 'cookie_domain' => '', 'cookie_secure' => FALSE, 'cookie_httponly' => FALSE, 'sess_time_to_update' => 300, + 'time_reference' => 'local', 'cookie_prefix' => '', 'encryption_key' => 'foobar', + 'sess_valid_drivers' => array('Mock_Libraries_Session_native', 'Mock_Libraries_Session_cookie')); + $this->session = new Mock_Libraries_Session($config); + } + + /** + * Tear down test framework + */ + public function tear_down() + { + // Restore environment + if (session_id()) session_destroy(); + $_SESSION = array(); + $_COOKIE = $this->cookie_vals; + + // Restore settings + foreach ($this->settings as $name => $value) { + ini_set('session.'.$name, $this->setting_vals[$name]); + } + } + + /** + * Test set_userdata() function + */ + public function test_set_userdata() + { + // Set a userdata message for each driver + $cmsg = 'Some test data'; + $this->session->cookie->set_userdata('test1', $cmsg); + $nmsg = 'Other test data'; + $this->session->native->set_userdata('test1', $nmsg); + + // Verify independent messages + $this->assertEquals($this->session->cookie->userdata('test1'), $cmsg); + $this->assertEquals($this->session->native->userdata('test1'), $nmsg); + } + + /** + * Test the has_userdata() function + */ + public function test_has_userdata() + { + // Set a userdata message for each driver + $cmsg = 'My test data'; + $this->session->cookie->set_userdata('test2', $cmsg); + $nmsg = 'Your test data'; + $this->session->native->set_userdata('test2', $nmsg); + + // Verify independent messages + $this->assertTrue($this->session->cookie->has_userdata('test2')); + $this->assertTrue($this->session->native->has_userdata('test2')); + } + + /** + * Test the all_userdata() function + */ + public function test_all_userdata() + { + // Set a specific series of data for each driver + $cdata = array('one' => 'first', 'two' => 'second', 'three' => 'third', 'foo' => 'bar', 'bar' => 'baz'); + $this->session->cookie->set_userdata($cdata); + $ndata = array('one' => 'gold', 'two' => 'silver', 'three' => 'bronze', 'foo' => 'baz', 'bar' => 'foo'); + $this->session->native->set_userdata($ndata); + + // Make sure all values are present + $call = $this->session->cookie->all_userdata(); + foreach ($cdata as $key => $value) { + $this->assertEquals($value, $call[$key]); + } + $nall = $this->session->native->all_userdata(); + foreach ($ndata as $key => $value) { + $this->assertEquals($value, $nall[$key]); + } + } + + /** + * Test the unset_userdata() function + */ + public function test_unset_userdata() + { + // Set a userdata message for each driver + $cmsg = 'Other test data'; + $this->session->cookie->set_userdata('test3', $cmsg); + $nmsg = 'Sundry test data'; + $this->session->native->set_userdata('test3', $nmsg); + + // Verify independent messages + $this->assertEquals($this->session->cookie->userdata('test3'), $cmsg); + $this->assertEquals($this->session->native->userdata('test3'), $nmsg); + + // Unset them and verify absence + $this->session->cookie->unset_userdata('test3'); + $this->session->native->unset_userdata('test3'); + $this->assertEquals($this->session->cookie->userdata('test3'), NULL); + $this->assertEquals($this->session->native->userdata('test3'), NULL); + } + + /** + * Test the set_flashdata() function + */ + public function test_set_flashdata() + { + // Set flashdata message for each driver + $cmsg = 'Some flash data'; + $this->session->cookie->set_flashdata('test4', $cmsg); + $nmsg = 'Other flash data'; + $this->session->native->set_flashdata('test4', $nmsg); + + // Simulate page reload + $this->session->cookie->reload(); + $this->session->native->reload(); + + // Verify independent messages + $this->assertEquals($this->session->cookie->flashdata('test4'), $cmsg); + $this->assertEquals($this->session->native->flashdata('test4'), $nmsg); + + // Simulate next page reload + $this->session->cookie->reload(); + $this->session->native->reload(); + + // Verify absence of messages + $this->assertEquals($this->session->cookie->flashdata('test4'), NULL); + $this->assertEquals($this->session->native->flashdata('test4'), NULL); + } + + /** + * Test the keep_flashdata() function + */ + public function test_keep_flashdata() + { + // Set flashdata message for each driver + $cmsg = 'My flash data'; + $this->session->cookie->set_flashdata('test5', $cmsg); + $nmsg = 'Your flash data'; + $this->session->native->set_flashdata('test5', $nmsg); + + // Simulate page reload and verify independent messages + $this->session->cookie->reload(); + $this->session->native->reload(); + $this->assertEquals($this->session->cookie->flashdata('test5'), $cmsg); + $this->assertEquals($this->session->native->flashdata('test5'), $nmsg); + + // Keep messages + $this->session->cookie->keep_flashdata('test5'); + $this->session->native->keep_flashdata('test5'); + + // Simulate next page reload and verify message persistence + $this->session->cookie->reload(); + $this->session->native->reload(); + $this->assertEquals($this->session->cookie->flashdata('test5'), $cmsg); + $this->assertEquals($this->session->native->flashdata('test5'), $nmsg); + + // Simulate next page reload and verify absence of messages + $this->session->cookie->reload(); + $this->session->native->reload(); + $this->assertEquals($this->session->cookie->flashdata('test5'), NULL); + $this->assertEquals($this->session->native->flashdata('test5'), NULL); + } + + /** + * Test the all_flashdata() function + */ + public function test_all_flashdata() + { + // Set a specific series of data for each driver + $cdata = array('one' => 'first', 'two' => 'second', 'three' => 'third', 'foo' => 'bar', 'bar' => 'baz'); + $this->session->cookie->set_flashdata($cdata); + $ndata = array('one' => 'gold', 'two' => 'silver', 'three' => 'bronze', 'foo' => 'baz', 'bar' => 'foo'); + $this->session->native->set_flashdata($ndata); + + // Simulate page reload and make sure all values are present + $this->session->cookie->reload(); + $this->session->native->reload(); + $this->assertEquals($cdata, $this->session->cookie->all_flashdata()); + $this->assertEquals($ndata, $this->session->native->all_flashdata()); + } + + /** + * Test the set_tempdata() function + */ + public function test_set_tempdata() + { + // Set tempdata message for each driver - 1 second timeout + $cmsg = 'Some temp data'; + $this->session->cookie->set_tempdata('test6', $cmsg, 1); + $nmsg = 'Other temp data'; + $this->session->native->set_tempdata('test6', $nmsg, 1); + + // Simulate page reload and verify independent messages + $this->session->cookie->reload(); + $this->session->native->reload(); + $this->assertEquals($this->session->cookie->tempdata('test6'), $cmsg); + $this->assertEquals($this->session->native->tempdata('test6'), $nmsg); + + // Wait 2 seconds, simulate page reload and verify message absence + sleep(2); + $this->session->cookie->reload(); + $this->session->native->reload(); + $this->assertEquals($this->session->cookie->tempdata('test6'), NULL); + $this->assertEquals($this->session->native->tempdata('test6'), NULL); + } + + /** + * Test the unset_tempdata() function + */ + public function test_unset_tempdata() + { + // Set tempdata message for each driver - 1 second timeout + $cmsg = 'My temp data'; + $this->session->cookie->set_tempdata('test7', $cmsg, 1); + $nmsg = 'Your temp data'; + $this->session->native->set_tempdata('test7', $nmsg, 1); + + // Verify independent messages + $this->assertEquals($this->session->cookie->tempdata('test7'), $cmsg); + $this->assertEquals($this->session->native->tempdata('test7'), $nmsg); + + // Unset data and verify message absence + $this->session->cookie->unset_tempdata('test7'); + $this->session->native->unset_tempdata('test7'); + $this->assertEquals($this->session->cookie->tempdata('test7'), NULL); + $this->assertEquals($this->session->native->tempdata('test7'), NULL); + } + + /** + * Test the sess_regenerate() function + */ + public function test_sess_regenerate() + { + // Get current session id, regenerate, and compare + // Cookie driver + $oldid = $this->session->cookie->userdata('session_id'); + $this->session->cookie->sess_regenerate(); + $newid = $this->session->cookie->userdata('session_id'); + $this->assertFalse($oldid === $newid); + + // Native driver - bug #55267 (https://bugs.php.net/bug.php?id=55267) prevents testing this + /*$oldid = session_id(); + $this->session->native->sess_regenerate(); + $oldid = session_id(); + $this->assertFalse($oldid === $newid);*/ + } + + /** + * Test the sess_destroy() function + */ + public function test_sess_destroy() + { + // Set a userdata message, destroy session, and verify absence + $msg = 'More test data'; + + // Cookie driver + $this->session->cookie->set_userdata('test8', $msg); + $this->assertEquals($this->session->cookie->userdata('test8'), $msg); + $this->session->cookie->sess_destroy(); + $this->assertEquals($this->session->cookie->userdata('test8'), NULL); + + // Native driver + $this->session->native->set_userdata('test8', $msg); + $this->assertEquals($this->session->native->userdata('test8'), $msg); + $this->session->native->sess_destroy(); + $this->assertEquals($this->session->native->userdata('test8'), NULL); + } +} + -- cgit v1.2.3-24-g4f1b From 4153c928229ff174743b78472ae27138cd715efe Mon Sep 17 00:00:00 2001 From: dchill42 Date: Tue, 31 Jul 2012 10:38:21 -0400 Subject: Coding standard cleanup and added userdata resync on sess_regenerate() --- tests/codeigniter/libraries/Session_test.php | 73 +++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 12 deletions(-) (limited to 'tests/codeigniter/libraries/Session_test.php') diff --git a/tests/codeigniter/libraries/Session_test.php b/tests/codeigniter/libraries/Session_test.php index db7efb6b7..5d58a9e69 100644 --- a/tests/codeigniter/libraries/Session_test.php +++ b/tests/codeigniter/libraries/Session_test.php @@ -4,7 +4,11 @@ * Session driver library unit test */ class Session_test extends CI_TestCase { - protected $settings = array('use_cookies' => 0, 'use_only_cookies' => 0, 'cache_limiter' => false); + protected $settings = array( + 'use_cookies' => 0, + 'use_only_cookies' => 0, + 'cache_limiter' => false + ); protected $setting_vals = array(); protected $cookie_vals; protected $session; @@ -26,19 +30,40 @@ class Session_test extends CI_TestCase { // Establish necessary support classes $obj = new stdClass; - foreach (array('config' => 'cfg', 'load' => 'load', 'input' => 'in') as $name => $abbr) { + $classes = array( + 'config' => 'cfg', + 'load' => 'load', + 'input' => 'in' + ); + foreach ($classes as $name => $abbr) { $class = $this->ci_core_class($abbr); $obj->$name = new $class; } $this->ci_instance($obj); // Attach session instance locally - $config = array('sess_encrypt_cookie' => FALSE, 'sess_use_database' => FALSE, 'sess_table_name' => '', - 'sess_expiration' => 7200, 'sess_expire_on_close' => FALSE, 'sess_match_ip' => FALSE, - 'sess_match_useragent' => TRUE, 'sess_cookie_name' => 'ci_session', 'cookie_path' => '', - 'cookie_domain' => '', 'cookie_secure' => FALSE, 'cookie_httponly' => FALSE, 'sess_time_to_update' => 300, - 'time_reference' => 'local', 'cookie_prefix' => '', 'encryption_key' => 'foobar', - 'sess_valid_drivers' => array('Mock_Libraries_Session_native', 'Mock_Libraries_Session_cookie')); + $config = array( + 'sess_encrypt_cookie' => FALSE, + 'sess_use_database' => FALSE, + 'sess_table_name' => '', + 'sess_expiration' => 7200, + 'sess_expire_on_close' => FALSE, + 'sess_match_ip' => FALSE, + 'sess_match_useragent' => TRUE, + 'sess_cookie_name' => 'ci_session', + 'cookie_path' => '', + 'cookie_domain' => '', + 'cookie_secure' => FALSE, + 'cookie_httponly' => FALSE, + 'sess_time_to_update' => 300, + 'time_reference' => 'local', + 'cookie_prefix' => '', + 'encryption_key' => 'foobar', + 'sess_valid_drivers' => array( + 'Mock_Libraries_Session_native', + 'Mock_Libraries_Session_cookie' + ) + ); $this->session = new Mock_Libraries_Session($config); } @@ -96,9 +121,21 @@ class Session_test extends CI_TestCase { public function test_all_userdata() { // Set a specific series of data for each driver - $cdata = array('one' => 'first', 'two' => 'second', 'three' => 'third', 'foo' => 'bar', 'bar' => 'baz'); + $cdata = array( + 'one' => 'first', + 'two' => 'second', + 'three' => 'third', + 'foo' => 'bar', + 'bar' => 'baz' + ); + $ndata = array( + 'one' => 'gold', + 'two' => 'silver', + 'three' => 'bronze', + 'foo' => 'baz', + 'bar' => 'foo' + ); $this->session->cookie->set_userdata($cdata); - $ndata = array('one' => 'gold', 'two' => 'silver', 'three' => 'bronze', 'foo' => 'baz', 'bar' => 'foo'); $this->session->native->set_userdata($ndata); // Make sure all values are present @@ -202,9 +239,21 @@ class Session_test extends CI_TestCase { public function test_all_flashdata() { // Set a specific series of data for each driver - $cdata = array('one' => 'first', 'two' => 'second', 'three' => 'third', 'foo' => 'bar', 'bar' => 'baz'); + $cdata = array( + 'one' => 'first', + 'two' => 'second', + 'three' => 'third', + 'foo' => 'bar', + 'bar' => 'baz' + ); + $ndata = array( + 'one' => 'gold', + 'two' => 'silver', + 'three' => 'bronze', + 'foo' => 'baz', + 'bar' => 'foo' + ); $this->session->cookie->set_flashdata($cdata); - $ndata = array('one' => 'gold', 'two' => 'silver', 'three' => 'bronze', 'foo' => 'baz', 'bar' => 'foo'); $this->session->native->set_flashdata($ndata); // Simulate page reload and make sure all values are present -- cgit v1.2.3-24-g4f1b From 08c8304778e573d725b5565f350e44c34fb0d830 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Tue, 28 Aug 2012 17:35:56 -0400 Subject: Minor session test improvements Signed-off-by: dchill42 --- tests/codeigniter/libraries/Session_test.php | 182 +++++++++++++++++---------- 1 file changed, 117 insertions(+), 65 deletions(-) (limited to 'tests/codeigniter/libraries/Session_test.php') diff --git a/tests/codeigniter/libraries/Session_test.php b/tests/codeigniter/libraries/Session_test.php index 5d58a9e69..135f71806 100644 --- a/tests/codeigniter/libraries/Session_test.php +++ b/tests/codeigniter/libraries/Session_test.php @@ -85,38 +85,66 @@ class Session_test extends CI_TestCase { /** * Test set_userdata() function + * + * @covers CI_Session::set_userdata + * @covers CI_Session::userdata */ public function test_set_userdata() { - // Set a userdata message for each driver - $cmsg = 'Some test data'; - $this->session->cookie->set_userdata('test1', $cmsg); - $nmsg = 'Other test data'; - $this->session->native->set_userdata('test1', $nmsg); + // Set userdata values for each driver + $key1 = 'test1'; + $ckey2 = 'test2'; + $nkey2 = 'test3'; + $cmsg1 = 'Some test data'; + $cmsg2 = 42; + $nmsg1 = 'Other test data'; + $nmsg2 = true; + $this->session->cookie->set_userdata($key1, $cmsg1); + $this->session->set_userdata($ckey2, $cmsg2); + $this->session->native->set_userdata($key1, $nmsg1); + $this->session->set_userdata($nkey2, $nmsg2); // Verify independent messages - $this->assertEquals($this->session->cookie->userdata('test1'), $cmsg); - $this->assertEquals($this->session->native->userdata('test1'), $nmsg); + $this->assertEquals($cmsg1, $this->session->cookie->userdata($key1)); + $this->assertEquals($nmsg1, $this->session->native->userdata($key1)); + + // Verify pre-selected driver sets + $this->assertEquals($cmsg2, $this->session->cookie->userdata($ckey2)); + $this->assertEquals($nmsg2, $this->session->native->userdata($nkey2)); + + // Verify no crossover + $this->assertNull($this->session->cookie->userdata($nkey2)); + $this->assertNull($this->session->native->userdata($ckey2)); } /** * Test the has_userdata() function + * + * @covers CI_Session::has_userdata */ public function test_has_userdata() { - // Set a userdata message for each driver + // Set a userdata value for each driver + $key = 'hastest'; $cmsg = 'My test data'; - $this->session->cookie->set_userdata('test2', $cmsg); + $this->session->cookie->set_userdata($key, $cmsg); $nmsg = 'Your test data'; - $this->session->native->set_userdata('test2', $nmsg); + $this->session->native->set_userdata($key, $nmsg); - // Verify independent messages - $this->assertTrue($this->session->cookie->has_userdata('test2')); - $this->assertTrue($this->session->native->has_userdata('test2')); + // Verify values exist + $this->assertTrue($this->session->cookie->has_userdata($key)); + $this->assertTrue($this->session->native->has_userdata($key)); + + // Verify non-existent values + $nokey = 'hasnot'; + $this->assertFalse($this->session->cookie->has_userdata($nokey)); + $this->assertFalse($this->session->native->has_userdata($nokey)); } /** * Test the all_userdata() function + * + * @covers CI_Session::all_userdata */ public function test_all_userdata() { @@ -151,90 +179,102 @@ class Session_test extends CI_TestCase { /** * Test the unset_userdata() function + * + * @covers CI_Session::unset_userdata */ public function test_unset_userdata() { // Set a userdata message for each driver + $key = 'untest'; $cmsg = 'Other test data'; - $this->session->cookie->set_userdata('test3', $cmsg); + $this->session->cookie->set_userdata($key, $cmsg); $nmsg = 'Sundry test data'; - $this->session->native->set_userdata('test3', $nmsg); + $this->session->native->set_userdata($key, $nmsg); // Verify independent messages - $this->assertEquals($this->session->cookie->userdata('test3'), $cmsg); - $this->assertEquals($this->session->native->userdata('test3'), $nmsg); + $this->assertEquals($this->session->cookie->userdata($key), $cmsg); + $this->assertEquals($this->session->native->userdata($key), $nmsg); // Unset them and verify absence - $this->session->cookie->unset_userdata('test3'); - $this->session->native->unset_userdata('test3'); - $this->assertEquals($this->session->cookie->userdata('test3'), NULL); - $this->assertEquals($this->session->native->userdata('test3'), NULL); + $this->session->cookie->unset_userdata($key); + $this->session->native->unset_userdata($key); + $this->assertNull($this->session->cookie->userdata($key)); + $this->assertNull($this->session->native->userdata($key)); } /** - * Test the set_flashdata() function + * Test the flashdata() functions + * + * @covers CI_Session::set_flashdata + * @covers CI_Session::flashdata */ - public function test_set_flashdata() + public function test_flashdata() { // Set flashdata message for each driver + $key = 'fltest'; $cmsg = 'Some flash data'; - $this->session->cookie->set_flashdata('test4', $cmsg); + $this->session->cookie->set_flashdata($key, $cmsg); $nmsg = 'Other flash data'; - $this->session->native->set_flashdata('test4', $nmsg); + $this->session->native->set_flashdata($key, $nmsg); // Simulate page reload $this->session->cookie->reload(); $this->session->native->reload(); // Verify independent messages - $this->assertEquals($this->session->cookie->flashdata('test4'), $cmsg); - $this->assertEquals($this->session->native->flashdata('test4'), $nmsg); + $this->assertEquals($cmsg, $this->session->cookie->flashdata($key)); + $this->assertEquals($nmsg, $this->session->native->flashdata($key)); // Simulate next page reload $this->session->cookie->reload(); $this->session->native->reload(); // Verify absence of messages - $this->assertEquals($this->session->cookie->flashdata('test4'), NULL); - $this->assertEquals($this->session->native->flashdata('test4'), NULL); + $this->assertNull($this->session->cookie->flashdata($key)); + $this->assertNull($this->session->native->flashdata($key)); } /** * Test the keep_flashdata() function + * + * @covers CI_Session::keep_flashdata */ public function test_keep_flashdata() { // Set flashdata message for each driver + $key = 'kfltest'; $cmsg = 'My flash data'; - $this->session->cookie->set_flashdata('test5', $cmsg); + $this->session->cookie->set_flashdata($key, $cmsg); $nmsg = 'Your flash data'; - $this->session->native->set_flashdata('test5', $nmsg); + $this->session->native->set_flashdata($key, $nmsg); // Simulate page reload and verify independent messages $this->session->cookie->reload(); $this->session->native->reload(); - $this->assertEquals($this->session->cookie->flashdata('test5'), $cmsg); - $this->assertEquals($this->session->native->flashdata('test5'), $nmsg); + $this->assertEquals($cmsg, $this->session->cookie->flashdata($key)); + $this->assertEquals($nmsg, $this->session->native->flashdata($key)); // Keep messages - $this->session->cookie->keep_flashdata('test5'); - $this->session->native->keep_flashdata('test5'); + $this->session->cookie->keep_flashdata($key); + $this->session->native->keep_flashdata($key); // Simulate next page reload and verify message persistence $this->session->cookie->reload(); $this->session->native->reload(); - $this->assertEquals($this->session->cookie->flashdata('test5'), $cmsg); - $this->assertEquals($this->session->native->flashdata('test5'), $nmsg); + $this->assertEquals($cmsg, $this->session->cookie->flashdata($key)); + $this->assertEquals($nmsg, $this->session->native->flashdata($key)); // Simulate next page reload and verify absence of messages $this->session->cookie->reload(); $this->session->native->reload(); - $this->assertEquals($this->session->cookie->flashdata('test5'), NULL); - $this->assertEquals($this->session->native->flashdata('test5'), NULL); + $this->assertNull($this->session->cookie->flashdata($key)); + $this->assertNull($this->session->native->flashdata($key)); } /** * Test the all_flashdata() function + * + * @covers CI_Session::all_flashdata */ public function test_all_flashdata() { @@ -264,54 +304,63 @@ class Session_test extends CI_TestCase { } /** - * Test the set_tempdata() function + * Test the tempdata() functions + * + * @covers CI_Session::set_tempdata + * @covers CI_Session::tempdata */ public function test_set_tempdata() { // Set tempdata message for each driver - 1 second timeout + $key = 'tmptest'; $cmsg = 'Some temp data'; - $this->session->cookie->set_tempdata('test6', $cmsg, 1); + $this->session->cookie->set_tempdata($key, $cmsg, 1); $nmsg = 'Other temp data'; - $this->session->native->set_tempdata('test6', $nmsg, 1); + $this->session->native->set_tempdata($key, $nmsg, 1); // Simulate page reload and verify independent messages $this->session->cookie->reload(); $this->session->native->reload(); - $this->assertEquals($this->session->cookie->tempdata('test6'), $cmsg); - $this->assertEquals($this->session->native->tempdata('test6'), $nmsg); + $this->assertEquals($cmsg, $this->session->cookie->tempdata($key)); + $this->assertEquals($nmsg, $this->session->native->tempdata($key)); // Wait 2 seconds, simulate page reload and verify message absence sleep(2); $this->session->cookie->reload(); $this->session->native->reload(); - $this->assertEquals($this->session->cookie->tempdata('test6'), NULL); - $this->assertEquals($this->session->native->tempdata('test6'), NULL); + $this->assertNull($this->session->cookie->tempdata($key)); + $this->assertNull($this->session->native->tempdata($key)); } /** * Test the unset_tempdata() function + * + * @covers CI_Session::unset_tempdata */ public function test_unset_tempdata() { // Set tempdata message for each driver - 1 second timeout + $key = 'utmptest'; $cmsg = 'My temp data'; - $this->session->cookie->set_tempdata('test7', $cmsg, 1); + $this->session->cookie->set_tempdata($key, $cmsg, 1); $nmsg = 'Your temp data'; - $this->session->native->set_tempdata('test7', $nmsg, 1); + $this->session->native->set_tempdata($key, $nmsg, 1); // Verify independent messages - $this->assertEquals($this->session->cookie->tempdata('test7'), $cmsg); - $this->assertEquals($this->session->native->tempdata('test7'), $nmsg); + $this->assertEquals($cmsg, $this->session->cookie->tempdata($key)); + $this->assertEquals($nmsg, $this->session->native->tempdata($key)); // Unset data and verify message absence - $this->session->cookie->unset_tempdata('test7'); - $this->session->native->unset_tempdata('test7'); - $this->assertEquals($this->session->cookie->tempdata('test7'), NULL); - $this->assertEquals($this->session->native->tempdata('test7'), NULL); + $this->session->cookie->unset_tempdata($key); + $this->session->native->unset_tempdata($key); + $this->assertNull($this->session->cookie->tempdata($key)); + $this->assertNull($this->session->native->tempdata($key)); } /** * Test the sess_regenerate() function + * + * @covers CI_Session::sess_regenerate */ public function test_sess_regenerate() { @@ -320,34 +369,37 @@ class Session_test extends CI_TestCase { $oldid = $this->session->cookie->userdata('session_id'); $this->session->cookie->sess_regenerate(); $newid = $this->session->cookie->userdata('session_id'); - $this->assertFalse($oldid === $newid); + $this->assertNotEquals($oldid, $newid); // Native driver - bug #55267 (https://bugs.php.net/bug.php?id=55267) prevents testing this - /*$oldid = session_id(); - $this->session->native->sess_regenerate(); - $oldid = session_id(); - $this->assertFalse($oldid === $newid);*/ + // $oldid = session_id(); + // $this->session->native->sess_regenerate(); + // $oldid = session_id(); + // $this->assertNotEquals($oldid, $newid); } /** * Test the sess_destroy() function + * + * @covers CI_Session::sess_destroy */ public function test_sess_destroy() { // Set a userdata message, destroy session, and verify absence + $key = 'dsttest'; $msg = 'More test data'; // Cookie driver - $this->session->cookie->set_userdata('test8', $msg); - $this->assertEquals($this->session->cookie->userdata('test8'), $msg); + $this->session->cookie->set_userdata($key, $msg); + $this->assertEquals($msg, $this->session->cookie->userdata($key)); $this->session->cookie->sess_destroy(); - $this->assertEquals($this->session->cookie->userdata('test8'), NULL); + $this->assertNull($this->session->cookie->userdata($key)); // Native driver - $this->session->native->set_userdata('test8', $msg); - $this->assertEquals($this->session->native->userdata('test8'), $msg); + $this->session->native->set_userdata($key, $msg); + $this->assertEquals($msg, $this->session->native->userdata($key)); $this->session->native->sess_destroy(); - $this->assertEquals($this->session->native->userdata('test8'), NULL); + $this->assertNull($this->session->native->userdata($key)); } } -- cgit v1.2.3-24-g4f1b