PagesControllerTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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\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. }
  42. /**
  43. * Test that missing view renders 404 page in production
  44. *
  45. * @expectedException \Cake\Network\Exception\NotFoundException
  46. * @expectedExceptionCode 404
  47. * @return void
  48. */
  49. public function testMissingView() {
  50. Configure::write('debug', false);
  51. $Pages = new PagesController(new Request(), new Response());
  52. $Pages->display('non_existing_page');
  53. }
  54. /**
  55. * Test that missing view in debug mode renders missing_view error page
  56. *
  57. * @expectedException \Cake\View\Exception\MissingViewException
  58. * @expectedExceptionCode 500
  59. * @return void
  60. */
  61. public function testMissingViewInDebug() {
  62. Configure::write('debug', true);
  63. $Pages = new PagesController(new Request(), new Response());
  64. $Pages->display('non_existing_page');
  65. }
  66. }