diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/all_tests.php | 4 | ||||
| -rw-r--r-- | tests/dbal/dbal.php | 5 | ||||
| -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/test_framework/phpbb_database_test_case.php | 59 | 
7 files changed, 259 insertions, 15 deletions
diff --git a/tests/all_tests.php b/tests/all_tests.php index 7894d688ee..bae7725ee7 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('./'); @@ -46,6 +48,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/dbal/dbal.php b/tests/dbal/dbal.php index 1cce891ca9..663323ad61 100644 --- a/tests/dbal/dbal.php +++ b/tests/dbal/dbal.php @@ -244,8 +244,9 @@ class phpbb_dbal_test extends phpbb_database_test_case  				array('username_clean' => 'bertie'))),  			// These here would throw errors and therefor $result should be false. -			array('user_id', array(), false, false, false, true), -			array('user_id', array(), true, false, false, true), +			// Removing for now because SQLite accepts empty IN() syntax +			/*array('user_id', array(), false, false, false, true), +			array('user_id', array(), true, false, false, true),*/  		);  	} 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/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index d558874c6f..f6bf420ebc 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -19,7 +19,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test  		}  	} -	function get_dbms_data($dbms) +	public function get_dbms_data($dbms)  	{  		$available_dbms = array(  			'firebird'	=> array( @@ -65,7 +65,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test  			'sqlite'		=> array(  				'SCHEMA'		=> 'sqlite',  				'DELIM'			=> ';', -				'PDO'			=> 'sqlite', +				'PDO'			=> 'sqlite2',  			),  		); @@ -79,10 +79,13 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test  		}  	} -	function split_sql_file($sql, $delimiter) +	// NOTE: This function is not the same as split_sql_file from functions_install +	public function split_sql_file($sql, $dbms)  	{ +		$dbms_data = $this->get_dbms_data($dbms); +  		$sql = str_replace("\r" , '', $sql); -		$data = preg_split('/' . preg_quote($delimiter, '/') . '$/m', $sql); +		$data = preg_split('/' . preg_quote($dbms_data['DELIM'], '/') . '$/m', $sql);  		$data = array_map('trim', $data); @@ -94,6 +97,15 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test  			unset($data[key($data)]);  		} +		if ($dbms == 'sqlite') +		{ +			// trim # off query to satisfy sqlite +			foreach ($data as $i => $query) +			{ +				$data[$i] = preg_replace('/^#.*$/m', "\n", $query); +			} +		} +  		return $data;  	} @@ -108,21 +120,42 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test  		if ($already_connected)  		{ -			$pdo = new PDO($dbms_data['PDO'] . ':host=' . $database_config['dbhost'] . ';dbname=' . $database_config['dbname'], $database_config['dbuser'], $database_config['dbpasswd']); +			if ($database_config['dbms'] == 'sqlite') +			{ +				$pdo = new PDO($dbms_data['PDO'] . ':' . $database_config['dbhost']); +			} +			else +			{ +				$pdo = new PDO($dbms_data['PDO'] . ':host=' . $database_config['dbhost'] . ';dbname=' . $database_config['dbname'], $database_config['dbuser'], $database_config['dbpasswd']); +			}  		}  		else  		{ -			$pdo = new PDO($dbms_data['PDO'] . ':host=' . $database_config['dbhost'] . ';', $database_config['dbuser'], $database_config['dbpasswd']); - -			try +			if ($database_config['dbms'] == 'sqlite')  			{ -				$pdo->exec('DROP DATABASE ' . $database_config['dbname']); +				// delete existing database +				if (file_exists($database_config['dbhost'])) +				{ +					unlink($database_config['dbhost']); +				} + +				$pdo = new PDO($dbms_data['PDO'] . ':' . $database_config['dbhost']);  			} -			catch (PDOException $e){} // ignore non existent db +			else +			{ +				$pdo = new PDO($dbms_data['PDO'] . ':host=' . $database_config['dbhost'] . ';', $database_config['dbuser'], $database_config['dbpasswd']);try +				{ +					$pdo->exec('DROP DATABASE ' . $database_config['dbname']); +				} +				catch (PDOException $e){} // ignore non existent db -			$pdo->exec('CREATE DATABASE ' . $database_config['dbname']); +				$pdo->exec('CREATE DATABASE ' . $database_config['dbname']); + +				$pdo = new PDO($dbms_data['PDO'] . ':host=' . $database_config['dbhost'] . ';dbname=' . $database_config['dbname'], $database_config['dbuser'], $database_config['dbpasswd']); +			} -			$pdo = new PDO($dbms_data['PDO'] . ':host=' . $database_config['dbhost'] . ';dbname=' . $database_config['dbname'], $database_config['dbuser'], $database_config['dbpasswd']); +			// good for debug +			// $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);  			if ($database_config['dbms'] == 'mysql')  			{ @@ -141,7 +174,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test  				unset($row, $sth);  			} -			$sql_query = $this->split_sql_file(file_get_contents("../phpBB/install/schemas/{$dbms_data['SCHEMA']}_schema.sql"), $dbms_data['DELIM']); +			$sql_query = $this->split_sql_file(file_get_contents("../phpBB/install/schemas/{$dbms_data['SCHEMA']}_schema.sql"), $database_config['dbms']);  			foreach ($sql_query as $sql)  			{  | 
