Improve auto-paragraph to preserve newlines and handle edge-cases better.
[htmlpurifier.git] / tests / HTMLPurifier / ConfigSchemaTest.php
blob9020a3b65df54a5acc7771863a0ce5c93d014743
1 <?php
3 class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness
6 protected $schema;
8 public function setup() {
9 $this->schema = new HTMLPurifier_ConfigSchema();
12 function test_defineNamespace() {
13 $this->schema->addNamespace('http');
14 $this->assertIdentical($this->schema->info['http'], array());
15 $this->assertIdentical($this->schema->defaults['http'], array());
18 function test_define() {
19 $this->schema->addNamespace('Car');
21 $this->schema->add('Car', 'Seats', 5, 'int', false);
23 $this->assertIdentical($this->schema->defaults['Car']['Seats'], 5);
24 $this->assertIdentical($this->schema->info['Car']['Seats']->type, HTMLPurifier_VarParser::INT);
26 $this->schema->add('Car', 'Age', null, 'int', true);
28 $this->assertIdentical($this->schema->defaults['Car']['Age'], null);
29 $this->assertIdentical($this->schema->info['Car']['Age']->type, HTMLPurifier_VarParser::INT);
33 function test_defineAllowedValues() {
34 $this->schema->addNamespace('QuantumNumber', 'D');
35 $this->schema->add('QuantumNumber', 'Spin', 0.5, 'float', false);
36 $this->schema->add('QuantumNumber', 'Current', 's', 'string', false);
37 $this->schema->add('QuantumNumber', 'Difficulty', null, 'string', true);
39 $this->schema->addAllowedValues( // okay, since default is null
40 'QuantumNumber', 'Difficulty', array('easy' => true, 'medium' => true, 'hard' => true)
43 $this->assertIdentical($this->schema->defaults['QuantumNumber']['Difficulty'], null);
44 $this->assertIdentical($this->schema->info['QuantumNumber']['Difficulty']->type, HTMLPurifier_VarParser::STRING);
45 $this->assertIdentical($this->schema->info['QuantumNumber']['Difficulty']->allow_null, true);
46 $this->assertIdentical($this->schema->info['QuantumNumber']['Difficulty']->allowed,
47 array(
48 'easy' => true,
49 'medium' => true,
50 'hard' => true
56 function test_defineValueAliases() {
57 $this->schema->addNamespace('Abbrev', 'Stuff on abbreviations.');
58 $this->schema->add('Abbrev', 'HTH', 'Happy to Help', 'string', false);
59 $this->schema->addAllowedValues(
60 'Abbrev', 'HTH', array(
61 'Happy to Help' => true,
62 'Hope that Helps' => true,
63 'HAIL THE HAND!' => true,
66 $this->schema->addValueAliases(
67 'Abbrev', 'HTH', array(
68 'happy' => 'Happy to Help',
69 'hope' => 'Hope that Helps'
72 $this->schema->addValueAliases( // delayed addition
73 'Abbrev', 'HTH', array(
74 'hail' => 'HAIL THE HAND!'
78 $this->assertIdentical($this->schema->defaults['Abbrev']['HTH'], 'Happy to Help');
79 $this->assertIdentical($this->schema->info['Abbrev']['HTH']->type, HTMLPurifier_VarParser::STRING);
80 $this->assertIdentical($this->schema->info['Abbrev']['HTH']->allowed,
81 array(
82 'Happy to Help' => true,
83 'Hope that Helps' => true,
84 'HAIL THE HAND!' => true
87 $this->assertIdentical($this->schema->info['Abbrev']['HTH']->aliases,
88 array(
89 'happy' => 'Happy to Help',
90 'hope' => 'Hope that Helps',
91 'hail' => 'HAIL THE HAND!'
97 function testAlias() {
98 $this->schema->addNamespace('Home');
99 $this->schema->add('Home', 'Rug', 3, 'int', false);
100 $this->schema->addAlias('Home', 'Carpet', 'Home', 'Rug');
102 $this->assertTrue(!isset($this->schema->defaults['Home']['Carpet']));
103 $this->assertIdentical($this->schema->info['Home']['Carpet']->namespace, 'Home');
104 $this->assertIdentical($this->schema->info['Home']['Carpet']->name, 'Rug');
105 $this->assertIdentical($this->schema->info['Home']['Carpet']->isAlias, true);