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. * @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\Error\MissingViewException;
  24. use TestApp\Controller\PagesController;
  25. /**
  26. * PagesControllerTest class
  27. *
  28. */
  29. class PagesControllerTest extends TestCase {
  30. /**
  31. * testDisplay method
  32. *
  33. * @return void
  34. */
  35. public function testDisplay() {
  36. $Pages = new PagesController(new Request(), new Response());
  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 \Cake\Error\NotFoundException
  51. * @expectedExceptionCode 404
  52. * @return void
  53. */
  54. public function testMissingView() {
  55. Configure::write('debug', false);
  56. $Pages = new PagesController(new Request(), new Response());
  57. $Pages->display('non_existing_page');
  58. }
  59. /**
  60. * Test that missing view in debug mode renders missing_view error page
  61. *
  62. * @expectedException \Cake\View\Error\MissingViewException
  63. * @expectedExceptionCode 500
  64. * @return void
  65. */
  66. public function testMissingViewInDebug() {
  67. Configure::write('debug', true);
  68. $Pages = new PagesController(new Request(), new Response());
  69. $Pages->display('non_existing_page');
  70. }
  71. }