2008-01-27 19:59:12 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class ConfigSchema_StringHashAdapterTest extends UnitTestCase
|
|
|
|
{
|
|
|
|
function __construct() {
|
|
|
|
generate_mock_once('HTMLPurifier_ConfigSchema');
|
|
|
|
parent::UnitTestCase();
|
|
|
|
}
|
|
|
|
|
2008-02-05 01:54:20 +00:00
|
|
|
function assertAdapt($input, $calls = array()) {
|
2008-01-27 19:59:12 +00:00
|
|
|
$schema = new HTMLPurifier_ConfigSchemaMock();
|
2008-02-05 21:04:00 +00:00
|
|
|
$called = array();
|
|
|
|
foreach ($calls as $signature) {
|
|
|
|
list($func, $params) = $signature;
|
|
|
|
if (!isset($called[$func])) $called[$func] = 0;
|
|
|
|
$schema->expectAt($called[$func]++, $func, $params);
|
2008-01-27 19:59:12 +00:00
|
|
|
}
|
|
|
|
$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(
|
2008-02-05 21:04:00 +00:00
|
|
|
array('add', array(
|
2008-01-27 19:59:12 +00:00
|
|
|
'Namespace', 'Directive', 'defaultbar', 'string',
|
|
|
|
"Description of default.\n"
|
2008-02-05 21:04:00 +00:00
|
|
|
)),
|
2008-01-27 19:59:12 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2008-02-05 01:54:20 +00:00
|
|
|
|
|
|
|
function testNamespace() {
|
|
|
|
$this->assertAdapt(
|
|
|
|
array(
|
|
|
|
'ID' => 'Namespace',
|
2008-02-05 21:04:00 +00:00
|
|
|
'DESCRIPTION' => 'Description of namespace',
|
2008-02-05 01:54:20 +00:00
|
|
|
),
|
|
|
|
array(
|
2008-02-05 21:04:00 +00:00
|
|
|
array('addNamespace', array('Namespace', 'Description of namespace')),
|
2008-02-05 01:54:20 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-02-05 21:04:00 +00:00
|
|
|
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(
|
2008-02-07 17:41:40 +00:00
|
|
|
array('addAlias', array('Ns', 'Dir2', 'Ns', 'Dir')),
|
|
|
|
array('addAlias', array('Ns2', 'Dir', 'Ns', 'Dir')),
|
2008-02-05 21:04:00 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testCombo() {
|
|
|
|
$this->assertAdapt(
|
|
|
|
array(
|
|
|
|
'ID' => 'Ns.Dir',
|
2008-02-07 17:41:40 +00:00
|
|
|
'DEFAULT' => "'val' . '1'",
|
2008-02-05 21:04:00 +00:00
|
|
|
'TYPE' => 'string',
|
|
|
|
'DESCRIPTION' => "Description of default.\n",
|
|
|
|
'VALUE-ALIASES' => "
|
2008-02-07 17:41:40 +00:00
|
|
|
'milk' => 'val1',
|
|
|
|
'cheese' => 'val1',
|
2008-02-05 21:04:00 +00:00
|
|
|
",
|
|
|
|
'ALLOWED' => "'val1', 'val2'",
|
|
|
|
'ALIASES' => "Ns.Dir2, Ns2.Dir",
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
array('add', array(
|
2008-02-07 17:41:40 +00:00
|
|
|
'Ns', 'Dir', 'val1', 'string',
|
2008-02-05 21:04:00 +00:00
|
|
|
"Description of default.\n"
|
|
|
|
)),
|
|
|
|
array('addAllowedValues', array('Ns', 'Dir', array('val1', 'val2'))),
|
2008-02-07 17:41:40 +00:00
|
|
|
array('addValueAliases', array('Ns', 'Dir', array('milk' => 'val1', 'cheese' => 'val1'))),
|
|
|
|
array('addAlias', array('Ns', 'Dir2', 'Ns', 'Dir')),
|
|
|
|
array('addAlias', array('Ns2', 'Dir', 'Ns', 'Dir')),
|
2008-02-05 21:04:00 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testMissingIdError() {
|
2008-02-05 01:54:20 +00:00
|
|
|
$this->expectError('Missing key ID in string hash');
|
|
|
|
$this->assertAdapt(array());
|
|
|
|
}
|
|
|
|
|
2008-02-05 21:04:00 +00:00
|
|
|
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')),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2008-02-05 01:54:20 +00:00
|
|
|
|
2008-01-27 19:59:12 +00:00
|
|
|
}
|