PagesControllerTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * PagesControllerTest file
  4. *
  5. * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
  6. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  7. *
  8. * Licensed under The MIT License
  9. * For full copyright and license information, please see the LICENSE.txt
  10. * Redistributions of files must retain the above copyright notice
  11. *
  12. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  13. * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
  14. * @package Cake.Test.Case.Controller
  15. * @since CakePHP(tm) v 1.2.0.5436
  16. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  17. */
  18. App::uses('PagesController', 'Controller');
  19. /**
  20. * PagesControllerTest class
  21. *
  22. * @package Cake.Test.Case.Controller
  23. */
  24. class PagesControllerTest extends CakeTestCase {
  25. /**
  26. * testDisplay method
  27. *
  28. * @return void
  29. */
  30. public function testDisplay() {
  31. App::build(array(
  32. 'View' => array(
  33. CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS
  34. )
  35. ));
  36. $Pages = new PagesController(new CakeRequest(null, false), new CakeResponse());
  37. $Pages->viewPath = 'Posts';
  38. $Pages->display('index');
  39. $this->assertRegExp('/posts index/', $Pages->response->body());
  40. $this->assertEquals('index', $Pages->viewVars['page']);
  41. $Pages->viewPath = 'Themed';
  42. $Pages->display('TestTheme', 'Posts', 'index');
  43. $this->assertRegExp('/posts index themed view/', $Pages->response->body());
  44. $this->assertEquals('TestTheme', $Pages->viewVars['page']);
  45. $this->assertEquals('Posts', $Pages->viewVars['subpage']);
  46. }
  47. /**
  48. * Test that missing view renders 404 page in production
  49. *
  50. * @expectedException NotFoundException
  51. * @expectedExceptionCode 404
  52. * @return void
  53. */
  54. public function testMissingView() {
  55. Configure::write('debug', 0);
  56. $Pages = new PagesController(new CakeRequest(null, false), new CakeResponse());
  57. $Pages->display('non_existing_page');
  58. }
  59. /**
  60. * Test that missing view in debug mode renders missing_view error page
  61. *
  62. * @expectedException MissingViewException
  63. * @expectedExceptionCode 500
  64. * @return void
  65. */
  66. public function testMissingViewInDebug() {
  67. Configure::write('debug', 1);
  68. $Pages = new PagesController(new CakeRequest(null, false), new CakeResponse());
  69. $Pages->display('non_existing_page');
  70. }
  71. }