2007-07-09 17:33:03 +00:00
< ? php
/* SVN FILE: $Id$ */
/**
* Short description for file .
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP ( tm ) Tests < https :// trac . cakephp . org / wiki / Developement / TestSuite >
2008-01-01 22:18:17 +00:00
* Copyright 2005 - 2008 , Cake Software Foundation , Inc .
2007-07-09 17:33:03 +00:00
* 1785 E . Sahara Avenue , Suite 490 - 204
* Las Vegas , Nevada 89104
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice .
*
* @ filesource
2008-01-01 22:18:17 +00:00
* @ copyright Copyright 2005 - 2008 , Cake Software Foundation , Inc .
2007-07-09 17:33:03 +00:00
* @ link https :// trac . cakephp . org / wiki / Developement / TestSuite CakePHP ( tm ) Tests
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . view . helpers
* @ since CakePHP ( tm ) v 1.2 . 0.4206
* @ version $Revision $
* @ modifiedby $LastChangedBy $
* @ lastmodified $Date $
* @ license http :// www . opensource . org / licenses / opengroup . php The Open Group Test Suite License
*/
if ( ! defined ( 'CAKEPHP_UNIT_TEST_EXECUTION' )) {
define ( 'CAKEPHP_UNIT_TEST_EXECUTION' , 1 );
}
2008-05-09 12:27:07 +00:00
App :: import ( 'Core' , array ( 'Helper' , 'AppHelper' , 'Controller' , 'View' ));
App :: import ( 'Helper' , array ( 'Session' ));
2007-07-09 17:33:03 +00:00
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . view . helpers
*/
2008-05-09 12:27:07 +00:00
class SessionHelperTest extends CakeTestCase {
2008-05-15 05:13:44 +00:00
2007-07-09 17:33:03 +00:00
function setUp () {
2008-05-09 16:13:30 +00:00
$this -> Session = new SessionHelper ();
2008-05-09 12:27:07 +00:00
$this -> Session -> __start ();
2008-05-09 16:13:30 +00:00
$_SESSION = array (
'test' => 'info' ,
'Message' => array (
'flash' => array (
'layout' => 'default' ,
'params' => array (),
'message' => 'This is a calling'
),
'notification' => array (
2008-05-15 05:13:44 +00:00
'layout' => 'session_helper' ,
2008-05-09 16:13:30 +00:00
'params' => array ( 'title' => 'Notice!' , 'name' => 'Alert!' ),
'message' => 'This is a test of the emergency broadcasting system' ,
),
'bare' => array (
'layout' => null ,
'message' => 'Bare message' ,
'params' => array (),
),
),
'Deeply' => array ( 'nested' => array ( 'key' => 'value' )),
);
2007-07-09 17:33:03 +00:00
}
function tearDown () {
2008-05-15 05:13:44 +00:00
$_SESSION = array ();
2007-07-09 17:33:03 +00:00
unset ( $this -> Session );
}
2008-05-15 05:13:44 +00:00
2008-05-09 12:27:07 +00:00
function testRead () {
$result = $this -> Session -> read ( 'Deeply.nested.key' );
$this -> assertEqual ( $result , 'value' );
2008-05-09 16:13:30 +00:00
2008-05-09 12:27:07 +00:00
$result = $this -> Session -> read ( 'test' );
$this -> assertEqual ( $result , 'info' );
}
2008-05-15 05:13:44 +00:00
2008-05-09 12:27:07 +00:00
function testCheck () {
$this -> assertTrue ( $this -> Session -> check ( 'test' ));
2008-05-09 16:13:30 +00:00
2008-05-09 12:27:07 +00:00
$this -> assertTrue ( $this -> Session -> check ( 'Message.flash.layout' ));
2008-05-09 16:13:30 +00:00
2008-05-09 12:27:07 +00:00
$this -> assertFalse ( $this -> Session -> check ( 'Does.not.exist' ));
2008-05-09 16:13:30 +00:00
2008-05-09 12:27:07 +00:00
$this -> assertFalse ( $this -> Session -> check ( 'Nope' ));
}
2008-05-15 05:13:44 +00:00
2008-05-09 12:27:07 +00:00
function testWrite () {
$this -> expectError ();
$this -> Session -> write ( 'NoWay' , 'AccessDenied' );
}
2008-05-15 05:13:44 +00:00
2008-05-09 12:27:07 +00:00
function testFlash () {
2008-05-09 16:13:30 +00:00
ob_start ();
$this -> Session -> flash ();
2008-05-09 12:27:07 +00:00
$result = ob_get_contents ();
ob_clean ();
2008-05-15 05:13:44 +00:00
2008-05-09 12:27:07 +00:00
$expected = '<div id="flashMessage" class="message">This is a calling</div>' ;
2008-05-15 05:13:44 +00:00
$this -> assertEqual ( $result , $expected );
2008-05-09 12:27:07 +00:00
$this -> assertFalse ( $this -> Session -> check ( 'Message.flash' ));
2008-05-15 05:13:44 +00:00
2008-05-09 16:13:30 +00:00
Configure :: write ( 'viewPaths' , array ( TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS ));
2008-05-09 12:27:07 +00:00
$controller = new Controller ();
$this -> Session -> view = new View ( $controller );
2008-05-15 05:13:44 +00:00
2008-05-09 12:27:07 +00:00
ob_start ();
$this -> Session -> flash ( 'notification' );
$result = ob_get_contents ();
ob_clean ();
2008-05-09 16:13:30 +00:00
2008-05-09 12:27:07 +00:00
$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 );
2008-05-09 16:13:30 +00:00
$this -> assertFalse ( $this -> Session -> check ( 'Message.notification' ));
2008-05-09 12:27:07 +00:00
ob_start ();
$this -> Session -> flash ( 'bare' );
$result = ob_get_contents ();
ob_clean ();
$expected = 'Bare message' ;
$this -> assertEqual ( $result , $expected );
$this -> assertFalse ( $this -> Session -> check ( 'Message.bare' ));
}
2008-05-09 16:13:30 +00:00
2008-05-09 12:27:07 +00:00
function testID () {
$id = session_id ();
$result = $this -> Session -> id ();
$this -> assertEqual ( $id , $result );
}
2008-05-09 16:13:30 +00:00
2008-05-09 12:27:07 +00:00
function testError () {
$result = $this -> Session -> error ();
$this -> assertFalse ( $result );
2008-05-09 16:13:30 +00:00
2008-05-09 12:27:07 +00:00
$this -> Session -> read ( 'CauseError' );
$result = $this -> Session -> error ();
$expected = " CauseError doesn't exist " ;
$this -> assertEqual ( $result , $expected );
}
2008-05-09 16:13:30 +00:00
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 );
}
2008-05-09 12:27:07 +00:00
function testValid () {
//wierd it always ends up false in the test suite
//$this->assertFalse($this->Session->valid());
}
2007-07-09 17:33:03 +00:00
}
?>