1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-07-31 19:30:21 +02:00

Revamp configuration backend.

Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
This commit is contained in:
Edward Z. Yang
2009-02-07 02:53:20 -05:00
parent fcbf724e6e
commit b107eec452
57 changed files with 483 additions and 529 deletions

View File

@@ -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']);
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -1,8 +1,5 @@
ERROR: Default in directive 'Ns.Dir' must be an allowed value
----
Ns
DESCRIPTION: Namespace
----
Ns.Dir
DESCRIPTION: Directive
TYPE: string

View File

@@ -1,6 +1,3 @@
Ns
DESCRIPTION: Namespace
----
Ns.Dir
DESCRIPTION: Directive
TYPE: string/null

View File

@@ -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

View File

@@ -1,8 +1,5 @@
ERROR: Description in directive 'Ns.Dir' must not be empty
----
Ns
DESCRIPTION: Our namespace.
----
Ns.Dir
TYPE: int
DEFAULT: 0

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,3 @@
Ns
DESCRIPTION: Namespace

View File

@@ -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

View File

@@ -1,8 +1,5 @@
ERROR: Invalid type 'foobar' in DEFAULT in directive hash 'Ns.Dir'
----
Ns
DESCRIPTION: Namespace
----
Ns.Dir
DESCRIPTION: Directive
TYPE: foobar

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -1,3 +0,0 @@
ERROR: Description in namespace 'Ns' must not be empty
----
ID: Ns

View File

@@ -1,4 +0,0 @@
ERROR: Namespace in namespace 'R&D' must be alphanumeric
----
ID: R&D
DESCRIPTION: ctype_alnum($ID) === false

View File

@@ -1,4 +0,0 @@
ERROR: Namespace in namespace '0' must not be empty
----
ID: 0
DESCRIPTION: empty($ID) === true

View File

@@ -1,2 +0,0 @@
Namespace
DESCRIPTION: This is a generic namespace.

View File

@@ -1,7 +0,0 @@
ERROR: Cannot redefine namespace 'Ns'
----
ID: Ns
DESCRIPTION: Version 1
----
ID: Ns
DESCRIPTION: Version 2

View File

@@ -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;
}

View File

