security.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Part of the Fuel framework.
  4. *
  5. * @package Fuel
  6. * @version 1.5
  7. * @author Fuel Development Team
  8. * @license MIT License
  9. * @copyright 2010 - 2013 Fuel Development Team
  10. * @link http://fuelphp.com
  11. */
  12. namespace Fuel\Core;
  13. /**
  14. * Security class tests
  15. *
  16. * @group Core
  17. * @group Security
  18. */
  19. class Test_Security extends TestCase
  20. {
  21. /**
  22. * Tests Security::htmlentities()
  23. *
  24. * @test
  25. */
  26. public function test_htmlentities_doublequote_and_ampersand()
  27. {
  28. $output = Security::htmlentities('"H&M"');
  29. $expected = '&quot;H&amp;M&quot;';
  30. $this->assertEquals($expected, $output);
  31. }
  32. /**
  33. * Tests Security::htmlentities()
  34. *
  35. * @test
  36. */
  37. public function test_htmlentities_singlequote()
  38. {
  39. $output = Security::htmlentities("'");
  40. $expected = '&#039;';
  41. $this->assertEquals($expected, $output);
  42. }
  43. /**
  44. * Tests Security::htmlentities()
  45. *
  46. * @test
  47. */
  48. public function test_htmlentities_charactor_references_no_double_encode()
  49. {
  50. $output = Security::htmlentities('You must write & as &amp;');
  51. $expected = 'You must write &amp; as &amp;';
  52. $this->assertEquals($expected, $output);
  53. }
  54. /**
  55. * Tests Security::htmlentities()
  56. *
  57. * @test
  58. */
  59. public function test_htmlentities_charactor_references_double_encode()
  60. {
  61. $config = \Config::get('security.htmlentities_double_encode');
  62. \Config::set('security.htmlentities_double_encode', true);
  63. $output = Security::htmlentities('You must write & as &amp;');
  64. $expected = 'You must write &amp; as &amp;amp;';
  65. $this->assertEquals($expected, $output);
  66. \Config::set('security.htmlentities_double_encode', $config);
  67. }
  68. /**
  69. * Tests Security::htmlentities()
  70. *
  71. * @test
  72. */
  73. public function test_htmlentities_double_encode()
  74. {
  75. $output = Security::htmlentities('"H&M"');
  76. $output = Security::htmlentities($output);
  77. $expected = '&quot;H&amp;M&quot;';
  78. $this->assertEquals($expected, $output);
  79. }
  80. }