mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
Merge branch 'develop-olympus' into develop
* develop-olympus: [ticket/217] Use positive assertions in tests. [ticket/217] Silence errors in tests, not code. [ticket/217] Use positive parameter statement for bbcode_init() [ticket/217] Adjust patch, add tests [ticket/217] Multiline [url] not converted
This commit is contained in:
commit
d02d00e951
3 changed files with 92 additions and 2 deletions
|
@ -102,20 +102,22 @@ class bbcode_firstpass extends bbcode
|
|||
/**
|
||||
* Init bbcode data for later parsing
|
||||
*/
|
||||
function bbcode_init()
|
||||
function bbcode_init($allow_custom_bbcode = true)
|
||||
{
|
||||
static $rowset;
|
||||
|
||||
// This array holds all bbcode data. BBCodes will be processed in this
|
||||
// order, so it is important to keep [code] in first position and
|
||||
// [quote] in second position.
|
||||
// To parse multiline URL we enable dotall option setting only for URL text
|
||||
// but not for link itself, thus [url][/url] is not affected.
|
||||
$this->bbcodes = array(
|
||||
'code' => array('bbcode_id' => 8, 'regexp' => array('#\[code(?:=([a-z]+))?\](.+\[/code\])#uise' => "\$this->bbcode_code('\$1', '\$2')")),
|
||||
'quote' => array('bbcode_id' => 0, 'regexp' => array('#\[quote(?:="(.*?)")?\](.+)\[/quote\]#uise' => "\$this->bbcode_quote('\$0')")),
|
||||
'attachment' => array('bbcode_id' => 12, 'regexp' => array('#\[attachment=([0-9]+)\](.*?)\[/attachment\]#uise' => "\$this->bbcode_attachment('\$1', '\$2')")),
|
||||
'b' => array('bbcode_id' => 1, 'regexp' => array('#\[b\](.*?)\[/b\]#uise' => "\$this->bbcode_strong('\$1')")),
|
||||
'i' => array('bbcode_id' => 2, 'regexp' => array('#\[i\](.*?)\[/i\]#uise' => "\$this->bbcode_italic('\$1')")),
|
||||
'url' => array('bbcode_id' => 3, 'regexp' => array('#\[url(=(.*))?\](.*)\[/url\]#uiUe' => "\$this->validate_url('\$2', '\$3')")),
|
||||
'url' => array('bbcode_id' => 3, 'regexp' => array('#\[url(=(.*))?\](?(1)((?s).*(?-s))|(.*))\[/url\]#uiUe' => "\$this->validate_url('\$2', ('\$3') ? '\$3' : '\$4')")),
|
||||
'img' => array('bbcode_id' => 4, 'regexp' => array('#\[img\](.*)\[/img\]#uiUe' => "\$this->bbcode_img('\$1')")),
|
||||
'size' => array('bbcode_id' => 5, 'regexp' => array('#\[size=([\-\+]?\d+)\](.*?)\[/size\]#uise' => "\$this->bbcode_size('\$1', '\$2')")),
|
||||
'color' => array('bbcode_id' => 6, 'regexp' => array('!\[color=(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z\-]+)\](.*?)\[/color\]!uise' => "\$this->bbcode_color('\$1', '\$2')")),
|
||||
|
@ -133,6 +135,11 @@ class bbcode_firstpass extends bbcode
|
|||
$this->parsed_items[$tag] = 0;
|
||||
}
|
||||
|
||||
if (!$allow_custom_bbcode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_array($rowset))
|
||||
{
|
||||
global $db;
|
||||
|
|
63
tests/bbcode/url_bbcode_test.php
Normal file
63
tests/bbcode/url_bbcode_test.php
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2010 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
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';
|
||||
require_once dirname(__FILE__) . '/../mock_user.php';
|
||||
|
||||
class phpbb_url_bbcode_test extends phpbb_test_case
|
||||
{
|
||||
public function url_bbcode_test_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'url only',
|
||||
'[url]http://www.phpbb.com/community/[/url]',
|
||||
'[url:]http://www.phpbb.com/community/[/url:]'
|
||||
),
|
||||
array(
|
||||
'url with title',
|
||||
'[url=http://www.phpbb.com/community/]One line URL text[/url]',
|
||||
'[url=http://www.phpbb.com/community/:]One line URL text[/url:]'
|
||||
),
|
||||
array(
|
||||
'url with multiline title',
|
||||
"[url=http://www.phpbb.com/community/]Multiline\x0AURL\x0Atext[/url]",
|
||||
"[url=http://www.phpbb.com/community/:]Multiline\x0AURL\x0Atext[/url:]"
|
||||
),
|
||||
array(
|
||||
'unclosed url with multiline',
|
||||
"test [url] test \x0A test [url=http://www.phpbb.com/]test[/url] test",
|
||||
"test [url] test \x0A test [url=http://www.phpbb.com/:]test[/url:] test"
|
||||
),
|
||||
array(
|
||||
'unclosed url with multiline and title',
|
||||
"test [url=http://www.phpbb.com/]test \x0A [url]http://phpbb.com[/url] test",
|
||||
"test [url=http://www.phpbb.com/:]test \x0A [url]http://phpbb.com[/url:] test"
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider url_bbcode_test_data
|
||||
*/
|
||||
public function test_url($description, $message, $expected)
|
||||
{
|
||||
global $user;
|
||||
$user = new phpbb_mock_user;
|
||||
|
||||
$bbcode = new bbcode_firstpass();
|
||||
$bbcode->message = $message;
|
||||
$bbcode->bbcode_init(false);
|
||||
$bbcode->parse_bbcode();
|
||||
$this->assertEquals($expected, $bbcode->message);
|
||||
}
|
||||
}
|
20
tests/mock_user.php
Normal file
20
tests/mock_user.php
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Mock user class.
|
||||
* This class is used when tests invoke phpBB code expecting to have a global
|
||||
* user object, to avoid instantiating the actual user object.
|
||||
* It has a minimum amount of functionality, just to make tests work.
|
||||
*/
|
||||
class phpbb_mock_user
|
||||
{
|
||||
public $host = "testhost";
|
||||
public $page = array('root_script_path' => '/');
|
||||
}
|
Loading…
Add table
Reference in a new issue