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