Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

100 lines
3.3KB

  1. <?php
  2. /**
  3. * This test is kinda weird, because it doesn't test the full safe object
  4. * functionality, just a small section of it. Or maybe it's actually the right
  5. * way.
  6. */
  7. class HTMLPurifier_Injector_SafeObjectTest extends HTMLPurifier_InjectorHarness
  8. {
  9. public function setup()
  10. {
  11. parent::setup();
  12. // there is no AutoFormat.SafeObject directive
  13. $this->config->set('AutoFormat.Custom', array(new HTMLPurifier_Injector_SafeObject()));
  14. $this->config->set('HTML.Trusted', true);
  15. }
  16. public function testPreserve()
  17. {
  18. $this->assertResult(
  19. '<b>asdf</b>'
  20. );
  21. }
  22. public function testRemoveStrayParam()
  23. {
  24. $this->assertResult(
  25. '<param />',
  26. ''
  27. );
  28. }
  29. public function testEditObjectParam()
  30. {
  31. $this->assertResult(
  32. '<object></object>',
  33. '<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object>'
  34. );
  35. }
  36. public function testIgnoreStrayParam()
  37. {
  38. $this->assertResult(
  39. '<object><param /></object>',
  40. '<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object>'
  41. );
  42. }
  43. public function testIgnoreDuplicates()
  44. {
  45. $this->assertResult(
  46. '<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object>'
  47. );
  48. }
  49. public function testIgnoreBogusData()
  50. {
  51. $this->assertResult(
  52. '<object><param name="allowScriptAccess" value="always" /><param name="allowNetworking" value="always" /></object>',
  53. '<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object>'
  54. );
  55. }
  56. public function testIgnoreInvalidData()
  57. {
  58. $this->assertResult(
  59. '<object><param name="foo" value="bar" /></object>',
  60. '<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object>'
  61. );
  62. }
  63. public function testKeepValidData()
  64. {
  65. $this->assertResult(
  66. '<object><param name="movie" value="bar" /></object>',
  67. '<object data="bar"><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><param name="movie" value="bar" /></object>'
  68. );
  69. }
  70. public function testNested()
  71. {
  72. $this->assertResult(
  73. '<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><object></object></object>',
  74. '<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object></object>'
  75. );
  76. }
  77. public function testNotActuallyNested()
  78. {
  79. $this->assertResult(
  80. '<object><p><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></p></object>',
  81. '<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><p></p></object>'
  82. );
  83. }
  84. }
  85. // vim: et sw=4 sts=4