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()
13 $this->validator
= new HTMLPurifier_ConfigSchema_Validator();
14 $this->interchange
= new HTMLPurifier_ConfigSchema_Interchange();
17 public function testDirectiveIntegrityViolation()
19 $d = $this->makeDirective('Ns.Dir');
20 $d->id
= new HTMLPurifier_ConfigSchema_Interchange_Id('Ns.Dir2');
21 $this->expectValidationException("Integrity violation: key 'Ns.Dir' does not match internal id 'Ns.Dir2'");
22 $this->validator
->validate($this->interchange
);
25 public function testDirectiveTypeNotEmpty()
27 $d = $this->makeDirective('Ns.Dir');
29 $d->description
= 'Description';
31 $this->expectValidationException("Type in directive 'Ns.Dir' must not be empty");
32 $this->validator
->validate($this->interchange
);
35 public function testDirectiveDefaultInvalid()
37 $d = $this->makeDirective('Ns.Dir');
40 $d->description
= 'Description';
42 $this->expectValidationException("Default in directive 'Ns.Dir' had error: Expected type int, got string");
43 $this->validator
->validate($this->interchange
);
46 public function testDirectiveIdIsString()
48 $d = $this->makeDirective(3);
51 $d->description
= 'Description';
53 $this->expectValidationException("Key in id '3' in directive '3' must be a string");
54 $this->validator
->validate($this->interchange
);
57 public function testDirectiveTypeAllowsNullIsBool()
59 $d = $this->makeDirective('Ns.Dir');
62 $d->description
= 'Description';
63 $d->typeAllowsNull
= 'yes';
65 $this->expectValidationException("TypeAllowsNull in directive 'Ns.Dir' must be a boolean");
66 $this->validator
->validate($this->interchange
);
69 public function testDirectiveValueAliasesIsArray()
71 $d = $this->makeDirective('Ns.Dir');
74 $d->description
= 'Description';
77 $this->expectValidationException("ValueAliases in directive 'Ns.Dir' must be an array");
78 $this->validator
->validate($this->interchange
);
81 public function testDirectiveAllowedIsLookup()
83 $d = $this->makeDirective('Ns.Dir');
86 $d->description
= 'Description';
87 $d->allowed
= array('foo' => 1);
89 $this->expectValidationException("Allowed in directive 'Ns.Dir' must be a lookup array");
90 $this->validator
->validate($this->interchange
);
96 protected function makeDirective($key)
98 $directive = new HTMLPurifier_ConfigSchema_Interchange_Directive();
99 $directive->id
= new HTMLPurifier_ConfigSchema_Interchange_Id($key);
100 $this->interchange
->addDirective($directive);
104 protected function expectValidationException($msg)
106 $this->expectException(new HTMLPurifier_ConfigSchema_Exception($msg));
111 // vim: et sw=4 sts=4