xref: /plugin/include/_test/nested_include.test.php (revision 2524d4070dd2d3a04a927b4ad11e6ee8599a434b)
1<?php
2require_once(DOKU_INC.'_test/lib/unittest.php');
3require_once(DOKU_INC.'inc/init.php');
4class plugin_include_nested_test extends Doku_UnitTestCase {
5    private $ids = array(
6        'test:plugin_include:nested:start',
7        'test:plugin_include:nested:second',
8        'test:plugin_include:nested:third'
9    );
10
11    public function tearDown() {
12        foreach($this->ids as $id) {
13            saveWikiText($id,'','deleted in tearDown()');
14            @unlink(metaFN($id, '.meta'));
15        }
16    }
17
18    public function setUp() {
19        saveWikiText('test:plugin_include:nested:start',
20            '====== Main Test Page ======'.DOKU_LF.DOKU_LF
21            .'Main Content'.DOKU_LF.DOKU_LF
22            .'{{page>second}}'.DOKU_LF,
23            'setup for test');
24        saveWikiText('test:plugin_include:nested:second',
25            '====== Second Test Page ======'.DOKU_LF.DOKU_LF
26            .'Second Content'.DOKU_LF.DOKU_LF
27            .'{{page>third}}'.DOKU_LF,
28            'setup for test');
29        saveWikiText('test:plugin_include:nested:third',
30            '====== Third Test Page ======'.DOKU_LF.DOKU_LF
31            .'Third Content'.DOKU_LF.DOKU_LF
32            .'{{page>third}}'.DOKU_LF,
33            'setup for test');
34    }
35
36    public function testOuterToInner() {
37        $mainHTML = p_wiki_xhtml('test:plugin_include:nested:start');
38        $secondHTML = p_wiki_xhtml('test:plugin_include:nested:second');
39        $thirdHTML = p_wiki_xhtml('test:plugin_include:nested:third');
40        $this->_validateContent($mainHTML, $secondHTML, $thirdHTML);
41    }
42
43    public function testInnerToOuter() {
44        $thirdHTML = p_wiki_xhtml('test:plugin_include:nested:third');
45        $secondHTML = p_wiki_xhtml('test:plugin_include:nested:second');
46        $mainHTML = p_wiki_xhtml('test:plugin_include:nested:start');
47        $this->_validateContent($mainHTML, $secondHTML, $thirdHTML);
48    }
49
50    private function _validateContent($mainHTML, $secondHTML, $thirdHTML) {
51        $this->assertTrue(strpos($mainHTML, 'Main Content') !== false, 'Main content contains "Main Content"');
52        $this->assertTrue($this->_matchHeader('1', 'Main Test Page', $mainHTML), 'Main page header is h1');
53        $this->assertTrue(strpos($mainHTML, 'Second Content') !== false, 'Main content contains "Second Content"');
54        $this->assertTrue($this->_matchHeader('2', 'Second Test Page', $mainHTML), 'Second page header on main page is h2');
55        $this->assertTrue(strpos($mainHTML, 'Third Content') !== false, 'Main content contains "Third Content"');
56        $this->assertTrue($this->_matchHeader('3', 'Third Test Page', $mainHTML), 'Third page header on main page is h3');
57        $this->assertTrue(strpos($secondHTML, 'Second Content') !== false, 'Second content contains "Second Content"');
58        $this->assertTrue($this->_matchHeader('1', 'Second Test Page', $secondHTML), 'Second page header on second page is h1');
59        $this->assertTrue(strpos($secondHTML, 'Third Content') !== false, 'Second content contains "Third Content"');
60        $this->assertTrue($this->_matchHeader('2', 'Third Test Page', $secondHTML), 'Third page header on second page is h2');
61        $this->assertTrue(strpos($thirdHTML, 'Third Content') !== false, 'Third content contains "Third Content"');
62        $this->assertTrue($this->_matchHeader('1', 'Third Test Page', $thirdHTML), 'Third page header on third page is h1');
63    }
64
65    private function _matchHeader($level, $text, $html) {
66        return preg_match('/<h'.$level.'[^>]*><a[^>]*>'.$text.'/', $html) > 0;
67    }
68}
69
70