xref: /plugin/include/_test/nested_include.test.php (revision c76c7b123fd75386fba2a2655cc9efce4e8c0239)
175668fa9SMichael Hamann<?php
2afa996bcSMichael Hamann
3*c76c7b12SAndreas Gohr/**
4*c76c7b12SAndreas Gohr * Class plugin_include_nested_test
5*c76c7b12SAndreas Gohr *
6*c76c7b12SAndreas Gohr * @group plugin_include
7*c76c7b12SAndreas Gohr * @group plugins
8*c76c7b12SAndreas Gohr */
9afa996bcSMichael Hamannclass plugin_include_nested_test extends DokuWikiTest {
1075668fa9SMichael Hamann    private $ids = array(
1175668fa9SMichael Hamann        'test:plugin_include:nested:start',
1275668fa9SMichael Hamann        'test:plugin_include:nested:second',
1375668fa9SMichael Hamann        'test:plugin_include:nested:third'
1475668fa9SMichael Hamann    );
1575668fa9SMichael Hamann
16afa996bcSMichael Hamann    public function setup() {
17afa996bcSMichael Hamann        $this->pluginsEnabled[] = 'include';
18afa996bcSMichael Hamann        parent::setup();
1975668fa9SMichael Hamann    }
2075668fa9SMichael Hamann
21afa996bcSMichael Hamann    public function test_outer_to_inner() {
22afa996bcSMichael Hamann        $this->_createPages();
2375668fa9SMichael Hamann        $mainHTML = p_wiki_xhtml('test:plugin_include:nested:start');
2475668fa9SMichael Hamann        $secondHTML = p_wiki_xhtml('test:plugin_include:nested:second');
2575668fa9SMichael Hamann        $thirdHTML = p_wiki_xhtml('test:plugin_include:nested:third');
2675668fa9SMichael Hamann        $this->_validateContent($mainHTML, $secondHTML, $thirdHTML);
2775668fa9SMichael Hamann    }
2875668fa9SMichael Hamann
29afa996bcSMichael Hamann    public function test_inner_to_outer() {
30afa996bcSMichael Hamann        $this->_createPages();
3175668fa9SMichael Hamann        $thirdHTML = p_wiki_xhtml('test:plugin_include:nested:third');
3275668fa9SMichael Hamann        $secondHTML = p_wiki_xhtml('test:plugin_include:nested:second');
3375668fa9SMichael Hamann        $mainHTML = p_wiki_xhtml('test:plugin_include:nested:start');
3475668fa9SMichael Hamann        $this->_validateContent($mainHTML, $secondHTML, $thirdHTML);
3575668fa9SMichael Hamann    }
3675668fa9SMichael Hamann
3775668fa9SMichael Hamann    private function _validateContent($mainHTML, $secondHTML, $thirdHTML) {
3875668fa9SMichael Hamann        $this->assertTrue(strpos($mainHTML, 'Main Content') !== false, 'Main content contains "Main Content"');
3975668fa9SMichael Hamann        $this->assertTrue($this->_matchHeader('1', 'Main Test Page', $mainHTML), 'Main page header is h1');
4075668fa9SMichael Hamann        $this->assertTrue(strpos($mainHTML, 'Second Content') !== false, 'Main content contains "Second Content"');
4175668fa9SMichael Hamann        $this->assertTrue($this->_matchHeader('2', 'Second Test Page', $mainHTML), 'Second page header on main page is h2');
4275668fa9SMichael Hamann        $this->assertTrue(strpos($mainHTML, 'Third Content') !== false, 'Main content contains "Third Content"');
4375668fa9SMichael Hamann        $this->assertTrue($this->_matchHeader('3', 'Third Test Page', $mainHTML), 'Third page header on main page is h3');
4475668fa9SMichael Hamann        $this->assertTrue(strpos($secondHTML, 'Second Content') !== false, 'Second content contains "Second Content"');
4575668fa9SMichael Hamann        $this->assertTrue($this->_matchHeader('1', 'Second Test Page', $secondHTML), 'Second page header on second page is h1');
4675668fa9SMichael Hamann        $this->assertTrue(strpos($secondHTML, 'Third Content') !== false, 'Second content contains "Third Content"');
4775668fa9SMichael Hamann        $this->assertTrue($this->_matchHeader('2', 'Third Test Page', $secondHTML), 'Third page header on second page is h2');
4875668fa9SMichael Hamann        $this->assertTrue(strpos($thirdHTML, 'Third Content') !== false, 'Third content contains "Third Content"');
4975668fa9SMichael Hamann        $this->assertTrue($this->_matchHeader('1', 'Third Test Page', $thirdHTML), 'Third page header on third page is h1');
5075668fa9SMichael Hamann    }
5175668fa9SMichael Hamann
5275668fa9SMichael Hamann    private function _matchHeader($level, $text, $html) {
53b26ef077SMichael Hamann        return preg_match('/<h'.$level.'[^>]*>(<a[^>]*>)?'.$text.'/', $html) > 0;
5475668fa9SMichael Hamann    }
55afa996bcSMichael Hamann
56afa996bcSMichael Hamann    private function _createPages() {
57afa996bcSMichael Hamann        saveWikiText('test:plugin_include:nested:start',
58afa996bcSMichael Hamann            '====== Main Test Page ======'.DOKU_LF.DOKU_LF
59afa996bcSMichael Hamann            .'Main Content'.rand().DOKU_LF.DOKU_LF
60afa996bcSMichael Hamann            .'{{page>second}}'.DOKU_LF,
61afa996bcSMichael Hamann            'setup for test');
62afa996bcSMichael Hamann        saveWikiText('test:plugin_include:nested:second',
63afa996bcSMichael Hamann            '====== Second Test Page ======'.DOKU_LF.DOKU_LF
64afa996bcSMichael Hamann            .'Second Content'.rand().DOKU_LF.DOKU_LF
65afa996bcSMichael Hamann            .'{{page>third}}'.DOKU_LF,
66afa996bcSMichael Hamann            'setup for test');
67afa996bcSMichael Hamann        saveWikiText('test:plugin_include:nested:third',
68afa996bcSMichael Hamann            '====== Third Test Page ======'.DOKU_LF.DOKU_LF
69afa996bcSMichael Hamann            .'Third Content'.rand().DOKU_LF.DOKU_LF
70afa996bcSMichael Hamann            .'{{page>third}}'.DOKU_LF,
71afa996bcSMichael Hamann            'setup for test');
72afa996bcSMichael Hamann    }
7375668fa9SMichael Hamann}
7475668fa9SMichael Hamann
75