4 * Special test-case for cases that can't be tested using
5 * HTMLPurifier_ConfigSchema_ValidatorTestCase.
7 class HTMLPurifier_ConfigSchema_ValidatorTest
extends UnitTestCase
9 public $validator, $interchange;
11 public function setup() {
12 $this->validator
= new HTMLPurifier_ConfigSchema_Validator();
13 $this->interchange
= new HTMLPurifier_ConfigSchema_Interchange();
16 function testDirectiveIntegrityViolation() {
17 $d = $this->makeDirective('Ns.Dir');
18 $d->id
= new HTMLPurifier_ConfigSchema_Interchange_Id('Ns.Dir2');
19 $this->expectValidationException("Integrity violation: key 'Ns.Dir' does not match internal id 'Ns.Dir2'");
20 $this->validator
->validate($this->interchange
);
23 function testDirectiveTypeNotEmpty() {
24 $d = $this->makeDirective('Ns.Dir');
26 $d->description
= 'Description';
28 $this->expectValidationException("Type in directive 'Ns.Dir' must not be empty");
29 $this->validator
->validate($this->interchange
);
32 function testDirectiveDefaultInvalid() {
33 $d = $this->makeDirective('Ns.Dir');
36 $d->description
= 'Description';
38 $this->expectValidationException("Default in directive 'Ns.Dir' had error: Expected type int, got string");
39 $this->validator
->validate($this->interchange
);
42 function testDirectiveIdIsString() {
43 $d = $this->makeDirective(3);
46 $d->description
= 'Description';
48 $this->expectValidationException("Key in id '3' in directive '3' must be a string");
49 $this->validator
->validate($this->interchange
);
52 function testDirectiveTypeAllowsNullIsBool() {
53 $d = $this->makeDirective('Ns.Dir');
56 $d->description
= 'Description';
57 $d->typeAllowsNull
= 'yes';
59 $this->expectValidationException("TypeAllowsNull in directive 'Ns.Dir' must be a boolean");
60 $this->validator
->validate($this->interchange
);
63 function testDirectiveValueAliasesIsArray() {
64 $d = $this->makeDirective('Ns.Dir');
67 $d->description
= 'Description';
70 $this->expectValidationException("ValueAliases in directive 'Ns.Dir' must be an array");
71 $this->validator
->validate($this->interchange
);
74 function testDirectiveAllowedIsLookup() {
75 $d = $this->makeDirective('Ns.Dir');
78 $d->description
= 'Description';
79 $d->allowed
= array('foo' => 1);
81 $this->expectValidationException("Allowed in directive 'Ns.Dir' must be a lookup array");
82 $this->validator
->validate($this->interchange
);
88 protected function makeDirective($key) {
89 $directive = new HTMLPurifier_ConfigSchema_Interchange_Directive();
90 $directive->id
= new HTMLPurifier_ConfigSchema_Interchange_Id($key);
91 $this->interchange
->addDirective($directive);
95 protected function expectValidationException($msg) {
96 $this->expectException(new HTMLPurifier_ConfigSchema_Exception($msg));
101 // vim: et sw=4 sts=4