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-12-06 07:28:20 +00:00
|
|
|
|
2008-01-27 20:21:31 +00:00
|
|
|
protected $schema;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
public function setup() {
|
2008-01-27 20:21:31 +00:00
|
|
|
$this->schema = new HTMLPurifier_ConfigSchema();
|
2006-08-11 20:23:41 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-20 22:59:20 +00:00
|
|
|
function test_define() {
|
2009-02-07 07:53:20 +00:00
|
|
|
$this->schema->add('Car.Seats', 5, 'int', false);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-07 07:53:20 +00:00
|
|
|
$this->assertIdentical($this->schema->defaults['Car.Seats'], 5);
|
|
|
|
$this->assertIdentical($this->schema->info['Car.Seats']->type, HTMLPurifier_VarParser::INT);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-07 07:53:20 +00:00
|
|
|
$this->schema->add('Car.Age', null, 'int', true);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-07 07:53:20 +00:00
|
|
|
$this->assertIdentical($this->schema->defaults['Car.Age'], null);
|
|
|
|
$this->assertIdentical($this->schema->info['Car.Age']->type, HTMLPurifier_VarParser::INT);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-20 22:59:20 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-20 22:59:20 +00:00
|
|
|
function test_defineAllowedValues() {
|
2009-02-07 07:53:20 +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);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-01-27 20:21:31 +00:00
|
|
|
$this->schema->addAllowedValues( // okay, since default is null
|
2009-02-07 07:53:20 +00:00
|
|
|
'QuantumNumber.Difficulty', array('easy' => true, 'medium' => true, 'hard' => true)
|
2007-01-20 22:59:20 +00:00
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-07 07:53:20 +00:00
|
|
|
$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,
|
2008-05-23 16:43:24 +00:00
|
|
|
array(
|
|
|
|
'easy' => true,
|
|
|
|
'medium' => true,
|
|
|
|
'hard' => true
|
2006-08-27 18:49:16 +00:00
|
|
|
)
|
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-20 22:59:20 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-20 22:59:20 +00:00
|
|
|
function test_defineValueAliases() {
|
2009-02-07 07:53:20 +00:00
|
|
|
$this->schema->add('Abbrev.HTH', 'Happy to Help', 'string', false);
|
2008-01-27 20:21:31 +00:00
|
|
|
$this->schema->addAllowedValues(
|
2009-02-07 07:53: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(
|
2009-02-07 07:53:20 +00:00
|
|
|
'Abbrev.HTH', array(
|
2007-01-20 22:59:20 +00:00
|
|
|
'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
|
2009-02-07 07:53:20 +00:00
|
|
|
'Abbrev.HTH', array(
|
2007-01-20 22:59:20 +00:00
|
|
|
'hail' => 'HAIL THE HAND!'
|
2006-08-27 18:49:16 +00:00
|
|
|
)
|
2007-01-20 22:59:20 +00:00
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-07 07:53:20 +00:00
|
|
|
$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,
|
2008-05-23 16:43:24 +00:00
|
|
|
array(
|
|
|
|
'Happy to Help' => true,
|
|
|
|
'Hope that Helps' => true,
|
|
|
|
'HAIL THE HAND!' => true
|
|
|
|
)
|
|
|
|
);
|
2009-02-07 07:53:20 +00:00
|
|
|
$this->assertIdentical($this->schema->info['Abbrev.HTH']->aliases,
|
2008-05-23 16:43:24 +00:00
|
|
|
array(
|
|
|
|
'happy' => 'Happy to Help',
|
|
|
|
'hope' => 'Hope that Helps',
|
|
|
|
'hail' => 'HAIL THE HAND!'
|
2007-01-20 22:59:20 +00:00
|
|
|
)
|
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-20 22:59:20 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-20 22:59:20 +00:00
|
|
|
function testAlias() {
|
2009-02-07 07:53:20 +00:00
|
|
|
$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']->key, 'Home.Rug');
|
|
|
|
$this->assertIdentical($this->schema->info['Home.Carpet']->isAlias, true);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-27 18:49:16 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-11 20:23:41 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|