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