diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/RUNNING_TESTS.txt | 33 | ||||
-rw-r--r-- | tests/all_tests.php | 4 | ||||
-rw-r--r-- | tests/class_loader/class_loader_test.php | 6 | ||||
-rw-r--r-- | tests/class_loader/includes/dir.php | 6 | ||||
-rw-r--r-- | tests/network/all_tests.php | 40 | ||||
-rw-r--r-- | tests/network/checkdnsrr.php | 63 | ||||
-rw-r--r-- | tests/random/all_tests.php | 40 | ||||
-rw-r--r-- | tests/random/gen_rand_string.php | 63 | ||||
-rw-r--r-- | tests/regex/email.php | 43 | ||||
-rw-r--r-- | tests/template/template.php | 6 |
10 files changed, 303 insertions, 1 deletions
diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.txt new file mode 100644 index 0000000000..f1b40f71ad --- /dev/null +++ b/tests/RUNNING_TESTS.txt @@ -0,0 +1,33 @@ +Running Tests +------------- + +Prerequisites +------------- + +PHPUnit +======= + +phpBB unit tests use PHPUnit framework. Version 3.3 or better is required +to run the tests. PHPUnit prefers to be installed via PEAR; refer to +http://www.phpunit.de/ for more information. + +PHP extensions +============== + +Unit tests use several PHP extensions that board code does not use. Currently +the following PHP extensions must be installed and enabled to run unit tests: + +- ctype + +Running +------- + +Once the prerequisites are installed, run the tests from tests directory: + +$ phpunit all_tests.php + +More Information +---------------- + +Further information is available on phpbb wiki: +http://wiki.phpbb.com/display/DEV/Unit+Tests diff --git a/tests/all_tests.php b/tests/all_tests.php index 4eee950860..07d6f89524 100644 --- a/tests/all_tests.php +++ b/tests/all_tests.php @@ -24,6 +24,8 @@ 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'; +require_once 'random/all_tests.php'; // exclude the test directory from code coverage reports PHPUnit_Util_Filter::addDirectoryToFilter('./'); @@ -48,6 +50,8 @@ 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()); + $suite->addTest(phpbb_random_all_tests::suite()); return $suite; } diff --git a/tests/class_loader/class_loader_test.php b/tests/class_loader/class_loader_test.php index 37c11657c4..e53507ded3 100644 --- a/tests/class_loader/class_loader_test.php +++ b/tests/class_loader/class_loader_test.php @@ -24,6 +24,12 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase $prefix .= 'includes/'; $this->assertEquals( + '', + $class_loader->resolve_path('phpbb_dir'), + 'Class with same name as a directory is unloadable' + ); + + $this->assertEquals( $prefix . 'class_name.php', $class_loader->resolve_path('phpbb_class_name'), 'Top level class' diff --git a/tests/class_loader/includes/dir.php b/tests/class_loader/includes/dir.php new file mode 100644 index 0000000000..1c8930d8e7 --- /dev/null +++ b/tests/class_loader/includes/dir.php @@ -0,0 +1,6 @@ +<?php + +class phpbb_dir +{ +} + diff --git a/tests/network/all_tests.php b/tests/network/all_tests.php new file mode 100644 index 0000000000..b500647f81 --- /dev/null +++ b/tests/network/all_tests.php @@ -0,0 +1,40 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +if (!defined('PHPUnit_MAIN_METHOD')) +{ + define('PHPUnit_MAIN_METHOD', 'phpbb_network_all_tests::main'); +} + +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() + { + PHPUnit_TextUI_TestRunner::run(self::suite()); + } + + public static function suite() + { + $suite = new PHPUnit_Framework_TestSuite('phpBB Network Functions'); + + $suite->addTestSuite('phpbb_network_checkdnsrr_test'); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'phpbb_network_all_tests::main') +{ + phpbb_network_all_tests::main(); +} 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 @@ +<?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 '../phpBB/includes/functions.php'; + +class phpbb_network_checkdnsrr_test extends phpbb_test_case +{ + public function data_provider() + { + return array( + // Existing MX record + array('phpbb.com', 'MX', true), + + // Non-existing MX record + array('does-not-exist.phpbb.com', 'MX', false), + + // Existing A record + array('www.phpbb.com', 'A', true), + + // Non-existing A record + array('does-not-exist.phpbb.com', 'A', false), + + // Existing AAAA record + array('www.six.heise.de', 'AAAA', true), + + // Non-existing AAAA record + array('does-not-exist.phpbb.com', 'AAAA', false), + + // Existing CNAME record + array('news.cnet.com', 'CNAME', true), + + // Non-existing CNAME record + array('does-not-exist.phpbb.com', 'CNAME', false), + + // Existing NS record + array('phpbb.com', 'NS', true), + + // Non-existing NS record + array('does-not-exist', 'NS', false), + + // Existing TXT record + array('phpbb.com', 'TXT', true), + + // Non-existing TXT record + array('does-not-exist', 'TXT', false), + ); + } + + /** + * @dataProvider data_provider + */ + public function test_checkdnsrr($host, $type, $expected) + { + $this->assertEquals($expected, phpbb_checkdnsrr($host, $type)); + } +} 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 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +if (!defined('PHPUnit_MAIN_METHOD')) +{ + define('PHPUnit_MAIN_METHOD', 'phpbb_random_all_tests::main'); +} + +require_once 'test_framework/framework.php'; +require_once 'PHPUnit/TextUI/TestRunner.php'; + +require_once 'random/gen_rand_string.php'; + +class phpbb_random_all_tests +{ + public static function main() + { + PHPUnit_TextUI_TestRunner::run(self::suite()); + } + + public static function suite() + { + $suite = new PHPUnit_Framework_TestSuite('phpBB Random Functions'); + + $suite->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 @@ +<?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 '../phpBB/includes/functions.php'; + +class phpbb_random_gen_rand_string_test extends phpbb_test_case +{ + const TEST_COUNT = 100; + const MIN_STRING_LENGTH = 1; + const MAX_STRING_LENGTH = 15; + + public function setUp() + { + global $config; + + if (!is_array($config)) + { + $config = array(); + } + + $config['rand_seed'] = ''; + $config['rand_seed_last_update'] = time() + 600; + } + + public function test_gen_rand_string() + { + 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($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-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); + } + } + } +} 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('abc<def@example.com'), // invalid character < array('abc>def@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)); } diff --git a/tests/template/template.php b/tests/template/template.php index 9436ab2d98..0a685bfd61 100644 --- a/tests/template/template.php +++ b/tests/template/template.php @@ -360,9 +360,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)"); } |