ErrorCollectorEMock.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. generate_mock_once('HTMLPurifier_ErrorCollector');
  3. /**
  4. * Extended error collector mock that has the ability to expect context
  5. */
  6. class HTMLPurifier_ErrorCollectorEMock extends HTMLPurifier_ErrorCollectorMock
  7. {
  8. private $_context;
  9. private $_expected_context = array();
  10. private $_expected_context_at = array();
  11. public function prepare($context) {
  12. $this->_context = $context;
  13. }
  14. public function expectContext($key, $value) {
  15. $this->_expected_context[$key] = $value;
  16. }
  17. public function expectContextAt($step, $key, $value) {
  18. $this->_expected_context_at[$step][$key] = $value;
  19. }
  20. public function send($v1, $v2) {
  21. // test for context
  22. $context = SimpleTest::getContext();
  23. $test = $context->getTest();
  24. $mock = $this->mock;
  25. foreach ($this->_expected_context as $key => $value) {
  26. $test->assertEqual($value, $this->_context->get($key));
  27. }
  28. $step = $mock->getCallCount('send');
  29. if (isset($this->_expected_context_at[$step])) {
  30. foreach ($this->_expected_context_at[$step] as $key => $value) {
  31. $test->assertEqual($value, $this->_context->get($key));
  32. }
  33. }
  34. // boilerplate mock code, does not have return value or references
  35. $args = func_get_args();
  36. $mock->invoke('send', $args);
  37. }
  38. }
  39. // vim: et sw=4 sts=4