Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

114 строки
3.0KB

  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @link https://cakephp.org CakePHP(tm) Project
  13. * @since 1.2.0
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. namespace App\Test\TestCase\Controller;
  17. use Cake\Core\Configure;
  18. use Cake\TestSuite\Constraint\Response\StatusCode;
  19. use Cake\TestSuite\IntegrationTestTrait;
  20. use Cake\TestSuite\TestCase;
  21. /**
  22. * PagesControllerTest class
  23. */
  24. class PagesControllerTest extends TestCase
  25. {
  26. use IntegrationTestTrait;
  27. /**
  28. * testDisplay method
  29. *
  30. * @return void
  31. */
  32. public function testDisplay()
  33. {
  34. Configure::write('debug', true);
  35. $this->get('/pages/home');
  36. $this->assertResponseOk();
  37. $this->assertResponseContains('CakePHP');
  38. $this->assertResponseContains('<html>');
  39. }
  40. /**
  41. * Test that missing template renders 404 page in production
  42. *
  43. * @return void
  44. */
  45. public function testMissingTemplate()
  46. {
  47. Configure::write('debug', false);
  48. $this->get('/pages/not_existing');
  49. $this->assertResponseError();
  50. $this->assertResponseContains('Error');
  51. }
  52. /**
  53. * Test that missing template in debug mode renders missing_template error page
  54. *
  55. * @return void
  56. */
  57. public function testMissingTemplateInDebug()
  58. {
  59. Configure::write('debug', true);
  60. $this->get('/pages/not_existing');
  61. $this->assertResponseFailure();
  62. $this->assertResponseContains('Missing Template');
  63. $this->assertResponseContains('stack-frames');
  64. $this->assertResponseContains('not_existing.php');
  65. }
  66. /**
  67. * Test directory traversal protection
  68. *
  69. * @return void
  70. */
  71. public function testDirectoryTraversalProtection()
  72. {
  73. $this->get('/pages/../Layout/ajax');
  74. $this->assertResponseCode(403);
  75. $this->assertResponseContains('Forbidden');
  76. }
  77. /**
  78. * Test that CSRF protection is applied to page rendering.
  79. *
  80. * @return void
  81. */
  82. public function testCsrfAppliedError()
  83. {
  84. $this->post('/pages/home', ['hello' => 'world']);
  85. $this->assertResponseCode(403);
  86. $this->assertResponseContains('CSRF');
  87. }
  88. /**
  89. * Test that CSRF protection is applied to page rendering.
  90. *
  91. * @return void
  92. */
  93. public function testCsrfAppliedOk()
  94. {
  95. $this->enableCsrfToken();
  96. $this->post('/pages/home', ['hello' => 'world']);
  97. $this->assertThat(403, $this->logicalNot(new StatusCode($this->_response)));
  98. $this->assertResponseNotContains('CSRF');
  99. }
  100. }

Powered by TurnKey Linux.