Additional test coverage for SessionHelper

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6778 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-05-09 16:13:30 +00:00
parent a53d308fa3
commit a5822e6967

View file

@ -42,30 +42,30 @@ App::import('Helper', array('Session'));
class SessionHelperTest extends CakeTestCase { class SessionHelperTest extends CakeTestCase {
function setUp() { function setUp() {
$this->Session = new SessionHelper(); $this->Session = new SessionHelper();
$this->Session->__start(); $this->Session->__start();
$_SESSION = array('test' => 'info', $_SESSION = array(
'Message' => array( 'test' => 'info',
'flash' => array( 'Message' => array(
'layout' => 'default', 'flash' => array(
'params' => array(), 'layout' => 'default',
'message' => 'This is a calling' 'params' => array(),
), 'message' => 'This is a calling'
'notification' => array( ),
'layout' => 'sessionHelper', 'notification' => array(
'params' => array('title' => 'Notice!', 'layout' => 'sessionHelper',
'name' => 'Alert!'), 'params' => array('title' => 'Notice!', 'name' => 'Alert!'),
'message' => 'This is a test of the emergency broadcasting system', 'message' => 'This is a test of the emergency broadcasting system',
), ),
'bare' => array( 'bare' => array(
'layout' => null, 'layout' => null,
'message' => 'Bare message', 'message' => 'Bare message',
'params' => array(), 'params' => array(),
), ),
), ),
'Deeply' => array('nested' => array('key' => 'value')), 'Deeply' => array('nested' => array('key' => 'value')),
); );
} }
function tearDown() { function tearDown() {
@ -76,19 +76,18 @@ class SessionHelperTest extends CakeTestCase {
function testRead() { function testRead() {
$result = $this->Session->read('Deeply.nested.key'); $result = $this->Session->read('Deeply.nested.key');
$this->assertEqual($result, 'value'); $this->assertEqual($result, 'value');
$result = $this->Session->read('test'); $result = $this->Session->read('test');
$this->assertEqual($result, 'info'); $this->assertEqual($result, 'info');
} }
function testCheck() { function testCheck() {
$this->assertTrue($this->Session->check('test')); $this->assertTrue($this->Session->check('test'));
$this->assertTrue($this->Session->check('Message.flash.layout')); $this->assertTrue($this->Session->check('Message.flash.layout'));
$this->assertFalse($this->Session->check('Does.not.exist')); $this->assertFalse($this->Session->check('Does.not.exist'));
$this->assertFalse($this->Session->check('Nope')); $this->assertFalse($this->Session->check('Nope'));
} }
@ -98,8 +97,8 @@ class SessionHelperTest extends CakeTestCase {
} }
function testFlash() { function testFlash() {
ob_start(); ob_start();
$this->Session->flash(); $this->Session->flash();
$result = ob_get_contents(); $result = ob_get_contents();
ob_clean(); ob_clean();
@ -107,7 +106,7 @@ class SessionHelperTest extends CakeTestCase {
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$this->assertFalse($this->Session->check('Message.flash')); $this->assertFalse($this->Session->check('Message.flash'));
Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)); Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS));
$controller = new Controller(); $controller = new Controller();
$this->Session->view = new View($controller); $this->Session->view = new View($controller);
@ -115,11 +114,11 @@ class SessionHelperTest extends CakeTestCase {
$this->Session->flash('notification'); $this->Session->flash('notification');
$result = ob_get_contents(); $result = ob_get_contents();
ob_clean(); ob_clean();
$expected = "<div id=\"notificationLayout\">\n\t<h1>Alert!</h1>\n\t<h3>Notice!</h3>\n\t<p>This is a test of the emergency broadcasting system</p>\n</div>"; $expected = "<div id=\"notificationLayout\">\n\t<h1>Alert!</h1>\n\t<h3>Notice!</h3>\n\t<p>This is a test of the emergency broadcasting system</p>\n</div>";
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$this->assertFalse($this->Session->check('Message.notification')); $this->assertFalse($this->Session->check('Message.notification'));
ob_start(); ob_start();
$this->Session->flash('bare'); $this->Session->flash('bare');
$result = ob_get_contents(); $result = ob_get_contents();
@ -129,23 +128,39 @@ class SessionHelperTest extends CakeTestCase {
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$this->assertFalse($this->Session->check('Message.bare')); $this->assertFalse($this->Session->check('Message.bare'));
} }
function testID() { function testID() {
$id = session_id(); $id = session_id();
$result = $this->Session->id(); $result = $this->Session->id();
$this->assertEqual($id, $result); $this->assertEqual($id, $result);
} }
function testError() { function testError() {
$result = $this->Session->error(); $result = $this->Session->error();
$this->assertFalse($result); $this->assertFalse($result);
$this->Session->read('CauseError'); $this->Session->read('CauseError');
$result = $this->Session->error(); $result = $this->Session->error();
$expected = "CauseError doesn't exist"; $expected = "CauseError doesn't exist";
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
} }
function testDisabling() {
Configure::write('Session.start', false);
$this->Session = new SessionHelper();
$this->assertFalse($this->Session->check('test'));
$this->assertFalse($this->Session->read('test'));
$this->Session->read('CauseError');
$this->assertFalse($this->Session->error());
ob_start();
$this->assertFalse($this->Session->flash('bare'));
$result = ob_get_contents();
ob_clean();
$this->assertFalse($result);
}
function testValid() { function testValid() {
//wierd it always ends up false in the test suite //wierd it always ends up false in the test suite
//$this->assertFalse($this->Session->valid()); //$this->assertFalse($this->Session->valid());