SecurityExceptionTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 3.2.6
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. namespace Cake\Test\TestCase\Controller\Exception;
  17. use Cake\Controller\Exception\SecurityException;
  18. use Cake\TestSuite\TestCase;
  19. /**
  20. * SecurityException Test class
  21. */
  22. class SecurityExceptionTest extends TestCase
  23. {
  24. /**
  25. * @var \Cake\Controller\Exception\SecurityException
  26. */
  27. protected $securityException;
  28. /**
  29. * setUp method
  30. *
  31. * @return void
  32. */
  33. public function setUp(): void
  34. {
  35. parent::setUp();
  36. $this->securityException = new SecurityException();
  37. }
  38. /**
  39. * Test the getType() function.
  40. *
  41. * @return void
  42. */
  43. public function testGetType(): void
  44. {
  45. $this->assertEquals(
  46. 'secure',
  47. $this->securityException->getType(),
  48. '::getType should always return the type of `secure`.'
  49. );
  50. }
  51. /**
  52. * Test the setMessage() function.
  53. *
  54. * @return void
  55. */
  56. public function testSetMessage(): void
  57. {
  58. $sampleMessage = 'foo';
  59. $this->securityException->setMessage($sampleMessage);
  60. $this->assertEquals(
  61. $sampleMessage,
  62. $this->securityException->getMessage(),
  63. '::getMessage should always return the message set.'
  64. );
  65. }
  66. /**
  67. * Test the setReason() and corresponding getReason() function.
  68. *
  69. * @return void
  70. */
  71. public function testSetGetReason(): void
  72. {
  73. $sampleReason = 'canary';
  74. $this->securityException->setReason($sampleReason);
  75. $this->assertEquals(
  76. $sampleReason,
  77. $this->securityException->getReason(),
  78. '::getReason should always return the reason set.'
  79. );
  80. }
  81. }