From c6c4d01fe9619a1db585b7446343517762cd18b1 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 8 Jul 2010 20:26:50 +0200 Subject: [ticket/9714] Use correct variable name in email regular expression tests. PHPBB3-9714 --- tests/regex/email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/regex/email.php b/tests/regex/email.php index b1519dfa5f..85b6406ffc 100644 --- a/tests/regex/email.php +++ b/tests/regex/email.php @@ -70,7 +70,7 @@ class phpbb_regex_email_test extends phpbb_test_case /** * @dataProvider negative_match_data */ - public function test_negative_match($address) + public function test_negative_match($email) { $this->assertEquals(0, preg_match($this->regex, $email)); } -- cgit v1.2.1 From bbc3105466ccd43d94423325a68c626c76dec5f9 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 8 Jul 2010 22:44:28 +0200 Subject: [ticket/9701] Prevent notices from being hidden by template tests The template tests disable NOTICEs for the duration of template execution since the current version of the template engine does not generate sufficiently clean code. The error level is reset aftwards, however that part is skipped when trigger_error is called which is converted into a regular exception by PHPUnit and passed down until caught. Such exceptions are now caught to reset the error level, and then the exception is rethrown. This uncovered another issue in the template tests which only passed because NOTICEs were unintentionally disabled at this point. assign_display is also required to operate without NOTICEs. The respective code has been added around its callee as well. However no handling of exceptions takes place there. If another test checking for errors in that function is ever added similar catch logic will have to be added there. PHPBB3-9701 --- tests/template/template.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/template/template.php b/tests/template/template.php index 145fe8de61..024d3712f7 100644 --- a/tests/template/template.php +++ b/tests/template/template.php @@ -26,12 +26,24 @@ class phpbb_template_template_test extends phpbb_test_case error_reporting($error_level & ~E_NOTICE); ob_start(); - $this->assertTrue($this->template->display($handle, false)); + + try + { + $this->assertTrue($this->template->display($handle, false)); + } + catch (Exception $exception) + { + // reset the error level even when an error occured + // PHPUnit turns trigger_error into exceptions as well + error_reporting($error_level); + throw $exception; + } + + $result = self::trim_template_result(ob_get_clean()); // reset error level error_reporting($error_level); - - return self::trim_template_result(ob_get_clean()); + return $result; } private static function trim_template_result($result) @@ -368,9 +380,15 @@ class phpbb_template_template_test extends phpbb_test_case $this->template->destroy_block_vars($block); } + $error_level = error_reporting(); + error_reporting($error_level & ~E_NOTICE); + $this->assertEquals($expected, self::trim_template_result($this->template->assign_display('test')), "Testing assign_display($file)"); $this->template->assign_display('test', 'VARIABLE', false); + + error_reporting($error_level); + $this->assertEquals($expected, $this->display('container'), "Testing assign_display($file)"); } -- cgit v1.2.1 From a0b9f7806a6c3b08dd2c7e9cccfc7f742e42be1d Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Sun, 11 Jul 2010 15:18:21 -0700 Subject: [ticket/9715] Extend email unit tests Adding more email tests for a wider range of valid email formats. PHPBB3-9715 --- tests/regex/email.php | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/regex/email.php b/tests/regex/email.php index b1519dfa5f..8658b8af36 100644 --- a/tests/regex/email.php +++ b/tests/regex/email.php @@ -33,6 +33,27 @@ class phpbb_regex_email_test extends phpbb_test_case //array('"John Doe"@example.com'), //array('Alice@[192.168.2.1]'), // IPv4 //array('Bob@[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]'), // IPv6 + + // http://fightingforalostcause.net/misc/2006/compare-email-regex.php + array('l3tt3rsAndNumb3rs@domain.com'), + array('has-dash@domain.com'), + array('hasApostrophe.o\'leary@domain.org'), + array('uncommonTLD@domain.museum'), + array('uncommonTLD@domain.travel'), + array('uncommonTLD@domain.mobi'), + array('countryCodeTLD@domain.uk'), + array('countryCodeTLD@domain.rw'), + array('numbersInDomain@911.com'), + array('underscore_inLocal@domain.net'), + array('IPInsteadOfDomain@127.0.0.1'), + array('IPAndPort@127.0.0.1:25'), + array('subdomain@sub.domain.com'), + array('local@dash-inDomain.com'), + array('dot.inLocal@foo.com'), + array('a@singleLetterLocal.org'), + array('singleLetterDomain@x.org'), + array('&*=?^+{}\'~@validCharsInLocal.net'), + array('foor@bar.newTLD'), ); } @@ -56,6 +77,26 @@ class phpbb_regex_email_test extends phpbb_test_case array('abc,def@example.com'), // invalid character , array('abcdef@example.com'), // invalid character > + + // http://fightingforalostcause.net/misc/2006/compare-email-regex.php + array('missingDomain@.com'), + array('@missingLocal.org'), + array('missingatSign.net'), + array('missingDot@com'), + array('two@@signs.com'), + array('colonButNoPort@127.0.0.1:'), + array(''), + array('someone-else@127.0.0.1.26'), + array('.localStartsWithDot@domain.com'), + array('localEndsWithDot.@domain.com'), + array('two..consecutiveDots@domain.com'), + array('domainStartsWithDash@-domain.com'), + array('domainEndsWithDash@domain-.com'), + array('numbersInTLD@domain.c0m'), + array('missingTLD@domain.'), + array('! "#$%(),/;<>[]`|@invalidCharsInLocal.org'), + array('invalidCharsInDomain@! "#$%(),/;<>_[]`|.org'), + array('local@SecondLevelDomainNamesAreInvalidIfTheyAreLongerThan64Charactersss.org'), ); } @@ -70,7 +111,7 @@ class phpbb_regex_email_test extends phpbb_test_case /** * @dataProvider negative_match_data */ - public function test_negative_match($address) + public function test_negative_match($email) { $this->assertEquals(0, preg_match($this->regex, $email)); } -- cgit v1.2.1 From 3e111bb41ad6a2ea954dd52bcf78b954114c37e9 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 14 May 2010 03:21:08 +0200 Subject: [ticket/9599] Adding network function tests. PHPBB3-9599 --- tests/all_tests.php | 2 ++ tests/network/all_tests.php | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 tests/network/all_tests.php (limited to 'tests') diff --git a/tests/all_tests.php b/tests/all_tests.php index 7894d688ee..8dc07872e8 100644 --- a/tests/all_tests.php +++ b/tests/all_tests.php @@ -24,6 +24,7 @@ require_once 'template/all_tests.php'; require_once 'text_processing/all_tests.php'; require_once 'dbal/all_tests.php'; require_once 'regex/all_tests.php'; +require_once 'network/all_tests.php'; // exclude the test directory from code coverage reports PHPUnit_Util_Filter::addDirectoryToFilter('./'); @@ -46,6 +47,7 @@ class phpbb_all_tests $suite->addTest(phpbb_text_processing_all_tests::suite()); $suite->addTest(phpbb_dbal_all_tests::suite()); $suite->addTest(phpbb_regex_all_tests::suite()); + $suite->addTest(phpbb_network_all_tests::suite()); return $suite; } diff --git a/tests/network/all_tests.php b/tests/network/all_tests.php new file mode 100644 index 0000000000..07a7e57d48 --- /dev/null +++ b/tests/network/all_tests.php @@ -0,0 +1,36 @@ + Date: Fri, 14 May 2010 03:57:17 +0200 Subject: [ticket/9599] Adding tests for phpbb_checkdnsrr(). Tests for existing and non-existing records of the types: MX, A, AAAA, NS, CNAME, TXT PHPBB3-9599 --- tests/network/all_tests.php | 4 +++ tests/network/checkdnsrr.php | 63 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 tests/network/checkdnsrr.php (limited to 'tests') diff --git a/tests/network/all_tests.php b/tests/network/all_tests.php index 07a7e57d48..b500647f81 100644 --- a/tests/network/all_tests.php +++ b/tests/network/all_tests.php @@ -15,6 +15,8 @@ if (!defined('PHPUnit_MAIN_METHOD')) require_once 'test_framework/framework.php'; require_once 'PHPUnit/TextUI/TestRunner.php'; +require_once 'network/checkdnsrr.php'; + class phpbb_network_all_tests { public static function main() @@ -26,6 +28,8 @@ class phpbb_network_all_tests { $suite = new PHPUnit_Framework_TestSuite('phpBB Network Functions'); + $suite->addTestSuite('phpbb_network_checkdnsrr_test'); + return $suite; } } diff --git a/tests/network/checkdnsrr.php b/tests/network/checkdnsrr.php new file mode 100644 index 0000000000..57fe2761cc --- /dev/null +++ b/tests/network/checkdnsrr.php @@ -0,0 +1,63 @@ +assertEquals($expected, phpbb_checkdnsrr($host, $type)); + } +} -- cgit v1.2.1 From e09d6c6d7139375d8b645664bef295c82d585653 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 20 Aug 2010 21:12:18 +0200 Subject: [ticket/9780] Adding unit tests for gen_rand_string(). PHPBB3-9780 --- tests/all_tests.php | 2 ++ tests/random/all_tests.php | 40 +++++++++++++++++++++++++ tests/random/gen_rand_string.php | 63 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 tests/random/all_tests.php create mode 100644 tests/random/gen_rand_string.php (limited to 'tests') diff --git a/tests/all_tests.php b/tests/all_tests.php index 8dc07872e8..bae7725ee7 100644 --- a/tests/all_tests.php +++ b/tests/all_tests.php @@ -25,6 +25,7 @@ require_once 'text_processing/all_tests.php'; require_once 'dbal/all_tests.php'; require_once 'regex/all_tests.php'; require_once 'network/all_tests.php'; +require_once 'random/all_tests.php'; // exclude the test directory from code coverage reports PHPUnit_Util_Filter::addDirectoryToFilter('./'); @@ -48,6 +49,7 @@ class phpbb_all_tests $suite->addTest(phpbb_dbal_all_tests::suite()); $suite->addTest(phpbb_regex_all_tests::suite()); $suite->addTest(phpbb_network_all_tests::suite()); + $suite->addTest(phpbb_random_all_tests::suite()); return $suite; } diff --git a/tests/random/all_tests.php b/tests/random/all_tests.php new file mode 100644 index 0000000000..c6ffe78024 --- /dev/null +++ b/tests/random/all_tests.php @@ -0,0 +1,40 @@ +addTestSuite('phpbb_random_gen_rand_string_test'); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'phpbb_random_all_tests::main') +{ + phpbb_random_all_tests::main(); +} diff --git a/tests/random/gen_rand_string.php b/tests/random/gen_rand_string.php new file mode 100644 index 0000000000..cd58d14ed3 --- /dev/null +++ b/tests/random/gen_rand_string.php @@ -0,0 +1,63 @@ +assertTrue($random_string_length >= self::MIN_STRING_LENGTH); + $this->assertTrue($random_string_length <= $num_chars); + $this->assertRegExp('#^[A-Z0-9]+$#', $random_string); + } + } + } + + public function test_gen_rand_string_friendly() + { + for ($tests = 0; $tests <= self::TEST_COUNT; ++$tests) + { + for ($num_chars = self::MIN_STRING_LENGTH; $num_chars <= self::MAX_STRING_LENGTH; ++$num_chars) + { + $random_string = gen_rand_string_friendly($num_chars); + $random_string_length = strlen($random_string); + + $this->assertTrue($random_string_length >= self::MIN_STRING_LENGTH); + $this->assertTrue($random_string_length <= $num_chars); + $this->assertRegExp('#^[A-NP-Z1-9]+$#', $random_string); + } + } + } +} -- cgit v1.2.1