mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-31 03:10:09 +02:00
Complete Adapter implementation, also unit-test keys with dashes in them in parser.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1531 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -9,8 +9,11 @@ class ConfigSchema_StringHashAdapterTest extends UnitTestCase
|
||||
|
||||
function assertAdapt($input, $calls = array()) {
|
||||
$schema = new HTMLPurifier_ConfigSchemaMock();
|
||||
foreach ($calls as $func => $params) {
|
||||
$schema->expectOnce($func, $params);
|
||||
$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 ConfigSchema_StringHashAdapter();
|
||||
$adapter->adapt($input, $schema);
|
||||
@@ -25,10 +28,10 @@ class ConfigSchema_StringHashAdapterTest extends UnitTestCase
|
||||
'DESCRIPTION' => "Description of default.\n",
|
||||
),
|
||||
array(
|
||||
'add' => array(
|
||||
array('add', array(
|
||||
'Namespace', 'Directive', 'defaultbar', 'string',
|
||||
"Description of default.\n"
|
||||
)
|
||||
)),
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -37,19 +40,98 @@ class ConfigSchema_StringHashAdapterTest extends UnitTestCase
|
||||
$this->assertAdapt(
|
||||
array(
|
||||
'ID' => 'Namespace',
|
||||
'DESCRIPTION' => 'Description of namespace'
|
||||
'DESCRIPTION' => 'Description of namespace',
|
||||
),
|
||||
array(
|
||||
'addNamespace' => array('Namespace', 'Description of namespace'),
|
||||
array('addNamespace', array('Namespace', 'Description of namespace')),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function testMissingId() {
|
||||
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', 'Dir', 'Ns', 'Dir2')),
|
||||
array('addAlias', array('Ns', 'Dir', 'Ns2', 'Dir')),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function testCombo() {
|
||||
$this->assertAdapt(
|
||||
array(
|
||||
'ID' => 'Ns.Dir',
|
||||
'DEFAULT' => "'default' . 'bar'",
|
||||
'TYPE' => 'string',
|
||||
'DESCRIPTION' => "Description of default.\n",
|
||||
'VALUE-ALIASES' => "
|
||||
'milk' => 'dairy',
|
||||
'cheese' => 'dairy',
|
||||
",
|
||||
'ALLOWED' => "'val1', 'val2'",
|
||||
'ALIASES' => "Ns.Dir2, Ns2.Dir",
|
||||
),
|
||||
array(
|
||||
array('add', array(
|
||||
'Ns', 'Dir', 'defaultbar', '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')),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
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')),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,8 @@
|
||||
Namespace.Directive
|
||||
TYPE: string
|
||||
CHAIN-ME: 2
|
||||
--DESCRIPTION--
|
||||
Multiline
|
||||
stuff
|
||||
--FOR-WHO--
|
||||
Single multiline
|
||||
|
@@ -27,7 +27,9 @@ class ConfigSchema_StringHashParserTest extends UnitTestCase
|
||||
$this->assertParse('Simple.txt', array(
|
||||
'ID' => 'Namespace.Directive',
|
||||
'TYPE' => 'string',
|
||||
'DESCRIPTION' => "Multiline\nstuff\n"
|
||||
'CHAIN-ME' => '2',
|
||||
'DESCRIPTION' => "Multiline\nstuff\n",
|
||||
'FOR-WHO' => "Single multiline\n",
|
||||
));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user