PagesControllerTest.php 2.3 KB

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