mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-06 06:07:26 +02:00
Revamp configuration backend.
Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
This commit is contained in:
@@ -9,16 +9,9 @@ class HTMLPurifier_ConfigSchema_InterchangeTest extends UnitTestCase
|
||||
$this->interchange = new HTMLPurifier_ConfigSchema_Interchange();
|
||||
}
|
||||
|
||||
function testAddNamespace() {
|
||||
$v = new HTMLPurifier_ConfigSchema_Interchange_Namespace();
|
||||
$v->namespace = 'Namespace';
|
||||
$this->interchange->addNamespace($v);
|
||||
$this->assertIdentical($v, $this->interchange->namespaces['Namespace']);
|
||||
}
|
||||
|
||||
function testAddDirective() {
|
||||
$v = new HTMLPurifier_ConfigSchema_Interchange_Directive();
|
||||
$v->id = new HTMLPurifier_ConfigSchema_Interchange_Id('Namespace', 'Directive');
|
||||
$v->id = new HTMLPurifier_ConfigSchema_Interchange_Id('Namespace.Directive');
|
||||
$this->interchange->addDirective($v);
|
||||
$this->assertIdentical($v, $this->interchange->directives['Namespace.Directive']);
|
||||
}
|
||||
|
@@ -1,8 +1,5 @@
|
||||
ERROR: Alias 'Ns.BothWantThisName' in aliases in directive 'Ns.Dir2' collides with alias for directive 'Ns.Dir'
|
||||
----
|
||||
Ns
|
||||
DESCRIPTION: Namespace
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: int
|
||||
|
@@ -1,8 +1,5 @@
|
||||
ERROR: Alias 'Ns.Innocent' in aliases in directive 'Ns.Dir' collides with another directive
|
||||
----
|
||||
Ns
|
||||
DESCRIPTION: Namespace
|
||||
----
|
||||
Ns.Innocent
|
||||
DESCRIPTION: Innocent directive
|
||||
TYPE: int
|
||||
|
@@ -1,10 +0,0 @@
|
||||
ERROR: Directive in id 'Ns.R&D' in aliases in directive 'Ns.Dir' must be alphanumeric
|
||||
----
|
||||
Ns
|
||||
DESCRIPTION: Namespace
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: string
|
||||
DEFAULT: 'a'
|
||||
ALIASES: Ns.R&D
|
@@ -1,8 +1,5 @@
|
||||
ERROR: Value 3 in allowed in directive 'Ns.Dir' must be a string
|
||||
----
|
||||
Ns
|
||||
DESCRIPTION: Generic namespace.
|
||||
----
|
||||
ID: Ns.Dir
|
||||
TYPE: string
|
||||
DESCRIPTION: Description
|
||||
|
@@ -1,8 +1,5 @@
|
||||
ERROR: Allowed in directive 'Ns.Dir' must not be empty
|
||||
----
|
||||
Ns
|
||||
DESCRIPTION: Generic namespace.
|
||||
----
|
||||
ID: Ns.Dir
|
||||
TYPE: string
|
||||
DESCRIPTION: Description
|
||||
|
@@ -1,8 +1,5 @@
|
||||
ERROR: Default in directive 'Ns.Dir' must be an allowed value
|
||||
----
|
||||
Ns
|
||||
DESCRIPTION: Namespace
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: string
|
||||
|
@@ -1,6 +1,3 @@
|
||||
Ns
|
||||
DESCRIPTION: Namespace
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: string/null
|
||||
|
@@ -1,8 +1,5 @@
|
||||
ERROR: Expected type string, got integer in DEFAULT in directive hash 'Ns.Dir'
|
||||
----
|
||||
Ns
|
||||
DESCRIPTION: Namespace
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: string
|
||||
|
@@ -1,8 +1,5 @@
|
||||
ERROR: Description in directive 'Ns.Dir' must not be empty
|
||||
----
|
||||
Ns
|
||||
DESCRIPTION: Our namespace.
|
||||
----
|
||||
Ns.Dir
|
||||
TYPE: int
|
||||
DEFAULT: 0
|
||||
|
@@ -1,9 +0,0 @@
|
||||
ERROR: Directive in id 'Ns.+' in directive 'Ns.+' must be alphanumeric
|
||||
----
|
||||
Ns
|
||||
DESCRIPTION: Generic namespace.
|
||||
----
|
||||
ID: Ns.+
|
||||
TYPE: int
|
||||
DESCRIPTION: Description
|
||||
DEFAULT: 0
|
@@ -1,9 +0,0 @@
|
||||
ERROR: Directive in id 'Ns.' in directive 'Ns.' must not be empty
|
||||
----
|
||||
Ns
|
||||
DESCRIPTION: Our namespace
|
||||
----
|
||||
ID: Ns.
|
||||
TYPE: int
|
||||
DESCRIPTION: Description.
|
||||
DEFAULT: 0
|
@@ -1,6 +0,0 @@
|
||||
ERROR: Namespace in id 'Rd.Dir' in directive 'Rd.Dir' does not exist
|
||||
----
|
||||
ID: Rd.Dir
|
||||
TYPE: int
|
||||
DESCRIPTION: Description
|
||||
DEFAULT: 0
|
@@ -0,0 +1,3 @@
|
||||
Ns
|
||||
DESCRIPTION: Namespace
|
||||
|
@@ -1,8 +1,5 @@
|
||||
ERROR: TYPE in directive hash 'Ns.Dir' not defined
|
||||
----
|
||||
Ns
|
||||
DESCRIPTION: Namespace
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Notice that TYPE is missing
|
||||
DEFAULT: 0
|
||||
|
@@ -1,8 +1,5 @@
|
||||
ERROR: Invalid type 'foobar' in DEFAULT in directive hash 'Ns.Dir'
|
||||
----
|
||||
Ns
|
||||
DESCRIPTION: Namespace
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: foobar
|
||||
|
@@ -1,8 +1,5 @@
|
||||
ERROR: Type in directive 'Ns.Dir' must be a string type when used with allowed or value aliases
|
||||
----
|
||||
Ns
|
||||
DESCRIPTION: Namespace
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: int
|
||||
|
@@ -1,8 +1,5 @@
|
||||
ERROR: Type in directive 'Ns.Dir' must be a string type when used with allowed or value aliases
|
||||
----
|
||||
Ns
|
||||
DESCRIPTION: Namespace
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: int
|
||||
|
@@ -1,8 +1,5 @@
|
||||
ERROR: Alias 3 in valueAliases in directive 'Ns.Dir' must be a string
|
||||
----
|
||||
Ns
|
||||
DESCRIPTION: Namespace
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: string
|
||||
|
@@ -1,8 +1,5 @@
|
||||
ERROR: Alias 'b' in valueAliases in directive 'Ns.Dir' must not be an allowed value
|
||||
----
|
||||
Ns
|
||||
DESCRIPTION: Namespace
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: string
|
||||
|
@@ -1,8 +1,5 @@
|
||||
ERROR: Alias 'bar' in valueAliases in directive 'Ns.Dir' must not be an alias to itself
|
||||
----
|
||||
Ns
|
||||
DESCRIPTION: Namespace
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: string
|
||||
|
@@ -1,8 +1,5 @@
|
||||
ERROR: Alias 'c' in valueAliases in directive 'Ns.Dir' must be an alias to an allowed value
|
||||
----
|
||||
Ns
|
||||
DESCRIPTION: Namespace
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: string
|
||||
|
@@ -1,8 +1,5 @@
|
||||
ERROR: Alias target 3 from alias 'b' in valueAliases in directive 'Ns.Dir' must be a string
|
||||
----
|
||||
Ns
|
||||
DESCRIPTION: Namespace
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: string
|
||||
|
@@ -1,3 +0,0 @@
|
||||
ERROR: Description in namespace 'Ns' must not be empty
|
||||
----
|
||||
ID: Ns
|
@@ -1,4 +0,0 @@
|
||||
ERROR: Namespace in namespace 'R&D' must be alphanumeric
|
||||
----
|
||||
ID: R&D
|
||||
DESCRIPTION: ctype_alnum($ID) === false
|
@@ -1,4 +0,0 @@
|
||||
ERROR: Namespace in namespace '0' must not be empty
|
||||
----
|
||||
ID: 0
|
||||
DESCRIPTION: empty($ID) === true
|
@@ -1,2 +0,0 @@
|
||||
Namespace
|
||||
DESCRIPTION: This is a generic namespace.
|
@@ -1,7 +0,0 @@
|
||||
ERROR: Cannot redefine namespace 'Ns'
|
||||
----
|
||||
ID: Ns
|
||||
DESCRIPTION: Version 1
|
||||
----
|
||||
ID: Ns
|
||||
DESCRIPTION: Version 2
|
@@ -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