0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-23 08:51:53 +00:00
htmlpurifier/tests/ConfigSchema/StringHashReverseAdapterTest.php

61 lines
2.1 KiB
PHP

<?php
class ConfigSchema_StringHashReverseAdapterTest extends UnitTestCase
{
function makeSchema() {
$schema = new HTMLPurifier_ConfigSchema();
$schema->addNamespace('Ns', 'Description of ns.');
$schema->addNamespace('Ns2', 'Description of ns2.');
$schema->add('Ns', 'Dir', 'dairy', 'string',
"Description of default.\n");
$schema->addAllowedValues('Ns', 'Dir', array('dairy', 'meat'));
$schema->addValueAliases('Ns', 'Dir', array('milk' => 'dairy', 'cheese' => 'dairy'));
$schema->addAlias('Ns', 'Dir2', 'Ns', 'Dir');
$schema->addAlias('Ns2', 'Dir', 'Ns', 'Dir');
return $schema;
}
function testNamespace() {
$adapter = new ConfigSchema_StringHashReverseAdapter($this->makeSchema());
$result = $adapter->get('Ns');
$expect = array(
'ID' => 'Ns',
'DESCRIPTION' => "Description of ns.",
);
$this->assertIdentical($result, $expect);
}
function testBadNamespace() {
$adapter = new ConfigSchema_StringHashReverseAdapter($this->makeSchema());
$this->expectError("Namespace 'BadNs' doesn't exist in schema");
$adapter->get('BadNs');
}
function testDirective() {
$adapter = new ConfigSchema_StringHashReverseAdapter($this->makeSchema());
$result = $adapter->get('Ns', 'Dir');
$expect = array(
'ID' => 'Ns.Dir',
'TYPE' => 'string',
'DEFAULT' => "'dairy'",
'DESCRIPTION' => "Description of default.\n",
'ALLOWED' => "'dairy', 'meat'",
'VALUE-ALIASES' => "'milk' => 'dairy',\n'cheese' => 'dairy',\n",
'ALIASES' => "Ns.Dir2, Ns2.Dir",
);
$this->assertIdentical($result, $expect);
}
function testBadDirective() {
$adapter = new ConfigSchema_StringHashReverseAdapter($this->makeSchema());
$this->expectError("Directive 'BadNs.BadDir' doesn't exist in schema");
$adapter->get('BadNs', 'BadDir');
}
}