config->set('Core.MaintainLineNumbers', true); $lexer = HTMLPurifier_Lexer::create($this->config); $this->assertIsA($lexer, 'HTMLPurifier_Lexer_DirectLex'); } 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'); } 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); } 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() ----------------------------------------- function assertParseData($input, $expect = true) { if ($expect === true) $expect = $input; $lexer = new HTMLPurifier_Lexer(); $this->assertIdentical($expect, $lexer->parseData($input)); } function test_parseData_plainText() { $this->assertParseData('asdf'); } function test_parseData_ampersandEntity() { $this->assertParseData('&', '&'); } function test_parseData_quotEntity() { $this->assertParseData('"', '"'); } function test_parseData_aposNumericEntity() { $this->assertParseData(''', "'"); } function test_parseData_aposCompactNumericEntity() { $this->assertParseData(''', "'"); } function test_parseData_adjacentAmpersandEntities() { $this->assertParseData('&&&', '&&&'); } function test_parseData_trailingUnescapedAmpersand() { $this->assertParseData('&&', '&&'); } function test_parseData_internalUnescapedAmpersand() { $this->assertParseData('Procter & Gamble'); } function test_parseData_improperEntityFaultToleranceTest() { $this->assertParseData('-'); } // HTMLPurifier_Lexer->extractBody() --------------------------------------- function assertExtractBody($text, $extract = true) { $lexer = new HTMLPurifier_Lexer(); $result = $lexer->extractBody($text); if ($extract === true) $extract = $text; $this->assertIdentical($extract, $result); } function test_extractBody_noBodyTags() { $this->assertExtractBody('Bold'); } function test_extractBody_lowercaseBodyTags() { $this->assertExtractBody('
Bold', 'Bold'); } function test_extractBody_uppercaseBodyTags() { $this->assertExtractBody('Bold', 'Bold'); } function test_extractBody_realisticUseCase() { $this->assertExtractBody( '