PageRenderTime 57ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/cakeusermanagement/cake/tests/cases/libs/error.test.php

https://github.com/miamiruby/cakestuff
PHP | 373 lines | 164 code | 2 blank | 207 comment | 4 complexity | 661844721bd8e29b618279091adf1e6b MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.0, MIT
  1. <?php
  2. /* SVN FILE: $Id: error.test.php 7690 2008-10-02 04:56:53Z nate $ */
  3. /**
  4. * Short description for 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-2008, Cake Software Foundation, Inc.
  12. * 1785 E. Sahara Avenue, Suite 490-204
  13. * Las Vegas, Nevada 89104
  14. *
  15. * Licensed under The Open Group Test Suite License
  16. * Redistributions of files must retain the above copyright notice.
  17. *
  18. * @filesource
  19. * @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
  20. * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
  21. * @package cake.tests
  22. * @subpackage cake.tests.cases.libs
  23. * @since CakePHP(tm) v 1.2.0.5432
  24. * @version $Revision: 7690 $
  25. * @modifiedby $LastChangedBy: nate $
  26. * @lastmodified $Date: 2008-10-02 00:56:53 -0400 (Thu, 02 Oct 2008) $
  27. * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  28. */
  29. if (class_exists('TestErrorHandler')) {
  30. return;
  31. }
  32. if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
  33. define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
  34. }
  35. /**
  36. * BlueberryComponent class
  37. *
  38. * @package cake
  39. * @subpackage cake.tests.cases.libs
  40. */
  41. class BlueberryComponent extends Object {
  42. /**
  43. * testName property
  44. *
  45. * @access public
  46. * @return void
  47. */
  48. var $testName = null;
  49. /**
  50. * initialize method
  51. *
  52. * @access public
  53. * @return void
  54. */
  55. function initialize(&$controller) {
  56. $this->testName = 'BlueberryComponent';
  57. }
  58. }
  59. /**
  60. * AppController class
  61. *
  62. * @package cake
  63. * @subpackage cake.tests.cases.libs
  64. */
  65. if (!class_exists('AppController')) {
  66. /**
  67. * AppController class
  68. *
  69. * @package cake
  70. * @subpackage cake.tests.cases.libs
  71. */
  72. class AppController extends Controller {
  73. /**
  74. * components property
  75. *
  76. * @access public
  77. * @return void
  78. */
  79. var $components = array('Blueberry');
  80. /**
  81. * beforeRender method
  82. *
  83. * @access public
  84. * @return void
  85. */
  86. function beforeRender() {
  87. echo $this->Blueberry->testName;
  88. }
  89. /**
  90. * header method
  91. *
  92. * @access public
  93. * @return void
  94. */
  95. function header($header) {
  96. echo $header;
  97. }
  98. }
  99. }
  100. App::import('Core', array('Error', 'Controller'));
  101. /**
  102. * TestErrorController class
  103. *
  104. * @package cake
  105. * @subpackage cake.tests.cases.libs
  106. */
  107. class TestErrorController extends AppController {
  108. /**
  109. * uses property
  110. *
  111. * @var array
  112. * @access public
  113. */
  114. var $uses = array();
  115. /**
  116. * index method
  117. *
  118. * @access public
  119. * @return void
  120. */
  121. function index() {
  122. $this->autoRender = false;
  123. return 'what up';
  124. }
  125. }
  126. /**
  127. * TestErrorHandler class
  128. *
  129. * @package cake
  130. * @subpackage cake.tests.cases.libs
  131. */
  132. class TestErrorHandler extends ErrorHandler {
  133. /**
  134. * stop method
  135. *
  136. * @access public
  137. * @return void
  138. */
  139. function _stop() {
  140. return;
  141. }
  142. }
  143. /**
  144. * Short description for class.
  145. *
  146. * @package cake.tests
  147. * @subpackage cake.tests.cases.libs
  148. */
  149. class TestErrorHandlerTest extends CakeTestCase {
  150. /**
  151. * skip method
  152. *
  153. * @access public
  154. * @return void
  155. */
  156. function skip() {
  157. $this->skipif ((PHP_SAPI == 'cli'), 'TestErrorHandlerTest cannot be run from console');
  158. }
  159. /**
  160. * testError method
  161. *
  162. * @access public
  163. * @return void
  164. */
  165. function testError() {
  166. ob_start();
  167. $TestErrorHandler = new TestErrorHandler('error404', array('message' => 'Page not found'));
  168. ob_clean();
  169. ob_start();
  170. $TestErrorHandler->error(array(
  171. 'code' => 404,
  172. 'message' => 'Page not Found',
  173. 'name' => "Couldn't find what you were looking for"));
  174. $result = ob_get_clean();
  175. $this->assertPattern("/<h2>Couldn't find what you were looking for<\/h2>/", $result);
  176. $this->assertPattern('/Page not Found/', $result);
  177. }
  178. /**
  179. * testError404 method
  180. *
  181. * @access public
  182. * @return void
  183. */
  184. function testError404() {
  185. ob_start();
  186. $TestErrorHandler = new TestErrorHandler('error404', array('message' => 'Page not found', 'url' => '/test_error'));
  187. $result = ob_get_clean();
  188. $this->assertPattern('/<h2>Not Found<\/h2>/', $result);
  189. $this->assertPattern("/<strong>'\/test_error'<\/strong>/", $result);
  190. }
  191. /**
  192. * testMissingController method
  193. *
  194. * @access public
  195. * @return void
  196. */
  197. function testMissingController() {
  198. ob_start();
  199. $TestErrorHandler = new TestErrorHandler('missingController', array('className' => 'PostsController'));
  200. $result = ob_get_clean();
  201. $this->assertPattern('/<h2>Missing Controller<\/h2>/', $result);
  202. $this->assertPattern('/<em>PostsController<\/em>/', $result);
  203. $this->assertPattern('/BlueberryComponent/', $result);
  204. }
  205. /**
  206. * testMissingAction method
  207. *
  208. * @access public
  209. * @return void
  210. */
  211. function testMissingAction() {
  212. ob_start();
  213. $TestErrorHandler = new TestErrorHandler('missingAction', array('className' => 'PostsController', 'action' => 'index'));
  214. $result = ob_get_clean();
  215. $this->assertPattern('/<h2>Missing Method in PostsController<\/h2>/', $result);
  216. $this->assertPattern('/<em>PostsController::<\/em><em>index\(\)<\/em>/', $result);
  217. }
  218. /**
  219. * testPrivateAction method
  220. *
  221. * @access public
  222. * @return void
  223. */
  224. function testPrivateAction() {
  225. ob_start();
  226. $TestErrorHandler = new TestErrorHandler('privateAction', array('className' => 'PostsController', 'action' => '_secretSauce'));
  227. $result = ob_get_clean();
  228. $this->assertPattern('/<h2>Private Method in PostsController<\/h2>/', $result);
  229. $this->assertPattern('/<em>PostsController::<\/em><em>_secretSauce\(\)<\/em>/', $result);
  230. }
  231. /**
  232. * testMissingTable method
  233. *
  234. * @access public
  235. * @return void
  236. */
  237. function testMissingTable() {
  238. ob_start();
  239. $TestErrorHandler = new TestErrorHandler('missingTable', array('className' => 'Article', 'table' => 'articles'));
  240. $result = ob_get_clean();
  241. $this->assertPattern('/<h2>Missing Database Table<\/h2>/', $result);
  242. $this->assertPattern('/table <em>articles<\/em> for model <em>Article<\/em>/', $result);
  243. }
  244. /**
  245. * testMissingDatabase method
  246. *
  247. * @access public
  248. * @return void
  249. */
  250. function testMissingDatabase() {
  251. ob_start();
  252. $TestErrorHandler = new TestErrorHandler('missingDatabase', array());
  253. $result = ob_get_clean();
  254. $this->assertPattern('/<h2>Missing Database Connection<\/h2>/', $result);
  255. $this->assertPattern('/Confirm you have created the file/', $result);
  256. }
  257. /**
  258. * testMissingView method
  259. *
  260. * @access public
  261. * @return void
  262. */
  263. function testMissingView() {
  264. restore_error_handler();
  265. ob_start();
  266. $TestErrorHandler = new TestErrorHandler('missingView', array('className' => 'Pages', 'action' => 'display', 'file' => 'pages/about.ctp', 'base' => ''));
  267. $expected = ob_get_clean();
  268. set_error_handler('simpleTestErrorHandler');
  269. $this->assertPattern("/PagesController::/", $expected);
  270. $this->assertPattern("/pages\/about.ctp/", $expected);
  271. }
  272. /**
  273. * testMissingLayout method
  274. *
  275. * @access public
  276. * @return void
  277. */
  278. function testMissingLayout() {
  279. restore_error_handler();
  280. ob_start();
  281. $TestErrorHandler = new TestErrorHandler('missingLayout', array( 'layout' => 'my_layout', 'file' => 'layouts/my_layout.ctp', 'base' => ''));
  282. $expected = ob_get_clean();
  283. set_error_handler('simpleTestErrorHandler');
  284. $this->assertPattern("/Missing Layout/", $expected);
  285. $this->assertPattern("/layouts\/my_layout.ctp/", $expected);
  286. }
  287. /**
  288. * testMissingConnection method
  289. *
  290. * @access public
  291. * @return void
  292. */
  293. function testMissingConnection() {
  294. ob_start();
  295. $TestErrorHandler = new TestErrorHandler('missingConnection', array('className' => 'Article'));
  296. $result = ob_get_clean();
  297. $this->assertPattern('/<h2>Missing Database Connection<\/h2>/', $result);
  298. $this->assertPattern('/Article requires a database connection/', $result);
  299. }
  300. /**
  301. * testMissingHelperFile method
  302. *
  303. * @access public
  304. * @return void
  305. */
  306. function testMissingHelperFile() {
  307. ob_start();
  308. $TestErrorHandler = new TestErrorHandler('missingHelperFile', array('helper' => 'MyCustom', 'file' => 'my_custom.php'));
  309. $result = ob_get_clean();
  310. $this->assertPattern('/<h2>Missing Helper File<\/h2>/', $result);
  311. $this->assertPattern('/Create the class below in file:/', $result);
  312. $this->assertPattern('/\/my_custom.php/', $result);
  313. }
  314. /**
  315. * testMissingHelperClass method
  316. *
  317. * @access public
  318. * @return void
  319. */
  320. function testMissingHelperClass() {
  321. ob_start();
  322. $TestErrorHandler = new TestErrorHandler('missingHelperClass', array('helper' => 'MyCustom', 'file' => 'my_custom.php'));
  323. $result = ob_get_clean();
  324. $this->assertPattern('/<h2>Missing Helper Class<\/h2>/', $result);
  325. $this->assertPattern('/The helper class <em>MyCustomHelper<\/em> can not be found or does not exist./', $result);
  326. $this->assertPattern('/\/my_custom.php/', $result);
  327. }
  328. /**
  329. * testMissingComponentFile method
  330. *
  331. * @access public
  332. * @return void
  333. */
  334. function testMissingComponentFile() {
  335. ob_start();
  336. $TestErrorHandler = new TestErrorHandler('missingComponentFile', array('className' => 'PostsController', 'component' => 'Sidebox', 'file' => 'sidebox.php'));
  337. $result = ob_get_clean();
  338. $this->assertPattern('/<h2>Missing Component File<\/h2>/', $result);
  339. $this->assertPattern('/Create the class <em>SideboxComponent<\/em> in file:/', $result);
  340. $this->assertPattern('/\/sidebox.php/', $result);
  341. }
  342. /**
  343. * testMissingComponentClass method
  344. *
  345. * @access public
  346. * @return void
  347. */
  348. function testMissingComponentClass() {
  349. ob_start();
  350. $TestErrorHandler = new TestErrorHandler('missingComponentClass', array('className' => 'PostsController', 'component' => 'Sidebox', 'file' => 'sidebox.php'));
  351. $result = ob_get_clean();
  352. $this->assertPattern('/<h2>Missing Component Class<\/h2>/', $result);
  353. $this->assertPattern('/Create the class <em>SideboxComponent<\/em> in file:/', $result);
  354. $this->assertPattern('/\/sidebox.php/', $result);
  355. }
  356. /**
  357. * testMissingModel method
  358. *
  359. * @access public
  360. * @return void
  361. */
  362. function testMissingModel() {
  363. ob_start();
  364. $TestErrorHandler = new TestErrorHandler('missingModel', array('className' => 'Article', 'file' => 'article.php'));
  365. $result = ob_get_clean();
  366. $this->assertPattern('/<h2>Missing Model<\/h2>/', $result);
  367. $this->assertPattern('/<em>Article<\/em> could not be found./', $result);
  368. $this->assertPattern('/\/article.php/', $result);
  369. }
  370. }
  371. ?>