xref: /dokuwiki/_test/tests/inc/parser/renderer_pipeline.test.php (revision 36ba8eadc205a4e1af5099c74b747e2256faadd4)
1<?php
2
3use DOMWrap\Document;
4
5/**
6 * End-to-end test for the parse + render pipeline.
7 *
8 * Renders the syntax wiki page and inspects the resulting XHTML to catch
9 * wholesale regressions in parsing, the call list, or the XHTML renderer.
10 */
11class renderer_pipeline_test extends DokuWikiTest
12{
13    public function testWikiSyntaxPageRendersExpectedStructure()
14    {
15        global $ID;
16        $ID = 'wiki:syntax';
17
18        $html = p_wiki_xhtml('wiki:syntax');
19        $this->assertNotEmpty($html, 'wiki:syntax must render to non-empty HTML');
20
21        // DOMWrap needs a single root; wrap in a container.
22        $doc = (new Document())->html('<div id="root">' . $html . '</div>');
23
24        // Top-level heading from the page source: "====== Formatting Syntax ======"
25        $h1 = $doc->find('h1');
26        $this->assertSame(1, $h1->count(), 'page must have exactly one h1');
27        $this->assertSame('Formatting Syntax', trim($h1->text()));
28
29        // Headers of various levels — page has dozens of sections.
30        $this->assertGreaterThan(10, $doc->find('h2')->count(), 'page must have many h2 sections');
31        $this->assertGreaterThan(0, $doc->find('h3')->count());
32        $this->assertGreaterThan(0, $doc->find('h4')->count());
33
34        // Section edit markers — verifies finalize/Block ran.
35        $this->assertGreaterThan(
36            5,
37            substr_count($html, '<!-- EDIT{'),
38            'expected multiple section edit markers'
39        );
40
41        // Internal wiki links and external links from the page.
42        $this->assertGreaterThan(0, $doc->find('a.wikilink1, a.wikilink2')->count());
43        $this->assertGreaterThan(0, $doc->find('a.urlextern')->count());
44        $this->assertGreaterThan(0, $doc->find('a.interwiki')->count());
45
46        // Inline formatting.
47        $this->assertGreaterThan(0, $doc->find('em')->count());
48        $this->assertGreaterThan(0, $doc->find('strong')->count());
49        $this->assertGreaterThan(0, $doc->find('code')->count());
50
51        // A table is rendered by the page.
52        $this->assertGreaterThan(0, $doc->find('table.inline')->count());
53
54        // Footnote block (the page uses ((...)) footnotes).
55        $this->assertSame(1, $doc->find('div.footnotes')->count());
56
57        // The info plugin produces the syntax-plugin list.
58        $pluginSection = $doc->find('h2#syntax_plugins')->following('div.level2');
59        $this->assertSame(1, $pluginSection->find('ul')->count(), 'info plugin must emit a <ul>');
60        $this->assertGreaterThan(
61            0,
62            $pluginSection->find('ul li.level1 a.urlextern')->count(),
63            'info plugin must list at least one syntax plugin entry'
64        );
65    }
66}
67