HTMLModuleTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. class HTMLPurifier_HTMLModuleTest extends HTMLPurifier_Harness
  3. {
  4. function test_addElementToContentSet() {
  5. $module = new HTMLPurifier_HTMLModule();
  6. $module->addElementToContentSet('b', 'Inline');
  7. $this->assertIdentical($module->content_sets, array('Inline' => 'b'));
  8. $module->addElementToContentSet('i', 'Inline');
  9. $this->assertIdentical($module->content_sets, array('Inline' => 'b | i'));
  10. }
  11. function test_addElement() {
  12. $module = new HTMLPurifier_HTMLModule();
  13. $def = $module->addElement(
  14. 'a', 'Inline', 'Optional: #PCDATA', array('Common'),
  15. array(
  16. 'href' => 'URI'
  17. )
  18. );
  19. $module2 = new HTMLPurifier_HTMLModule();
  20. $def2 = new HTMLPurifier_ElementDef();
  21. $def2->content_model = '#PCDATA';
  22. $def2->content_model_type = 'optional';
  23. $def2->attr = array(
  24. 'href' => 'URI',
  25. 0 => array('Common')
  26. );
  27. $module2->info['a'] = $def2;
  28. $module2->elements = array('a');
  29. $module2->content_sets['Inline'] = 'a';
  30. $this->assertIdentical($module, $module2);
  31. $this->assertIdentical($def, $def2);
  32. $this->assertReference($def, $module->info['a']);
  33. }
  34. function test_parseContents() {
  35. $module = new HTMLPurifier_HTMLModule();
  36. // pre-defined templates
  37. $this->assertIdentical(
  38. $module->parseContents('Inline'),
  39. array('optional', 'Inline | #PCDATA')
  40. );
  41. $this->assertIdentical(
  42. $module->parseContents('Flow'),
  43. array('optional', 'Flow | #PCDATA')
  44. );
  45. $this->assertIdentical(
  46. $module->parseContents('Empty'),
  47. array('empty', '')
  48. );
  49. // normalization procedures
  50. $this->assertIdentical(
  51. $module->parseContents('optional: a'),
  52. array('optional', 'a')
  53. );
  54. $this->assertIdentical(
  55. $module->parseContents('OPTIONAL :a'),
  56. array('optional', 'a')
  57. );
  58. $this->assertIdentical(
  59. $module->parseContents('Optional: a'),
  60. array('optional', 'a')
  61. );
  62. // others
  63. $this->assertIdentical(
  64. $module->parseContents('Optional: a | b | c'),
  65. array('optional', 'a | b | c')
  66. );
  67. // object pass-through
  68. generate_mock_once('HTMLPurifier_AttrDef');
  69. $this->assertIdentical(
  70. $module->parseContents(new HTMLPurifier_AttrDefMock()),
  71. array(null, null)
  72. );
  73. }
  74. function test_mergeInAttrIncludes() {
  75. $module = new HTMLPurifier_HTMLModule();
  76. $attr = array();
  77. $module->mergeInAttrIncludes($attr, 'Common');
  78. $this->assertIdentical($attr, array(0 => array('Common')));
  79. $attr = array('a' => 'b');
  80. $module->mergeInAttrIncludes($attr, array('Common', 'Good'));
  81. $this->assertIdentical($attr, array('a' => 'b', 0 => array('Common', 'Good')));
  82. }
  83. function test_addBlankElement() {
  84. $module = new HTMLPurifier_HTMLModule();
  85. $def = $module->addBlankElement('a');
  86. $def2 = new HTMLPurifier_ElementDef();
  87. $def2->standalone = false;
  88. $this->assertReference($module->info['a'], $def);
  89. $this->assertIdentical($def, $def2);
  90. }
  91. function test_makeLookup() {
  92. $module = new HTMLPurifier_HTMLModule();
  93. $this->assertIdentical(
  94. $module->makeLookup('foo'),
  95. array('foo' => true)
  96. );
  97. $this->assertIdentical(
  98. $module->makeLookup(array('foo')),
  99. array('foo' => true)
  100. );
  101. $this->assertIdentical(
  102. $module->makeLookup('foo', 'two'),
  103. array('foo' => true, 'two' => true)
  104. );
  105. $this->assertIdentical(
  106. $module->makeLookup(array('foo', 'two')),
  107. array('foo' => true, 'two' => true)
  108. );
  109. }
  110. }
  111. // vim: et sw=4 sts=4