aboutsummaryrefslogtreecommitdiffstats
path: root/tests/functions_acp/validate_config_vars_test.php
blob: 5ccd73fe8da9ac92d264889e8ee2274bf1b581c6 (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
/**
*
* @package testing
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/

require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php';

class phpbb_functions_acp_validate_config_vars_test extends phpbb_test_case
{
	protected function setUp()
	{
		parent::setUp();

		global $user;

		$user = new phpbb_mock_user();
		$user->lang = new phpbb_mock_lang();
	}

	/**
	* Data sets that don't throw an error.
	*/
	public function validate_config_vars_fit_data()
	{
		return array(
			array(
				array(
					'test_bool'				=> array('lang' => 'TEST_BOOL',			'validate' => 'bool'),
					'test_string'			=> array('lang' => 'TEST_STRING',		'validate' => 'string'),
					'test_string'			=> array('lang' => 'TEST_STRING',		'validate' => 'string'),
					'test_string_128'		=> array('lang' => 'TEST_STRING_128',	'validate' => 'string:128'),
					'test_string_128'		=> array('lang' => 'TEST_STRING_128',	'validate' => 'string:128'),
					'test_string_32_64'		=> array('lang' => 'TEST_STRING_32_64',	'validate' => 'string:32:64'),
					'test_string_32_64'		=> array('lang' => 'TEST_STRING_32_64',	'validate' => 'string:32:64'),
					'test_int'				=> array('lang' => 'TEST_INT',			'validate' => 'int'),
					'test_int_32'			=> array('lang' => 'TEST_INT',			'validate' => 'int:32'),
					'test_int_32_64'		=> array('lang' => 'TEST_INT',			'validate' => 'int:32:64'),
					'test_lang'				=> array('lang' => 'TEST_LANG',			'validate' => 'lang'),
					/*
					'test_sp'				=> array('lang' => 'TEST_SP',			'validate' => 'script_path'),
					'test_rpath'			=> array('lang' => 'TEST_RPATH',		'validate' => 'rpath'),
					'test_rwpath'			=> array('lang' => 'TEST_RWPATH',		'validate' => 'rwpath'),
					'test_path'				=> array('lang' => 'TEST_PATH',			'validate' => 'path'),
					'test_wpath'			=> array('lang' => 'TEST_WPATH',		'validate' => 'wpath'),
					*/
				),
				array(
					'test_bool'			=> true,
					'test_string'		=> str_repeat('a', 255),
					'test_string'		=> str_repeat("\xC3\x84", 255),
					'test_string_128'	=> str_repeat('a', 128),
					'test_string_128'	=> str_repeat("\xC3\x84", 128),
					'test_string_32_64'	=> str_repeat('a', 48),
					'test_string_32_64'	=> str_repeat("\xC3\x84", 48),
					'test_int'			=> 128,
					'test_int_32'		=> 32,
					'test_int_32_64'	=> 48,
					'test_lang'			=> 'en',
				),
			),
		);
	}

	/**
	* @dataProvider validate_config_vars_fit_data
	*/
	public function test_validate_config_vars_fit($test_data, $cfg_array)
	{
		$phpbb_error = array();
		validate_config_vars($test_data, $cfg_array, $phpbb_error);

		$this->assertEquals(array(), $phpbb_error);
	}

	/**
	* Data sets that throw the error.
	*/
	public function validate_config_vars_error_data()
	{
		return array(
			array(
				array('test_string_32_64'		=> array('lang' => 'TEST_STRING_32_64',	'validate' => 'string:32:64')),
				array('test_string_32_64'	=> str_repeat('a', 20)),
				array('SETTING_TOO_SHORT'),
			),
			array(
				array('test_string_32_64'		=> array('lang' => 'TEST_STRING_32_64',	'validate' => 'string:32:64')),
				array('test_string_32_64'	=> str_repeat("\xC3\x84", 20)),
				array('SETTING_TOO_SHORT'),
			),
			array(
				array('test_string'		=> array('lang' => 'TEST_STRING',	'validate' => 'string')),
				array('test_string'		=> str_repeat('a', 256)),
				array('SETTING_TOO_LONG'),
			),
			array(
				array('test_string'		=> array('lang' => 'TEST_STRING',	'validate' => 'string')),
				array('test_string'		=> str_repeat("\xC3\x84", 256)),
				array('SETTING_TOO_LONG'),
			),
			array(
				array('test_string_32_64'	=> array('lang' => 'TEST_STRING_32_64',	'validate' => 'string:32:64')),
				array('test_string_32_64'	=> str_repeat('a', 65)),
				array('SETTING_TOO_LONG'),
			),
			array(
				array('test_string_32_64'	=> array('lang' => 'TEST_STRING_32_64',	'validate' => 'string:32:64')),
				array('test_string_32_64'	=> str_repeat("\xC3\x84", 65)),
				array('SETTING_TOO_LONG'),
			),

			array(
				array('test_int_32'		=> array('lang' => 'TEST_INT',			'validate' => 'int:32')),
				array('test_int_32'		=> 31),
				array('SETTING_TOO_LOW'),
			),
			array(
				array('test_int_32_64'	=> array('lang' => 'TEST_INT',			'validate' => 'int:32:64')),
				array('test_int_32_64'	=> 31),
				array('SETTING_TOO_LOW'),
			),
			array(
				array('test_int_32_64'	=> array('lang' => 'TEST_INT',			'validate' => 'int:32:64')),
				array('test_int_32_64'	=> 65),
				array('SETTING_TOO_BIG'),
			),
			array(
				array(
					'test_int_min'	=> array('lang' => 'TEST_INT_MIN',		'validate' => 'int:32:64'),
					'test_int_max'	=> array('lang' => 'TEST_INT_MAX',		'validate' => 'int:32:64'),
				),
				array(
					'test_int_min'	=> 52,
					'test_int_max'	=> 48,
				),
				array('SETTING_TOO_LOW'),
			),
			array(
				array('test_lang'		=> array('lang' => 'TEST_LANG',			'validate' => 'lang')),
				array('test_lang'		=> 'this_is_no_language'),
				array('WRONG_DATA_LANG'),
			),
		);
	}

	/**
	* @dataProvider validate_config_vars_error_data
	*/
	public function test_validate_config_vars_error($test_data, $cfg_array, $expected)
	{
		$phpbb_error = array();
		validate_config_vars($test_data, $cfg_array, $phpbb_error);

		$this->assertEquals($expected, $phpbb_error);
	}
}