aboutsummaryrefslogtreecommitdiffstats
path: root/tests/functions_acp/validate_config_vars_test.php
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@phpbb.com>2011-02-04 00:32:10 +0100
committerAndreas Fischer <bantu@phpbb.com>2011-02-04 00:32:10 +0100
commitbdc590aac89ec654c075f2b0327bc5f61cd0e402 (patch)
tree72c746c340aed1c50cf469942370cc9db6b30670 /tests/functions_acp/validate_config_vars_test.php
parent4aafe4b42239101b81d9216f552e00ad911ee25c (diff)
parent7dc293232114fc8a16326675fa229ef924b1b289 (diff)
downloadforums-bdc590aac89ec654c075f2b0327bc5f61cd0e402.tar
forums-bdc590aac89ec654c075f2b0327bc5f61cd0e402.tar.gz
forums-bdc590aac89ec654c075f2b0327bc5f61cd0e402.tar.bz2
forums-bdc590aac89ec654c075f2b0327bc5f61cd0e402.tar.xz
forums-bdc590aac89ec654c075f2b0327bc5f61cd0e402.zip
Merge branch 'ticket/nickvergessen/9823' into develop
* ticket/nickvergessen/9823: [ticket/9823] Replace 0x80000000 with -2147483648 in tests. [ticket/9823] Move mock file into the mock/ folder. [ticket/9823] Update Unit tests to the new system and correct some minor issues [ticket/9823] Update copyright year and add newline at the end of the file. [ticket/9823] Correct unit-tests to use self:: instead of the class-name. [ticket/9823] Unit tests for validate_config_vars. [ticket/9823] Unit tests for build_cfg_template. [ticket/9823] Unit tests for validate_rang. [ticket/9823] Unit tests for h_radio. [ticket/9823] Moving the functions. Unit tests for build_select. Conflicts: phpBB/adm/index.php
Diffstat (limited to 'tests/functions_acp/validate_config_vars_test.php')
-rw-r--r--tests/functions_acp/validate_config_vars_test.php151
1 files changed, 151 insertions, 0 deletions
diff --git a/tests/functions_acp/validate_config_vars_test.php b/tests/functions_acp/validate_config_vars_test.php
new file mode 100644
index 0000000000..aa63bc38df
--- /dev/null
+++ b/tests/functions_acp/validate_config_vars_test.php
@@ -0,0 +1,151 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+require_once dirname(__FILE__) . '/../mock/lang.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php';
+
+class phpbb_functions_acp_validate_config_vars_test extends phpbb_test_case
+{
+ /**
+ * Helper function which returns a string in a given length.
+ */
+ static public function return_string($length)
+ {
+ $string = '';
+ for ($i = 0; $i < $length; $i++)
+ {
+ $string .= 'a';
+ }
+ return $string;
+ }
+
+ /**
+ * 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_128' => array('lang' => 'TEST_STRING_128', 'validate' => 'string:128'),
+ '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' => self::return_string(255),
+ 'test_string_128' => self::return_string(128),
+ 'test_string_32_64' => self::return_string(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)
+ {
+ global $user;
+
+ $user->lang = new phpbb_mock_lang();
+
+ $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' => self::return_string(20)),
+ array('SETTING_TOO_SHORT'),
+ ),
+ array(
+ array('test_string' => array('lang' => 'TEST_STRING', 'validate' => 'string')),
+ array('test_string' => self::return_string(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' => self::return_string(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)
+ {
+ global $user;
+
+ $user->lang = new phpbb_mock_lang();
+
+ $phpbb_error = array();
+ validate_config_vars($test_data, $cfg_array, $phpbb_error);
+
+ $this->assertEquals($expected, $phpbb_error);
+ }
+}