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