1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-21 21:57:34 +02:00

Bbcode test and parser cleanup.

This commit is contained in:
Cameron
2021-01-14 14:46:49 -08:00
parent 7e90b791ba
commit 62d6341303
19 changed files with 310 additions and 623 deletions

View File

@@ -27,7 +27,11 @@
$this->assertTrue(false, $e->getMessage());
}
$this->bb->__construct();
}
/*
public function testSetClass()
{
@@ -68,12 +72,165 @@
{
}
*/
public function testParseBBCodes()
{
$codes = array (
'_br' =>
array (
),
'b' =>
array (
),
'alert' => array (
'warning' => array('input'=>'Warning Message', 'expected'=>"<div class='alert alert-warning'>Warning Message</div>"),
),
'block' =>
array (
),
'code' =>
array (
),
'glyph' =>
array (
),
'h' =>
array (
),
'img' =>
array (
),
'nobr' =>
array (
),
'p' =>
array (
),
'video' =>
array (
),
'youtube' =>
array (
),
'blockquote' =>
array (
),
'br' =>
array (
),
'center' =>
array (
),
'color' =>
array (
),
'email' =>
array (
),
'file' =>
array (
),
'flash' =>
array (
),
'hide' =>
array (
),
'html' =>
array (
),
'i' =>
array (
),
'index.html' =>
array (
),
'justify' =>
array (
),
'left' =>
array (
),
'link' => array (
// [bbcode=xxxxxx] param [bbcode]xxxxxx[/bbode] expected output
'http://mysite.com external' => array('input'=>'http://mysite.com', 'expected'=>"<a class='bbcode bbcode-link' href='http://mysite.com' rel='external' >http://mysite.com</a>"),
'http://mysite.com rel=external' => array('input'=>'http://mysite.com', 'expected'=>"<a class='bbcode bbcode-link' href='http://mysite.com' rel='external' >http://mysite.com</a>"),
'external' => array('input'=>'http://mysite.com', 'expected'=>"<a class='bbcode bbcode-link' href='http://mysite.com' rel='external' >http://mysite.com</a>"),
'mailto:myemail@email.com' => array('input'=>'My Name', 'expected'=>"<a class='bbcode' rel='external' href='javascript:window.location=\"mai\"+\"lto:\"+\"myemail\"+\"@\"+\"email.com\";self.close();' onmouseover='window.status=\"mai\"+\"lto:\"+\"myemail\"+\"@\"+\"email.com\"; return true;' onmouseout='window.status=\"\";return true;'>My Name</a>"),
'external=http://mysite.com' => array('input'=>'http://mysite.com', 'expected'=>"<a class='bbcode bbcode-link' href='http://mysite.com' rel='external' >http://mysite.com</a>"),
),
'list' =>
array (
),
'quote' =>
array (
),
'right' =>
array (
),
'sanitised' =>
array (
),
'size' =>
array (
),
'spoiler' =>
array (
),
'stream' =>
array (
),
'table' =>
array (
),
'tbody' =>
array (
),
'td' =>
array (
),
'textarea' =>
array (
),
'th' =>
array (
),
'time' =>
array (
),
'tr' =>
array (
),
'u' =>
array (
),
'url' =>
array (
),
);
$ret = [];
foreach($codes as $bbcode=>$var)
{
if(empty($var))
{
$input = '['.$bbcode.']http://mysite.com[/'.$bbcode.']';
$result = $this->bb->parseBBCodes($input, true); // parsing to check for PHP errors.
continue;
}
foreach($var as $parms=>$p)
{
$input2 = '['.$bbcode.'='.$parms.']'.$p['input'].'[/'.$bbcode.']';
$result2 = $this->bb->parseBBCodes($input2);
$this->assertEquals($p['expected'], $result2);
}
}
}
/*
public function testClearClass()
{

View File

@@ -130,6 +130,7 @@ while(&#036;row = &#036;sql-&gt;fetch())
}
*/
public function testParseTemplateWithEnabledCoreShortcodes()
{
$needle = '<ul class="nav navbar-nav nav-main ml-auto">';
@@ -1556,6 +1557,7 @@ while(&#036;row = &#036;sql-&gt;fetch())
4 => array('input' => 'test123 xxx.jpg', 'mode' => 'file', 'expected' => 'test123-xxx.jpg'),
5 => array('input' => '2.1.4 (test)', 'mode' => 'version', 'expected' => '2.1.4'),
6 => array('input' => $url, 'mode'=>'url', 'expected' => $url),
7 => array('input' => array('1', 'xxx'), 'mode'=>'str', 'expected' => array('1', 'xxx')),
);
foreach($tests as $var)