ValidatorAtomTest.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. class HTMLPurifier_ConfigSchema_ValidatorAtomTest extends UnitTestCase
  3. {
  4. protected function expectValidationException($msg) {
  5. $this->expectException(new HTMLPurifier_ConfigSchema_Exception($msg));
  6. }
  7. protected function makeAtom($value) {
  8. $obj = new stdClass();
  9. $obj->property = $value;
  10. // Note that 'property' and 'context' are magic wildcard values
  11. return new HTMLPurifier_ConfigSchema_ValidatorAtom('context', $obj, 'property');
  12. }
  13. function testAssertIsString() {
  14. $this->makeAtom('foo')->assertIsString();
  15. }
  16. function testAssertIsStringFail() {
  17. $this->expectValidationException("Property in context must be a string");
  18. $this->makeAtom(3)->assertIsString();
  19. }
  20. function testAssertNotNull() {
  21. $this->makeAtom('foo')->assertNotNull();
  22. }
  23. function testAssertNotNullFail() {
  24. $this->expectValidationException("Property in context must not be null");
  25. $this->makeAtom(null)->assertNotNull();
  26. }
  27. function testAssertAlnum() {
  28. $this->makeAtom('foo2')->assertAlnum();
  29. }
  30. function testAssertAlnumFail() {
  31. $this->expectValidationException("Property in context must be alphanumeric");
  32. $this->makeAtom('%a')->assertAlnum();
  33. }
  34. function testAssertAlnumFailIsString() {
  35. $this->expectValidationException("Property in context must be a string");
  36. $this->makeAtom(3)->assertAlnum();
  37. }
  38. function testAssertNotEmpty() {
  39. $this->makeAtom('foo')->assertNotEmpty();
  40. }
  41. function testAssertNotEmptyFail() {
  42. $this->expectValidationException("Property in context must not be empty");
  43. $this->makeAtom('')->assertNotEmpty();
  44. }
  45. function testAssertIsBool() {
  46. $this->makeAtom(false)->assertIsBool();
  47. }
  48. function testAssertIsBoolFail() {
  49. $this->expectValidationException("Property in context must be a boolean");
  50. $this->makeAtom('0')->assertIsBool();
  51. }
  52. function testAssertIsArray() {
  53. $this->makeAtom(array())->assertIsArray();
  54. }
  55. function testAssertIsArrayFail() {
  56. $this->expectValidationException("Property in context must be an array");
  57. $this->makeAtom('asdf')->assertIsArray();
  58. }
  59. function testAssertIsLookup() {
  60. $this->makeAtom(array('foo' => true))->assertIsLookup();
  61. }
  62. function testAssertIsLookupFail() {
  63. $this->expectValidationException("Property in context must be a lookup array");
  64. $this->makeAtom(array('foo' => 4))->assertIsLookup();
  65. }
  66. function testAssertIsLookupFailIsArray() {
  67. $this->expectValidationException("Property in context must be an array");
  68. $this->makeAtom('asdf')->assertIsLookup();
  69. }
  70. }
  71. // vim: et sw=4 sts=4