Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

ContextTest.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. // mocks
  3. class HTMLPurifier_ContextTest extends HTMLPurifier_Harness
  4. {
  5. protected $context;
  6. public function setUp()
  7. {
  8. $this->context = new HTMLPurifier_Context();
  9. }
  10. public function testStandardUsage()
  11. {
  12. generate_mock_once('HTMLPurifier_IDAccumulator');
  13. $this->assertFalse($this->context->exists('IDAccumulator'));
  14. $accumulator = new HTMLPurifier_IDAccumulatorMock();
  15. $this->context->register('IDAccumulator', $accumulator);
  16. $this->assertTrue($this->context->exists('IDAccumulator'));
  17. $accumulator_2 =& $this->context->get('IDAccumulator');
  18. $this->assertReference($accumulator, $accumulator_2);
  19. $this->context->destroy('IDAccumulator');
  20. $this->assertFalse($this->context->exists('IDAccumulator'));
  21. $this->expectError('Attempted to retrieve non-existent variable IDAccumulator');
  22. $accumulator_3 =& $this->context->get('IDAccumulator');
  23. $this->assertNull($accumulator_3);
  24. $this->expectError('Attempted to destroy non-existent variable IDAccumulator');
  25. $this->context->destroy('IDAccumulator');
  26. }
  27. public function testReRegister()
  28. {
  29. $var = true;
  30. $this->context->register('OnceOnly', $var);
  31. $this->expectError('Name OnceOnly produces collision, cannot re-register');
  32. $this->context->register('OnceOnly', $var);
  33. // destroy it, now registration is okay
  34. $this->context->destroy('OnceOnly');
  35. $this->context->register('OnceOnly', $var);
  36. }
  37. public function test_loadArray()
  38. {
  39. // references can be *really* wonky!
  40. $context_manual = new HTMLPurifier_Context();
  41. $context_load = new HTMLPurifier_Context();
  42. $var1 = 1;
  43. $var2 = 2;
  44. $context_manual->register('var1', $var1);
  45. $context_manual->register('var2', $var2);
  46. // you MUST set up the references when constructing the array,
  47. // otherwise the registered version will be a copy
  48. $array = array(
  49. 'var1' => &$var1,
  50. 'var2' => &$var2
  51. );
  52. $context_load->loadArray($array);
  53. $this->assertIdentical($context_manual, $context_load);
  54. $var1 = 10;
  55. $var2 = 20;
  56. $this->assertIdentical($context_manual, $context_load);
  57. }
  58. public function testNull() {
  59. $context = new HTMLPurifier_Context();
  60. $var = NULL;
  61. $context->register('var', $var);
  62. $this->assertNull($context->get('var'));
  63. $context->destroy('var');
  64. }
  65. }
  66. // vim: et sw=4 sts=4