Whoops, forgot to edit WHATSNEW
[htmlpurifier.git] / tests / HTMLPurifier / ConfigSchema / ValidatorTest.php
blob18affc36b2a19c7730ab53f364a87c29c1909251
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()
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');
28 $d->default = 0;
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');
38 $d->default = 'asdf';
39 $d->type = 'int';
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);
49 $d->default = 0;
50 $d->type = 'int';
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');
60 $d->default = 0;
61 $d->type = 'int';
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');
72 $d->default = 'a';
73 $d->type = 'string';
74 $d->description = 'Description';
75 $d->valueAliases = 2;
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');
84 $d->default = 'foo';
85 $d->type = 'string';
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);
93 // helper functions
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);
101 return $directive;
104 protected function expectValidationException($msg)
106 $this->expectException(new HTMLPurifier_ConfigSchema_Exception($msg));
111 // vim: et sw=4 sts=4