2008-05-30 11:40:08 +00:00
< ? php
/**
2009-03-19 21:10:13 +00:00
* SessionHelperTest file
2008-05-30 11:40:08 +00:00
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP ( tm ) Tests < https :// trac . cakephp . org / wiki / Developement / TestSuite >
2009-09-01 04:03:56 +00:00
* Copyright 2005 - 2009 , Cake Software Foundation , Inc . ( http :// www . cakefoundation . org )
2008-05-30 11:40:08 +00:00
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice .
*
* @ filesource
2009-09-01 04:03:56 +00:00
* @ copyright Copyright 2005 - 2009 , Cake Software Foundation , Inc . ( http :// www . cakefoundation . org )
2008-10-30 17:30:26 +00:00
* @ link https :// trac . cakephp . org / wiki / Developement / TestSuite CakePHP ( tm ) Tests
2009-03-19 21:10:13 +00:00
* @ package cake
2008-10-30 17:30:26 +00:00
* @ subpackage cake . tests . cases . libs . view . helpers
* @ since CakePHP ( tm ) v 1.2 . 0.4206
* @ license http :// www . opensource . org / licenses / opengroup . php The Open Group Test Suite License
2008-05-30 11:40:08 +00:00
*/
if ( ! defined ( 'CAKEPHP_UNIT_TEST_EXECUTION' )) {
define ( 'CAKEPHP_UNIT_TEST_EXECUTION' , 1 );
}
App :: import ( 'Core' , array ( 'Helper' , 'AppHelper' , 'Controller' , 'View' ));
App :: import ( 'Helper' , array ( 'Session' ));
2009-07-24 19:18:37 +00:00
2008-05-30 11:40:08 +00:00
/**
2009-03-19 21:10:13 +00:00
* SessionHelperTest class
2008-05-30 11:40:08 +00:00
*
2009-03-19 21:10:13 +00:00
* @ package cake
2008-10-30 17:30:26 +00:00
* @ subpackage cake . tests . cases . libs . view . helpers
2008-05-30 11:40:08 +00:00
*/
class SessionHelperTest extends CakeTestCase {
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
* setUp method
2008-06-20 19:30:29 +00:00
*
2008-06-02 19:22:55 +00:00
* @ access public
* @ return void
*/
2009-09-17 23:57:56 +00:00
function startTest () {
2008-05-30 11:40:08 +00:00
$this -> Session = new SessionHelper ();
$_SESSION = array (
'test' => 'info' ,
'Message' => array (
'flash' => array (
2009-09-01 04:03:56 +00:00
'element' => 'default' ,
2008-05-30 11:40:08 +00:00
'params' => array (),
'message' => 'This is a calling'
),
'notification' => array (
2009-09-01 04:03:56 +00:00
'element' => 'session_helper' ,
2008-05-30 11:40:08 +00:00
'params' => array ( 'title' => 'Notice!' , 'name' => 'Alert!' ),
'message' => 'This is a test of the emergency broadcasting system' ,
),
'classy' => array (
2009-09-01 04:03:56 +00:00
'element' => 'default' ,
2008-05-30 11:40:08 +00:00
'params' => array ( 'class' => 'positive' ),
'message' => 'Recorded'
),
'bare' => array (
2009-09-01 04:03:56 +00:00
'element' => null ,
2008-05-30 11:40:08 +00:00
'message' => 'Bare message' ,
'params' => array (),
),
),
'Deeply' => array ( 'nested' => array ( 'key' => 'value' )),
);
}
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
* tearDown method
2008-06-20 19:30:29 +00:00
*
2008-06-02 19:22:55 +00:00
* @ access public
* @ return void
*/
2008-05-30 11:40:08 +00:00
function tearDown () {
$_SESSION = array ();
unset ( $this -> Session );
}
2009-07-24 19:18:37 +00:00
2009-06-11 16:13:16 +00:00
/**
* endTest
*
* @ access public
* @ return void
*/
function endTest () {
App :: build ();
2009-07-24 19:18:37 +00:00
}
2009-09-17 23:57:56 +00:00
/**
* test construction and initial property settings
*
* @ return void
**/
function testConstruct () {
$this -> assertFalse ( empty ( $this -> Session -> sessionTime ));
$this -> assertFalse ( empty ( $this -> Session -> security ));
}
2008-06-02 19:22:55 +00:00
/**
* testRead method
2008-06-20 19:30:29 +00:00
*
2008-06-02 19:22:55 +00:00
* @ access public
* @ return void
*/
2008-05-30 11:40:08 +00:00
function testRead () {
$result = $this -> Session -> read ( 'Deeply.nested.key' );
$this -> assertEqual ( $result , 'value' );
$result = $this -> Session -> read ( 'test' );
$this -> assertEqual ( $result , 'info' );
}
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
* testCheck method
2008-06-20 19:30:29 +00:00
*
2008-06-02 19:22:55 +00:00
* @ access public
* @ return void
*/
2008-05-30 11:40:08 +00:00
function testCheck () {
$this -> assertTrue ( $this -> Session -> check ( 'test' ));
2009-09-01 04:03:56 +00:00
$this -> assertTrue ( $this -> Session -> check ( 'Message.flash.element' ));
2008-05-30 11:40:08 +00:00
$this -> assertFalse ( $this -> Session -> check ( 'Does.not.exist' ));
$this -> assertFalse ( $this -> Session -> check ( 'Nope' ));
}
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
* testWrite method
2008-06-20 19:30:29 +00:00
*
2008-06-02 19:22:55 +00:00
* @ access public
* @ return void
*/
2008-05-30 11:40:08 +00:00
function testWrite () {
$this -> expectError ();
$this -> Session -> write ( 'NoWay' , 'AccessDenied' );
}
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
* testFlash method
2008-06-20 19:30:29 +00:00
*
2008-06-02 19:22:55 +00:00
* @ access public
* @ return void
*/
2008-05-30 11:40:08 +00:00
function testFlash () {
ob_start ();
$this -> Session -> flash ();
$result = ob_get_contents ();
ob_clean ();
$expected = '<div id="flashMessage" class="message">This is a calling</div>' ;
$this -> assertEqual ( $result , $expected );
$this -> assertFalse ( $this -> Session -> check ( 'Message.flash' ));
$expected = '<div id="classyMessage" class="positive">Recorded</div>' ;
ob_start ();
$this -> Session -> flash ( 'classy' );
$result = ob_get_clean ();
$this -> assertEqual ( $result , $expected );
2008-06-20 19:30:29 +00:00
2009-06-11 16:13:16 +00:00
App :: build ( array (
'views' => array ( TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS )
));
2008-05-30 11:40:08 +00:00
$controller = new Controller ();
$this -> Session -> view = new View ( $controller );
ob_start ();
$this -> Session -> flash ( 'notification' );
$result = ob_get_contents ();
ob_clean ();
2008-06-20 19:30:29 +00:00
$result = str_replace ( " \r \n " , " \n " , $result );
2008-05-30 11:40:08 +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 );
$this -> assertFalse ( $this -> Session -> check ( 'Message.notification' ));
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' ));
}
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
* testID method
2008-06-20 19:30:29 +00:00
*
2008-06-02 19:22:55 +00:00
* @ access public
* @ return void
*/
2008-05-30 11:40:08 +00:00
function testID () {
$id = session_id ();
$result = $this -> Session -> id ();
$this -> assertEqual ( $id , $result );
}
2009-07-24 19:18:37 +00:00
2008-06-05 15:20:45 +00:00
/**
* testError method
2008-06-20 19:30:29 +00:00
*
2008-06-05 15:20:45 +00:00
* @ access public
* @ return void
*/
2008-05-30 11:40:08 +00:00
function testError () {
$result = $this -> Session -> error ();
$this -> assertFalse ( $result );
$this -> Session -> read ( 'CauseError' );
$result = $this -> Session -> error ();
$expected = " CauseError doesn't exist " ;
$this -> assertEqual ( $result , $expected );
}
2009-07-24 19:18:37 +00:00
2008-06-05 15:20:45 +00:00
/**
* testDisabling method
2008-06-20 19:30:29 +00:00
*
2008-06-05 15:20:45 +00:00
* @ access public
* @ return void
*/
2008-05-30 11:40:08 +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 );
}
2009-07-24 19:18:37 +00:00
2008-06-05 15:20:45 +00:00
/**
* testValid method
2008-06-20 19:30:29 +00:00
*
2008-06-05 15:20:45 +00:00
* @ access public
* @ return void
*/
2008-05-30 11:40:08 +00:00
function testValid () {
//wierd it always ends up false in the test suite
//$this->assertFalse($this->Session->valid());
}
}
2008-06-27 08:17:02 +00:00
?>