SecurityTestController.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. declare(strict_types=1);
  3. namespace TestApp\Controller;
  4. use Cake\Controller\Controller;
  5. use Cake\Http\Response;
  6. use TestApp\Controller\Component\TestSecurityComponent;
  7. class SecurityTestController extends Controller
  8. {
  9. /**
  10. * failed property
  11. *
  12. * @var bool
  13. */
  14. public $failed = false;
  15. /**
  16. * Used for keeping track of headers in test
  17. *
  18. * @var array
  19. */
  20. public $testHeaders = [];
  21. public function initialize(): void
  22. {
  23. $this->loadComponent('TestSecurity', ['className' => TestSecurityComponent::class]);
  24. }
  25. /**
  26. * fail method
  27. *
  28. * @return void
  29. */
  30. public function fail(): void
  31. {
  32. $this->failed = true;
  33. }
  34. /**
  35. * @inheritDoc
  36. */
  37. public function redirect($url, ?int $status = null): ?Response
  38. {
  39. return $status;
  40. }
  41. /**
  42. * Convenience method for header()
  43. *
  44. * @return void
  45. */
  46. public function header(string $status): void
  47. {
  48. $this->testHeaders[] = $status;
  49. }
  50. }