aboutsummaryrefslogtreecommitdiffstats
path: root/tests/group/helper_test_case.php
blob: e29877033104205f47e2420d976fabbc4d06d6dc (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
115
116
117
118
119
120
121
122
123
<?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.
 *
 */

class phpbb_group_helper_test_case extends phpbb_test_case
{
	/** @var  \phpbb\group\helper */
	protected $group_helper;

	protected function config_defaults()
	{
		$defaults = array(
			'ranks_path' => 'images/ranks'
		);
		return $defaults;
	}

	protected function get_test_language_data_set()
	{
		return array(
			'G_BOTS'					=> 'Bots',
			'G_NEW_GROUP'				=> 'Some new group',
			'G_not_uppercase'			=> 'The key does not contain uppercase letters',
			'G_GROUP_WITH_ÜMLAUTS'		=> 'Should work',
		);
	}

	protected function get_test_rank_data_set()
	{
		return array(
			'special' => array(
				1 => array(
					'rank_id'		=> 1,
					'rank_title'	=> 'Site admin',
					'rank_special'	=> 1,
					'rank_image'	=> 'siteadmin.png',
				),
				2 => array(
					'rank_id'		=> 2,
					'rank_title'	=> 'Test member',
					'rank_special'	=> 1,
					'rank_image'	=> '',
				)
			)
		);
	}

	protected function setup_engine(array $new_config = array())
	{
		global $phpbb_dispatcher, $phpbb_root_path, $phpEx;

		// Set up authentication data for testing
		$auth = $this->getMock('\phpbb\auth\auth');
		$auth->expects($this->any())
			->method('acl_get')
			->with($this->stringContains('_'), $this->anything())
			->will($this->returnValueMap(array(
				array('u_viewprofile', true),
			)));

		// Set up cache service
		$cache_service = $this->getMockBuilder('\phpbb\cache\service')->disableOriginalConstructor()->getMock();
		$cache_service->expects($this->any())
			->method('obtain_ranks')
			->will($this->returnValue($this->get_test_rank_data_set()));

		// Set up configuration
		$defaults = $this->config_defaults();
		$config = new \phpbb\config\config(array_merge($defaults, $new_config));

		// Set up language service
		$lang = new \phpbb\language\language(
			new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)
		);

		// Set up language data for testing
		$reflection_class = new ReflectionClass('\phpbb\language\language');

		// Set default language files loaded flag to true
		$loaded_flag = $reflection_class->getProperty('common_language_files_loaded');
		$loaded_flag->setAccessible(true);
		$loaded_flag->setValue($lang, true);

		// Set up test language data
		$lang_array = $reflection_class->getProperty('lang');
		$lang_array->setAccessible(true);
		$lang_array->setValue($lang, $this->get_test_language_data_set());

		// Set up event dispatcher
		$phpbb_dispatcher = new phpbb_mock_event_dispatcher();

		// Set up path helper
		$path_helper = $this->getMockBuilder('\phpbb\path_helper')
			->disableOriginalConstructor()
			->setMethods(array())
			->getMock();
		$path_helper->method('get_phpbb_root_path')
			->willReturn($phpbb_root_path);
		$path_helper->method('get_php_ext')
			->willReturn($phpEx);
		$path_helper->method('update_web_root_path')
			->will($this->returnArgument(0));

		$user = new \phpbb\user($lang, '\phpbb\datetime');
		$user->data['user_id'] = ANONYMOUS;

		$this->group_helper = new \phpbb\group\helper($auth, $cache_service, $config, $lang, $phpbb_dispatcher, $path_helper, $user);
	}

	public function setUp()
	{
		$this->setup_engine();
	}
}