1d2085866SAndreas Gohr<?php 2d2085866SAndreas Gohr 3d2085866SAndreas Gohrnamespace dokuwiki\test\Parsing\ParserMode; 4d2085866SAndreas Gohr 5d2085866SAndreas Gohruse dokuwiki\Parsing\ParserMode\GfmHtmlEntity; 6d2085866SAndreas Gohr 7d2085866SAndreas Gohr/** 8*eb15e634SAndreas Gohr * Sanity tests for the GfmHtmlEntity lexer mode. 9*eb15e634SAndreas Gohr * 10*eb15e634SAndreas Gohr * Decoding semantics are tested exhaustively in 11*eb15e634SAndreas Gohr * {@see \dokuwiki\test\Parsing\Helpers\HtmlEntityTest}; this class 12*eb15e634SAndreas Gohr * covers only that the mode wires up to the lexer correctly and emits 13*eb15e634SAndreas Gohr * cdata at the right positions. Consecutive cdata calls are coalesced 14*eb15e634SAndreas Gohr * by Handler\Block::addCall during finalize(), so a successful match 15*eb15e634SAndreas Gohr * shows up as a single cdata containing the decoded character spliced 16*eb15e634SAndreas Gohr * into the surrounding text. 17d2085866SAndreas Gohr */ 18d2085866SAndreas Gohrclass GfmHtmlEntityTest extends ParserTestBase 19d2085866SAndreas Gohr{ 20d2085866SAndreas Gohr private function assertParsedCdata(string $input, string $expectedCdata): void 21d2085866SAndreas Gohr { 22d2085866SAndreas Gohr $this->P->addMode('gfm_html_entity', new GfmHtmlEntity()); 23d2085866SAndreas Gohr $this->P->parse($input); 24d2085866SAndreas Gohr $this->assertCalls([ 25d2085866SAndreas Gohr ['document_start', []], 26d2085866SAndreas Gohr ['p_open', []], 27d2085866SAndreas Gohr ['cdata', [$expectedCdata]], 28d2085866SAndreas Gohr ['p_close', []], 29d2085866SAndreas Gohr ['document_end', []], 30d2085866SAndreas Gohr ], $this->H->calls); 31d2085866SAndreas Gohr } 32d2085866SAndreas Gohr 33*eb15e634SAndreas Gohr public function testNumericDecodes() 34d2085866SAndreas Gohr { 35d2085866SAndreas Gohr $this->assertParsedCdata('x # y', "\nx # y"); 36d2085866SAndreas Gohr } 37d2085866SAndreas Gohr 38*eb15e634SAndreas Gohr public function testNamedDecodes() 39d2085866SAndreas Gohr { 40d2085866SAndreas Gohr $this->assertParsedCdata('a©b', "\na\u{00A9}b"); 41d2085866SAndreas Gohr } 42d2085866SAndreas Gohr 43*eb15e634SAndreas Gohr public function testUnknownNameStaysLiteral() 44d2085866SAndreas Gohr { 45d2085866SAndreas Gohr $this->assertParsedCdata('a&MadeUpEntity;b', "\na&MadeUpEntity;b"); 46d2085866SAndreas Gohr } 47d2085866SAndreas Gohr 48*eb15e634SAndreas Gohr public function testNonMatchingInputStaysLiteral() 49d2085866SAndreas Gohr { 50*eb15e634SAndreas Gohr $this->assertParsedCdata('a&#abcdef0;b', "\na&#abcdef0;b"); 51d2085866SAndreas Gohr } 52d2085866SAndreas Gohr} 53