1<?php
2
3/**
4 * Class plugin_include_nested_test
5 *
6 * @group plugin_include
7 * @group plugins
8 */
9class plugin_include_nested_test extends DokuWikiTest {
10    private $ids = array(
11        'test:plugin_include:nested:start',
12        'test:plugin_include:nested:second',
13        'test:plugin_include:nested:third'
14    );
15
16    public function setUp() : void
17    {
18        $this->pluginsEnabled[] = 'include';
19        parent::setUp();
20    }
21
22    public function test_outer_to_inner() {
23        $this->_createPages();
24        $mainHTML = p_wiki_xhtml('test:plugin_include:nested:start');
25        $secondHTML = p_wiki_xhtml('test:plugin_include:nested:second');
26        $thirdHTML = p_wiki_xhtml('test:plugin_include:nested:third');
27        $this->_validateContent($mainHTML, $secondHTML, $thirdHTML);
28    }
29
30    public function test_inner_to_outer() {
31        $this->_createPages();
32        $thirdHTML = p_wiki_xhtml('test:plugin_include:nested:third');
33        $secondHTML = p_wiki_xhtml('test:plugin_include:nested:second');
34        $mainHTML = p_wiki_xhtml('test:plugin_include:nested:start');
35        $this->_validateContent($mainHTML, $secondHTML, $thirdHTML);
36    }
37
38    private function _validateContent($mainHTML, $secondHTML, $thirdHTML) {
39        $this->assertTrue(strpos($mainHTML, 'Main Content') !== false, 'Main content contains "Main Content"');
40        $this->assertTrue($this->_matchHeader('1', 'Main Test Page', $mainHTML), 'Main page header is h1');
41        $this->assertTrue(strpos($mainHTML, 'Second Content') !== false, 'Main content contains "Second Content"');
42        $this->assertTrue($this->_matchHeader('2', 'Second Test Page', $mainHTML), 'Second page header on main page is h2');
43        $this->assertTrue(strpos($mainHTML, 'Third Content') !== false, 'Main content contains "Third Content"');
44        $this->assertTrue($this->_matchHeader('3', 'Third Test Page', $mainHTML), 'Third page header on main page is h3');
45        $this->assertTrue(strpos($secondHTML, 'Second Content') !== false, 'Second content contains "Second Content"');
46        $this->assertTrue($this->_matchHeader('1', 'Second Test Page', $secondHTML), 'Second page header on second page is h1');
47        $this->assertTrue(strpos($secondHTML, 'Third Content') !== false, 'Second content contains "Third Content"');
48        $this->assertTrue($this->_matchHeader('2', 'Third Test Page', $secondHTML), 'Third page header on second page is h2');
49        $this->assertTrue(strpos($thirdHTML, 'Third Content') !== false, 'Third content contains "Third Content"');
50        $this->assertTrue($this->_matchHeader('1', 'Third Test Page', $thirdHTML), 'Third page header on third page is h1');
51    }
52
53    private function _matchHeader($level, $text, $html) {
54        return preg_match('/<h'.$level.'[^>]*>(<a[^>]*>)?'.$text.'/', $html) > 0;
55    }
56
57    private function _createPages() {
58        saveWikiText('test:plugin_include:nested:start',
59            '====== Main Test Page ======'.DOKU_LF.DOKU_LF
60            .'Main Content'.rand().DOKU_LF.DOKU_LF
61            .'{{page>second}}'.DOKU_LF,
62            'setup for test');
63        saveWikiText('test:plugin_include:nested:second',
64            '====== Second Test Page ======'.DOKU_LF.DOKU_LF
65            .'Second Content'.rand().DOKU_LF.DOKU_LF
66            .'{{page>third}}'.DOKU_LF,
67            'setup for test');
68        saveWikiText('test:plugin_include:nested:third',
69            '====== Third Test Page ======'.DOKU_LF.DOKU_LF
70            .'Third Content'.rand().DOKU_LF.DOKU_LF
71            .'{{page>third}}'.DOKU_LF,
72            'setup for test');
73    }
74}
75
76