mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-16 02:53:58 +02:00
Implement ReverseAdapter. Also, debug some order of execution things in the Adapter.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1532 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -82,8 +82,8 @@ class ConfigSchema_StringHashAdapterTest extends UnitTestCase
|
||||
'ALIASES' => "Ns.Dir2, Ns2.Dir",
|
||||
),
|
||||
array(
|
||||
array('addAlias', array('Ns', 'Dir', 'Ns', 'Dir2')),
|
||||
array('addAlias', array('Ns', 'Dir', 'Ns2', 'Dir')),
|
||||
array('addAlias', array('Ns', 'Dir2', 'Ns', 'Dir')),
|
||||
array('addAlias', array('Ns2', 'Dir', 'Ns', 'Dir')),
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -92,25 +92,25 @@ class ConfigSchema_StringHashAdapterTest extends UnitTestCase
|
||||
$this->assertAdapt(
|
||||
array(
|
||||
'ID' => 'Ns.Dir',
|
||||
'DEFAULT' => "'default' . 'bar'",
|
||||
'DEFAULT' => "'val' . '1'",
|
||||
'TYPE' => 'string',
|
||||
'DESCRIPTION' => "Description of default.\n",
|
||||
'VALUE-ALIASES' => "
|
||||
'milk' => 'dairy',
|
||||
'cheese' => 'dairy',
|
||||
'milk' => 'val1',
|
||||
'cheese' => 'val1',
|
||||
",
|
||||
'ALLOWED' => "'val1', 'val2'",
|
||||
'ALIASES' => "Ns.Dir2, Ns2.Dir",
|
||||
),
|
||||
array(
|
||||
array('add', array(
|
||||
'Ns', 'Dir', 'defaultbar', 'string',
|
||||
'Ns', 'Dir', 'val1', 'string',
|
||||
"Description of default.\n"
|
||||
)),
|
||||
array('addValueAliases', array('Ns', 'Dir', array('milk' => 'dairy', 'cheese' => 'dairy'))),
|
||||
array('addAllowedValues', array('Ns', 'Dir', array('val1', 'val2'))),
|
||||
array('addAlias', array('Ns', 'Dir', 'Ns', 'Dir2')),
|
||||
array('addAlias', array('Ns', 'Dir', 'Ns2', 'Dir')),
|
||||
array('addValueAliases', array('Ns', 'Dir', array('milk' => 'val1', 'cheese' => 'val1'))),
|
||||
array('addAlias', array('Ns', 'Dir2', 'Ns', 'Dir')),
|
||||
array('addAlias', array('Ns2', 'Dir', 'Ns', 'Dir')),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
60
tests/ConfigSchema/StringHashReverseAdapterTest.php
Normal file
60
tests/ConfigSchema/StringHashReverseAdapterTest.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?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');
|
||||
}
|
||||
|
||||
}
|
@@ -137,5 +137,6 @@ $test_files[] = 'FSTools/FileTest.php';
|
||||
// ConfigSchema auxiliary library
|
||||
|
||||
$test_files[] = 'ConfigSchema/StringHashAdapterTest.php';
|
||||
$test_files[] = 'ConfigSchema/StringHashReverseAdapterTest.php';
|
||||
$test_files[] = 'ConfigSchema/StringHashParserTest.php';
|
||||
$test_files[] = 'ConfigSchema/StringHashTest.php';
|
||||
|
Reference in New Issue
Block a user