Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
34.00% |
17 / 50 |
|
54.55% |
6 / 11 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_functions_content_get_username_string_test | |
34.00% |
17 / 50 |
|
54.55% |
6 / 11 |
45.79 | |
0.00% |
0 / 1 |
| setUp | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |||
| get_username_string_profile_data | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| test_get_username_string_profile | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_username_string_username_data | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| test_get_username_string_username | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_username_string_colour_data | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| test_get_username_string_colour | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_username_string_full_data | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| test_get_username_string_full | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_username_string_no_profile_data | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| test_get_username_string_no_profile | |
100.00% |
1 / 1 |
|
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 | |
| 14 | class phpbb_functions_content_get_username_string_test extends phpbb_test_case |
| 15 | { |
| 16 | protected function setUp(): void |
| 17 | { |
| 18 | parent::setUp(); |
| 19 | |
| 20 | global $auth, $phpbb_dispatcher, $user; |
| 21 | $auth = $this->createMock('\phpbb\auth\auth'); |
| 22 | $auth->expects($this->any()) |
| 23 | ->method('acl_get') |
| 24 | ->with($this->stringContains('_'), $this->anything()) |
| 25 | ->will($this->returnValueMap(array( |
| 26 | array('u_viewprofile', true), |
| 27 | ))); |
| 28 | $phpbb_dispatcher = new phpbb_mock_event_dispatcher; |
| 29 | $user->data['user_id'] = ANONYMOUS; |
| 30 | $user->lang['GUEST'] = 'Guest'; |
| 31 | } |
| 32 | |
| 33 | public static function get_username_string_profile_data() |
| 34 | { |
| 35 | global $phpbb_root_path, $phpEx; |
| 36 | |
| 37 | return array( |
| 38 | array(ANONYMOUS, 'Anonymous', '', false, false, ''), |
| 39 | array(2, 'Administrator', 'FF0000', false, false, "{$phpbb_root_path}memberlist.$phpEx?mode=viewprofile&u=2"), |
| 40 | array(42, 'User42', '', false, 'http://www.example.org/user.php?mode=show', 'http://www.example.org/user.php?mode=show&u=42'), |
| 41 | ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @dataProvider get_username_string_profile_data |
| 46 | */ |
| 47 | public function test_get_username_string_profile($user_id, $username, $user_colour, $guest_username, $custom_profile_url, $expected) |
| 48 | { |
| 49 | $this->assertEquals($expected, get_username_string('profile', $user_id, $username, $user_colour, $guest_username, $custom_profile_url)); |
| 50 | } |
| 51 | |
| 52 | public static function get_username_string_username_data() |
| 53 | { |
| 54 | return array( |
| 55 | array(ANONYMOUS, '', '', false, false, 'Guest'), |
| 56 | array(ANONYMOUS, '', '', 'CustomName', false, 'CustomName'), |
| 57 | array(2, 'User2', '', false, false, 'User2'), |
| 58 | array(5, 'User5', '', 'Anonymous', false, 'User5'), |
| 59 | array(128, 'User128', '', false, false, 'User128'), |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @dataProvider get_username_string_username_data |
| 65 | */ |
| 66 | public function test_get_username_string_username($user_id, $username, $user_colour, $guest_username, $custom_profile_url, $expected) |
| 67 | { |
| 68 | $this->assertEquals($expected, get_username_string('username', $user_id, $username, $user_colour, $guest_username, $custom_profile_url)); |
| 69 | } |
| 70 | |
| 71 | public static function get_username_string_colour_data() |
| 72 | { |
| 73 | return array( |
| 74 | array(0, '', '', false, false, ''), |
| 75 | array(0, '', 'F0F0F0', false, false, '#F0F0F0'), |
| 76 | array(ANONYMOUS, 'Anonymous', '000000', false, false, '#000000'), |
| 77 | array(2, 'Administrator', '', false, false, ''), |
| 78 | ); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * @dataProvider get_username_string_colour_data |
| 83 | */ |
| 84 | public function test_get_username_string_colour($user_id, $username, $user_colour, $guest_username, $custom_profile_url, $expected) |
| 85 | { |
| 86 | $this->assertEquals($expected, get_username_string('colour', $user_id, $username, $user_colour, $guest_username, $custom_profile_url)); |
| 87 | } |
| 88 | |
| 89 | public static function get_username_string_full_data() |
| 90 | { |
| 91 | global $phpbb_root_path, $phpEx; |
| 92 | |
| 93 | return array( |
| 94 | array(0, '', '', false, false, '<span class="username">Guest</span>'), |
| 95 | array(ANONYMOUS, 'Anonymous', '', false, false, '<span class="username">Anonymous</span>'), |
| 96 | array(2, 'Administrator', 'FF0000', false, false, '<a href="' . $phpbb_root_path . 'memberlist.' . $phpEx . '?mode=viewprofile&u=2" style="color: #FF0000;" class="username-coloured">Administrator</a>'), |
| 97 | array(5, 'User5', '', false, 'http://www.example.org/user.php?mode=show', '<a href="http://www.example.org/user.php?mode=show&u=5" class="username">User5</a>'), |
| 98 | array(8, 'Eight', '', false, false, '<a href="' . $phpbb_root_path . 'memberlist.php?mode=viewprofile&u=8" class="username">Eight</a>'), |
| 99 | ); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * @dataProvider get_username_string_full_data |
| 104 | */ |
| 105 | public function test_get_username_string_full($user_id, $username, $user_colour, $guest_username, $custom_profile_url, $expected) |
| 106 | { |
| 107 | $this->assertEquals($expected, get_username_string('full', $user_id, $username, $user_colour, $guest_username, $custom_profile_url)); |
| 108 | } |
| 109 | |
| 110 | public static function get_username_string_no_profile_data() |
| 111 | { |
| 112 | return array( |
| 113 | array(ANONYMOUS, 'Anonymous', '', false, false, '<span class="username">Anonymous</span>'), |
| 114 | array(ANONYMOUS, 'Anonymous', '', '', false, '<span class="username">Guest</span>'), |
| 115 | array(2, 'Administrator', 'FF0000', false, false, '<span style="color: #FF0000;" class="username-coloured">Administrator</span>'), |
| 116 | array(8, 'Eight', '', false, false, '<span class="username">Eight</span>'), |
| 117 | ); |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * @dataProvider get_username_string_no_profile_data |
| 122 | */ |
| 123 | public function test_get_username_string_no_profile($user_id, $username, $user_colour, $guest_username, $custom_profile_url, $expected) |
| 124 | { |
| 125 | $this->assertEquals($expected, get_username_string('no_profile', $user_id, $username, $user_colour, $guest_username, $custom_profile_url)); |
| 126 | } |
| 127 | } |