Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
codemasher committed Mar 2, 2016
1 parent ef1b451 commit e52dbb9
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 16 deletions.
21 changes: 7 additions & 14 deletions tests/normal/Modules/HTML5ModuleTest.php
Expand Up @@ -88,8 +88,7 @@ public function containerDataProvider(){
* @dataProvider containerDataProvider
*/
public function testContainerModule($bbcode, $expected){
$parsed = $this->parser->parse($bbcode);
$this->assertEquals($expected, $parsed);
$this->assertEquals($expected, $this->parser->parse($bbcode));
}

public function expanderDataProvider(){
Expand All @@ -109,8 +108,7 @@ public function expanderDataProvider(){
* @dataProvider expanderDataProvider
*/
public function testExpanderModule($bbcode, $expected){
$parsed = $this->parser->parse($bbcode);
$parsed = preg_replace('/\"([a-f\d]{8})\"/i', '"abcdef12"', $parsed);
$parsed = preg_replace('/\"([a-f\d]{8})\"/i', '"abcdef12"', $this->parser->parse($bbcode));
$this->assertEquals($expected, $parsed);
}

Expand All @@ -126,8 +124,7 @@ public function linkDataProvider(){
* @dataProvider linkDataProvider
*/
public function testLinkModule($bbcode, $expected){
$parsed = $this->parser->parse($bbcode);
$this->assertEquals($expected, $parsed);
$this->assertEquals($expected, $this->parser->parse($bbcode));
}

public function testListModule(){
Expand Down Expand Up @@ -194,8 +191,7 @@ public function styledTextDataProvider(){
* @dataProvider styledTextDataProvider
*/
public function testStyledTextModule($bbcode, $expected){
$parsed = $this->parser->parse($bbcode);
$this->assertEquals($expected, $parsed);
$this->assertEquals($expected, $this->parser->parse($bbcode));
}

public function videoURLDataProvider(){
Expand All @@ -220,8 +216,7 @@ public function videoURLDataProvider(){
* @dataProvider videoURLDataProvider
*/
public function testVideoModuleURLMatch($url, $expected){
$parsed = $this->parser->parse('[video]'.$url.'[/video]');
$this->assertEquals($expected, $parsed);
$this->assertEquals($expected, $this->parser->parse('[video]'.$url.'[/video]'));
}

public function videoBBCodeDataProvider(){
Expand Down Expand Up @@ -254,8 +249,7 @@ public function videoBBCodeDataProvider(){
* @dataProvider videoBBCodeDataProvider
*/
public function testVideoModuleBBCode($bbcode, $expected){
$parsed = $this->parser->parse($bbcode);
$this->assertEquals($expected, $parsed);
$this->assertEquals($expected, $this->parser->parse($bbcode));
}

public function tableDataProvider(){
Expand All @@ -271,8 +265,7 @@ public function tableDataProvider(){
* @dataProvider tableDataProvider
*/
public function testTableModule($bbcode, $expected){
$parsed = $this->parser->parse($bbcode);
$this->assertEquals($expected, $parsed);
$this->assertEquals($expected, $this->parser->parse($bbcode));
}

}
82 changes: 80 additions & 2 deletions tests/normal/Modules/MarkdownModuleTest.php
Expand Up @@ -11,6 +11,7 @@

namespace chillerlan\BBCodeTest\normal\Modules;

use chillerlan\bbcode\Modules\Markdown\Headers;
use chillerlan\bbcode\Modules\Markdown\MarkdownBaseModule;
use chillerlan\bbcode\Parser;
use chillerlan\bbcode\ParserOptions;
Expand All @@ -28,9 +29,86 @@ protected function setUp(){
$options->allow_all = true;
$this->parser = new Parser($options);
}

public function testSanitizeCoverage(){
$this->assertEquals('**&**', $this->parser->parse('[b]&[/b]'));
}


public function testEmptyTags(){
$singletags = $this->parser->getSingle();
$_singletags = [
'br' => PHP_EOL,
'hr' => PHP_EOL.'----'.PHP_EOL,
];

foreach(array_keys($this->parser->getTagmap()) as $tag){
if(!in_array($tag, $singletags)){
$this->assertEquals('', $this->parser->parse('['.$tag.'][/'.$tag.']'));
}
else{
$this->assertEquals($_singletags[$tag], $this->parser->parse('['.$tag.']'));
}
}
}

public function headerDataProvider(){
$this->setUp();

return array_map(function($v){
return [$v];
}, array_keys($this->parser->getTagmap(), Headers::class));
}

/**
* @dataProvider headerDataProvider
*/
public function testHeaderModule($tag){
$expected = str_repeat('#', preg_replace('/[^\d]/', '', $tag)).' test'.PHP_EOL;

$this->assertEquals($expected, $this->parser->parse('['.$tag.']test[/'.$tag.']'));
}

public function testImageModule(){
$this->assertEquals('', $this->parser->parse('[img]javascript:alert(\'XSS\');[/img]'));
$this->assertEquals('![image](https://travis-ci.org/chillerlan/bbcode.svg)', $this->parser->parse('[img]https://travis-ci.org/chillerlan/bbcode.svg[/img]'));
$this->assertEquals('![foobar](https://travis-ci.org/chillerlan/bbcode.svg)', $this->parser->parse('[img alt=foobar]https://travis-ci.org/chillerlan/bbcode.svg[/img]'));
}

public function linkDataProvider(){
return [
['', '[url]javascript:alert(\'XSS\');[/url]'],
['', '[url=javascript:alert(\'XSS\');]test[/url]'],
['', '[url=javascript:alert(\'XSS\');]javascript:alert(\'XSS\');[/url]'],
['https://travis-ci.org/chillerlan/bbcode', '[url]https://travis-ci.org/chillerlan/bbcode[/url]'],
['[Travis CI: chillerlan/bbcode](https://travis-ci.org/chillerlan/bbcode)', '[url=https://travis-ci.org/chillerlan/bbcode]Travis CI: chillerlan/bbcode[/url]'],
['http://youtu.be/6r1-HTiwGiY', '[video]http://youtu.be/6r1-HTiwGiY[/video]'],
];
}

/**
* @dataProvider linkDataProvider
*/
public function testLinkModule($expected, $bbcode){
$this->assertEquals($expected, $this->parser->parse($bbcode));
}

public function styledTextDataProvider(){
return [
['[b]bold[/b]', '**bold**'],
['[strong]bold[/strong]', '**bold**'],
['[del]strikethrough[/del]', '~~strikethrough~~'],
['[s]strikethrough[/s]', '~~strikethrough~~'],
['[c]inline-code[/c]', '`inline-code`'],
['[i]italic[/i]', '_italic_'],
];
}

/**
* @dataProvider styledTextDataProvider
*/
public function testStyledTextModule($bbcode, $expected){
$this->assertEquals($expected, $this->parser->parse($bbcode));
}


}

0 comments on commit e52dbb9

Please sign in to comment.