PagesControllerTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. * @since 1.2.0
  15. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  16. */
  17. namespace Cake\Test\TestCase\Controller;
  18. use Cake\Core\App;
  19. use Cake\Core\Configure;
  20. use Cake\Network\Request;
  21. use Cake\Network\Response;
  22. use Cake\TestSuite\TestCase;
  23. use Cake\View\Exception\MissingTemplateException;
  24. use TestApp\Controller\PagesController;
  25. /**
  26. * PagesControllerTest class
  27. *
  28. */
  29. class PagesControllerTest extends TestCase
  30. {
  31. /**
  32. * testDisplay method
  33. *
  34. * @return void
  35. */
  36. public function testDisplay()
  37. {
  38. $Pages = new PagesController(new Request(), new Response());
  39. $Pages->viewPath = 'Posts';
  40. $Pages->display('index');
  41. $this->assertRegExp('/posts index/', $Pages->response->body());
  42. $this->assertEquals('index', $Pages->viewVars['page']);
  43. }
  44. /**
  45. * Test that missing view renders 404 page in production
  46. *
  47. * @expectedException \Cake\Network\Exception\NotFoundException
  48. * @expectedExceptionCode 404
  49. * @return void
  50. */
  51. public function testMissingView()
  52. {
  53. Configure::write('debug', false);
  54. $Pages = new PagesController(new Request(), new Response());
  55. $Pages->display('non_existing_page');
  56. }
  57. /**
  58. * Test that missing view in debug mode renders missing_view error page
  59. *
  60. * @expectedException \Cake\View\Exception\MissingTemplateException
  61. * @expectedExceptionCode 500
  62. * @return void
  63. */
  64. public function testMissingViewInDebug()
  65. {
  66. Configure::write('debug', true);
  67. $Pages = new PagesController(new Request(), new Response());
  68. $Pages->display('non_existing_page');
  69. }
  70. }