xref: /plugin/dwtimeline/_test/RenderPageTimelineTest.php (revision 545c554be65100e9bb5eff6d4aa54c829680442a)
1<?php
2
3namespace dokuwiki\plugin\dwtimeline\test;
4
5use DokuWikiTest;
6
7/**
8 * Tests for <dwtimeline page=... />
9 *
10 * @group plugin_dwtimeline
11 * @group plugins
12 */
13class RenderPageTimelineTest extends DokuWikiTest
14{
15    protected $pluginsEnabled = ['dwtimeline'];
16
17    public function setUp(): void
18    {
19        parent::setUp();
20    }
21
22    public function test_renders_title_and_milestones()
23    {
24        // Prepare a source page with H1 + H2 + content
25        $srcId    = 'playground:source';
26        $wikitext = <<<TXT
27====== Project Alpha ======
28===== Kickoff =====
29Intro text.
30
31===== Build =====
32Build details.
33
34==== Substep A ====
35More details.
36
37===== Launch =====
38Final text.
39TXT;
40        saveWikiText($srcId, $wikitext, 'setup');
41
42        // Render a page that uses renderpage
43        $pageId     = 'playground:target';
44        $targetText = '<dwtimeline page=' . $srcId . ' />';
45        $html       = p_render('xhtml', p_get_instructions($targetText), $info);
46
47        // Title must appear
48        $this->assertStringContainsString('Project Alpha', $html, 'Timeline title missing');
49
50        // Milestone titles must appear
51        $this->assertStringContainsString('Kickoff', $html);
52        $this->assertStringContainsString('Build', $html);
53        $this->assertStringContainsString('Launch', $html);
54
55        // Body content of first milestone should be included
56        $this->assertStringContainsString('Intro text.', $html);
57
58        // Body content of "Build" should include its H3 section text
59        $this->assertStringContainsString('Build details.', $html);
60        $this->assertStringContainsString('More details.', $html);
61    }
62
63    public function test_non_existing_page()
64    {
65        $srcId = 'no:such:page';
66        $html  = p_render('xhtml', p_get_instructions('<dwtimeline page=' . $srcId . ' />'), $info);
67        $this->assertStringContainsString('Page not found:', strip_tags($html), 'Missing not-found message key');
68    }
69
70    public function test_self_include_guard()
71    {
72        $srcId    = 'playground:self';
73        $wikitext = "====== Self test ======\n\n<dwtimeline page=$srcId />";
74        saveWikiText($srcId, $wikitext, 'setup');
75        $html = p_wiki_xhtml($srcId);
76        $this->assertTrue(
77            str_contains(strip_tags($html), 'Source and destination are equal:'),
78            'Missing same-page guard'
79        );
80    }
81}
82