addCodeDefinitionSet(new JBBCode\DefaultCodeDefinitionSet()); $parser->parse($bbcode); return $parser->getAsHtml(); } /** * Asserts that the given bbcode matches the given html when * the bbcode is run through defaultParse. */ private function assertProduces($bbcode, $html) { $this->assertEquals($html, $this->defaultParse($bbcode)); } public function testEmptyString() { $this->assertProduces('', ''); } public function testOneTag() { $this->assertProduces('[b]this is bold[/b]', 'this is bold'); } public function testOneTagWithSurroundingText() { $this->assertProduces('buffer text [b]this is bold[/b] buffer text', 'buffer text this is bold buffer text'); } public function testMultipleTags() { $bbcode = <<bold tags and italics and things like that. EOD; $this->assertProduces($bbcode, $html); } public function testCodeOptions() { $code = 'This contains a [url=http://jbbcode.com/?b=2]url[/url] which uses an option.'; $html = 'This contains a url which uses an option.'; $this->assertProduces($code, $html); } public function testAttributes() { $parser = new JBBCode\Parser(); $builder = new JBBCode\CodeDefinitionBuilder('img', '{alt}'); $parser->addCodeDefinition($builder->setUseOption(true)->setParseContent(false)->build()); $expected = 'Multiple alt text options.'; $code = 'Multiple [img height="50" alt="alt text"]http://jbbcode.com/img.png[/img] options.'; $parser->parse($code); $result = $parser->getAsHTML(); $this->assertEquals($expected, $result); $code = 'Multiple [img height=50 alt="alt text"]http://jbbcode.com/img.png[/img] options.'; $parser->parse($code); $result = $parser->getAsHTML(); $this->assertEquals($expected, $result); } /** * @depends testCodeOptions */ public function testOmittedOption() { $code = 'This doesn\'t use the url option [url]http://jbbcode.com[/url].'; $html = 'This doesn\'t use the url option http://jbbcode.com.'; $this->assertProduces($code, $html); } public function testUnclosedTag() { $code = 'hello [b]world'; $html = 'hello world'; $this->assertProduces($code, $html); } public function testNestingTags() { $code = '[url=http://jbbcode.com][b]hello [u]world[/u][/b][/url]'; $html = 'hello world'; $this->assertProduces($code, $html); } public function testBracketInTag() { $this->assertProduces('[b]:-[[/b]', ':-['); } public function testBracketWithSpaceInTag() { $this->assertProduces('[b]:-[ [/b]', ':-[ '); } public function testBracketWithTextInTag() { $this->assertProduces('[b]:-[ foobar[/b]', ':-[ foobar'); } public function testMultibleBracketsWithTextInTag() { $this->assertProduces('[b]:-[ [fo[o[bar[/b]', ':-[ [fo[o[bar'); } }