Skip to content

Commit

Permalink
add unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
ssahara committed Dec 7, 2021
1 parent 0d86f9a commit 394f40a
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 6 deletions.
90 changes: 90 additions & 0 deletions _test/syntax.test.php
@@ -0,0 +1,90 @@
<?php

/**
* DokuWiki Comment Syntax Plugin tests
*
* @group plugin_commentsyntax
* @group plugins
*/
class plugin_commentsyntax_test extends DokuWikiTest
{
protected $pluginsEnabled = array('commentsyntax');

public static function setUpBeforeClass() : void
{
parent::setUpBeforeClass();
//TestUtils::rcopy(dirname(DOKU_CONF), dirname(__FILE__).'/conf');
}

public function setup() : void
{
global $conf;
parent::setup();
$conf ['plugin']['commentsyntax']['use_cstyle_nest'] = 1;
$conf ['plugin']['commentsyntax']['use_oneline_style'] = 1;
$conf ['plugin']['commentsyntax']['log_invalid_macro'] = 0;
}

// remove newlines from string
private function normalizeLineEndings($s, $eol = '')
{
return str_replace(["\r", "\n"], $eol, $s);
}

private function getHTML($text)
{
$instructions = p_get_instructions($text);
$xhtml = p_render('xhtml', $instructions, $info);
return $this->normalizeLineEndings($xhtml);
}

/**
* C-style comment syntax
*/
function test_cstyle_syntax()
{
$text = "\nWiki /* comment out */ text\n";
$expectHtml = '<p>Wiki text</p>';
$this->assertEquals($expectHtml, $this->getHtml($text));

$text = <<<'EOS'
* item 1
/** item 2 omit this line! */
* item 3
EOS;
$expectHtml = '<ul>'
.'<li class="level1"><div class="li"> item 1</div></li>'
.'<li class="level1"><div class="li"> item 3</div></li>'
.'</ul>';
$this->assertEquals($expectHtml, $this->getHtml($text));

// nested comment
$text = <<<'EOS'
/** item 1
/** item 2 omit this line! */
* item 3 */
* item 4
EOS;
$expectHtml = '<ul>'
.'<li class="level1"><div class="li"> item 4</div></li>'
.'</ul>';
$this->assertEquals($expectHtml, $this->getHtml($text));
}

/**
* One line comment
*/
function test_oneline_syntax()
{
$text = "\nWiki text // allow slash (/) in one line comment\n";
$expectHtml = '<p>Wiki text</p>';
$this->assertEquals($expectHtml, $this->getHtml($text));

$text = "\nWiki //text// // allow slash (/) in one line comment\n";
$expectHtml = '<p>Wiki <em>text</em></p>';
$this->assertEquals($expectHtml, $this->getHtml($text));
}
}
// vim:set fileencoding=utf-8 :
6 changes: 4 additions & 2 deletions syntax/cstyle.php
Expand Up @@ -15,13 +15,15 @@
*/
class syntax_plugin_commentsyntax_cstyle extends DokuWiki_Syntax_Plugin
{
/** syntax type */
public function getType()
{ // Syntax Type
{
return 'protected';
}

/** sort number used to determine priority of this mode */
public function getSort()
{ // sort number used to determine priority of this mode
{
return 8; // precedence of Doku_Parser_Mode_listblock priority (=10)
}

Expand Down
6 changes: 4 additions & 2 deletions syntax/htmlcomment.php
Expand Up @@ -14,13 +14,15 @@
*/
class syntax_plugin_commentsyntax_htmlcomment extends DokuWiki_Syntax_Plugin
{
/** syntax type */
public function getType()
{ // Syntax Type
{
return 'substition';
}

/** sort number used to determine priority of this mode */
public function getSort()
{ // sort number used to determine priority of this mode
{
return 325;
}

Expand Down
6 changes: 4 additions & 2 deletions syntax/preventive.php
Expand Up @@ -12,13 +12,15 @@
*/
class syntax_plugin_commentsyntax_preventive extends DokuWiki_Syntax_Plugin
{
/** syntax type */
public function getType()
{ // Syntax Type
{
return 'substition';
}

/** sort number used to determine priority of this mode */
public function getSort()
{ // sort number used to determine priority of this mode
{
return 9999; // very low priority
}

Expand Down

0 comments on commit 394f40a

Please sign in to comment.