@@ -9,41 +9,32 @@ class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness
$this->schema = new HTMLPurifier_ConfigSchema();
}
function test_defineNamespace() {
$this->schema->addNamespace('http');
$this->assertIdentical($this->schema->info['http'], array());
$this->assertIdentical($this->schema->defaults['http'], array());
}
function test_define() {
$this->schema->addNamespace('Car');
$this->schema->add('Car.Seats', 5, 'int', false);
$this->schema->add('Car', 'Seats', 5, 'int', false);
$this->assertIdentical($this->schema->defaults['Car.Seats'], 5);
$this->assertIdentical($this->schema->info['Car.Seats']->type, HTMLPurifier_VarParser::INT);
$this->assertIdentical($this->schema->defaults['Car']['Seats'], 5);
$this->assertIdentical($this->schema->info['Car']['Seats']->type, HTMLPurifier_VarParser::INT);
$this->schema->add('Car.Age', null, 'int', true);
$this->schema->add('Car', 'Age', null, 'int', true);
$this->assertIdentical($this->schema->defaults['Car']['Age'], null);
$this->assertIdentical($this->schema->info['Car']['Age']->type, HTMLPurifier_VarParser::INT);
$this->assertIdentical($this->schema->defaults['Car.Age'], null);
$this->assertIdentical($this->schema->info['Car.Age']->type, HTMLPurifier_VarParser::INT);
}
function test_defineAllowedValues() {
$this->schema->addNamespace('QuantumNumber', 'D');
$this->schema->add('QuantumNumber', 'Spin', 0.5, 'float', false);
$this->schema->add('QuantumNumber', 'Current', 's', 'string', false);
$this->schema->add('QuantumNumber', 'Difficulty', null, 'string', true);
$this->schema->add('QuantumNumber.Spin', 0.5, 'float', false);
$this->schema->add('QuantumNumber.Current', 's', 'string', false);
$this->schema->add('QuantumNumber.Difficulty', null, 'string', true);
$this->schema->addAllowedValues( // okay, since default is null
'QuantumNumber', 'Difficulty', array('easy' => true, 'medium' => true, 'hard' => true)
'QuantumNumber.Difficulty', array('easy' => true, 'medium' => true, 'hard' => true)
);
$this->assertIdentical($this->schema->defaults['QuantumNumber']['Difficulty'], null);
$this->assertIdentical($this->schema->info['QuantumNumber']['Difficulty']->type, HTMLPurifier_VarParser::STRING);
$this->assertIdentical($this->schema->info['QuantumNumber']['Difficulty']->allow_null, true);
$this->assertIdentical($this->schema->info['QuantumNumber']['Difficulty']->allowed,
$this->assertIdentical($this->schema->defaults['QuantumNumber.Difficulty'], null);
$this->assertIdentical($this->schema->info['QuantumNumber.Difficulty']->type, HTMLPurifier_VarParser::STRING);
$this->assertIdentical($this->schema->info['QuantumNumber.Difficulty']->allow_null, true);
$this->assertIdentical($this->schema->info['QuantumNumber.Difficulty']->allowed,
array(
'easy' => true,
'medium' => true,
@@ -54,37 +45,36 @@ class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness
}
function test_defineValueAliases() {
$this->schema->addNamespace('Abbrev', 'Stuff on abbreviations.');
$this->schema->add('Abbrev', 'HTH', 'Happy to Help', 'string', false);
$this->schema->add('Abbrev.HTH', 'Happy to Help', 'string', false);
$this->schema->addAllowedValues(
'Abbrev', 'HTH', array(
'Abbrev.HTH', array(
'Happy to Help' => true,
'Hope that Helps' => true,
'HAIL THE HAND!' => true,
)
);
$this->schema->addValueAliases(
'Abbrev', 'HTH', array(
'Abbrev.HTH', array(
'happy' => 'Happy to Help',
'hope' => 'Hope that Helps'
)
);
$this->schema->addValueAliases( // delayed addition
'Abbrev', 'HTH', array(
'Abbrev.HTH', array(
'hail' => 'HAIL THE HAND!'
)
);
$this->assertIdentical($this->schema->defaults['Abbrev']['HTH'], 'Happy to Help');
$this->assertIdentical($this->schema->info['Abbrev']['HTH']->type, HTMLPurifier_VarParser::STRING);
$this->assertIdentical($this->schema->info['Abbrev']['HTH']->allowed,
$this->assertIdentical($this->schema->defaults['Abbrev.HTH'], 'Happy to Help');
$this->assertIdentical($this->schema->info['Abbrev.HTH']->type, HTMLPurifier_VarParser::STRING);
$this->assertIdentical($this->schema->info['Abbrev.HTH']->allowed,
array(
'Happy to Help' => true,
'Hope that Helps' => true,
'HAIL THE HAND!' => true
)
);
$this->assertIdentical($this->schema->info['Abbrev']['HTH']->aliases,
$this->assertIdentical($this->schema->info['Abbrev.HTH']->aliases,
array(
'happy' => 'Happy to Help',
'hope' => 'Hope that Helps',
@@ -95,14 +85,12 @@ class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness
}
function testAlias() {
$this->schema->addNamespace('Home');
$this->schema->add('Home', 'Rug', 3, 'int', false);
$this->schema->addAlias('Home', 'Carpet', 'Home', 'Rug');
$this->schema->add('Home.Rug', 3, 'int', false);
$this->schema->addAlias('Home.Carpet', 'Home.Rug');
$this->assertTrue(!isset($this->schema->defaults['Home']['Carpet']));
$this->assertIdentical($this->schema->info['Home']['Carpet']->namespace, 'Home');
$this->assertIdentical($this->schema->info['Home']['Carpet']->name, 'Rug');
$this->assertIdentical($this->schema->info['Home']['Carpet']->isAlias, true);
$this->assertTrue(!isset($this->schema->defaults['Home.Carpet']));
$this->assertIdentical($this->schema->info['Home.Carpet']->key, 'Home.Rug');
$this->assertIdentical($this->schema->info['Home.Carpet']->isAlias, true);
}

View File

@@ -13,17 +13,15 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
// test functionality based on ConfigSchema
function testNormal() {
$this->schema->addNamespace('Element');
$this->schema->add('Element', 'Abbr', 'H', 'string', false);
$this->schema->add('Element', 'Name', 'hydrogen', 'istring', false);
$this->schema->add('Element', 'Number', 1, 'int', false);
$this->schema->add('Element', 'Mass', 1.00794, 'float', false);
$this->schema->add('Element', 'Radioactive', false, 'bool', false);
$this->schema->add('Element', 'Isotopes', array(1 => true, 2 => true, 3 => true), 'lookup', false);
$this->schema->add('Element', 'Traits', array('nonmetallic', 'odorless', 'flammable'), 'list', false);
$this->schema->add('Element', 'IsotopeNames', array(1 => 'protium', 2 => 'deuterium', 3 => 'tritium'), 'hash', false);
$this->schema->add('Element', 'Object', new stdClass(), 'mixed', false);
$this->schema->add('Element.Abbr', 'H', 'string', false);
$this->schema->add('Element.Name', 'hydrogen', 'istring', false);
$this->schema->add('Element.Number', 1, 'int', false);
$this->schema->add('Element.Mass', 1.00794, 'float', false);
$this->schema->add('Element.Radioactive', false, 'bool', false);
$this->schema->add('Element.Isotopes', array(1 => true, 2 => true, 3 => true), 'lookup', false);
$this->schema->add('Element.Traits', array('nonmetallic', 'odorless', 'flammable'), 'list', false);
$this->schema->add('Element.IsotopeNames', array(1 => 'protium', 2 => 'deuterium', 3 => 'tritium'), 'hash', false);
$this->schema->add('Element.Object', new stdClass(), 'mixed', false);
$config = new HTMLPurifier_Config($this->schema);
$config->autoFinalize = false;
@@ -74,22 +72,20 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
function testEnumerated() {
$this->schema->addNamespace('Instrument', 'Of the musical type.');
// case sensitive
$this->schema->add('Instrument', 'Manufacturer', 'Yamaha', 'string', false);
$this->schema->addAllowedValues('Instrument', 'Manufacturer', array(
$this->schema->add('Instrument.Manufacturer', 'Yamaha', 'string', false);
$this->schema->addAllowedValues('Instrument.Manufacturer', array(
'Yamaha' => true, 'Conn-Selmer' => true, 'Vandoren' => true,
'Laubin' => true, 'Buffet' => true, 'other' => true));
$this->schema->addValueAliases('Instrument', 'Manufacturer', array(
$this->schema->addValueAliases('Instrument.Manufacturer', array(
'Selmer' => 'Conn-Selmer'));
// case insensitive
$this->schema->add('Instrument', 'Family', 'woodwind', 'istring', false);
$this->schema->addAllowedValues('Instrument', 'Family', array(
$this->schema->add('Instrument.Family', 'woodwind', 'istring', false);
$this->schema->addAllowedValues('Instrument.Family', array(
'brass' => true, 'woodwind' => true, 'percussion' => true,
'string' => true, 'keyboard' => true, 'electronic' => true));
$this->schema->addValueAliases('Instrument', 'Family', array(
$this->schema->addValueAliases('Instrument.Family', array(
'synth' => 'electronic'));
$config = new HTMLPurifier_Config($this->schema);
@@ -124,9 +120,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
function testNull() {
$this->schema->addNamespace('ReportCard');
$this->schema->add('ReportCard', 'English', null, 'string', true);
$this->schema->add('ReportCard', 'Absences', 0, 'int', false);
$this->schema->add('ReportCard.English', null, 'string', true);
$this->schema->add('ReportCard.Absences', 0, 'int', false);
$config = new HTMLPurifier_Config($this->schema);
$config->autoFinalize = false;
@@ -145,9 +140,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
function testAliases() {
$this->schema->addNamespace('Home');
$this->schema->add('Home', 'Rug', 3, 'int', false);
$this->schema->addAlias('Home', 'Carpet', 'Home', 'Rug');
$this->schema->add('Home.Rug', 3, 'int', false);
$this->schema->addAlias('Home.Carpet', 'Home.Rug');
$config = new HTMLPurifier_Config($this->schema);
$config->autoFinalize = false;
@@ -167,9 +161,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
function test_getBatch() {
$this->schema->addNamespace('Variables');
$this->schema->add('Variables', 'TangentialAcceleration', 'a_tan', 'string', false);
$this->schema->add('Variables', 'AngularAcceleration', 'alpha', 'string', false);
$this->schema->add('Variables.TangentialAcceleration', 'a_tan', 'string', false);
$this->schema->add('Variables.AngularAcceleration', 'alpha', 'string', false);
$config = new HTMLPurifier_Config($this->schema);
$config->autoFinalize = false;
@@ -191,10 +184,9 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
function test_loadIni() {
$this->schema->addNamespace('Shortcut', 'Keyboard shortcuts for commands');
$this->schema->add('Shortcut', 'Copy', 'c', 'istring', false);
$this->schema->add('Shortcut', 'Paste', 'v', 'istring', false);
$this->schema->add('Shortcut', 'Cut', 'x', 'istring', false);
$this->schema->add('Shortcut.Copy', 'c', 'istring', false);
$this->schema->add('Shortcut.Paste', 'v', 'istring', false);
$this->schema->add('Shortcut.Cut', 'x', 'istring', false);
$config = new HTMLPurifier_Config($this->schema);
$config->autoFinalize = false;
@@ -259,9 +251,7 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
}
function test_getDefinition() {
$this->schema->addNamespace('Cache', 'Cache stuff');
$this->schema->add('Cache', 'DefinitionImpl', null, 'string', true);
$this->schema->addNamespace('Crust', 'Krusty Krabs');
$this->schema->add('Cache.DefinitionImpl', null, 'string', true);
$config = new HTMLPurifier_Config($this->schema);
$this->expectException(new HTMLPurifier_Exception("Definition of Crust type not supported"));
$config->getDefinition('Crust');
@@ -269,11 +259,10 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
function test_loadArray() {
// setup a few dummy namespaces/directives for our testing
$this->schema->addNamespace('Zoo');
$this->schema->add('Zoo', 'Aadvark', 0, 'int', false);
$this->schema->add('Zoo', 'Boar', 0, 'int', false);
$this->schema->add('Zoo', 'Camel', 0, 'int', false);
$this->schema->add('Zoo', 'Others', array(), 'list', false);
$this->schema->add('Zoo.Aadvark', 0, 'int', false);
$this->schema->add('Zoo.Boar', 0, 'int', false);
$this->schema->add('Zoo.Camel', 0, 'int', false);
$this->schema->add('Zoo.Others', array(), 'list', false);
$config_manual = new HTMLPurifier_Config($this->schema);
$config_loadabbr = new HTMLPurifier_Config($this->schema);
@@ -309,9 +298,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
function test_create() {
$this->schema->addNamespace('Cake');
$this->schema->add('Cake', 'Sprinkles', 666, 'int', false);
$this->schema->add('Cake', 'Flavor', 'vanilla', 'string', false);
$this->schema->add('Cake.Sprinkles', 666, 'int', false);
$this->schema->add('Cake.Flavor', 'vanilla', 'string', false);
$config = new HTMLPurifier_Config($this->schema);
$config->set('Cake', 'Sprinkles', 42);
@@ -334,8 +322,7 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
// test finalization
$this->schema->addNamespace('Poem');
$this->schema->add('Poem', 'Meter', 'iambic', 'string', false);
$this->schema->add('Poem.Meter', 'iambic', 'string', false);
$config = new HTMLPurifier_Config($this->schema);
$config->autoFinalize = false;
@@ -357,17 +344,15 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
function test_loadArrayFromForm() {
$this->schema->addNamespace('Pancake');
$this->schema->add('Pancake', 'Mix', 'buttermilk', 'string', false);
$this->schema->add('Pancake', 'Served', true, 'bool', false);
$this->schema->addNamespace('Toppings', false);
$this->schema->add('Toppings', 'Syrup', true, 'bool', false);
$this->schema->add('Toppings', 'Flavor', 'maple', 'string', false);
$this->schema->add('Toppings', 'Strawberries', 3, 'int', false);
$this->schema->add('Toppings', 'Calories', 2000, 'int', true);
$this->schema->add('Toppings', 'DefinitionID', null, 'string', true);
$this->schema->add('Toppings', 'DefinitionRev', 1, 'int', false);
$this->schema->add('Toppings', 'Protected', 1, 'int', false);
$this->schema->add('Pancake.Mix', 'buttermilk', 'string', false);
$this->schema->add('Pancake.Served', true, 'bool', false);
$this->schema->add('Toppings.Syrup', true, 'bool', false);
$this->schema->add('Toppings.Flavor', 'maple', 'string', false);
$this->schema->add('Toppings.Strawberries', 3, 'int', false);
$this->schema->add('Toppings.Calories', 2000, 'int', true);
$this->schema->add('Toppings.DefinitionID', null, 'string', true);
$this->schema->add('Toppings.DefinitionRev', 1, 'int', false);
$this->schema->add('Toppings.Protected', 1, 'int', false);
$get = array(
'breakfast' => array(
@@ -418,16 +403,13 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
}
function test_getAllowedDirectivesForForm() {
$this->schema->addNamespace('Unused');
$this->schema->add('Unused', 'Unused', 'Foobar', 'string', false);
$this->schema->addNamespace('Partial');
$this->schema->add('Partial', 'Allowed', true, 'bool', false);
$this->schema->add('Partial', 'Unused', 'Foobar', 'string', false);
$this->schema->addNamespace('All');
$this->schema->add('All', 'Allowed', true, 'bool', false);
$this->schema->add('All', 'Blacklisted', 'Foobar', 'string', false); // explicitly blacklisted
$this->schema->add('All', 'DefinitionID', 'Foobar', 'string', true); // auto-blacklisted
$this->schema->add('All', 'DefinitionRev', 2, 'int', false); // auto-blacklisted
$this->schema->add('Unused.Unused', 'Foobar', 'string', false);
$this->schema->add('Partial.Allowed', true, 'bool', false);
$this->schema->add('Partial.Unused', 'Foobar', 'string', false);
$this->schema->add('All.Allowed', true, 'bool', false);
$this->schema->add('All.Blacklisted', 'Foobar', 'string', false); // explicitly blacklisted
$this->schema->add('All.DefinitionID', 'Foobar', 'string', true); // auto-blacklisted
$this->schema->add('All.DefinitionRev', 2, 'int', false); // auto-blacklisted
$input = array('Partial.Allowed', 'All', '-All.Blacklisted');
$output = HTMLPurifier_Config::getAllowedDirectivesForForm($input, $this->schema);