Fix two minor bugs, updating Phorum and removing unused $dir variable.
[htmlpurifier/darkodev.git] / tests / HTMLPurifier / ConfigSchema / ValidatorTest.php
blob9cbf36e2da12d5954de5846e112039995b197932
1 <?php
3 /**
4 * Special test-case for cases that can't be tested using
5 * HTMLPurifier_ConfigSchema_ValidatorTestCase.
6 */
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');
25 $d->default = 0;
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');
34 $d->default = 'asdf';
35 $d->type = 'int';
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);
44 $d->default = 0;
45 $d->type = 'int';
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');
54 $d->default = 0;
55 $d->type = 'int';
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');
65 $d->default = 'a';
66 $d->type = 'string';
67 $d->description = 'Description';
68 $d->valueAliases = 2;
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');
76 $d->default = 'foo';
77 $d->type = 'string';
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);
85 // helper functions
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);
92 return $directive;
95 protected function expectValidationException($msg) {
96 $this->expectException(new HTMLPurifier_ConfigSchema_Exception($msg));
101 // vim: et sw=4 sts=4