syntax.test.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * DokuWiki Comment Syntax Plugin tests
  4. *
  5. * @group plugin_commentsyntax
  6. * @group plugins
  7. */
  8. class plugin_commentsyntax_test extends DokuWikiTest
  9. {
  10. protected $pluginsEnabled = array('commentsyntax');
  11. public static function setUpBeforeClass() : void
  12. {
  13. parent::setUpBeforeClass();
  14. //TestUtils::rcopy(dirname(DOKU_CONF), dirname(__FILE__).'/conf');
  15. }
  16. public function setup() : void
  17. {
  18. global $conf;
  19. parent::setup();
  20. $conf ['plugin']['commentsyntax']['use_cstyle_nest'] = 1;
  21. $conf ['plugin']['commentsyntax']['use_oneline_style'] = 1;
  22. $conf ['plugin']['commentsyntax']['log_invalid_macro'] = 0;
  23. }
  24. // remove newlines from string
  25. private function normalizeLineEndings($s, $eol = '')
  26. {
  27. return str_replace(["\r", "\n"], $eol, $s);
  28. }
  29. private function getHTML($text)
  30. {
  31. $instructions = p_get_instructions($text);
  32. $xhtml = p_render('xhtml', $instructions, $info);
  33. return $this->normalizeLineEndings($xhtml);
  34. }
  35. /**
  36. * C-style comment syntax
  37. */
  38. function test_cstyle_syntax()
  39. {
  40. $text = "\nWiki /* comment out */ text\n";
  41. $expectHtml = '<p>Wiki text</p>';
  42. $this->assertEquals($expectHtml, $this->getHtml($text));
  43. $text = <<<'EOS'
  44. * item 1
  45. /** item 2 omit this line! */
  46. * item 3
  47. EOS;
  48. $expectHtml = '<ul>'
  49. .'<li class="level1"><div class="li"> item 1</div></li>'
  50. .'<li class="level1"><div class="li"> item 3</div></li>'
  51. .'</ul>';
  52. $this->assertEquals($expectHtml, $this->getHtml($text));
  53. // nested comment
  54. $text = <<<'EOS'
  55. /** item 1
  56. /** item 2 omit this line! */
  57. * item 3 */
  58. * item 4
  59. EOS;
  60. $expectHtml = '<ul>'
  61. .'<li class="level1"><div class="li"> item 4</div></li>'
  62. .'</ul>';
  63. $this->assertEquals($expectHtml, $this->getHtml($text));
  64. }
  65. /**
  66. * One line comment
  67. */
  68. function test_oneline_syntax()
  69. {
  70. $text = "\nWiki text // allow slash (/) in one line comment\n";
  71. $expectHtml = '<p>Wiki text</p>';
  72. $this->assertEquals($expectHtml, $this->getHtml($text));
  73. $text = "\nWiki //text// // allow slash (/) in one line comment\n";
  74. $expectHtml = '<p>Wiki <em>text</em></p>';
  75. $this->assertEquals($expectHtml, $this->getHtml($text));
  76. }
  77. }
  78. // vim:set fileencoding=utf-8 :