aboutsummaryrefslogtreecommitdiffstats
path: root/tests/functions_acp
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2010-09-16 13:04:12 +0200
committerJoas Schilling <nickvergessen@gmx.de>2011-02-01 13:38:44 +0100
commit737849bc23dc8081a82f00c78247e824b6a42daf (patch)
treeb703716ca4e1051a8db95e95fffe46163badda21 /tests/functions_acp
parent11e3804f97fc0ac5317d8e211c117c6572699976 (diff)
downloadforums-737849bc23dc8081a82f00c78247e824b6a42daf.tar
forums-737849bc23dc8081a82f00c78247e824b6a42daf.tar.gz
forums-737849bc23dc8081a82f00c78247e824b6a42daf.tar.bz2
forums-737849bc23dc8081a82f00c78247e824b6a42daf.tar.xz
forums-737849bc23dc8081a82f00c78247e824b6a42daf.zip
[ticket/9823] Unit tests for validate_config_vars.
Fix some documentations and use the $max-var instead of the magic-number in validate_config_vars. PHPBB3-9823
Diffstat (limited to 'tests/functions_acp')
-rw-r--r--tests/functions_acp/all_tests.php2
-rw-r--r--tests/functions_acp/validate_config_vars.php152
-rw-r--r--tests/functions_acp/validate_range.php11
3 files changed, 157 insertions, 8 deletions
diff --git a/tests/functions_acp/all_tests.php b/tests/functions_acp/all_tests.php
index d2895da311..64956593fd 100644
--- a/tests/functions_acp/all_tests.php
+++ b/tests/functions_acp/all_tests.php
@@ -18,6 +18,7 @@ require_once 'PHPUnit/TextUI/TestRunner.php';
require_once 'functions_acp/build_cfg_template.php';
require_once 'functions_acp/build_select.php';
require_once 'functions_acp/h_radio.php';
+require_once 'functions_acp/validate_config_vars.php';
require_once 'functions_acp/validate_range.php';
class phpbb_functions_acp_all_tests
@@ -34,6 +35,7 @@ class phpbb_functions_acp_all_tests
$suite->addTestSuite('phpbb_functions_acp_build_cfg_template_test');
$suite->addTestSuite('phpbb_functions_acp_built_select_test');
$suite->addTestSuite('phpbb_functions_acp_h_radio_test');
+ $suite->addTestSuite('phpbb_functions_acp_validate_config_vars_test');
$suite->addTestSuite('phpbb_functions_acp_validate_range_test');
return $suite;
diff --git a/tests/functions_acp/validate_config_vars.php b/tests/functions_acp/validate_config_vars.php
new file mode 100644
index 0000000000..be7c3bf6de
--- /dev/null
+++ b/tests/functions_acp/validate_config_vars.php
@@ -0,0 +1,152 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+require_once 'test_framework/framework.php';
+require_once 'functions_acp/user_mock.php';
+require_once '../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' => phpbb_functions_acp_validate_config_vars_test::return_string(255),
+ 'test_string_128' => phpbb_functions_acp_validate_config_vars_test::return_string(128),
+ 'test_string_32_64' => phpbb_functions_acp_validate_config_vars_test::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' => phpbb_functions_acp_validate_config_vars_test::return_string(20)),
+ array('SETTING_TOO_SHORT'),
+ ),
+ array(
+ array('test_string' => array('lang' => 'TEST_STRING', 'validate' => 'string')),
+ array('test_string' => phpbb_functions_acp_validate_config_vars_test::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' => phpbb_functions_acp_validate_config_vars_test::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);
+ }
+}
diff --git a/tests/functions_acp/validate_range.php b/tests/functions_acp/validate_range.php
index fc2eaf1a60..253ef8d266 100644
--- a/tests/functions_acp/validate_range.php
+++ b/tests/functions_acp/validate_range.php
@@ -13,14 +13,9 @@ require_once '../phpBB/includes/functions_acp.php';
class phpbb_functions_acp_validate_range_test extends phpbb_test_case
{
-/* 'BOOL' => array('php_type' => 'int', 'min' => 0, 'max' => 1),
- 'USINT' => array('php_type' => 'int', 'min' => 0, 'max' => 65535),
- 'UINT' => array('php_type' => 'int', 'min' => 0, 'max' => (int) 0x7fffffff),
- 'INT' => array('php_type' => 'int', 'min' => (int) 0x80000000, 'max' => (int) 0x7fffffff),
- 'TINT' => array('php_type' => 'int', 'min' => -128, 'max' => 127),
-
- 'VCHAR' => array('php_type' => 'string', 'min' => 0, 'max' => 255),
-*/
+ /**
+ * Helper function which returns a string in a given length.
+ */
static public function return_string($length)
{
$string = '';