/** * testReadAndWriteWithDatabaseStorage method * * @return void */ public function testReadAndWriteWithDatabaseStorage() { Configure::write('Session.defaults', 'database'); Configure::write('Session.handler.engine', 'TestDatabaseSession'); Configure::write('Session.handler.table', 'sessions'); Configure::write('Session.handler.model', 'Session'); Configure::write('Session.handler.database', 'test'); TestCakeSession::init(); $this->assertNull(TestCakeSession::id()); TestCakeSession::start(); $expected = session_id(); $this->assertEquals($expected, TestCakeSession::id()); TestCakeSession::renew(); $this->assertFalse($expected === TestCakeSession::id()); $expected = session_id(); $this->assertEquals($expected, TestCakeSession::id()); TestCakeSession::write('SessionTestCase', 0); $this->assertEquals(0, TestCakeSession::read('SessionTestCase')); TestCakeSession::write('SessionTestCase', '0'); $this->assertEquals('0', TestCakeSession::read('SessionTestCase')); $this->assertFalse(TestCakeSession::read('SessionTestCase') === 0); TestCakeSession::write('SessionTestCase', false); $this->assertFalse(TestCakeSession::read('SessionTestCase')); TestCakeSession::write('SessionTestCase', null); $this->assertEquals(null, TestCakeSession::read('SessionTestCase')); TestCakeSession::write('SessionTestCase', 'This is a Test'); $this->assertEquals('This is a Test', TestCakeSession::read('SessionTestCase')); TestCakeSession::write('SessionTestCase', 'Some additional data'); $this->assertEquals('Some additional data', TestCakeSession::read('SessionTestCase')); TestCakeSession::destroy(); $this->assertNull(TestCakeSession::read('SessionTestCase')); Configure::write('Session', array('defaults' => 'php')); TestCakeSession::init(); }
/** * test that changing the config name of the cache config works. * * @return void */ public function testReadAndWriteWithCustomCacheConfig() { Configure::write('Session.defaults', 'cache'); Configure::write('Session.handler.config', 'session_test'); Cache::config('session_test', array('engine' => 'File', 'prefix' => 'session_test_')); TestCakeSession::init(); TestCakeSession::start(); TestCakeSession::write('SessionTestCase', 'Some value'); $this->assertEquals('Some value', TestCakeSession::read('SessionTestCase')); $id = TestCakeSession::id(); Cache::delete($id, 'session_test'); }