aboutsummaryrefslogtreecommitdiffstats
path: root/tests/functions_acp
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2010-09-16 01:08:18 +0200
committerJoas Schilling <nickvergessen@gmx.de>2011-02-01 13:38:42 +0100
commitc80afb555e1264f1acf736f7bf464dc4298cdfe1 (patch)
tree579b79d71910ac6cffec28227ddc88c94bb36c92 /tests/functions_acp
parentd59327a9c4dfcef41ccb884f396dadeff6aa1fbd (diff)
downloadforums-c80afb555e1264f1acf736f7bf464dc4298cdfe1.tar
forums-c80afb555e1264f1acf736f7bf464dc4298cdfe1.tar.gz
forums-c80afb555e1264f1acf736f7bf464dc4298cdfe1.tar.bz2
forums-c80afb555e1264f1acf736f7bf464dc4298cdfe1.tar.xz
forums-c80afb555e1264f1acf736f7bf464dc4298cdfe1.zip
[ticket/9823] Unit tests for validate_rang.
PHPBB3-9823
Diffstat (limited to 'tests/functions_acp')
-rw-r--r--tests/functions_acp/all_tests.php2
-rw-r--r--tests/functions_acp/validate_range.php185
2 files changed, 187 insertions, 0 deletions
diff --git a/tests/functions_acp/all_tests.php b/tests/functions_acp/all_tests.php
index d5f0c86dc9..2b9c06f0ed 100644
--- a/tests/functions_acp/all_tests.php
+++ b/tests/functions_acp/all_tests.php
@@ -17,6 +17,7 @@ require_once 'PHPUnit/TextUI/TestRunner.php';
require_once 'functions_acp/build_select.php';
require_once 'functions_acp/h_radio.php';
+require_once 'functions_acp/validate_range.php';
class phpbb_functions_acp_all_tests
{
@@ -31,6 +32,7 @@ class phpbb_functions_acp_all_tests
$suite->addTestSuite('phpbb_functions_acp_built_select_test');
$suite->addTestSuite('phpbb_functions_acp_h_radio_test');
+ $suite->addTestSuite('phpbb_functions_acp_validate_range_test');
return $suite;
}
diff --git a/tests/functions_acp/validate_range.php b/tests/functions_acp/validate_range.php
new file mode 100644
index 0000000000..fc2eaf1a60
--- /dev/null
+++ b/tests/functions_acp/validate_range.php
@@ -0,0 +1,185 @@
+<?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_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),
+*/
+ 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_range_data_fit()
+ {
+ return array(
+ array(array(array('column_type' => 'BOOL', 'lang' => 'TEST', 'value' => 0))),
+ array(array(array('column_type' => 'BOOL', 'lang' => 'TEST', 'value' => 1))),
+
+ array(array(array('column_type' => 'USINT', 'lang' => 'TEST', 'value' => 0))),
+ array(array(array('column_type' => 'USINT', 'lang' => 'TEST', 'value' => 65535))),
+ array(array(array('column_type' => 'USINT:32:128', 'lang' => 'TEST', 'value' => 35))),
+
+ array(array(array('column_type' => 'UINT', 'lang' => 'TEST', 'value' => 0))),
+ array(array(array('column_type' => 'UINT', 'lang' => 'TEST', 'value' => (int) 0x7fffffff))),
+ array(array(array('column_type' => 'UINT:32:128', 'lang' => 'TEST', 'value' => 35))),
+
+ array(array(array('column_type' => 'INT', 'lang' => 'TEST', 'value' => (int) 0x80000000))),
+ array(array(array('column_type' => 'INT', 'lang' => 'TEST', 'value' => (int) 0x7fffffff))),
+ array(array(array('column_type' => 'INT:-32:128', 'lang' => 'TEST', 'value' => -28))),
+ array(array(array('column_type' => 'INT:-32:128', 'lang' => 'TEST', 'value' => 35))),
+
+ array(array(array('column_type' => 'TINT', 'lang' => 'TEST', 'value' => -128))),
+ array(array(array('column_type' => 'TINT', 'lang' => 'TEST', 'value' => 127))),
+ array(array(array('column_type' => 'TINT:-32:64', 'lang' => 'TEST', 'value' => -16))),
+ array(array(array('column_type' => 'TINT:-32:64', 'lang' => 'TEST', 'value' => 16))),
+
+ array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => ''))),
+ array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => phpbb_functions_acp_validate_range_test::return_string(255)))),
+ array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => phpbb_functions_acp_validate_range_test::return_string(128)))),
+ );
+ }
+
+ /**
+ * @dataProvider validate_range_data_fit
+ */
+ public function test_validate_range_fit($test_data)
+ {
+ global $user;
+
+ $user->lang = new phpbb_mock_lang();
+
+ $phpbb_error = array();
+ validate_range($test_data, $phpbb_error);
+
+ $this->assertEquals(array(), $phpbb_error);
+ }
+
+ /**
+ * Data sets that throw the SETTING_TOO_LOW-error.
+ */
+ public function validate_range_data_too_low()
+ {
+ return array(
+ array(array(array('column_type' => 'BOOL', 'lang' => 'TEST', 'value' => -1))),
+
+ array(array(array('column_type' => 'USINT', 'lang' => 'TEST', 'value' => -1))),
+ array(array(array('column_type' => 'USINT:32:128', 'lang' => 'TEST', 'value' => 31))),
+
+ array(array(array('column_type' => 'UINT', 'lang' => 'TEST', 'value' => -1))),
+ array(array(array('column_type' => 'UINT:32:128', 'lang' => 'TEST', 'value' => 31))),
+
+ array(array(array('column_type' => 'INT', 'lang' => 'TEST', 'value' => ((int) 0x80000000) - 1))),
+ array(array(array('column_type' => 'INT:32:128', 'lang' => 'TEST', 'value' => 31))),
+ array(array(array('column_type' => 'INT:-32:128', 'lang' => 'TEST', 'value' => -33))),
+
+ array(array(array('column_type' => 'TINT', 'lang' => 'TEST', 'value' => -129))),
+ array(array(array('column_type' => 'TINT:32:64', 'lang' => 'TEST', 'value' => 31))),
+ array(array(array('column_type' => 'TINT:-32:64', 'lang' => 'TEST', 'value' => -33))),
+ );
+ }
+
+ /**
+ * @dataProvider validate_range_data_too_low
+ */
+ public function test_validate_range_too_low($test_data)
+ {
+ global $user;
+
+ $user->lang = new phpbb_mock_lang();
+
+ $phpbb_error = array();
+ validate_range($test_data, $phpbb_error);
+
+ $this->assertEquals(array('SETTING_TOO_LOW'), $phpbb_error);
+ }
+
+ /**
+ * Data sets that throw the SETTING_TOO_BIG-error.
+ */
+ public function validate_range_data_too_big()
+ {
+ return array(
+ array(array(array('column_type' => 'BOOL', 'lang' => 'TEST', 'value' => 2))),
+
+ array(array(array('column_type' => 'USINT', 'lang' => 'TEST', 'value' => 65536))),
+ array(array(array('column_type' => 'USINT:32:128', 'lang' => 'TEST', 'value' => 129))),
+
+ array(array(array('column_type' => 'UINT', 'lang' => 'TEST', 'value' => ((int) 0x7fffffff) + 1))),
+ array(array(array('column_type' => 'UINT:32:128', 'lang' => 'TEST', 'value' => 129))),
+
+ array(array(array('column_type' => 'INT', 'lang' => 'TEST', 'value' => ((int) 0x7fffffff) + 1))),
+ array(array(array('column_type' => 'INT:-32:-16', 'lang' => 'TEST', 'value' => -15))),
+ array(array(array('column_type' => 'INT:-32:128', 'lang' => 'TEST', 'value' => 129))),
+
+ array(array(array('column_type' => 'TINT', 'lang' => 'TEST', 'value' => 128))),
+ array(array(array('column_type' => 'TINT:-32:-16', 'lang' => 'TEST', 'value' => -15))),
+ array(array(array('column_type' => 'TINT:-32:64', 'lang' => 'TEST', 'value' => 65))),
+ );
+ }
+
+ /**
+ * @dataProvider validate_range_data_too_big
+ */
+ public function test_validate_range_too_big($test_data)
+ {
+ global $user;
+
+ $user->lang = new phpbb_mock_lang();
+
+ $phpbb_error = array();
+ validate_range($test_data, $phpbb_error);
+
+ $this->assertEquals(array('SETTING_TOO_BIG'), $phpbb_error);
+ }
+
+ /**
+ * Data sets that throw the SETTING_TOO_LONG-error.
+ */
+ public function validate_range_data_too_long()
+ {
+ return array(
+ array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => phpbb_functions_acp_validate_range_test::return_string(256)))),
+ array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => phpbb_functions_acp_validate_range_test::return_string(129)))),
+ );
+ }
+
+ /**
+ * @dataProvider validate_range_data_too_long
+ */
+ public function test_validate_range_too_long($test_data)
+ {
+ global $user;
+
+ $user->lang = new phpbb_mock_lang();
+
+ $phpbb_error = array();
+ validate_range($test_data, $phpbb_error);
+
+ $this->assertEquals(array('SETTING_TOO_LONG'), $phpbb_error);
+ }
+}