Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

111 linhas
2.9KB

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