New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ticket/11250 Remake the unit tests for the BBCode parser #1142
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
754dc9c
[ticket/11250] Add parsing tests for our basic bbcodes in simple cases
nickvergessen ade9f83
[ticket/11250] Move quote special cases from class to unit tests
nickvergessen deceeb7
[ticket/11250] Add some more tests for quotes
nickvergessen 90a81a0
[ticket/11250] Add some comments and fix a description
nickvergessen bf312b5
[ticket/11250] Fix method names
nickvergessen cce821f
[ticket/11250] Add tests for size and attachment
nickvergessen 1e5da14
[ticket/11250] Fix parsing result with special chars
nickvergessen 8bbf3a7
[ticket/11250] Run tests by default and add an option for incomplete …
nickvergessen 4f080ba
[ticket/11250] Add tests for simple nesting and code
nickvergessen ebe1f5d
[ticket/11250] Use user defined message as incomplete message
nickvergessen File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,28 +2,265 @@ | |
/** | ||
* | ||
* @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.'); | ||
|
||
$parser = new phpbb_bbcode_parser(); | ||
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:]', | ||
), | ||
|
||
$result = $parser->first_pass('[i]Italic [u]underlined text[/u][/i]'); | ||
$result = $parser->second_pass($result); | ||
// 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]', | ||
), | ||
|
||
$expected = '<span style="font-style: italic">Italic <span style="text-decoration: underline">underlined text</span></span>'; | ||
// 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:]', | ||
), | ||
|
||
$this->assertEquals($expected, $result, 'Simple nested BBCode first+second pass'); | ||
// 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:]', | ||
), | ||
|
||
// 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: 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('New bbcode parser has not been backported from feature/ascraeus-experiment yet.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You sure that this is text better than the personalized one? (like the one in line 240) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
} | ||
|
||
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); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct?
Specially the part:
test [/quote:][
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this is how it should be, see the mentioned ticket in the description http://tracker.phpbb.com/browse/PHPBB3-9364
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, misread how the uid works.