aboutsummaryrefslogtreecommitdiff
blob: 7ea0f156e4debd4b324d17cac5a8fee6bf1626ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
 *
 * This file is part of the phpBB Forum Software package.
 *
 * @copyright (c) phpBB Limited <https://www.phpbb.com>
 * @license GNU General Public License, version 2 (GPL-2.0)
 *
 * For full copyright and license information, please see
 * the docs/CREDITS.txt file.
 *
 */

require_once dirname(__FILE__) . '/helper_test_case.php';

class phpbb_group_helper_get_name_string_test extends phpbb_group_helper_test_case
{

	public function get_name_string_profile_data()
	{
		global $phpbb_root_path, $phpEx;

		return array(
			array(0, 'Non existing group', '', false, ''),
			array(2, 'Administrators', 'AA0000', false, "{$phpbb_root_path}memberlist.$phpEx?mode=group&amp;g=2"),
			array(42, 'Example Group', '', 'http://www.example.org/group.php?mode=show', 'http://www.example.org/group.php?mode=show&amp;g=42'),
		);
	}

	/**
	* @dataProvider get_name_string_profile_data
	*/
	public function test_get_name_string_profile($group_id, $group_name, $group_colour, $custom_profile_url, $expected)
	{
		$this->assertEquals($expected, $this->group_helper->get_name_string('profile', $group_id, $group_name, $group_colour, $custom_profile_url));
	}

	public function get_name_string_group_name_data()
	{
		return array(
			// Should be fine
			array(0, 'Bots', 'AA0000', false, 'Bots'),
			array(1, 'new_group', '', false, 'Some new group'),
			array(2, 'group_with_ümlauts', '', 'http://www.example.org/group.php?mode=show', 'Should work'),

			// Should fail and thus return the same
			array(3, 'not_uppercase', 'FFFFFF', false, 'not_uppercase'),
			array(4, 'Awesome group', '', false, 'Awesome group'),
		);
	}

	/**
	 * @dataProvider get_name_string_group_name_data
	 */
	public function test_get_name_string_group_name($group_id, $group_name, $group_colour, $custom_profile_url, $expected)
	{
		$this->assertEquals($expected, $this->group_helper->get_name_string('group_name', $group_id, $group_name, $group_colour, $custom_profile_url));
	}

	public function get_name_string_colour_data()
	{
		return array(
			array(0, '', '', false, ''),
			array(0, '', 'F0F0F0', false, '#F0F0F0'),
			array(1, 'Guests', '000000', false, '#000000'),
			array(2, 'Administrators', '', false, ''),
		);
	}

	/**
	 * @dataProvider get_name_string_colour_data
	 */
	public function test_get_name_string_colour($group_id, $group_name, $group_colour, $custom_profile_url, $expected)
	{
		$this->assertEquals($expected, $this->group_helper->get_name_string('colour', $group_id, $group_name, $group_colour, $custom_profile_url));
	}

	public function get_name_string_full_data()
	{
		global $phpbb_root_path, $phpEx;

		return array(
			array(0, 'Bots', '000000', false, '<span class="username-coloured" style="color: #000000;">Bots</span>'),
			array(7, 'new_group', 'FFA500', false, '<a class="username-coloured" href="' . $phpbb_root_path . 'memberlist.' . $phpEx . '?mode=group&amp;g=7" style="color: #FFA500;">Some new group</a>'),
			array(14, 'Awesome group', '', 'http://www.example.org/group.php?mode=show', '<a class="username" href="http://www.example.org/group.php?mode=show&amp;g=14">Awesome group</a>'),
		);
	}

	/**
	 * @dataProvider get_name_string_full_data
	 */
	public function test_get_name_string_full($group_id, $group_name, $group_colour, $custom_profile_url, $expected)
	{
		$this->assertEquals($expected, $this->group_helper->get_name_string('full', $group_id, $group_name, $group_colour, $custom_profile_url));
	}

	public function get_name_string_no_profile_data()
	{
		return array(
			array(0, 'Bots', '000000', false, '<span class="username-coloured" style="color: #000000;">Bots</span>'),
			array(1, 'new_group', '', false, '<span class="username">Some new group</span>'),
			arraY(2, 'not_uppercase', 'FF0000', false, '<span class="username-coloured" style="color: #FF0000;">not_uppercase</span>'),
			array(5, 'Awesome group', '', 'http://www.example.org/group.php?mode=show', '<span class="username">Awesome group</span>'),
		);
	}

	/**
	 * @dataProvider get_name_string_no_profile_data
	 */
	public function test_get_name_string_no_profile($group_id, $group_name, $group_colour, $custom_profile_url, $expected)
	{
		$this->assertEquals($expected, $this->group_helper->get_name_string('no_profile', $group_id, $group_name, $group_colour, $custom_profile_url));
	}
}