Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

PropertyListTest.php 3.2KB

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