mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-03 12:47:56 +02:00
Revamp configuration backend.
Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
This commit is contained in:
@@ -13,36 +13,15 @@ class HTMLPurifier_ConfigSchema_ValidatorTest extends UnitTestCase
|
||||
$this->interchange = new HTMLPurifier_ConfigSchema_Interchange();
|
||||
}
|
||||
|
||||
function testNamespaceIntegrityViolation() {
|
||||
$ns = $this->makeNamespace('Ns');
|
||||
$ns->namespace = 'AltNs';
|
||||
$this->expectValidationException("Integrity violation: key 'Ns' does not match internal id 'AltNs'");
|
||||
$this->validator->validate($this->interchange);
|
||||
}
|
||||
|
||||
function testNamespaceNamespaceIsString() {
|
||||
$this->makeNamespace(3);
|
||||
$this->expectValidationException("Namespace in namespace '3' must be a string");
|
||||
$this->validator->validate($this->interchange);
|
||||
}
|
||||
|
||||
function testNamespaceDescriptionIsString() {
|
||||
$ns = $this->makeNamespace('Ns');
|
||||
$ns->description = 3;
|
||||
$this->expectValidationException("Description in namespace 'Ns' must be a string");
|
||||
$this->validator->validate($this->interchange);
|
||||
}
|
||||
|
||||
function testDirectiveIntegrityViolation() {
|
||||
$d = $this->makeDirective('Ns', 'Dir');
|
||||
$d->id = new HTMLPurifier_ConfigSchema_Interchange_Id('Ns', 'Dir2');
|
||||
$d = $this->makeDirective('Ns.Dir');
|
||||
$d->id = new HTMLPurifier_ConfigSchema_Interchange_Id('Ns.Dir2');
|
||||
$this->expectValidationException("Integrity violation: key 'Ns.Dir' does not match internal id 'Ns.Dir2'");
|
||||
$this->validator->validate($this->interchange);
|
||||
}
|
||||
|
||||
function testDirectiveTypeNotEmpty() {
|
||||
$this->makeNamespace('Ns');
|
||||
$d = $this->makeDirective('Ns', 'Dir');
|
||||
$d = $this->makeDirective('Ns.Dir');
|
||||
$d->default = 0;
|
||||
$d->description = 'Description';
|
||||
|
||||
@@ -51,8 +30,7 @@ class HTMLPurifier_ConfigSchema_ValidatorTest extends UnitTestCase
|
||||
}
|
||||
|
||||
function testDirectiveDefaultInvalid() {
|
||||
$this->makeNamespace('Ns');
|
||||
$d = $this->makeDirective('Ns', 'Dir');
|
||||
$d = $this->makeDirective('Ns.Dir');
|
||||
$d->default = 'asdf';
|
||||
$d->type = 'int';
|
||||
$d->description = 'Description';
|
||||
@@ -61,20 +39,18 @@ class HTMLPurifier_ConfigSchema_ValidatorTest extends UnitTestCase
|
||||
$this->validator->validate($this->interchange);
|
||||
}
|
||||
|
||||
function testDirectiveIdDirectiveIsString() {
|
||||
$this->makeNamespace('Ns');
|
||||
$d = $this->makeDirective('Ns', 3);
|
||||
function testDirectiveIdIsString() {
|
||||
$d = $this->makeDirective(3);
|
||||
$d->default = 0;
|
||||
$d->type = 'int';
|
||||
$d->description = 'Description';
|
||||
|
||||
$this->expectValidationException("Directive in id 'Ns.3' in directive 'Ns.3' must be a string");
|
||||
$this->expectValidationException("Key in id '3' in directive '3' must be a string");
|
||||
$this->validator->validate($this->interchange);
|
||||
}
|
||||
|
||||
function testDirectiveTypeAllowsNullIsBool() {
|
||||
$this->makeNamespace('Ns');
|
||||
$d = $this->makeDirective('Ns', 'Dir');
|
||||
$d = $this->makeDirective('Ns.Dir');
|
||||
$d->default = 0;
|
||||
$d->type = 'int';
|
||||
$d->description = 'Description';
|
||||
@@ -85,8 +61,7 @@ class HTMLPurifier_ConfigSchema_ValidatorTest extends UnitTestCase
|
||||
}
|
||||
|
||||
function testDirectiveValueAliasesIsArray() {
|
||||
$this->makeNamespace('Ns');
|
||||
$d = $this->makeDirective('Ns', 'Dir');
|
||||
$d = $this->makeDirective('Ns.Dir');
|
||||
$d->default = 'a';
|
||||
$d->type = 'string';
|
||||
$d->description = 'Description';
|
||||
@@ -97,8 +72,7 @@ class HTMLPurifier_ConfigSchema_ValidatorTest extends UnitTestCase
|
||||
}
|
||||
|
||||
function testDirectiveAllowedIsLookup() {
|
||||
$this->makeNamespace('Ns');
|
||||
$d = $this->makeDirective('Ns', 'Dir');
|
||||
$d = $this->makeDirective('Ns.Dir');
|
||||
$d->default = 'foo';
|
||||
$d->type = 'string';
|
||||
$d->description = 'Description';
|
||||
@@ -110,17 +84,10 @@ class HTMLPurifier_ConfigSchema_ValidatorTest extends UnitTestCase
|
||||
|
||||
// helper functions
|
||||
|
||||
protected function makeNamespace($n) {
|
||||
$namespace = new HTMLPurifier_ConfigSchema_Interchange_Namespace();
|
||||
$namespace->namespace = $n;
|
||||
$namespace->description = 'Description'; // non-essential, but we won't set it most of the time
|
||||
$this->interchange->addNamespace($namespace);
|
||||
return $namespace;
|
||||
}
|
||||
|
||||
protected function makeDirective($n, $d) {
|
||||
protected function makeDirective($key) {
|
||||
$directive = new HTMLPurifier_ConfigSchema_Interchange_Directive();
|
||||
$directive->id = new HTMLPurifier_ConfigSchema_Interchange_Id($n, $d);
|
||||
$directive->id = new HTMLPurifier_ConfigSchema_Interchange_Id($key);
|
||||
$this->interchange->addDirective($directive);
|
||||
return $directive;
|
||||
}
|
||||
|
Reference in New Issue
Block a user