2008-01-27 18:50:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @note Sample input files are located in the StringHashParser/ directory.
|
|
|
|
*/
|
2008-03-22 19:30:37 +00:00
|
|
|
class HTMLPurifier_StringHashParserTest extends UnitTestCase
|
2008-01-27 18:50:36 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instance of ConfigSchema_StringHashParser being tested.
|
|
|
|
*/
|
|
|
|
protected $parser;
|
|
|
|
|
2008-03-23 00:02:37 +00:00
|
|
|
public function setup() {
|
2008-03-22 19:30:37 +00:00
|
|
|
$this->parser = new HTMLPurifier_StringHashParser();
|
2008-01-27 18:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assert that $file gets parsed into the form of $expect
|
|
|
|
*/
|
2008-04-21 15:24:18 +00:00
|
|
|
protected function assertParse($file, $expect) {
|
2008-01-27 18:50:36 +00:00
|
|
|
$result = $this->parser->parseFile(dirname(__FILE__) . '/StringHashParser/' . $file);
|
|
|
|
$this->assertIdentical($result, $expect);
|
|
|
|
}
|
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testSimple() {
|
2008-01-27 18:50:36 +00:00
|
|
|
$this->assertParse('Simple.txt', array(
|
|
|
|
'ID' => 'Namespace.Directive',
|
|
|
|
'TYPE' => 'string',
|
2008-02-05 21:04:00 +00:00
|
|
|
'CHAIN-ME' => '2',
|
|
|
|
'DESCRIPTION' => "Multiline\nstuff\n",
|
|
|
|
'FOR-WHO' => "Single multiline\n",
|
2008-01-27 18:50:36 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testOverrideSingle() {
|
2008-01-27 18:50:36 +00:00
|
|
|
$this->assertParse('OverrideSingle.txt', array(
|
|
|
|
'KEY' => 'New',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testAppendMultiline() {
|
2008-01-27 18:50:36 +00:00
|
|
|
$this->assertParse('AppendMultiline.txt', array(
|
|
|
|
'KEY' => "Line1\nLine2\n",
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testDefault() {
|
2008-01-27 18:50:36 +00:00
|
|
|
$this->parser->default = 'NEW-ID';
|
|
|
|
$this->assertParse('Default.txt', array(
|
|
|
|
'NEW-ID' => 'DefaultValue',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testError() {
|
2008-03-01 17:06:23 +00:00
|
|
|
try {
|
|
|
|
$this->parser->parseFile('NoExist.txt');
|
|
|
|
} catch (HTMLPurifier_ConfigSchema_Exception $e) {
|
|
|
|
$this->assertIdentical($e->getMessage(), 'File NoExist.txt does not exist');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testParseMultiple() {
|
2008-03-23 00:02:37 +00:00
|
|
|
$result = $this->parser->parseMultiFile(dirname(__FILE__) . '/StringHashParser/Multi.txt');
|
|
|
|
$this->assertIdentical(
|
|
|
|
$result,
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'ID' => 'Namespace.Directive',
|
|
|
|
'TYPE' => 'string',
|
|
|
|
'CHAIN-ME' => '2',
|
|
|
|
'DESCRIPTION' => "Multiline\nstuff\n",
|
|
|
|
'FOR-WHO' => "Single multiline\n",
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'ID' => 'Namespace.Directive2',
|
|
|
|
'TYPE' => 'integer',
|
|
|
|
'CHAIN-ME' => '3',
|
|
|
|
'DESCRIPTION' => "M\nstuff\n",
|
|
|
|
'FOR-WHO' => "Single multiline2\n",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-01-27 18:50:36 +00:00
|
|
|
}
|