2006-08-11 20:23:41 +00:00
|
|
|
<?php
|
|
|
|
|
2007-08-01 14:06:59 +00:00
|
|
|
class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness
|
2006-08-11 20:23:41 +00:00
|
|
|
{
|
|
|
|
|
2008-01-27 20:21:31 +00:00
|
|
|
protected $schema;
|
2007-01-20 22:59:20 +00:00
|
|
|
|
2008-01-27 20:21:31 +00:00
|
|
|
function setup() {
|
|
|
|
$this->schema = new HTMLPurifier_ConfigSchema();
|
2006-08-11 20:23:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function tearDown() {
|
2007-02-17 19:37:48 +00:00
|
|
|
tally_errors($this);
|
2007-01-20 22:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_defineNamespace() {
|
2008-03-22 03:55:59 +00:00
|
|
|
$this->schema->addNamespace('http');
|
|
|
|
$this->assertIdentical($this->schema->info['http'], array());
|
|
|
|
$this->assertIdentical($this->schema->defaults['http'], array());
|
2007-01-20 22:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_define() {
|
2008-03-22 03:55:59 +00:00
|
|
|
$this->schema->addNamespace('Car');
|
2006-08-27 18:49:16 +00:00
|
|
|
|
2008-03-22 03:55:59 +00:00
|
|
|
$this->schema->add('Car', 'Seats', 5, 'int', false);
|
2006-08-27 18:49:16 +00:00
|
|
|
|
2008-01-27 20:21:31 +00:00
|
|
|
$this->assertIdentical($this->schema->defaults['Car']['Seats'], 5);
|
|
|
|
$this->assertIdentical($this->schema->info['Car']['Seats'],
|
2008-03-22 03:55:59 +00:00
|
|
|
new HTMLPurifier_ConfigDef_Directive('int')
|
2006-08-27 18:49:16 +00:00
|
|
|
);
|
2006-08-11 20:23:41 +00:00
|
|
|
|
2008-03-22 03:55:59 +00:00
|
|
|
$this->schema->add('Car', 'Age', null, 'int', true);
|
2006-08-27 18:49:16 +00:00
|
|
|
|
2008-01-27 20:21:31 +00:00
|
|
|
$this->assertIdentical($this->schema->defaults['Car']['Age'], null);
|
|
|
|
$this->assertIdentical($this->schema->info['Car']['Age'],
|
2008-03-22 03:55:59 +00:00
|
|
|
new HTMLPurifier_ConfigDef_Directive('int', true)
|
2007-01-20 22:59:20 +00:00
|
|
|
);
|
2006-08-27 18:49:16 +00:00
|
|
|
|
2007-01-20 22:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_defineAllowedValues() {
|
2008-01-27 20:21:31 +00:00
|
|
|
$this->schema->addNamespace('QuantumNumber', 'D');
|
2008-03-22 03:55:59 +00:00
|
|
|
$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);
|
2007-01-20 22:59:20 +00:00
|
|
|
|
2008-01-27 20:21:31 +00:00
|
|
|
$this->schema->addAllowedValues( // okay, since default is null
|
2008-03-22 03:55:59 +00:00
|
|
|
'QuantumNumber', 'Difficulty', array('easy' => true, 'medium' => true, 'hard' => true)
|
2007-01-20 22:59:20 +00:00
|
|
|
);
|
2006-08-27 18:49:16 +00:00
|
|
|
|
2008-01-27 20:21:31 +00:00
|
|
|
$this->assertIdentical($this->schema->defaults['QuantumNumber']['Difficulty'], null);
|
|
|
|
$this->assertIdentical($this->schema->info['QuantumNumber']['Difficulty'],
|
2007-02-05 03:22:32 +00:00
|
|
|
new HTMLPurifier_ConfigDef_Directive(
|
2007-01-20 22:59:20 +00:00
|
|
|
'string',
|
|
|
|
true,
|
|
|
|
array(
|
|
|
|
'easy' => true,
|
|
|
|
'medium' => true,
|
|
|
|
'hard' => true
|
|
|
|
)
|
2006-08-27 18:49:16 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2007-01-20 22:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_defineValueAliases() {
|
2008-01-27 20:21:31 +00:00
|
|
|
$this->schema->addNamespace('Abbrev', 'Stuff on abbreviations.');
|
2008-03-22 03:55:59 +00:00
|
|
|
$this->schema->add('Abbrev', 'HTH', 'Happy to Help', 'string', false);
|
2008-01-27 20:21:31 +00:00
|
|
|
$this->schema->addAllowedValues(
|
2007-01-20 22:59:20 +00:00
|
|
|
'Abbrev', 'HTH', array(
|
2008-03-22 03:55:59 +00:00
|
|
|
'Happy to Help' => true,
|
|
|
|
'Hope that Helps' => true,
|
|
|
|
'HAIL THE HAND!' => true,
|
2006-08-27 18:49:16 +00:00
|
|
|
)
|
2007-01-20 22:59:20 +00:00
|
|
|
);
|
2008-01-27 20:21:31 +00:00
|
|
|
$this->schema->addValueAliases(
|
2007-01-20 22:59:20 +00:00
|
|
|
'Abbrev', 'HTH', array(
|
|
|
|
'happy' => 'Happy to Help',
|
|
|
|
'hope' => 'Hope that Helps'
|
2006-08-27 18:49:16 +00:00
|
|
|
)
|
|
|
|
);
|
2008-01-27 20:21:31 +00:00
|
|
|
$this->schema->addValueAliases( // delayed addition
|
2007-01-20 22:59:20 +00:00
|
|
|
'Abbrev', 'HTH', array(
|
|
|
|
'hail' => 'HAIL THE HAND!'
|
2006-08-27 18:49:16 +00:00
|
|
|
)
|
2007-01-20 22:59:20 +00:00
|
|
|
);
|
2006-08-27 18:49:16 +00:00
|
|
|
|
2008-01-27 20:21:31 +00:00
|
|
|
$this->assertIdentical($this->schema->defaults['Abbrev']['HTH'], 'Happy to Help');
|
|
|
|
$this->assertIdentical($this->schema->info['Abbrev']['HTH'],
|
2007-02-05 03:22:32 +00:00
|
|
|
new HTMLPurifier_ConfigDef_Directive(
|
2007-01-20 22:59:20 +00:00
|
|
|
'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!'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2006-08-27 18:49:16 +00:00
|
|
|
|
2007-01-20 22:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testAlias() {
|
2008-03-22 03:55:59 +00:00
|
|
|
$this->schema->addNamespace('Home');
|
|
|
|
$this->schema->add('Home', 'Rug', 3, 'int', false);
|
2008-01-27 20:21:31 +00:00
|
|
|
$this->schema->addAlias('Home', 'Carpet', 'Home', 'Rug');
|
2007-01-20 22:59:20 +00:00
|
|
|
|
2008-01-27 20:21:31 +00:00
|
|
|
$this->assertTrue(!isset($this->schema->defaults['Home']['Carpet']));
|
|
|
|
$this->assertIdentical($this->schema->info['Home']['Carpet'],
|
2007-02-05 03:22:32 +00:00
|
|
|
new HTMLPurifier_ConfigDef_DirectiveAlias('Home', 'Rug')
|
2006-09-06 02:07:46 +00:00
|
|
|
);
|
|
|
|
|
2006-08-27 18:49:16 +00:00
|
|
|
}
|
|
|
|
|
2006-08-11 20:23:41 +00:00
|
|
|
}
|
|
|
|
|