mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-12-23 17:01:51 +00:00
ec59062a9d
- Optimize ConfigSchema by removing non-essential runtime data. We can probably optimize even more by collapsing object structures to arrays. - Removed validation data from ConfigSchema; this will be reimplemented on Interchange - Implement a sane Interchange composite hierarchy that doesn't use arrays - Implement StringHash -> Interchange -> ConfigSchema, and rewrite maintenance file to account for this git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1615 48356398-32a2-884e-a903-53898d9a118a
122 lines
4.0 KiB
PHP
122 lines
4.0 KiB
PHP
<?php
|
|
|
|
class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness
|
|
{
|
|
|
|
protected $schema;
|
|
|
|
function setup() {
|
|
$this->schema = new HTMLPurifier_ConfigSchema();
|
|
}
|
|
|
|
function tearDown() {
|
|
tally_errors($this);
|
|
}
|
|
|
|
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->assertIdentical($this->schema->defaults['Car']['Seats'], 5);
|
|
$this->assertIdentical($this->schema->info['Car']['Seats'],
|
|
new HTMLPurifier_ConfigDef_Directive('int')
|
|
);
|
|
|
|
$this->schema->add('Car', 'Age', null, 'int', true);
|
|
|
|
$this->assertIdentical($this->schema->defaults['Car']['Age'], null);
|
|
$this->assertIdentical($this->schema->info['Car']['Age'],
|
|
new HTMLPurifier_ConfigDef_Directive('int', true)
|
|
);
|
|
|
|
}
|
|
|
|
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->addAllowedValues( // okay, since default is null
|
|
'QuantumNumber', 'Difficulty', array('easy' => true, 'medium' => true, 'hard' => true)
|
|
);
|
|
|
|
$this->assertIdentical($this->schema->defaults['QuantumNumber']['Difficulty'], null);
|
|
$this->assertIdentical($this->schema->info['QuantumNumber']['Difficulty'],
|
|
new HTMLPurifier_ConfigDef_Directive(
|
|
'string',
|
|
true,
|
|
array(
|
|
'easy' => true,
|
|
'medium' => true,
|
|
'hard' => true
|
|
)
|
|
)
|
|
);
|
|
|
|
}
|
|
|
|
function test_defineValueAliases() {
|
|
$this->schema->addNamespace('Abbrev', 'Stuff on abbreviations.');
|
|
$this->schema->add('Abbrev', 'HTH', 'Happy to Help', 'string', false);
|
|
$this->schema->addAllowedValues(
|
|
'Abbrev', 'HTH', array(
|
|
'Happy to Help' => true,
|
|
'Hope that Helps' => true,
|
|
'HAIL THE HAND!' => true,
|
|
)
|
|
);
|
|
$this->schema->addValueAliases(
|
|
'Abbrev', 'HTH', array(
|
|
'happy' => 'Happy to Help',
|
|
'hope' => 'Hope that Helps'
|
|
)
|
|
);
|
|
$this->schema->addValueAliases( // delayed addition
|
|
'Abbrev', 'HTH', array(
|
|
'hail' => 'HAIL THE HAND!'
|
|
)
|
|
);
|
|
|
|
$this->assertIdentical($this->schema->defaults['Abbrev']['HTH'], 'Happy to Help');
|
|
$this->assertIdentical($this->schema->info['Abbrev']['HTH'],
|
|
new HTMLPurifier_ConfigDef_Directive(
|
|
'string',
|
|
false,
|
|
array(
|
|
'Happy to Help' => true,
|
|
'Hope that Helps' => true,
|
|
'HAIL THE HAND!' => true
|
|
),
|
|
array(
|
|
'happy' => 'Happy to Help',
|
|
'hope' => 'Hope that Helps',
|
|
'hail' => 'HAIL THE HAND!'
|
|
)
|
|
)
|
|
);
|
|
|
|
}
|
|
|
|
function testAlias() {
|
|
$this->schema->addNamespace('Home');
|
|
$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'],
|
|
new HTMLPurifier_ConfigDef_DirectiveAlias('Home', 'Rug')
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|