SafeObjectTest.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. function setup() {
  10. parent::setup();
  11. // there is no AutoFormat.SafeObject directive
  12. $this->config->set('AutoFormat.Custom', array(new HTMLPurifier_Injector_SafeObject()));
  13. $this->config->set('HTML.Trusted', true);
  14. }
  15. function testPreserve() {
  16. $this->assertResult(
  17. '<b>asdf</b>'
  18. );
  19. }
  20. function testRemoveStrayParam() {
  21. $this->assertResult(
  22. '<param />',
  23. ''
  24. );
  25. }
  26. function testEditObjectParam() {
  27. $this->assertResult(
  28. '<object></object>',
  29. '<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object>'
  30. );
  31. }
  32. function testIgnoreStrayParam() {
  33. $this->assertResult(
  34. '<object><param /></object>',
  35. '<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object>'
  36. );
  37. }
  38. function testIgnoreDuplicates() {
  39. $this->assertResult(
  40. '<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object>'
  41. );
  42. }
  43. function testIgnoreBogusData() {
  44. $this->assertResult(
  45. '<object><param name="allowScriptAccess" value="always" /><param name="allowNetworking" value="always" /></object>',
  46. '<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object>'
  47. );
  48. }
  49. function testIgnoreInvalidData() {
  50. $this->assertResult(
  51. '<object><param name="foo" value="bar" /></object>',
  52. '<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object>'
  53. );
  54. }
  55. function testKeepValidData() {
  56. $this->assertResult(
  57. '<object><param name="movie" value="bar" /></object>',
  58. '<object data="bar"><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><param name="movie" value="bar" /></object>'
  59. );
  60. }
  61. function testNested() {
  62. $this->assertResult(
  63. '<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><object></object></object>',
  64. '<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object></object>'
  65. );
  66. }
  67. function testNotActuallyNested() {
  68. $this->assertResult(
  69. '<object><p><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></p></object>',
  70. '<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><p></p></object>'
  71. );
  72. }
  73. }
  74. // vim: et sw=4 sts=4