PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/cake/tests/cases/libs/view/helpers/session.test.php

http://github.com/klevo/wildflower
PHP | 286 lines | 167 code | 18 blank | 101 comment | 2 complexity | 0a6d9a4385c49549a6bc14f6393b9950 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /* SVN FILE: $Id$ */
  3. /**
  4. * SessionHelperTest file
  5. *
  6. * Long description for file
  7. *
  8. * PHP versions 4 and 5
  9. *
  10. * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
  11. * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  12. *
  13. * Licensed under The Open Group Test Suite License
  14. * Redistributions of files must retain the above copyright notice.
  15. *
  16. * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  17. * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
  18. * @package cake
  19. * @subpackage cake.tests.cases.libs.view.helpers
  20. * @since CakePHP(tm) v 1.2.0.4206
  21. * @version $Revision$
  22. * @modifiedby $LastChangedBy$
  23. * @lastmodified $Date$
  24. * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  25. */
  26. if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
  27. define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
  28. }
  29. if (!class_exists('AppError')) {
  30. App::import('Error');
  31. /**
  32. * AppController class
  33. *
  34. * @package cake
  35. * @subpackage cake.tests.cases.libs
  36. */
  37. class AppError extends ErrorHandler {
  38. /**
  39. * _stop method
  40. *
  41. * @access public
  42. * @return void
  43. */
  44. function _stop() {
  45. return;
  46. }
  47. }
  48. }
  49. App::import('Core', array('Helper', 'AppHelper', 'Controller', 'View'));
  50. App::import('Helper', array('Session'));
  51. /**
  52. * SessionHelperTest class
  53. *
  54. * @package cake
  55. * @subpackage cake.tests.cases.libs.view.helpers
  56. */
  57. class SessionHelperTest extends CakeTestCase {
  58. /**
  59. * setUp method
  60. *
  61. * @access public
  62. * @return void
  63. */
  64. function startTest() {
  65. $this->Session = new SessionHelper();
  66. $_SESSION = array(
  67. 'test' => 'info',
  68. 'Message' => array(
  69. 'flash' => array(
  70. 'layout' => 'default',
  71. 'params' => array(),
  72. 'message' => 'This is a calling'
  73. ),
  74. 'notification' => array(
  75. 'layout' => 'session_helper',
  76. 'params' => array('title' => 'Notice!', 'name' => 'Alert!'),
  77. 'message' => 'This is a test of the emergency broadcasting system',
  78. ),
  79. 'classy' => array(
  80. 'layout' => 'default',
  81. 'params' => array('class' => 'positive'),
  82. 'message' => 'Recorded'
  83. ),
  84. 'bare' => array(
  85. 'layout' => null,
  86. 'message' => 'Bare message',
  87. 'params' => array(),
  88. ),
  89. ),
  90. 'Deeply' => array('nested' => array('key' => 'value')),
  91. );
  92. }
  93. /**
  94. * tearDown method
  95. *
  96. * @access public
  97. * @return void
  98. */
  99. function tearDown() {
  100. $_SESSION = array();
  101. unset($this->Session);
  102. }
  103. /**
  104. * test construction and initial property settings
  105. *
  106. * @return void
  107. **/
  108. function testConstruct() {
  109. $this->assertFalse(empty($this->Session->sessionTime));
  110. $this->assertFalse(empty($this->Session->security));
  111. }
  112. /**
  113. * testRead method
  114. *
  115. * @access public
  116. * @return void
  117. */
  118. function testRead() {
  119. $result = $this->Session->read('Deeply.nested.key');
  120. $this->assertEqual($result, 'value');
  121. $result = $this->Session->read('test');
  122. $this->assertEqual($result, 'info');
  123. }
  124. /**
  125. * testCheck method
  126. *
  127. * @access public
  128. * @return void
  129. */
  130. function testCheck() {
  131. $this->assertTrue($this->Session->check('test'));
  132. $this->assertTrue($this->Session->check('Message.flash.layout'));
  133. $this->assertFalse($this->Session->check('Does.not.exist'));
  134. $this->assertFalse($this->Session->check('Nope'));
  135. }
  136. /**
  137. * testWrite method
  138. *
  139. * @access public
  140. * @return void
  141. */
  142. function testWrite() {
  143. $this->expectError();
  144. $this->Session->write('NoWay', 'AccessDenied');
  145. }
  146. /**
  147. * testFlash method
  148. *
  149. * @access public
  150. * @return void
  151. */
  152. function testFlash() {
  153. ob_start();
  154. $this->Session->flash();
  155. $result = ob_get_contents();
  156. ob_clean();
  157. $expected = '<div id="flashMessage" class="message">This is a calling</div>';
  158. $this->assertEqual($result, $expected);
  159. $this->assertFalse($this->Session->check('Message.flash'));
  160. $expected = '<div id="classyMessage" class="positive">Recorded</div>';
  161. ob_start();
  162. $this->Session->flash('classy');
  163. $result = ob_get_clean();
  164. $this->assertEqual($result, $expected);
  165. $_viewPaths = Configure::read('viewPaths');
  166. Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS));
  167. $controller = new Controller();
  168. $this->Session->view = new View($controller);
  169. ob_start();
  170. $this->Session->flash('notification');
  171. $result = ob_get_contents();
  172. ob_clean();
  173. $result = str_replace("\r\n", "\n", $result);
  174. $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>";
  175. $this->assertEqual($result, $expected);
  176. $this->assertFalse($this->Session->check('Message.notification'));
  177. ob_start();
  178. $this->Session->flash('bare');
  179. $result = ob_get_contents();
  180. ob_clean();
  181. $expected = 'Bare message';
  182. $this->assertEqual($result, $expected);
  183. $this->assertFalse($this->Session->check('Message.bare'));
  184. Configure::write('viewPaths', $_viewPaths);
  185. }
  186. /**
  187. * testFlash method
  188. *
  189. * @access public
  190. * @return void
  191. */
  192. function testFlashMissingLayout() {
  193. $_SESSION = array(
  194. 'Message' => array(
  195. 'notification' => array(
  196. 'layout' => 'does_not_exist',
  197. 'params' => array('title' => 'Notice!', 'name' => 'Alert!'),
  198. 'message' => 'This is a test of the emergency broadcasting system',
  199. )
  200. )
  201. );
  202. $controller = new Controller();
  203. $this->Session->view = new View($controller);
  204. ob_start();
  205. $this->Session->flash('notification');
  206. $result = ob_get_contents();
  207. ob_clean();
  208. $this->assertPattern("/Missing Layout/", $result);
  209. $this->assertPattern("/layouts(\\\|\/)does_not_exist.ctp/", $result);
  210. }
  211. /**
  212. * testID method
  213. *
  214. * @access public
  215. * @return void
  216. */
  217. function testID() {
  218. $id = session_id();
  219. $result = $this->Session->id();
  220. $this->assertEqual($id, $result);
  221. }
  222. /**
  223. * testError method
  224. *
  225. * @access public
  226. * @return void
  227. */
  228. function testError() {
  229. $result = $this->Session->error();
  230. $this->assertFalse($result);
  231. $this->Session->read('CauseError');
  232. $result = $this->Session->error();
  233. $expected = "CauseError doesn't exist";
  234. $this->assertEqual($result, $expected);
  235. }
  236. /**
  237. * testDisabling method
  238. *
  239. * @access public
  240. * @return void
  241. */
  242. function testDisabling() {
  243. Configure::write('Session.start', false);
  244. $this->Session = new SessionHelper();
  245. $this->assertFalse($this->Session->check('test'));
  246. $this->assertFalse($this->Session->read('test'));
  247. $this->Session->read('CauseError');
  248. $this->assertFalse($this->Session->error());
  249. ob_start();
  250. $this->assertFalse($this->Session->flash('bare'));
  251. $result = ob_get_contents();
  252. ob_clean();
  253. $this->assertFalse($result);
  254. }
  255. /**
  256. * testValid method
  257. *
  258. * @access public
  259. * @return void
  260. */
  261. function testValid() {
  262. //wierd it always ends up false in the test suite
  263. //$this->assertFalse($this->Session->valid());
  264. }
  265. }
  266. ?>