ElementDefTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. class HTMLPurifier_ElementDefTest extends HTMLPurifier_Harness
  3. {
  4. function test_mergeIn() {
  5. $def1 = new HTMLPurifier_ElementDef();
  6. $def2 = new HTMLPurifier_ElementDef();
  7. $def3 = new HTMLPurifier_ElementDef();
  8. $old = 1;
  9. $new = 2;
  10. $overloaded_old = 3;
  11. $overloaded_new = 4;
  12. $removed = 5;
  13. $def1->standalone = true;
  14. $def1->attr = array(
  15. 0 => array('old-include'),
  16. 'old-attr' => $old,
  17. 'overloaded-attr' => $overloaded_old,
  18. 'removed-attr' => $removed,
  19. );
  20. /*
  21. $def1->attr_transform_pre =
  22. $def1->attr_transform_post = array(
  23. 'old-transform' => $old,
  24. 'overloaded-transform' => $overloaded_old,
  25. 'removed-transform' => $removed,
  26. );
  27. */
  28. $def1->attr_transform_pre[] = $old;
  29. $def1->attr_transform_post[] = $old;
  30. $def1->child = $overloaded_old;
  31. $def1->content_model = 'old';
  32. $def1->content_model_type = $overloaded_old;
  33. $def1->descendants_are_inline = false;
  34. $def1->excludes = array(
  35. 'old' => true,
  36. 'removed-old' => true
  37. );
  38. $def2->standalone = false;
  39. $def2->attr = array(
  40. 0 => array('new-include'),
  41. 'new-attr' => $new,
  42. 'overloaded-attr' => $overloaded_new,
  43. 'removed-attr' => false,
  44. );
  45. /*
  46. $def2->attr_transform_pre =
  47. $def2->attr_transform_post = array(
  48. 'new-transform' => $new,
  49. 'overloaded-transform' => $overloaded_new,
  50. 'removed-transform' => false,
  51. );
  52. */
  53. $def2->attr_transform_pre[] = $new;
  54. $def2->attr_transform_post[] = $new;
  55. $def2->child = $new;
  56. $def2->content_model = '#SUPER | new';
  57. $def2->content_model_type = $overloaded_new;
  58. $def2->descendants_are_inline = true;
  59. $def2->excludes = array(
  60. 'new' => true,
  61. 'removed-old' => false
  62. );
  63. $def1->mergeIn($def2);
  64. $def1->mergeIn($def3); // empty, has no effect
  65. $this->assertIdentical($def1->standalone, true);
  66. $this->assertIdentical($def1->attr, array(
  67. 0 => array('old-include', 'new-include'),
  68. 'old-attr' => $old,
  69. 'overloaded-attr' => $overloaded_new,
  70. 'new-attr' => $new,
  71. ));
  72. $this->assertIdentical($def1->attr_transform_pre, $def1->attr_transform_post);
  73. $this->assertIdentical($def1->attr_transform_pre, array($old, $new));
  74. /*
  75. $this->assertIdentical($def1->attr_transform_pre, array(
  76. 'old-transform' => $old,
  77. 'overloaded-transform' => $overloaded_new,
  78. 'new-transform' => $new,
  79. ));
  80. */
  81. $this->assertIdentical($def1->child, $new);
  82. $this->assertIdentical($def1->content_model, 'old | new');
  83. $this->assertIdentical($def1->content_model_type, $overloaded_new);
  84. $this->assertIdentical($def1->descendants_are_inline, true);
  85. $this->assertIdentical($def1->excludes, array(
  86. 'old' => true,
  87. 'new' => true
  88. ));
  89. }
  90. }
  91. // vim: et sw=4 sts=4