You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
3.8KB

  1. <?php
  2. Mock::generatePartial(
  3. 'HTMLPurifier_AttrCollections',
  4. 'HTMLPurifier_AttrCollections_TestForConstruct',
  5. array('performInclusions', 'expandIdentifiers')
  6. );
  7. class HTMLPurifier_AttrCollectionsTest extends HTMLPurifier_Harness
  8. {
  9. public function testConstruction()
  10. {
  11. generate_mock_once('HTMLPurifier_AttrTypes');
  12. $collections = new HTMLPurifier_AttrCollections_TestForConstruct();
  13. $types = new HTMLPurifier_AttrTypesMock();
  14. $modules = array();
  15. $modules['Module1'] = new HTMLPurifier_HTMLModule();
  16. $modules['Module1']->attr_collections = array(
  17. 'Core' => array(
  18. 0 => array('Soup', 'Undefined'),
  19. 'attribute' => 'Type',
  20. 'attribute-2' => 'Type2',
  21. ),
  22. 'Soup' => array(
  23. 'attribute-3' => 'Type3-old' // overwritten
  24. )
  25. );
  26. $modules['Module2'] = new HTMLPurifier_HTMLModule();
  27. $modules['Module2']->attr_collections = array(
  28. 'Core' => array(
  29. 0 => array('Brocolli')
  30. ),
  31. 'Soup' => array(
  32. 'attribute-3' => 'Type3'
  33. ),
  34. 'Brocolli' => array()
  35. );
  36. $collections->__construct($types, $modules);
  37. // this is without identifier expansion or inclusions
  38. $this->assertIdentical(
  39. $collections->info,
  40. array(
  41. 'Core' => array(
  42. 0 => array('Soup', 'Undefined', 'Brocolli'),
  43. 'attribute' => 'Type',
  44. 'attribute-2' => 'Type2'
  45. ),
  46. 'Soup' => array(
  47. 'attribute-3' => 'Type3'
  48. ),
  49. 'Brocolli' => array()
  50. )
  51. );
  52. }
  53. public function test_performInclusions()
  54. {
  55. generate_mock_once('HTMLPurifier_AttrTypes');
  56. $types = new HTMLPurifier_AttrTypesMock();
  57. $collections = new HTMLPurifier_AttrCollections($types, array());
  58. $collections->info = array(
  59. 'Core' => array(0 => array('Inclusion', 'Undefined'), 'attr-original' => 'Type'),
  60. 'Inclusion' => array(0 => array('SubInclusion'), 'attr' => 'Type'),
  61. 'SubInclusion' => array('attr2' => 'Type')
  62. );
  63. $collections->performInclusions($collections->info['Core']);
  64. $this->assertIdentical(
  65. $collections->info['Core'],
  66. array(
  67. 'attr-original' => 'Type',
  68. 'attr' => 'Type',
  69. 'attr2' => 'Type'
  70. )
  71. );
  72. // test recursive
  73. $collections->info = array(
  74. 'One' => array(0 => array('Two'), 'one' => 'Type'),
  75. 'Two' => array(0 => array('One'), 'two' => 'Type')
  76. );
  77. $collections->performInclusions($collections->info['One']);
  78. $this->assertIdentical(
  79. $collections->info['One'],
  80. array(
  81. 'one' => 'Type',
  82. 'two' => 'Type'
  83. )
  84. );
  85. }
  86. public function test_expandIdentifiers()
  87. {
  88. generate_mock_once('HTMLPurifier_AttrTypes');
  89. $types = new HTMLPurifier_AttrTypesMock();
  90. $collections = new HTMLPurifier_AttrCollections($types, array());
  91. $attr = array(
  92. 'attr1' => 'Color',
  93. 'attr2*' => 'URI'
  94. );
  95. $c_object = new HTMLPurifier_AttrDef_HTML_Color();
  96. $u_object = new HTMLPurifier_AttrDef_URI();
  97. $types->setReturnValue('get', $c_object, array('Color'));
  98. $types->setReturnValue('get', $u_object, array('URI'));
  99. $collections->expandIdentifiers($attr, $types);
  100. $u_object->required = true;
  101. $this->assertIdentical(
  102. $attr,
  103. array(
  104. 'attr1' => $c_object,
  105. 'attr2' => $u_object
  106. )
  107. );
  108. }
  109. }
  110. // vim: et sw=4 sts=4