config->set('Core.MaintainLineNumbers', true);
$lexer = HTMLPurifier_Lexer::create($this->config);
$this->assertIsA($lexer, 'HTMLPurifier_Lexer_DirectLex');
}
public function test_create_objectLexerImpl()
{
$this->config->set('Core.LexerImpl', new HTMLPurifier_Lexer_DirectLex());
$lexer = HTMLPurifier_Lexer::create($this->config);
$this->assertIsA($lexer, 'HTMLPurifier_Lexer_DirectLex');
}
public function test_create_unknownLexer()
{
$this->config->set('Core.LexerImpl', 'AsdfAsdf');
$this->expectException(new HTMLPurifier_Exception('Cannot instantiate unrecognized Lexer type AsdfAsdf'));
HTMLPurifier_Lexer::create($this->config);
}
public function test_create_incompatibleLexer()
{
$this->config->set('Core.LexerImpl', 'DOMLex');
$this->config->set('Core.MaintainLineNumbers', true);
$this->expectException(new HTMLPurifier_Exception('Cannot use lexer that does not support line numbers with Core.MaintainLineNumbers or Core.CollectErrors (use DirectLex instead)'));
HTMLPurifier_Lexer::create($this->config);
}
// HTMLPurifier_Lexer->parseData() -----------------------------------------
public function assertParseData($input, $expect = true, $is_attr = false)
{
if ($expect === true) $expect = $input;
$lexer = new HTMLPurifier_Lexer();
$this->assertIdentical($expect, $lexer->parseData($input, $is_attr, $this->config));
}
public function test_parseData_plainText()
{
$this->assertParseData('asdf');
}
public function test_parseData_ampersandEntity()
{
$this->assertParseData('&', '&');
}
public function test_parseData_quotEntity()
{
$this->assertParseData('"', '"');
}
public function test_parseData_aposNumericEntity()
{
$this->assertParseData(''', "'");
}
public function test_parseData_aposCompactNumericEntity()
{
$this->assertParseData(''', "'");
}
public function test_parseData_adjacentAmpersandEntities()
{
$this->assertParseData('&&&', '&&&');
}
public function test_parseData_trailingUnescapedAmpersand()
{
$this->assertParseData('&&', '&&');
}
public function test_parseData_internalUnescapedAmpersand()
{
$this->assertParseData('Procter & Gamble');
}
public function test_parseData_improperEntityFaultToleranceTest()
{
$this->assertParseData('-', '-');
}
public function test_parseData_noTrailingSemi()
{
$this->assertParseData('&A', '&A');
}
public function test_parseData_noTrailingSemiAttr()
{
$this->assertParseData('&A', '&A', true);
}
public function test_parseData_T119()
{
$this->assertParseData('&A', '&A', true);
}
public function test_parseData_T119b()
{
$this->assertParseData('&trade=', true, true);
}
public function test_parseData_legacy1()
{
$this->config->set('Core.LegacyEntityDecoder', true);
$this->assertParseData('&a', true);
$this->assertParseData('&=', "&=");
$this->assertParseData('&a', true, true);
$this->assertParseData('&=', "&=", true);
$this->assertParseData('<a', true);
$this->assertParseData('<=', "<=");
$this->assertParseData('<a', true, true);
$this->assertParseData('<=', "<=", true);
}
public function test_parseData_nonlegacy1()
{
$this->assertParseData('&a', "&a");
$this->assertParseData('&=', "&=");
$this->assertParseData('&a', true, true);
$this->assertParseData('&=', true, true);
$this->assertParseData('<a', "assertParseData('<=', "<=");
$this->assertParseData('<a', true, true);
$this->assertParseData('<=', true, true);
$this->assertParseData('<a;', "assertParseData('&imath');
}
// HTMLPurifier_Lexer->extractBody() ---------------------------------------
public function assertExtractBody($text, $extract = true)
{
$lexer = new HTMLPurifier_Lexer();
$result = $lexer->extractBody($text);
if ($extract === true) $extract = $text;
$this->assertIdentical($extract, $result);
}
public function test_extractBody_noBodyTags()
{
$this->assertExtractBody('Bold');
}
public function test_extractBody_lowercaseBodyTags()
{
$this->assertExtractBody('Bold', 'Bold');
}
public function test_extractBody_uppercaseBodyTags()
{
$this->assertExtractBody('Bold', 'Bold');
}
public function test_extractBody_realisticUseCase()
{
$this->assertExtractBody(
'