You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.7KB

  1. <?php
  2. class HTMLPurifier_VarParser_FlexibleTest extends HTMLPurifier_VarParserHarness
  3. {
  4. public function testValidate()
  5. {
  6. $this->assertValid('foobar', 'string');
  7. $this->assertValid('foobar', 'text');
  8. $this->assertValid('FOOBAR', 'istring', 'foobar');
  9. $this->assertValid('FOOBAR', 'itext', 'foobar');
  10. $this->assertValid(34, 'int');
  11. $this->assertValid(3.34, 'float');
  12. $this->assertValid(false, 'bool');
  13. $this->assertValid(0, 'bool', false);
  14. $this->assertValid(1, 'bool', true);
  15. $this->assertValid('true', 'bool', true);
  16. $this->assertValid('false', 'bool', false);
  17. $this->assertValid('1', 'bool', true);
  18. $this->assertInvalid(34, 'bool');
  19. $this->assertInvalid(null, 'bool');
  20. $this->assertValid(array('1', '2', '3'), 'list');
  21. $this->assertValid('foo,bar, cow', 'list', array('foo', 'bar', 'cow'));
  22. $this->assertValid('', 'list', array());
  23. $this->assertValid("foo\nbar", 'list', array('foo', 'bar'));
  24. $this->assertValid("foo\nbar,baz", 'list', array('foo', 'bar', 'baz'));
  25. $this->assertValid(array('1' => true, '2' => true), 'lookup');
  26. $this->assertValid(array('1', '2'), 'lookup', array('1' => true, '2' => true));
  27. $this->assertValid('foo,bar', 'lookup', array('foo' => true, 'bar' => true));
  28. $this->assertValid("foo\nbar", 'lookup', array('foo' => true, 'bar' => true));
  29. $this->assertValid("foo\nbar,baz", 'lookup', array('foo' => true, 'bar' => true, 'baz' => true));
  30. $this->assertValid('', 'lookup', array());
  31. $this->assertValid(array(), 'lookup');
  32. $this->assertValid(array('foo' => 'bar'), 'hash');
  33. $this->assertValid(array(1 => 'moo'), 'hash');
  34. $this->assertInvalid(array(0 => 'moo'), 'hash');
  35. $this->assertValid('', 'hash', array());
  36. $this->assertValid('foo:bar,too:two', 'hash', array('foo' => 'bar', 'too' => 'two'));
  37. $this->assertValid("foo:bar\ntoo:two,three:free", 'hash', array('foo' => 'bar', 'too' => 'two', 'three' => 'free'));
  38. $this->assertValid('foo:bar,too', 'hash', array('foo' => 'bar'));
  39. $this->assertValid('foo:bar,', 'hash', array('foo' => 'bar'));
  40. $this->assertValid('foo:bar:baz', 'hash', array('foo' => 'bar:baz'));
  41. $this->assertValid(23, 'mixed');
  42. }
  43. public function testValidate_withMagicNumbers()
  44. {
  45. $this->assertValid('foobar', HTMLPurifier_VarParser::STRING);
  46. }
  47. public function testValidate_null()
  48. {
  49. $this->assertIdentical($this->parser->parse(null, 'string', true), null);
  50. $this->expectException('HTMLPurifier_VarParserException');
  51. $this->parser->parse(null, 'string', false);
  52. }
  53. }
  54. // vim: et sw=4 sts=4