mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-06 23:55:26 +02:00
Merge PR #1142 branch 'nickvergessen/ticket/11250' into develop
* nickvergessen/ticket/11250: [ticket/11250] Use user defined message as incomplete message [ticket/11250] Add tests for simple nesting and code [ticket/11250] Run tests by default and add an option for incomplete ones [ticket/11250] Fix parsing result with special chars [ticket/11250] Add tests for size and attachment [ticket/11250] Fix method names [ticket/11250] Add some comments and fix a description [ticket/11250] Add some more tests for quotes [ticket/11250] Move quote special cases from class to unit tests [ticket/11250] Add parsing tests for our basic bbcodes in simple cases
This commit is contained in:
commit
85248cd63d
@ -702,17 +702,6 @@ class bbcode_firstpass extends bbcode
|
||||
{
|
||||
global $config, $user;
|
||||
|
||||
/**
|
||||
* If you change this code, make sure the cases described within the following reports are still working:
|
||||
* #3572 - [quote="[test]test"]test [ test[/quote] - (correct: parsed)
|
||||
* #14667 - [quote]test[/quote] test ] and [ test [quote]test[/quote] (correct: parsed)
|
||||
* #14770 - [quote="["]test[/quote] (correct: parsed)
|
||||
* [quote="[i]test[/i]"]test[/quote] (correct: parsed)
|
||||
* [quote="[quote]test[/quote]"]test[/quote] (correct: parsed - Username displayed as [quote]test[/quote])
|
||||
* #20735 - [quote]test[/[/b]quote] test [/quote][/quote] test - (correct: quoted: "test[/[/b]quote] test" / non-quoted: "[/quote] test" - also failed if layout distorted)
|
||||
* #40565 - [quote="a"]a[/quote][quote="a]a[/quote] (correct: first quote tag parsed, second quote tag unparsed)
|
||||
*/
|
||||
|
||||
$in = str_replace("\r\n", "\n", str_replace('\"', '"', trim($in)));
|
||||
|
||||
if (!$in)
|
||||
|
@ -2,28 +2,264 @@
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @version $Id$
|
||||
* @copyright (c) 2008 phpBB Group
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
// require_once dirname(__FILE__) . '/../../phpBB/includes/bbcode/bbcode_parser_base.php';
|
||||
// require_once dirname(__FILE__) . '/../../phpBB/includes/bbcode/bbcode_parser.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/bbcode.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/message_parser.php';
|
||||
|
||||
class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_both_passes()
|
||||
public function bbcode_firstpass_data()
|
||||
{
|
||||
$this->markTestIncomplete('New bbcode parser has not been backported from feature/ascraeus-experiment yet.');
|
||||
return array(
|
||||
// Default bbcodes from in their simplest way
|
||||
array(
|
||||
'Test default bbcodes: simple bold',
|
||||
'[b]bold[/b]',
|
||||
'[b:]bold[/b:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple underlined',
|
||||
'[u]underlined[/u]',
|
||||
'[u:]underlined[/u:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple italic',
|
||||
'[i]italic[/i]',
|
||||
'[i:]italic[/i:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple color rgb',
|
||||
'[color=#FF0000]colored[/color]',
|
||||
'[color=#FF0000:]colored[/color:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple color name',
|
||||
'[color=red]colored[/color]',
|
||||
'[color=red:]colored[/color:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple size',
|
||||
'[size=75]smaller[/size]',
|
||||
'[size=75:]smaller[/size:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple quote',
|
||||
'[quote]quoted[/quote]',
|
||||
'[quote:]quoted[/quote:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple quote with username',
|
||||
'[quote="username"]quoted[/quote]',
|
||||
'[quote="username":]quoted[/quote:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple code',
|
||||
'[code]unparsed code[/code]',
|
||||
'[code:]unparsed code[/code:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple php code',
|
||||
'[code=php]unparsed code[/code]',
|
||||
'[code=php:]<span class="syntaxdefault">unparsed code</span>[/code:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple list',
|
||||
'[list]no item[/list]',
|
||||
'[list:]no item[/list:u:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple list-item only',
|
||||
'[*]unparsed',
|
||||
'[*]unparsed',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple list-item',
|
||||
'[list][*]item[/list]',
|
||||
'[list:][*:]item[/*:m:][/list:u:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple list-item closed',
|
||||
'[list][*]item[/*][/list]',
|
||||
'[list:][*:]item[/*:][/list:u:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple list-item numbered',
|
||||
'[list=1][*]item[/list]',
|
||||
'[list=1:][*:]item[/*:m:][/list:o:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple list-item alpha',
|
||||
'[list=a][*]item[/list]',
|
||||
'[list=a:][*:]item[/*:m:][/list:o:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple list-item roman',
|
||||
'[list=i][*]item[/list]',
|
||||
'[list=i:][*:]item[/*:m:][/list:o:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple list-item disc',
|
||||
'[list=disc][*]item[/list]',
|
||||
'[list=disc:][*:]item[/*:m:][/list:u:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple list-item circle',
|
||||
'[list=circle][*]item[/list]',
|
||||
'[list=circle:][*:]item[/*:m:][/list:u:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple list-item square',
|
||||
'[list=square][*]item[/list]',
|
||||
'[list=square:][*:]item[/*:m:][/list:u:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple img',
|
||||
'[img]https://area51.phpbb.com/images/area51.png[/img]',
|
||||
'[img:]https://area51.phpbb.com/images/area51.png[/img:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple url',
|
||||
'[url]https://area51.phpbb.com/[/url]',
|
||||
'[url:]https://area51.phpbb.com/[/url:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple url with description',
|
||||
'[url=https://area51.phpbb.com/]Area51[/url]',
|
||||
'[url=https://area51.phpbb.com/:]Area51[/url:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple email',
|
||||
'[email]bbcode-test@phpbb.com[/email]',
|
||||
'[email:]bbcode-test@phpbb.com[/email:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple email with description',
|
||||
'[email=bbcode-test@phpbb.com]Email[/email]',
|
||||
'[email=bbcode-test@phpbb.com:]Email[/email:]',
|
||||
),
|
||||
array(
|
||||
'Test default bbcodes: simple attachment',
|
||||
'[attachment=0]filename[/attachment]',
|
||||
'[attachment=0:]<!-- ia0 -->filename<!-- ia0 -->[/attachment:]',
|
||||
),
|
||||
|
||||
$parser = new phpbb_bbcode_parser();
|
||||
// Special cases for quote which were reported as bugs before
|
||||
array(
|
||||
'PHPBB3-1401 - correct: parsed',
|
||||
'[quote="[test]test"]test [ test[/quote]',
|
||||
'[quote="[test]test":]test [ test[/quote:]',
|
||||
),
|
||||
array(
|
||||
'PHPBB3-6117 - correct: parsed',
|
||||
'[quote]test[/quote] test ] and [ test [quote]test[/quote]',
|
||||
'[quote:]test[/quote:] test ] and [ test [quote:]test[/quote:]',
|
||||
),
|
||||
array(
|
||||
'PHPBB3-6200 - correct: parsed',
|
||||
'[quote="["]test[/quote]',
|
||||
'[quote="[":]test[/quote:]',
|
||||
),
|
||||
array(
|
||||
'PHPBB3-9364 - quoted: "test[/[/b]quote] test" / non-quoted: "[/quote] test" - also failed if layout distorted',
|
||||
'[quote]test[/[/b]quote] test [/quote][/quote] test',
|
||||
'[quote:]test[/[/b]quote] test [/quote:][/quote] test',
|
||||
),
|
||||
array(
|
||||
'PHPBB3-8096 - first quote tag parsed, second quote tag unparsed',
|
||||
'[quote="a"]a[/quote][quote="a]a[/quote]',
|
||||
'[quote="a":]a[/quote:][quote="a]a[/quote]',
|
||||
),
|
||||
|
||||
$result = $parser->first_pass('[i]Italic [u]underlined text[/u][/i]');
|
||||
$result = $parser->second_pass($result);
|
||||
// Simple bbcodes nesting
|
||||
array(
|
||||
'Allow textual bbcodes in textual bbcodes',
|
||||
'[b]bold [i]bold + italic[/i][/b]',
|
||||
'[b:]bold [i:]bold + italic[/i:][/b:]',
|
||||
),
|
||||
array(
|
||||
'Allow textual bbcodes in url with description',
|
||||
'[url=https://area51.phpbb.com/]Area51 [i]italic[/i][/url]',
|
||||
'[url=https://area51.phpbb.com/:]Area51 [i:]italic[/i:][/url:]',
|
||||
),
|
||||
array(
|
||||
'Allow url with description in textual bbcodes',
|
||||
'[i]italic [url=https://area51.phpbb.com/]Area51[/url][/i]',
|
||||
'[i:]italic [url=https://area51.phpbb.com/:]Area51[/url:][/i:]',
|
||||
),
|
||||
|
||||
$expected = '<span style="font-style: italic">Italic <span style="text-decoration: underline">underlined text</span></span>';
|
||||
// Nesting bbcodes into quote usernames
|
||||
array(
|
||||
'Allow textual bbcodes in usernames',
|
||||
'[quote="[i]test[/i]"]test[/quote]',
|
||||
'[quote="[i:]test[/i:]":]test[/quote:]',
|
||||
),
|
||||
array(
|
||||
'Allow links bbcodes in usernames',
|
||||
'[quote="[url=https://area51.phpbb.com/]test[/url]"]test[/quote]',
|
||||
'[quote="[url=https://area51.phpbb.com/:]test[/url:]":]test[/quote:]',
|
||||
),
|
||||
array(
|
||||
'Allow img bbcodes in usernames - Username displayed the image',
|
||||
'[quote="[img]https://area51.phpbb.com/images/area51.png[/img]"]test[/quote]',
|
||||
'[quote="[img:]https://area51.phpbb.com/images/area51.png[/img:]":]test[/quote:]',
|
||||
),
|
||||
array(
|
||||
'Disallow flash bbcodes in usernames - Username displayed as [flash]http://www.phpbb.com/[/flash]',
|
||||
'[quote="[flash]http://www.phpbb.com/[/flash]"]test[/quote]',
|
||||
'[quote="[flash]http://www.phpbb.com/[/flash]":]test[/quote:]',
|
||||
),
|
||||
array(
|
||||
'Disallow quote bbcodes in usernames - Username displayed as [quote]test[/quote]',
|
||||
'[quote="[quote]test[/quote]"]test[/quote]',
|
||||
'[quote="[quote]test[/quote]":]test[/quote:]',
|
||||
),
|
||||
|
||||
$this->assertEquals($expected, $result, 'Simple nested BBCode first+second pass');
|
||||
// Do not parse bbcodes in code boxes
|
||||
array(
|
||||
'Do not parse textual bbcodes in code',
|
||||
'[code]unparsed code [b]bold [i]bold + italic[/i][/b][/code]',
|
||||
'[code:]unparsed code [b]bold [i]bold + italic[/i][/b][/code:]',
|
||||
),
|
||||
array(
|
||||
'Do not parse quote bbcodes in code',
|
||||
'[code]unparsed code [quote="username"]quoted[/quote][/code]',
|
||||
'[code:]unparsed code [quote="username"]quoted[/quote][/code:]',
|
||||
),
|
||||
|
||||
// New user friendly mixed nesting
|
||||
array(
|
||||
'Textual bbcode nesting into textual bbcode',
|
||||
'[b]bold [i]bold + italic[/b] italic[/i]',
|
||||
'[b:]bold [i:]bold + italic[/b:] italic[/i:]',
|
||||
'Incomplete test case: secondpass parses as [b:]bold [i:]bold + italic[/i:] italic[/b:]',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider bbcode_firstpass_data
|
||||
*/
|
||||
public function test_bbcode_firstpass($description, $message, $expected, $incomplete = false)
|
||||
{
|
||||
if ($incomplete)
|
||||
{
|
||||
$this->markTestIncomplete($incomplete);
|
||||
}
|
||||
|
||||
global $user, $request;
|
||||
$user = new phpbb_mock_user;
|
||||
$request = new phpbb_mock_request;
|
||||
|
||||
$bbcode = new bbcode_firstpass();
|
||||
$bbcode->message = $message;
|
||||
$bbcode->bbcode_init(false);
|
||||
$bbcode->parse_bbcode();
|
||||
$this->assertEquals($expected, $bbcode->message);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user