3
* SessionHelperTest file
7
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
8
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
10
* Licensed under The Open Group Test Suite License
11
* Redistributions of files must retain the above copyright notice.
13
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
14
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
16
* @subpackage cake.tests.cases.libs.view.helpers
17
* @since CakePHP(tm) v 1.2.0.4206
18
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
20
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
21
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
23
App::import('Core', array('Helper', 'AppHelper', 'Controller', 'View'));
24
App::import('Helper', array('Session'));
27
* SessionHelperTest class
30
* @subpackage cake.tests.cases.libs.view.helpers
32
class SessionHelperTest extends CakeTestCase {
40
function startTest() {
41
$this->Session = new SessionHelper();
47
'element' => 'default',
49
'message' => 'This is a calling'
51
'notification' => array(
52
'element' => 'session_helper',
53
'params' => array('title' => 'Notice!', 'name' => 'Alert!'),
54
'message' => 'This is a test of the emergency broadcasting system',
57
'element' => 'default',
58
'params' => array('class' => 'positive'),
59
'message' => 'Recorded'
63
'message' => 'Bare message',
67
'Deeply' => array('nested' => array('key' => 'value')),
79
unset($this->Session);
93
* test construction and initial property settings
97
function testConstruct() {
98
$this->assertFalse(empty($this->Session->sessionTime));
99
$this->assertFalse(empty($this->Session->security));
107
function testRead() {
108
$result = $this->Session->read('Deeply.nested.key');
109
$this->assertEqual($result, 'value');
111
$result = $this->Session->read('test');
112
$this->assertEqual($result, 'info');
121
function testCheck() {
122
$this->assertTrue($this->Session->check('test'));
124
$this->assertTrue($this->Session->check('Message.flash.element'));
126
$this->assertFalse($this->Session->check('Does.not.exist'));
128
$this->assertFalse($this->Session->check('Nope'));
137
function testWrite() {
138
$this->expectError();
139
$this->Session->write('NoWay', 'AccessDenied');
148
function testFlash() {
149
$result = $this->Session->flash('flash', true);
150
$expected = '<div id="flashMessage" class="message">This is a calling</div>';
151
$this->assertEqual($result, $expected);
152
$this->assertFalse($this->Session->check('Message.flash'));
154
$expected = '<div id="classyMessage" class="positive">Recorded</div>';
155
$result = $this->Session->flash('classy', true);
156
$this->assertEqual($result, $expected);
159
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
161
$controller = new Controller();
162
$this->Session->view = new View($controller);
164
$result = $this->Session->flash('notification', true);
165
$result = str_replace("\r\n", "\n", $result);
166
$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>";
167
$this->assertEqual($result, $expected);
168
$this->assertFalse($this->Session->check('Message.notification'));
170
$result = $this->Session->flash('bare');
171
$expected = 'Bare message';
172
$this->assertEqual($result, $expected);
173
$this->assertFalse($this->Session->check('Message.bare'));
184
$result = $this->Session->id();
185
$this->assertEqual($id, $result);
194
function testError() {
195
$result = $this->Session->error();
196
$this->assertFalse($result);
198
$this->Session->read('CauseError');
199
$result = $this->Session->error();
200
$expected = "CauseError doesn't exist";
201
$this->assertEqual($result, $expected);
205
* testDisabling method
210
function testDisabling() {
211
Configure::write('Session.start', false);
212
$this->Session = new SessionHelper();
213
$this->assertFalse($this->Session->check('test'));
214
$this->assertFalse($this->Session->read('test'));
216
$this->Session->read('CauseError');
217
$this->assertFalse($this->Session->error());
220
$this->assertFalse($this->Session->flash('bare'));
221
$result = ob_get_contents();
223
$this->assertFalse($result);
232
function testValid() {
233
//wierd it always ends up false in the test suite
234
//$this->assertFalse($this->Session->valid());