VarParserHarness.php 831 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. class HTMLPurifier_VarParserHarness extends UnitTestCase
  3. {
  4. protected $parser;
  5. public function setup() {
  6. $class = substr(get_class($this), 0, -4);
  7. $this->parser = new $class();
  8. }
  9. function assertValid($var, $type, $ret = null) {
  10. $ret = ($ret === null) ? $var : $ret;
  11. $this->assertIdentical($this->parser->parse($var, $type), $ret);
  12. }
  13. function assertInvalid($var, $type, $msg = null) {
  14. $caught = false;
  15. try {
  16. $this->parser->parse($var, $type);
  17. } catch (HTMLPurifier_VarParserException $e) {
  18. $caught = true;
  19. if ($msg !== null) $this->assertIdentical($e->getMessage(), $msg);
  20. }
  21. if (!$caught) {
  22. $this->fail('Did not catch expected error');
  23. }
  24. }
  25. }
  26. // vim: et sw=4 sts=4