aboutsummaryrefslogtreecommitdiffstats
path: root/tests/functions
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2013-06-03 16:06:11 +0200
committerMarc Alexander <admin@m-a-styles.de>2013-06-03 16:06:11 +0200
commit3487b70cc066f090c55990a9082ed9684d438147 (patch)
tree850fbd6caacdc29c3632cdf4ce76413f69498684 /tests/functions
parent33a0859f4ac3454c12dda651f708e16fc6c45adb (diff)
downloadforums-3487b70cc066f090c55990a9082ed9684d438147.tar
forums-3487b70cc066f090c55990a9082ed9684d438147.tar.gz
forums-3487b70cc066f090c55990a9082ed9684d438147.tar.bz2
forums-3487b70cc066f090c55990a9082ed9684d438147.tar.xz
forums-3487b70cc066f090c55990a9082ed9684d438147.zip
[ticket/11579] Use test case helper class and use assert prefix for method
PHPBB3-11579
Diffstat (limited to 'tests/functions')
-rw-r--r--tests/functions/validate_data_helper.php (renamed from tests/functions/common_validate_data.php)19
-rw-r--r--tests/functions/validate_data_simple_test.php119
-rw-r--r--tests/functions/validate_email_test.php26
-rw-r--r--tests/functions/validate_lang_iso_test.php20
-rw-r--r--tests/functions/validate_username_test.php11
5 files changed, 100 insertions, 95 deletions
diff --git a/tests/functions/common_validate_data.php b/tests/functions/validate_data_helper.php
index 64c9499ac3..b8e8bfded3 100644
--- a/tests/functions/common_validate_data.php
+++ b/tests/functions/validate_data_helper.php
@@ -7,25 +7,32 @@
*
*/
-class phpbb_functions_common_validate_data extends phpbb_test_case
+class phpbb_functions_validate_data_helper extends PHPUnit_Framework_TestCase
{
+ protected $test_case;
+
+ public function __construct($test_case)
+ {
+ $this->test_case = $test_case;
+ }
+
/**
* Test provided input data with supplied checks and compare to expected
* results
*
+ * @param array $expected Array containing the expected results. Either
+ * an array containing the error message or the an empty
+ * array if input is correct
* @param array $input Input data with specific array keys that need to
* be matched by the ones in the other 2 params
* @param array $validate_check Array containing validate_data check
* settings, i.e. array('foobar' => array('string'))
- * @param array $expected Array containing the expected results. Either
- * an array containing the error message or the an empty
- * array if input is correct
*/
- public function validate_data_check($input, $validate_check, $expected)
+ public function assert_validate_data($expected, $input, $validate_check)
{
foreach ($input as $key => $data)
{
- $this->assertEquals($expected[$key], validate_data(array($data), array($validate_check[$key])));
+ $this->test_case->assertEquals($expected[$key], validate_data(array($data), array($validate_check[$key])));
}
}
}
diff --git a/tests/functions/validate_data_simple_test.php b/tests/functions/validate_data_simple_test.php
index 002b1f2298..db4f218eed 100644
--- a/tests/functions/validate_data_simple_test.php
+++ b/tests/functions/validate_data_simple_test.php
@@ -9,22 +9,32 @@
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
-require_once dirname(__FILE__) . '/common_validate_data.php';
+require_once dirname(__FILE__) . '/validate_data_helper.php';
class phpbb_functions_validate_data_simple_test extends phpbb_test_case
{
- protected $common;
+ protected $helper;
protected function setUp()
{
parent::setUp();
- $this->common = new phpbb_functions_common_validate_data;
+ $this->helper = new phpbb_functions_validate_data_helper($this);
}
public function test_validate_string()
{
- $this->common->validate_data_check(array(
+ $this->helper->assert_validate_data(array(
+ 'empty_opt' => array(),
+ 'empty' => array(),
+ 'foo' => array(),
+ 'foo_minmax_correct' => array(),
+ 'foo_minmax_short' => array('TOO_SHORT'),
+ 'foo_minmax_long' => array('TOO_LONG'),
+ 'empty_short' => array('TOO_SHORT'),
+ 'empty_length_opt' => array(),
+ ),
+ array(
'empty_opt' => '',
'empty' => '',
'foo' => 'foobar',
@@ -43,22 +53,20 @@ class phpbb_functions_validate_data_simple_test extends phpbb_test_case
'foo_minmax_long' => array('string', false, 2, 5),
'empty_short' => array('string', false, 1, 6),
'empty_length_opt' => array('string', true, 1, 6),
- ),
- array(
- 'empty_opt' => array(),
- 'empty' => array(),
- 'foo' => array(),
- 'foo_minmax_correct' => array(),
- 'foo_minmax_short' => array('TOO_SHORT'),
- 'foo_minmax_long' => array('TOO_LONG'),
- 'empty_short' => array('TOO_SHORT'),
- 'empty_length_opt' => array(),
));
}
public function test_validate_num()
{
- $this->common->validate_data_check(array(
+ $this->helper->assert_validate_data(array(
+ 'empty' => array(),
+ 'zero' => array(),
+ 'five_minmax_correct' => array(),
+ 'five_minmax_short' => array('TOO_SMALL'),
+ 'five_minmax_long' => array('TOO_LARGE'),
+ 'string' => array(),
+ ),
+ array(
'empty' => '',
'zero' => 0,
'five_minmax_correct' => 5,
@@ -73,20 +81,25 @@ class phpbb_functions_validate_data_simple_test extends phpbb_test_case
'five_minmax_short' => array('num', false, 7, 10),
'five_minmax_long' => array('num', false, 2, 3),
'string' => array('num'),
- ),
- array(
- 'empty' => array(),
- 'zero' => array(),
- 'five_minmax_correct' => array(),
- 'five_minmax_short' => array('TOO_SMALL'),
- 'five_minmax_long' => array('TOO_LARGE'),
- 'string' => array(),
));
}
public function test_validate_date()
{
- $this->common->validate_data_check(array(
+ $this->helper->assert_validate_data(array(
+ 'empty' => array('INVALID'),
+ 'empty_opt' => array(),
+ 'double_single' => array(),
+ 'single_single' => array(),
+ 'double_double' => array(),
+ // Currently fails
+ //'zero_year' => array(),
+ 'month_high' => array('INVALID'),
+ 'month_low' => array('INVALID'),
+ 'day_high' => array('INVALID'),
+ 'day_low' => array('INVALID'),
+ ),
+ array(
'empty' => '',
'empty_opt' => '',
'double_single' => '17-06-1990',
@@ -111,25 +124,18 @@ class phpbb_functions_validate_data_simple_test extends phpbb_test_case
'month_low' => array('date'),
'day_high' => array('date'),
'day_low' => array('date'),
- ),
- array(
- 'empty' => array('INVALID'),
- 'empty_opt' => array(),
- 'double_single' => array(),
- 'single_single' => array(),
- 'double_double' => array(),
- // Currently fails
- //'zero_year' => array(),
- 'month_high' => array('INVALID'),
- 'month_low' => array('INVALID'),
- 'day_high' => array('INVALID'),
- 'day_low' => array('INVALID'),
));
}
public function test_validate_match()
{
- $this->common->validate_data_check(array(
+ $this->helper->assert_validate_data(array(
+ 'empty_opt' => array(),
+ 'empty_empty_match' => array(),
+ 'foobar' => array(),
+ 'foobar_fail' => array('WRONG_DATA'),
+ ),
+ array(
'empty_opt' => '',
'empty_empty_match' => '',
'foobar' => 'foobar',
@@ -140,12 +146,6 @@ class phpbb_functions_validate_data_simple_test extends phpbb_test_case
'empty_empty_match' => array('match'),
'foobar' => array('match', false, '/[a-z]$/'),
'foobar_fail' => array('match', false, '/[a-z]$/'),
- ),
- array(
- 'empty_opt' => array(),
- 'empty_empty_match' => array(),
- 'foobar' => array(),
- 'foobar_fail' => array('WRONG_DATA'),
));
}
@@ -193,7 +193,7 @@ class phpbb_functions_validate_data_simple_test extends phpbb_test_case
// Set complexity to mixed case letters, numbers and symbols
$config['pass_complex'] = $pass_complexity;
- $this->common->validate_data_check(array(
+ $this->helper->assert_validate_data($expected, array(
'empty' => '',
'foobar_any' => 'foobar',
'foobar_mixed' => 'FooBar',
@@ -206,13 +206,24 @@ class phpbb_functions_validate_data_simple_test extends phpbb_test_case
'foobar_mixed' => array('password'),
'foobar_alpha' => array('password'),
'foobar_symbol' => array('password'),
- ),
- $expected);
+ ));
}
public function test_validate_jabber()
{
- $this->common->validate_data_check(array(
+ $this->helper->assert_validate_data(array(
+ 'empty' => array(),
+ 'no_seperator' => array('WRONG_DATA'),
+ 'no_user' => array('WRONG_DATA'),
+ 'no_realm' => array('WRONG_DATA'),
+ 'dot_realm' => array('WRONG_DATA'),
+ '-realm' => array('WRONG_DATA'),
+ 'realm-' => array('WRONG_DATA'),
+ 'correct' => array(),
+ 'prohibited' => array('WRONG_DATA'),
+ 'prohibited_char' => array('WRONG_DATA'),
+ ),
+ array(
'empty' => '',
'no_seperator' => 'testjabber.ccc',
'no_user' => '@jabber.ccc',
@@ -235,18 +246,6 @@ class phpbb_functions_validate_data_simple_test extends phpbb_test_case
'correct' => array('jabber'),
'prohibited' => array('jabber'),
'prohibited_char' => array('jabber'),
- ),
- array(
- 'empty' => array(),
- 'no_seperator' => array('WRONG_DATA'),
- 'no_user' => array('WRONG_DATA'),
- 'no_realm' => array('WRONG_DATA'),
- 'dot_realm' => array('WRONG_DATA'),
- '-realm' => array('WRONG_DATA'),
- 'realm-' => array('WRONG_DATA'),
- 'correct' => array(),
- 'prohibited' => array('WRONG_DATA'),
- 'prohibited_char' => array('WRONG_DATA'),
));
}
}
diff --git a/tests/functions/validate_email_test.php b/tests/functions/validate_email_test.php
index 47aa37e11f..2e81d3277e 100644
--- a/tests/functions/validate_email_test.php
+++ b/tests/functions/validate_email_test.php
@@ -10,13 +10,13 @@
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php';
require_once dirname(__FILE__) . '/../mock/user.php';
-require_once dirname(__FILE__) . '/common_validate_data.php';
+require_once dirname(__FILE__) . '/validate_data_helper.php';
class phpbb_functions_validate_email_test extends phpbb_database_test_case
{
protected $db;
protected $user;
- protected $common;
+ protected $helper;
public function getDataSet()
{
@@ -29,7 +29,7 @@ class phpbb_functions_validate_email_test extends phpbb_database_test_case
$this->db = $this->new_dbal();
$this->user = new phpbb_mock_user;
- $this->common = new phpbb_functions_common_validate_data;
+ $this->helper = new phpbb_functions_validate_data_helper($this);
}
public function test_validate_email()
@@ -41,7 +41,16 @@ class phpbb_functions_validate_email_test extends phpbb_database_test_case
$user = $this->user;
$user->optionset('banned_users', array('banned@example.com'));
- $this->common->validate_data_check(array(
+ $this->helper->assert_validate_data(array(
+ 'empty' => array(),
+ 'allowed' => array(),
+ 'invalid' => array('EMAIL_INVALID'),
+ 'valid_complex' => array(),
+ 'taken' => array('EMAIL_TAKEN'),
+ 'banned' => array('EMAIL_BANNED'),
+ 'no_mx' => array('DOMAIN_NO_MX_RECORD'),
+ ),
+ array(
'empty' => '',
'allowed' => 'foobar@example.com',
'invalid' => 'fööbar@example.com',
@@ -58,15 +67,6 @@ class phpbb_functions_validate_email_test extends phpbb_database_test_case
'taken' => array('email'),
'banned' => array('email'),
'no_mx' => array('email'),
- ),
- array(
- 'empty' => array(),
- 'allowed' => array(),
- 'invalid' => array('EMAIL_INVALID'),
- 'valid_complex' => array(),
- 'taken' => array('EMAIL_TAKEN'),
- 'banned' => array('EMAIL_BANNED'),
- 'no_mx' => array('DOMAIN_NO_MX_RECORD'),
));
}
}
diff --git a/tests/functions/validate_lang_iso_test.php b/tests/functions/validate_lang_iso_test.php
index b8a1827432..baf75108b7 100644
--- a/tests/functions/validate_lang_iso_test.php
+++ b/tests/functions/validate_lang_iso_test.php
@@ -8,12 +8,12 @@
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php';
-require_once dirname(__FILE__) . '/common_validate_data.php';
+require_once dirname(__FILE__) . '/validate_data_helper.php';
class phpbb_functions_validate_lang_iso_test extends phpbb_database_test_case
{
protected $db;
- protected $common;
+ protected $helper;
public function getDataSet()
{
@@ -25,7 +25,7 @@ class phpbb_functions_validate_lang_iso_test extends phpbb_database_test_case
parent::setUp();
$this->db = $this->new_dbal();
- $this->common = new phpbb_functions_common_validate_data;
+ $this->helper = new phpbb_functions_validate_data_helper($this);
}
public function test_validate_lang_iso()
@@ -34,7 +34,13 @@ class phpbb_functions_validate_lang_iso_test extends phpbb_database_test_case
$db = $this->db;
- $this->common->validate_data_check(array(
+ $this->helper->assert_validate_data(array(
+ 'empty' => array('WRONG_DATA'),
+ 'en' => array(),
+ 'cs' => array(),
+ 'de' => array('WRONG_DATA'),
+ ),
+ array(
'empty' => '',
'en' => 'en',
'cs' => 'cs',
@@ -45,12 +51,6 @@ class phpbb_functions_validate_lang_iso_test extends phpbb_database_test_case
'en' => array('language_iso_name'),
'cs' => array('language_iso_name'),
'de' => array('language_iso_name'),
- ),
- array(
- 'empty' => array('WRONG_DATA'),
- 'en' => array(),
- 'cs' => array(),
- 'de' => array('WRONG_DATA'),
));
}
}
diff --git a/tests/functions/validate_username_test.php b/tests/functions/validate_username_test.php
index 656248cec3..92c5ba6ee1 100644
--- a/tests/functions/validate_username_test.php
+++ b/tests/functions/validate_username_test.php
@@ -10,13 +10,13 @@
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
require_once dirname(__FILE__) . '/../mock/cache.php';
-require_once dirname(__FILE__) . '/common_validate_data.php';
+require_once dirname(__FILE__) . '/validate_data_helper.php';
class phpbb_functions_validate_data_test extends phpbb_database_test_case
{
protected $db;
protected $cache;
- protected $common;
+ protected $helper;
public function getDataSet()
{
@@ -29,7 +29,7 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case
$this->db = $this->new_dbal();
$this->cache = new phpbb_mock_cache;
- $this->common = new phpbb_functions_common_validate_data;
+ $this->helper = new phpbb_functions_validate_data_helper($this);
}
public function validate_username_data()
@@ -129,7 +129,7 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case
$config['allow_name_chars'] = $allow_name_chars;
- $this->common->validate_data_check(array(
+ $this->helper->assert_validate_data($expected, array(
'foobar_allow' => 'foobar',
'foobar_ascii' => 'foobar',
'foobar_any' => 'f*~*^=oo_bar1',
@@ -154,7 +154,6 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case
'barfoo_disallow' => array('username'),
'admin_taken' => array('username'),
'group_taken' => array('username'),
- ),
- $expected);
+ ));
}
}