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) { if ($expect === true) $expect = $input; $lexer = new HTMLPurifier_Lexer (); $this->assertIdentical ( $expect, $lexer->parseData ( $input ) ); } 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 ( '-' ); } // 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 ( '