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