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
*
2010-10-03 16:15:01 +00:00
* PHP 5
2008-05-30 11:40:08 +00:00
*
2010-05-19 01:15:13 +00:00
* CakePHP ( tm ) Tests < http :// book . cakephp . org / view / 1196 / Testing >
2010-01-26 19:18:20 +00:00
* Copyright 2005 - 2010 , Cake Software Foundation , Inc . ( http :// cakefoundation . org )
2008-05-30 11:40:08 +00:00
*
2010-10-03 16:15:01 +00:00
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
2008-05-30 11:40:08 +00:00
*
2010-01-26 19:18:20 +00:00
* @ copyright Copyright 2005 - 2010 , Cake Software Foundation , Inc . ( http :// cakefoundation . org )
2010-05-19 01:15:13 +00:00
* @ link http :// book . cakephp . org / view / 1196 / Testing CakePHP ( tm ) Tests
2010-12-24 18:57:20 +00:00
* @ package cake . tests . cases . libs . view . helpers
2008-10-30 17:30:26 +00:00
* @ since CakePHP ( tm ) v 1.2 . 0.4206
2010-10-03 16:15:01 +00:00
* @ license MIT License ( http :// www . opensource . org / licenses / mit - license . php )
2008-05-30 11:40:08 +00:00
*/
2010-12-10 06:23:27 +00:00
App :: uses ( 'Controller' , 'Controller' );
App :: uses ( 'View' , 'View' );
App :: uses ( 'SessionHelper' , 'View/Helper' );
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
*
2010-12-24 18:57:20 +00:00
* @ package 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
*/
2010-06-05 04:12:21 +00:00
function setUp () {
2010-10-03 16:15:01 +00:00
parent :: setUp ();
2010-07-03 16:16:40 +00:00
$controller = null ;
$this -> View = new View ( $controller );
$this -> Session = new SessionHelper ( $this -> View );
2010-12-20 04:28:47 +00:00
CakeSession :: start ();
2008-05-30 11:40:08 +00:00
$_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 ();
2010-07-03 16:16:40 +00:00
unset ( $this -> View , $this -> Session );
2010-10-03 16:15:01 +00:00
parent :: tearDown ();
2009-07-24 19:18:37 +00:00
}
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
/**
* 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 () {
2009-11-16 23:15:24 +00:00
$result = $this -> Session -> flash ( 'flash' , true );
2008-05-30 11:40:08 +00:00
$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>' ;
2009-11-16 23:15:24 +00:00
$result = $this -> Session -> flash ( 'classy' , true );
2008-05-30 11:40:08 +00:00
$this -> assertEqual ( $result , $expected );
2008-06-20 19:30:29 +00:00
2009-06-11 16:13:16 +00:00
App :: build ( array (
2010-12-20 04:28:47 +00:00
'View' => array ( LIBS . 'tests' . DS . 'test_app' . DS . 'views' . DS )
2009-06-11 16:13:16 +00:00
));
2009-11-16 23:15:24 +00:00
$result = $this -> Session -> flash ( 'notification' , true );
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' ));
2009-11-16 23:15:24 +00:00
$result = $this -> Session -> flash ( 'bare' );
2008-05-30 11:40:08 +00:00
$expected = 'Bare message' ;
$this -> assertEqual ( $result , $expected );
$this -> assertFalse ( $this -> Session -> check ( 'Message.bare' ));
}
2009-07-24 19:18:37 +00:00
2008-05-30 11:40:08 +00:00
}