mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-15 01:28:42 +00:00
002fe649f7
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1576 48356398-32a2-884e-a903-53898d9a118a
138 lines
4.2 KiB
PHP
138 lines
4.2 KiB
PHP
<?php
|
|
|
|
class HTMLPurifier_ConfigSchema_StringHashAdapterTest extends UnitTestCase
|
|
{
|
|
function __construct() {
|
|
generate_mock_once('HTMLPurifier_ConfigSchema');
|
|
parent::UnitTestCase();
|
|
}
|
|
|
|
function assertAdapt($input, $calls = array()) {
|
|
$schema = new HTMLPurifier_ConfigSchemaMock();
|
|
$called = array();
|
|
foreach ($calls as $signature) {
|
|
list($func, $params) = $signature;
|
|
if (!isset($called[$func])) $called[$func] = 0;
|
|
$schema->expectAt($called[$func]++, $func, $params);
|
|
}
|
|
$adapter = new HTMLPurifier_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(
|
|
array('add', array(
|
|
'Namespace', 'Directive', 'defaultbar', 'string',
|
|
"Description of default.\n"
|
|
)),
|
|
)
|
|
);
|
|
}
|
|
|
|
function testNamespace() {
|
|
$this->assertAdapt(
|
|
array(
|
|
'ID' => 'Namespace',
|
|
'DESCRIPTION' => 'Description of namespace',
|
|
),
|
|
array(
|
|
array('addNamespace', array('Namespace', 'Description of namespace')),
|
|
)
|
|
);
|
|
}
|
|
|
|
function testValueAliases() {
|
|
$this->assertAdapt(
|
|
array(
|
|
'ID' => 'Ns.Dir',
|
|
'VALUE-ALIASES' => "
|
|
'milk' => 'dairy',
|
|
'cheese' => 'dairy',
|
|
",
|
|
),
|
|
array(
|
|
array('addValueAliases', array('Ns', 'Dir', array('milk' => 'dairy', 'cheese' => 'dairy'))),
|
|
)
|
|
);
|
|
}
|
|
|
|
function testAllowedValues() {
|
|
$this->assertAdapt(
|
|
array(
|
|
'ID' => 'Ns.Dir',
|
|
'ALLOWED' => "'val1', 'val2'",
|
|
),
|
|
array(
|
|
array('addAllowedValues', array('Ns', 'Dir', array('val1', 'val2'))),
|
|
)
|
|
);
|
|
}
|
|
|
|
function testAlias() {
|
|
$this->assertAdapt(
|
|
array(
|
|
'ID' => 'Ns.Dir',
|
|
'ALIASES' => "Ns.Dir2, Ns2.Dir",
|
|
),
|
|
array(
|
|
array('addAlias', array('Ns', 'Dir2', 'Ns', 'Dir')),
|
|
array('addAlias', array('Ns2', 'Dir', 'Ns', 'Dir')),
|
|
)
|
|
);
|
|
}
|
|
|
|
function testCombo() {
|
|
$this->assertAdapt(
|
|
array(
|
|
'ID' => 'Ns.Dir',
|
|
'DEFAULT' => "'val' . '1'",
|
|
'TYPE' => 'string',
|
|
'DESCRIPTION' => "Description of default.\n",
|
|
'VALUE-ALIASES' => "
|
|
'milk' => 'val1',
|
|
'cheese' => 'val1',
|
|
",
|
|
'ALLOWED' => "'val1', 'val2'",
|
|
'ALIASES' => "Ns.Dir2, Ns2.Dir",
|
|
),
|
|
array(
|
|
array('add', array(
|
|
'Ns', 'Dir', 'val1', 'string',
|
|
"Description of default.\n"
|
|
)),
|
|
array('addAllowedValues', array('Ns', 'Dir', array('val1', 'val2'))),
|
|
array('addValueAliases', array('Ns', 'Dir', array('milk' => 'val1', 'cheese' => 'val1'))),
|
|
array('addAlias', array('Ns', 'Dir2', 'Ns', 'Dir')),
|
|
array('addAlias', array('Ns2', 'Dir', 'Ns', 'Dir')),
|
|
)
|
|
);
|
|
}
|
|
|
|
function testMissingIdError() {
|
|
$this->expectError('Missing key ID in string hash');
|
|
$this->assertAdapt(array());
|
|
}
|
|
|
|
function testExtraError() {
|
|
$this->expectError("String hash key 'FOOBAR' not used by adapter");
|
|
$this->assertAdapt(
|
|
array(
|
|
'ID' => 'Namespace',
|
|
'DESCRIPTION' => 'Description of namespace',
|
|
'FOOBAR' => 'Extra stuff',
|
|
),
|
|
array(
|
|
array('addNamespace', array('Namespace', 'Description of namespace')),
|
|
)
|
|
);
|
|
}
|
|
|
|
}
|