PropertyListTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. class HTMLPurifier_PropertyListTest extends UnitTestCase
  3. {
  4. function testBasic() {
  5. $plist = new HTMLPurifier_PropertyList();
  6. $plist->set('key', 'value');
  7. $this->assertIdentical($plist->get('key'), 'value');
  8. }
  9. function testNotFound() {
  10. $this->expectException(new HTMLPurifier_Exception("Key 'key' not found"));
  11. $plist = new HTMLPurifier_PropertyList();
  12. $plist->get('key');
  13. }
  14. function testRecursion() {
  15. $parent_plist = new HTMLPurifier_PropertyList();
  16. $parent_plist->set('key', 'value');
  17. $plist = new HTMLPurifier_PropertyList();
  18. $plist->setParent($parent_plist);
  19. $this->assertIdentical($plist->get('key'), 'value');
  20. }
  21. function testOverride() {
  22. $parent_plist = new HTMLPurifier_PropertyList();
  23. $parent_plist->set('key', 'value');
  24. $plist = new HTMLPurifier_PropertyList();
  25. $plist->setParent($parent_plist);
  26. $plist->set('key', 'value2');
  27. $this->assertIdentical($plist->get('key'), 'value2');
  28. }
  29. function testRecursionNotFound() {
  30. $this->expectException(new HTMLPurifier_Exception("Key 'key' not found"));
  31. $parent_plist = new HTMLPurifier_PropertyList();
  32. $plist = new HTMLPurifier_PropertyList();
  33. $plist->setParent($parent_plist);
  34. $this->assertIdentical($plist->get('key'), 'value');
  35. }
  36. function testHas() {
  37. $plist = new HTMLPurifier_PropertyList();
  38. $this->assertIdentical($plist->has('key'), false);
  39. $plist->set('key', 'value');
  40. $this->assertIdentical($plist->has('key'), true);
  41. }
  42. function testReset() {
  43. $plist = new HTMLPurifier_PropertyList();
  44. $plist->set('key1', 'value');
  45. $plist->set('key2', 'value');
  46. $plist->set('key3', 'value');
  47. $this->assertIdentical($plist->has('key1'), true);
  48. $this->assertIdentical($plist->has('key2'), true);
  49. $this->assertIdentical($plist->has('key3'), true);
  50. $plist->reset('key2');
  51. $this->assertIdentical($plist->has('key1'), true);
  52. $this->assertIdentical($plist->has('key2'), false);
  53. $this->assertIdentical($plist->has('key3'), true);
  54. $plist->reset();
  55. $this->assertIdentical($plist->has('key1'), false);
  56. $this->assertIdentical($plist->has('key2'), false);
  57. $this->assertIdentical($plist->has('key3'), false);
  58. }
  59. function testSquash() {
  60. $parent = new HTMLPurifier_PropertyList();
  61. $parent->set('key1', 'hidden');
  62. $parent->set('key2', 2);
  63. $plist = new HTMLPurifier_PropertyList($parent);
  64. $plist->set('key1', 1);
  65. $plist->set('key3', 3);
  66. $this->assertIdentical(
  67. $plist->squash(),
  68. array('key1' => 1, 'key2' => 2, 'key3' => 3)
  69. );
  70. // updates don't show up...
  71. $plist->set('key2', 22);
  72. $this->assertIdentical(
  73. $plist->squash(),
  74. array('key1' => 1, 'key2' => 2, 'key3' => 3)
  75. );
  76. // until you force
  77. $this->assertIdentical(
  78. $plist->squash(true),
  79. array('key1' => 1, 'key2' => 22, 'key3' => 3)
  80. );
  81. }
  82. }
  83. // vim: et sw=4 sts=4