Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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