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
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-01-27 18:50:36 +00:00
|
|
|
/**
|
|
|
|
* Instance of ConfigSchema_StringHashParser being tested.
|
|
|
|
*/
|
|
|
|
protected $parser;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +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
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-01-27 18:50:36 +00:00
|
|
|
/**
|
|
|
|
* Assert that $file gets parsed into the form of $expect
|
|
|
|
*/
|
2013-07-16 11:56:14 +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-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public 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",
|
2008-07-05 01:26:26 +00:00
|
|
|
'EMPTY' => '',
|
2008-02-05 21:04:00 +00:00
|
|
|
'FOR-WHO' => "Single multiline\n",
|
2008-01-27 18:50:36 +00:00
|
|
|
));
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testOverrideSingle()
|
|
|
|
{
|
2008-01-27 18:50:36 +00:00
|
|
|
$this->assertParse('OverrideSingle.txt', array(
|
|
|
|
'KEY' => 'New',
|
|
|
|
));
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testAppendMultiline()
|
|
|
|
{
|
2008-01-27 18:50:36 +00:00
|
|
|
$this->assertParse('AppendMultiline.txt', array(
|
|
|
|
'KEY' => "Line1\nLine2\n",
|
|
|
|
));
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testDefault()
|
|
|
|
{
|
2008-01-27 18:50:36 +00:00
|
|
|
$this->parser->default = 'NEW-ID';
|
|
|
|
$this->assertParse('Default.txt', array(
|
|
|
|
'NEW-ID' => 'DefaultValue',
|
|
|
|
));
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public 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-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public 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-12-06 07:28:20 +00:00
|
|
|
|
2008-01-27 18:50:36 +00:00
|
|
|
}
|
2008-12-06 09:24:59 +00:00
|
|
|
|
|
|
|
// vim: et sw=4 sts=4
|