Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
38.64% covered (danger)
38.64%
17 / 44
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_url_bbcode_test
38.64% covered (danger)
38.64%
17 / 44
50.00% covered (danger)
50.00%
1 / 2
2.92
0.00% covered (danger)
0.00%
0 / 1
 url_bbcode_test_data
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 1
2
 test_url
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14require_once __DIR__ . '/../../phpBB/includes/bbcode.php';
15require_once __DIR__ . '/../../phpBB/includes/message_parser.php';
16
17class phpbb_url_bbcode_test extends phpbb_test_case
18{
19    public static function url_bbcode_test_data()
20    {
21        return array(
22            array(
23                'url only',
24                '[url]http://www.phpbb.com/community/[/url]',
25                '[url:]http&#58;//www&#46;phpbb&#46;com/community/[/url:]'
26            ),
27            array(
28                'url with title',
29                '[url=http://www.phpbb.com/community/]One line URL text[/url]',
30                '[url=http&#58;//www&#46;phpbb&#46;com/community/:]One line URL text[/url:]'
31            ),
32            array(
33                'url with multiline title',
34                "[url=http://www.phpbb.com/community/]Multiline\x0AURL\x0Atext[/url]",
35                "[url=http&#58;//www&#46;phpbb&#46;com/community/:]Multiline\x0AURL\x0Atext[/url:]"
36            ),
37            array(
38                'unclosed url with multiline',
39                "test [url] test \x0A test [url=http://www.phpbb.com/]test[/url] test",
40                "test [url] test \x0A test [url=http&#58;//www&#46;phpbb&#46;com/:]test[/url:] test"
41            ),
42            array(
43                'unclosed url with multiline and title',
44                "test [url=http://www.phpbb.com/]test \x0A [url]http://phpbb.com[/url] test",
45                "test [url=http&#58;//www&#46;phpbb&#46;com/:]test \x0A [url]http://phpbb.com[/url:] test"
46            ),
47        );
48    }
49
50    /**
51    * @dataProvider url_bbcode_test_data
52    */
53    public function test_url($description, $message, $expected)
54    {
55        global $user, $request, $symfony_request, $phpbb_dispatcher, $config, $phpEx;
56        $phpEx = 'php';
57        $config = new \phpbb\config\config([
58            'max_post_font_size' => 0,
59            'force_server_vars' => 0,
60            'server_name' => 'testhost',
61        ]);
62        $user = new phpbb_mock_user;
63        $user->lang['UNAUTHORISED_BBCODE'] = 'UNAUTHORISED_BBCODE';
64        $request = new phpbb_mock_request;
65        $symfony_request = new \phpbb\symfony_request($request);
66        $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
67
68        $bbcode = new bbcode_firstpass();
69        $bbcode->message = $message;
70        $bbcode->bbcode_init(false);
71        $bbcode->parse_bbcode();
72        $this->assertEquals($expected, $bbcode->message);
73    }
74}