nested_include.test.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Class plugin_include_nested_test
  4. *
  5. * @group plugin_include
  6. * @group plugins
  7. */
  8. class plugin_include_nested_test extends DokuWikiTest {
  9. private $ids = array(
  10. 'test:plugin_include:nested:start',
  11. 'test:plugin_include:nested:second',
  12. 'test:plugin_include:nested:third'
  13. );
  14. public function setUp() : void
  15. {
  16. $this->pluginsEnabled[] = 'include';
  17. parent::setUp();
  18. }
  19. public function test_outer_to_inner() {
  20. $this->_createPages();
  21. $mainHTML = p_wiki_xhtml('test:plugin_include:nested:start');
  22. $secondHTML = p_wiki_xhtml('test:plugin_include:nested:second');
  23. $thirdHTML = p_wiki_xhtml('test:plugin_include:nested:third');
  24. $this->_validateContent($mainHTML, $secondHTML, $thirdHTML);
  25. }
  26. public function test_inner_to_outer() {
  27. $this->_createPages();
  28. $thirdHTML = p_wiki_xhtml('test:plugin_include:nested:third');
  29. $secondHTML = p_wiki_xhtml('test:plugin_include:nested:second');
  30. $mainHTML = p_wiki_xhtml('test:plugin_include:nested:start');
  31. $this->_validateContent($mainHTML, $secondHTML, $thirdHTML);
  32. }
  33. private function _validateContent($mainHTML, $secondHTML, $thirdHTML) {
  34. $this->assertTrue(strpos($mainHTML, 'Main Content') !== false, 'Main content contains "Main Content"');
  35. $this->assertTrue($this->_matchHeader('1', 'Main Test Page', $mainHTML), 'Main page header is h1');
  36. $this->assertTrue(strpos($mainHTML, 'Second Content') !== false, 'Main content contains "Second Content"');
  37. $this->assertTrue($this->_matchHeader('2', 'Second Test Page', $mainHTML), 'Second page header on main page is h2');
  38. $this->assertTrue(strpos($mainHTML, 'Third Content') !== false, 'Main content contains "Third Content"');
  39. $this->assertTrue($this->_matchHeader('3', 'Third Test Page', $mainHTML), 'Third page header on main page is h3');
  40. $this->assertTrue(strpos($secondHTML, 'Second Content') !== false, 'Second content contains "Second Content"');
  41. $this->assertTrue($this->_matchHeader('1', 'Second Test Page', $secondHTML), 'Second page header on second page is h1');
  42. $this->assertTrue(strpos($secondHTML, 'Third Content') !== false, 'Second content contains "Third Content"');
  43. $this->assertTrue($this->_matchHeader('2', 'Third Test Page', $secondHTML), 'Third page header on second page is h2');
  44. $this->assertTrue(strpos($thirdHTML, 'Third Content') !== false, 'Third content contains "Third Content"');
  45. $this->assertTrue($this->_matchHeader('1', 'Third Test Page', $thirdHTML), 'Third page header on third page is h1');
  46. }
  47. private function _matchHeader($level, $text, $html) {
  48. return preg_match('/<h'.$level.'[^>]*>(<a[^>]*>)?'.$text.'/', $html) > 0;
  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. }