PagesControllerTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 TestApp\Controller\PagesController;
  24. /**
  25. * PagesControllerTest class
  26. *
  27. */
  28. class PagesControllerTest extends TestCase {
  29. /**
  30. * testDisplay method
  31. *
  32. * @return void
  33. */
  34. public function testDisplay() {
  35. $Pages = new PagesController(new Request(), new Response());
  36. $Pages->viewPath = 'Posts';
  37. $Pages->display('index');
  38. $this->assertRegExp('/posts index/', $Pages->response->body());
  39. $this->assertEquals('index', $Pages->viewVars['page']);
  40. $Pages->viewPath = 'Themed';
  41. $Pages->display('TestTheme', 'Posts', 'index');
  42. $this->assertRegExp('/posts index themed view/', $Pages->response->body());
  43. $this->assertEquals('TestTheme', $Pages->viewVars['page']);
  44. $this->assertEquals('Posts', $Pages->viewVars['subpage']);
  45. }
  46. /**
  47. * Test that missing view renders 404 page in production
  48. *
  49. * @expectedException \Cake\Error\NotFoundException
  50. * @expectedExceptionCode 404
  51. * @return void
  52. */
  53. public function testMissingView() {
  54. Configure::write('debug', false);
  55. $Pages = new PagesController(new Request(), new Response());
  56. $Pages->display('non_existing_page');
  57. }
  58. /**
  59. * Test that missing view in debug mode renders missing_view error page
  60. *
  61. * @expectedException \Cake\Error\MissingViewException
  62. * @expectedExceptionCode 500
  63. * @return void
  64. */
  65. public function testMissingViewInDebug() {
  66. Configure::write('debug', true);
  67. $Pages = new PagesController(new Request(), new Response());
  68. $Pages->display('non_existing_page');
  69. }
  70. }