AttrCollectionsTest.php 3.8 KB

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