mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-12-22 08:21:52 +00:00
[3.1.0] Initial commit of adapter functionality; not complete.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1524 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
41e3c091e1
commit
3baf1774b2
22
extras/ConfigSchema/StringHashAdapter.php
Normal file
22
extras/ConfigSchema/StringHashAdapter.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes an array of keys to strings, probably generated by
|
||||||
|
* ConfigSchema_StringHashParser
|
||||||
|
*/
|
||||||
|
class ConfigSchema_StringHashAdapter
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes a string hash and calls the appropriate functions in $schema
|
||||||
|
* based on its values.
|
||||||
|
*/
|
||||||
|
public function adapt($hash, $schema) {
|
||||||
|
list($ns, $directive) = explode('.', $hash['ID'], 2);
|
||||||
|
$default = eval("return {$hash['DEFAULT']};");
|
||||||
|
$type = $hash['TYPE'];
|
||||||
|
$description = $hash['DESCRIPTION'];
|
||||||
|
$schema->add($ns, $directive, $default, $type, $description);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
35
tests/ConfigSchema/StringHashAdapterTest.php
Normal file
35
tests/ConfigSchema/StringHashAdapterTest.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class ConfigSchema_StringHashAdapterTest extends UnitTestCase
|
||||||
|
{
|
||||||
|
function __construct() {
|
||||||
|
generate_mock_once('HTMLPurifier_ConfigSchema');
|
||||||
|
parent::UnitTestCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
function assertAdapt($input, $calls) {
|
||||||
|
$schema = new HTMLPurifier_ConfigSchemaMock();
|
||||||
|
foreach ($calls as $func => $params) {
|
||||||
|
$schema->expectOnce($func, $params);
|
||||||
|
}
|
||||||
|
$adapter = new ConfigSchema_StringHashAdapter();
|
||||||
|
$adapter->adapt($input, $schema);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testBasic() {
|
||||||
|
$this->assertAdapt(
|
||||||
|
array(
|
||||||
|
'ID' => 'Namespace.Directive',
|
||||||
|
'DEFAULT' => "'default' . 'bar'",
|
||||||
|
'TYPE' => 'string',
|
||||||
|
'DESCRIPTION' => "Description of default.\n",
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'add' => array(
|
||||||
|
'Namespace', 'Directive', 'defaultbar', 'string',
|
||||||
|
"Description of default.\n"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -136,4 +136,5 @@ $test_files[] = 'FSTools/FileTest.php';
|
|||||||
|
|
||||||
// ConfigSchema auxiliary library
|
// ConfigSchema auxiliary library
|
||||||
|
|
||||||
|
$test_files[] = 'ConfigSchema/StringHashAdapterTest.php';
|
||||||
$test_files[] = 'ConfigSchema/StringHashParserTest.php';
|
$test_files[] = 'ConfigSchema/StringHashParserTest.php';
|
||||||
|
Loading…
Reference in New Issue
Block a user