Mercurial > hg > Members > shoshi > webvirt
comparison cake/tests/cases/libs/view/helpers/session.test.php @ 0:261e66bd5a0c
hg init
author | Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 24 Jul 2011 21:08:31 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:261e66bd5a0c |
---|---|
1 <?php | |
2 /** | |
3 * SessionHelperTest file | |
4 * | |
5 * PHP versions 4 and 5 | |
6 * | |
7 * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing> | |
8 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) | |
9 * | |
10 * Licensed under The Open Group Test Suite License | |
11 * Redistributions of files must retain the above copyright notice. | |
12 * | |
13 * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) | |
14 * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests | |
15 * @package cake | |
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 | |
19 */ | |
20 if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) { | |
21 define('CAKEPHP_UNIT_TEST_EXECUTION', 1); | |
22 } | |
23 App::import('Core', array('Helper', 'AppHelper', 'Controller', 'View')); | |
24 App::import('Helper', array('Session')); | |
25 | |
26 /** | |
27 * SessionHelperTest class | |
28 * | |
29 * @package cake | |
30 * @subpackage cake.tests.cases.libs.view.helpers | |
31 */ | |
32 class SessionHelperTest extends CakeTestCase { | |
33 | |
34 /** | |
35 * setUp method | |
36 * | |
37 * @access public | |
38 * @return void | |
39 */ | |
40 function startTest() { | |
41 $this->Session = new SessionHelper(); | |
42 | |
43 $_SESSION = array( | |
44 'test' => 'info', | |
45 'Message' => array( | |
46 'flash' => array( | |
47 'element' => 'default', | |
48 'params' => array(), | |
49 'message' => 'This is a calling' | |
50 ), | |
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', | |
55 ), | |
56 'classy' => array( | |
57 'element' => 'default', | |
58 'params' => array('class' => 'positive'), | |
59 'message' => 'Recorded' | |
60 ), | |
61 'bare' => array( | |
62 'element' => null, | |
63 'message' => 'Bare message', | |
64 'params' => array(), | |
65 ), | |
66 ), | |
67 'Deeply' => array('nested' => array('key' => 'value')), | |
68 ); | |
69 } | |
70 | |
71 /** | |
72 * tearDown method | |
73 * | |
74 * @access public | |
75 * @return void | |
76 */ | |
77 function tearDown() { | |
78 $_SESSION = array(); | |
79 unset($this->Session); | |
80 } | |
81 | |
82 /** | |
83 * endTest | |
84 * | |
85 * @access public | |
86 * @return void | |
87 */ | |
88 function endTest() { | |
89 App::build(); | |
90 } | |
91 | |
92 /** | |
93 * test construction and initial property settings | |
94 * | |
95 * @return void | |
96 */ | |
97 function testConstruct() { | |
98 $this->assertFalse(empty($this->Session->sessionTime)); | |
99 $this->assertFalse(empty($this->Session->security)); | |
100 } | |
101 /** | |
102 * testRead method | |
103 * | |
104 * @access public | |
105 * @return void | |
106 */ | |
107 function testRead() { | |
108 $result = $this->Session->read('Deeply.nested.key'); | |
109 $this->assertEqual($result, 'value'); | |
110 | |
111 $result = $this->Session->read('test'); | |
112 $this->assertEqual($result, 'info'); | |
113 } | |
114 | |
115 /** | |
116 * testCheck method | |
117 * | |
118 * @access public | |
119 * @return void | |
120 */ | |
121 function testCheck() { | |
122 $this->assertTrue($this->Session->check('test')); | |
123 | |
124 $this->assertTrue($this->Session->check('Message.flash.element')); | |
125 | |
126 $this->assertFalse($this->Session->check('Does.not.exist')); | |
127 | |
128 $this->assertFalse($this->Session->check('Nope')); | |
129 } | |
130 | |
131 /** | |
132 * testWrite method | |
133 * | |
134 * @access public | |
135 * @return void | |
136 */ | |
137 function testWrite() { | |
138 $this->expectError(); | |
139 $this->Session->write('NoWay', 'AccessDenied'); | |
140 } | |
141 | |
142 /** | |
143 * testFlash method | |
144 * | |
145 * @access public | |
146 * @return void | |
147 */ | |
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')); | |
153 | |
154 $expected = '<div id="classyMessage" class="positive">Recorded</div>'; | |
155 $result = $this->Session->flash('classy', true); | |
156 $this->assertEqual($result, $expected); | |
157 | |
158 App::build(array( | |
159 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) | |
160 )); | |
161 $controller = new Controller(); | |
162 $this->Session->view = new View($controller); | |
163 | |
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')); | |
169 | |
170 $result = $this->Session->flash('bare'); | |
171 $expected = 'Bare message'; | |
172 $this->assertEqual($result, $expected); | |
173 $this->assertFalse($this->Session->check('Message.bare')); | |
174 } | |
175 | |
176 /** | |
177 * testID method | |
178 * | |
179 * @access public | |
180 * @return void | |
181 */ | |
182 function testID() { | |
183 $id = session_id(); | |
184 $result = $this->Session->id(); | |
185 $this->assertEqual($id, $result); | |
186 } | |
187 | |
188 /** | |
189 * testError method | |
190 * | |
191 * @access public | |
192 * @return void | |
193 */ | |
194 function testError() { | |
195 $result = $this->Session->error(); | |
196 $this->assertFalse($result); | |
197 | |
198 $this->Session->read('CauseError'); | |
199 $result = $this->Session->error(); | |
200 $expected = "CauseError doesn't exist"; | |
201 $this->assertEqual($result, $expected); | |
202 } | |
203 | |
204 /** | |
205 * testDisabling method | |
206 * | |
207 * @access public | |
208 * @return void | |
209 */ | |
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')); | |
215 | |
216 $this->Session->read('CauseError'); | |
217 $this->assertFalse($this->Session->error()); | |
218 | |
219 ob_start(); | |
220 $this->assertFalse($this->Session->flash('bare')); | |
221 $result = ob_get_contents(); | |
222 ob_clean(); | |
223 $this->assertFalse($result); | |
224 } | |
225 | |
226 /** | |
227 * testValid method | |
228 * | |
229 * @access public | |
230 * @return void | |
231 */ | |
232 function testValid() { | |
233 //wierd it always ends up false in the test suite | |
234 //$this->assertFalse($this->Session->valid()); | |
235 } | |
236 } |