diff options
Diffstat (limited to 'tests')
33 files changed, 873 insertions, 43 deletions
diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.txt index b976545c22..7c2a7c3fce 100644 --- a/tests/RUNNING_TESTS.txt +++ b/tests/RUNNING_TESTS.txt @@ -51,6 +51,27 @@ test_config.php file:        PHPBB_TEST_DBNAME='database' PHPBB_TEST_DBUSER='user' \        PHPBB_TEST_DBPASSWD='password' phpunit +Special Database Cases +---------------------- +In order to run tests on some of the databases that we support, it will be +necessary to provide a custom DSN string in test_config.php. This is only +needed for MSSQL 2000+ (PHP module), MSSQL via ODBC, and Firebird when +PDO_Firebird does not work on your system +(https://bugs.php.net/bug.php?id=61183). The variable must be named $custom_dsn. + +Examples: +Firebird using http://www.firebirdsql.org/en/odbc-driver/ +$custom_dsn = "Driver={Firebird/InterBase(r) driver};dbname=$dbhost:$dbname"; + +MSSQL +$custom_dsn = "Driver={SQL Server Native Client 10.0};Server=$dbhost;Database=$dbname"; + +The other fields in test_config.php should be filled out as you would normally +to connect to that database in phpBB. + +Additionally, you will need to be running the DbUnit fork from +https://github.com/phpbb/dbunit/tree/phpbb. +  Running  ======= diff --git a/tests/bbcode/url_bbcode_test.php b/tests/bbcode/url_bbcode_test.php index 15bdfc434f..6b5afe5808 100644 --- a/tests/bbcode/url_bbcode_test.php +++ b/tests/bbcode/url_bbcode_test.php @@ -11,7 +11,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';  require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';  require_once dirname(__FILE__) . '/../../phpBB/includes/bbcode.php';  require_once dirname(__FILE__) . '/../../phpBB/includes/message_parser.php'; -require_once dirname(__FILE__) . '/../mock_user.php'; +require_once dirname(__FILE__) . '/../mock/user.php';  class phpbb_url_bbcode_test extends phpbb_test_case  { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d6c5d25bc8..d687db622a 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -22,5 +22,20 @@ require_once 'test_framework/phpbb_database_test_connection_manager.php';  if (version_compare(PHP_VERSION, '5.3.0-dev', '>='))  { +	if (getenv('PHPBB_NO_COMPOSER_AUTOLOAD')) +	{ +		if (getenv('PHPBB_AUTOLOAD')) +		{ +			require(getenv('PHPBB_AUTOLOAD')); +		} +	} +	else +	{ +		if (!file_exists($phpbb_root_path . 'vendor/autoload.php')) +		{ +			trigger_error('You have not set up composer dependencies. See http://getcomposer.org/.', E_USER_ERROR); +		} +		require($phpbb_root_path . 'vendor/autoload.php'); +	}  	require_once 'test_framework/phpbb_functional_test_case.php';  } diff --git a/tests/compress/archive/.gitkeep b/tests/compress/archive/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/compress/archive/.gitkeep diff --git a/tests/compress/compress_test.php b/tests/compress/compress_test.php new file mode 100644 index 0000000000..65094671e3 --- /dev/null +++ b/tests/compress/compress_test.php @@ -0,0 +1,162 @@ +<?php +/** + * + * @package testing + * @copyright (c) 2012 phpBB Group + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 + * + */ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_admin.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_compress.php'; + +class phpbb_compress_test extends phpbb_test_case +{ +	const EXTRACT_DIR = '/extract/'; +	const ARCHIVE_DIR = '/archive/'; + +	private $path; + +	protected $filelist = array( +		'1.txt', +		'dir/2.txt', +		'dir/3.txt', +		'dir/subdir/4.txt', +	); + +	protected function setUp() +	{ +		// Required for compress::add_file +		global $phpbb_root_path; +		$phpbb_root_path = ''; + +		$this->path = dirname(__FILE__) . '/fixtures/'; + +		if (!@extension_loaded('zlib') || !@extension_loaded('bz2')) +		{ +			$this->markTestSkipped('PHP needs to be compiled with --with-zlib and --with-bz2 in order to run these tests'); +		} +	} + +	protected function tearDown() +	{ +		foreach (array(dirname(__FILE__) . self::EXTRACT_DIR, dirname(__FILE__) . self::ARCHIVE_DIR) as $dir) +		{ +			$this->clear_dir($dir); +		} +	} + +	protected function clear_dir($dir) +	{ +		$iterator = new DirectoryIterator($dir); +		foreach ($iterator as $fileinfo) +		{ +			$name = $fileinfo->getFilename(); +			$path = $fileinfo->getPathname(); + +			if ($name[0] !== '.') +			{ +				if ($fileinfo->isDir()) +				{ +					$this->clear_dir($path); +					rmdir($path); +				} +				else +				{ +					unlink($path); +				} +			} +		} +	} + +	protected function archive_files($compress) +	{ +		$compress->add_file($this->path . '1.txt', $this->path); +		$compress->add_file( +			'tests/compress/fixtures/dir/', +			'tests/compress/fixtures/', +			'', +			// The comma here is not an error, this is a comma-separated list +			'subdir/4.txt,3.txt' +		); +		$compress->add_custom_file($this->path . 'dir/3.txt', 'dir/3.txt'); +		$compress->add_data(file_get_contents($this->path . 'dir/subdir/4.txt'), 'dir/subdir/4.txt'); +	} + +	protected function valid_extraction($extra = array()) +	{ +		$filelist = array_merge($this->filelist, $extra); + +		foreach ($filelist as $filename) +		{ +			$path = dirname(__FILE__) . self::EXTRACT_DIR . $filename; +			$this->assertTrue(file_exists($path)); + +			// Check the file's contents is correct +			$contents = explode('_', basename($filename, '.txt')); +			$contents = $contents[0]; +			$this->assertEquals($contents . "\n", file_get_contents($path)); +		} +	} + +	public function tar_archive_list() +	{ +		return array( +			array('archive.tar', '.tar'), +			array('archive.tar.gz', '.tar.gz'), +			array('archive.tar.bz2', '.tar.bz2'), +		); +	} + +	/** +	 * @dataProvider tar_archive_list +	 */ +	public function test_extract_tar($filename, $type) +	{ +		$compress = new compress_tar('r', $this->path . $filename); +		$compress->extract('tests/compress/' . self::EXTRACT_DIR); +		$this->valid_extraction(); +	} + +	public function test_extract_zip() +	{ +		$compress = new compress_zip('r', $this->path . 'archive.zip'); +		$compress->extract('tests/compress/' . self::EXTRACT_DIR); +		$this->valid_extraction(); +	} + +	/** +	 * @depends test_extract_tar +	 * @dataProvider tar_archive_list +	 */ +	public function test_compress_tar($filename, $type) +	{ +		$tar = dirname(__FILE__) . self::ARCHIVE_DIR . $filename; +		$compress = new compress_tar('w', $tar); +		$this->archive_files($compress); +		$compress->close(); +		$this->assertTrue(file_exists($tar)); + +		$compress->mode = 'r'; +		$compress->open(); +		$compress->extract('tests/compress/' . self::EXTRACT_DIR); +		$this->valid_extraction(); +	} + +	/** +	 * @depends test_extract_zip +	 */ +	public function test_compress_zip() +	{ +		$zip =  dirname(__FILE__) . self::ARCHIVE_DIR . 'archive.zip'; +		$compress = new compress_zip('w', $zip); +		$this->archive_files($compress); +		$compress->close(); +		$this->assertTrue(file_exists($zip)); + +		$compress = new compress_zip('r', $zip); +		$compress->extract('tests/compress/' . self::EXTRACT_DIR); +		$this->valid_extraction(); +	} +} diff --git a/tests/compress/extract/.gitkeep b/tests/compress/extract/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/compress/extract/.gitkeep diff --git a/tests/compress/fixtures/1.txt b/tests/compress/fixtures/1.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/compress/fixtures/1.txt @@ -0,0 +1 @@ +1 diff --git a/tests/compress/fixtures/archive.tar b/tests/compress/fixtures/archive.tar Binary files differnew file mode 100644 index 0000000000..54ed56084e --- /dev/null +++ b/tests/compress/fixtures/archive.tar diff --git a/tests/compress/fixtures/archive.tar.bz2 b/tests/compress/fixtures/archive.tar.bz2 Binary files differnew file mode 100644 index 0000000000..04c0eccd74 --- /dev/null +++ b/tests/compress/fixtures/archive.tar.bz2 diff --git a/tests/compress/fixtures/archive.tar.gz b/tests/compress/fixtures/archive.tar.gz Binary files differnew file mode 100644 index 0000000000..195e7a060a --- /dev/null +++ b/tests/compress/fixtures/archive.tar.gz diff --git a/tests/compress/fixtures/archive.zip b/tests/compress/fixtures/archive.zip Binary files differnew file mode 100644 index 0000000000..bdb618fc26 --- /dev/null +++ b/tests/compress/fixtures/archive.zip diff --git a/tests/compress/fixtures/dir/2.txt b/tests/compress/fixtures/dir/2.txt new file mode 100644 index 0000000000..0cfbf08886 --- /dev/null +++ b/tests/compress/fixtures/dir/2.txt @@ -0,0 +1 @@ +2 diff --git a/tests/compress/fixtures/dir/3.txt b/tests/compress/fixtures/dir/3.txt new file mode 100644 index 0000000000..00750edc07 --- /dev/null +++ b/tests/compress/fixtures/dir/3.txt @@ -0,0 +1 @@ +3 diff --git a/tests/compress/fixtures/dir/subdir/4.txt b/tests/compress/fixtures/dir/subdir/4.txt new file mode 100644 index 0000000000..b8626c4cff --- /dev/null +++ b/tests/compress/fixtures/dir/subdir/4.txt @@ -0,0 +1 @@ +4 diff --git a/tests/dbal/select_test.php b/tests/dbal/select_test.php index 81cd13b006..6dbab05a41 100644 --- a/tests/dbal/select_test.php +++ b/tests/dbal/select_test.php @@ -17,7 +17,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case  		return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/three_users.xml');  	} -	public static function return_on_error_select_data() +	static public function return_on_error_select_data()  	{  		return array(  			array('phpbb_users', "username_clean = 'bertie'", array(array('username_clean' => 'bertie'))), @@ -44,7 +44,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case  		$this->assertEquals($expected, $db->sql_fetchrowset($result));  	} -	public static function fetchrow_data() +	static public function fetchrow_data()  	{  		return array(  			array('', array(array('username_clean' => 'barfoo'), @@ -95,7 +95,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case  		$db->sql_freeresult($result);  	} -	public static function fetchfield_data() +	static public function fetchfield_data()  	{  		return array(  			array('', array('barfoo', 'foobar', 'bertie')), @@ -125,7 +125,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case  		$this->assertEquals($expected, $ary);  	} -	public static function fetchfield_seek_data() +	static public function fetchfield_seek_data()  	{  		return array(  			array(1, 'foobar'), @@ -151,7 +151,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case  		$this->assertEquals($expected, $field);  	} -	public static function query_limit_data() +	static public function query_limit_data()  	{  		return array(  			array(0, 0, array(array('username_clean' => 'barfoo'), @@ -192,7 +192,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case  		$this->assertEquals($expected, $ary);  	} -	public static function like_expression_data() +	static public function like_expression_data()  	{  		// * = any_char; # = one_char  		return array( @@ -229,7 +229,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case  		$db->sql_freeresult($result);  	} -	public static function in_set_data() +	static public function in_set_data()  	{  		return array(  			array('user_id', 3, false, false, array(array('username_clean' => 'bertie'))), @@ -303,7 +303,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case  		$db->sql_freeresult($result);  	} -	public static function build_array_data() +	static public function build_array_data()  	{  		return array(  			array(array('username_clean' => 'barfoo'), array(array('username_clean' => 'barfoo'))), diff --git a/tests/dbal/write_test.php b/tests/dbal/write_test.php index 596c50a220..ecfd774896 100644 --- a/tests/dbal/write_test.php +++ b/tests/dbal/write_test.php @@ -16,7 +16,7 @@ class phpbb_dbal_write_test extends phpbb_database_test_case  		return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml');  	} -	public static function build_array_insert_data() +	static public function build_array_insert_data()  	{  		return array(  			array(array( @@ -104,7 +104,7 @@ class phpbb_dbal_write_test extends phpbb_database_test_case  		$db->sql_freeresult($result);  	} -	public static function update_data() +	static public function update_data()  	{  		return array(  			array( diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php new file mode 100644 index 0000000000..f54a3591b2 --- /dev/null +++ b/tests/functional/posting_test.php @@ -0,0 +1,102 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_posting_test extends phpbb_functional_test_case +{ +	public function test_post_new_topic() +	{ +		$this->login(); +		$this->add_lang('posting'); + +		$crawler = $this->request('GET', 'posting.php?mode=post&f=2&sid=' . $this->sid); +		$this->assertContains($this->lang('POST_TOPIC'), $crawler->filter('html')->text()); + +		$hidden_fields = array(); +		$hidden_fields[] = $crawler->filter('[type="hidden"]')->each(function ($node, $i) { +			return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); +		}); + +		$test_message = 'This is a test topic posted by the testing framework.'; +		$form_data = array( +			'subject'		=> 'Test Topic 1', +			'message'		=> $test_message, +			'post'			=> true, +			'f'				=> 2, +			'mode'			=> 'post', +			'sid'			=> $this->sid, +		); + +		foreach ($hidden_fields as $fields) +		{ +			foreach($fields as $field) +			{ +				$form_data[$field['name']] = $field['value']; +			} +		} + +		// Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened) +		// is not at least 2 seconds before submission, cancel the form +		$form_data['lastclick'] = 0; + +		// I use a request because the form submission method does not allow you to send data that is not +		// contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) +		// Instead, I send it as a request with the submit button "post" set to true. +		$crawler = $this->client->request('POST', 'posting.php', $form_data); +		$this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); + +		$crawler = $this->request('GET', 'viewtopic.php?t=2&sid=' . $this->sid); +		$this->assertContains($test_message, $crawler->filter('html')->text()); +	} + +	public function test_post_reply() +	{ +		$this->login(); +		$this->add_lang('posting'); + +		$crawler = $this->request('GET', 'posting.php?mode=reply&t=2&f=2&sid=' . $this->sid); +		$this->assertContains($this->lang('POST_REPLY'), $crawler->filter('html')->text()); + +		$hidden_fields = array(); +		$hidden_fields[] = $crawler->filter('[type="hidden"]')->each(function ($node, $i) { +			return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); +		}); + +		$test_message = 'This is a test post posted by the testing framework.'; +		$form_data = array( +			'subject'		=> 'Re: Test Topic 1', +			'message'		=> $test_message, +			'post'			=> true, +			't'				=> 2, +			'f'				=> 2, +			'mode'			=> 'reply', +			'sid'			=> $this->sid, +		); + +		foreach ($hidden_fields as $fields) +		{ +			foreach($fields as $field) +			{ +				$form_data[$field['name']] = $field['value']; +			} +		} + +		// For reasoning behind the following command, see the test_post_new_topic() test +		$form_data['lastclick'] = 0; + +		// Submit the post +		$crawler = $this->client->request('POST', 'posting.php', $form_data); +		$this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); + +		$crawler = $this->request('GET', 'viewtopic.php?t=2&sid=' . $this->sid); +		$this->assertContains($test_message, $crawler->filter('html')->text()); +	} +} diff --git a/tests/functions/clean_path_test.php b/tests/functions/clean_path_test.php new file mode 100644 index 0000000000..bcbe9838d9 --- /dev/null +++ b/tests/functions/clean_path_test.php @@ -0,0 +1,44 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_clean_path_test extends phpbb_test_case +{ +	public function clean_path_test_data() +	{ +		return array( +			array('foo', 'foo'), +			array('foo/bar', 'foo/bar'), +			array('foo/bar/', 'foo/bar/'), +			array('foo/./bar', 'foo/bar'), +			array('foo/./././bar', 'foo/bar'), +			array('foo/bar/.', 'foo/bar'), +			array('./foo/bar', './foo/bar'), +			array('../foo/bar', '../foo/bar'), +			array('one/two/three', 'one/two/three'), +			array('one/two/../three', 'one/three'), +			array('one/../two/three', 'two/three'), +			array('one/two/..', 'one'), +			array('one/two/../', 'one/'), +			array('one/two/../three/../four', 'one/four'), +			array('one/two/three/../../four', 'one/four'), +		); +	} + +	/** +	* @dataProvider clean_path_test_data +	*/ +	public function test_clean_path($input, $expected) +	{ +		$output = phpbb_clean_path($input); + +		$this->assertEquals($expected, $output); +	} +} diff --git a/tests/mock_user.php b/tests/mock/user.php index ec14ce430e..ec14ce430e 100644 --- a/tests/mock_user.php +++ b/tests/mock/user.php diff --git a/tests/privmsgs/delete_user_pms_test.php b/tests/privmsgs/delete_user_pms_test.php new file mode 100644 index 0000000000..f705825262 --- /dev/null +++ b/tests/privmsgs/delete_user_pms_test.php @@ -0,0 +1,102 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_privmsgs.php'; + +class phpbb_privmsgs_delete_user_pms_test extends phpbb_database_test_case +{ +	public function getDataSet() +	{ +		return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/delete_user_pms.xml'); +	} + +	static public function delete_user_pms_data() +	{ +		return array( +		//	array( +		//		(user we delete), +		//		array(remaining privmsgs ids), +		//		array(remaining privmsgs_to), +		//	), +			array( +				2, +				array( +					array('msg_id' => 1), +				), +				array( +					array('msg_id' => 1, 'user_id' => 3), +				), +			), +			array( +				3, +				array( +					array('msg_id' => 1), +					array('msg_id' => 2), +					array('msg_id' => 3), +					array('msg_id' => 5), +				), +				array( +					array('msg_id' => 1, 'user_id' => 2), +					array('msg_id' => 1, 'user_id' => 4), +					array('msg_id' => 2, 'user_id' => 2), +					array('msg_id' => 2, 'user_id' => 4), +					array('msg_id' => 3, 'user_id' => 2), +					array('msg_id' => 5, 'user_id' => 2), +					array('msg_id' => 5, 'user_id' => 4), +				), +			), +			array( +				5, +				array( +					array('msg_id' => 1), +					array('msg_id' => 2), +					array('msg_id' => 3), +					array('msg_id' => 4), +					array('msg_id' => 5), +				), +				array( +					array('msg_id' => 1, 'user_id' => 2), +					array('msg_id' => 1, 'user_id' => 3), +					array('msg_id' => 1, 'user_id' => 4), +					array('msg_id' => 2, 'user_id' => 2), +					array('msg_id' => 2, 'user_id' => 4), +					array('msg_id' => 3, 'user_id' => 2), +					array('msg_id' => 4, 'user_id' => 3), +					array('msg_id' => 5, 'user_id' => 2), +					array('msg_id' => 5, 'user_id' => 3), +					array('msg_id' => 5, 'user_id' => 4), +				), +			), +		); +	} + +	/** +	* @dataProvider delete_user_pms_data +	*/ +	public function test_delete_user_pms($delete_user, $remaining_privmsgs, $remaining_privmsgs_to) +	{ +		global $db; + +		$db = $this->new_dbal(); + +		phpbb_delete_user_pms($delete_user); + +		$sql = 'SELECT msg_id +			FROM ' . PRIVMSGS_TABLE; +		$result = $db->sql_query($sql); + +		$this->assertEquals($remaining_privmsgs, $db->sql_fetchrowset($result)); + +		$sql = 'SELECT msg_id, user_id +			FROM ' . PRIVMSGS_TO_TABLE; +		$result = $db->sql_query($sql); + +		$this->assertEquals($remaining_privmsgs_to, $db->sql_fetchrowset($result)); +	} +} diff --git a/tests/privmsgs/fixtures/delete_user_pms.xml b/tests/privmsgs/fixtures/delete_user_pms.xml new file mode 100644 index 0000000000..9a86501b7a --- /dev/null +++ b/tests/privmsgs/fixtures/delete_user_pms.xml @@ -0,0 +1,215 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_users"> +		<column>user_id</column> +		<column>username</column> +		<column>username_clean</column> +		<column>user_new_privmsg</column> +		<column>user_unread_privmsg</column> +		<column>user_permissions</column> +		<column>user_sig</column> +		<column>user_occ</column> +		<column>user_interests</column> +		<row> +			<value>2</value> +			<value>sender</value> +			<value>sender</value> +			<value>0</value> +			<value>0</value> +			<value></value> +			<value></value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>3</value> +			<value>pm in inbox</value> +			<value>pm in inbox</value> +			<value>0</value> +			<value>0</value> +			<value></value> +			<value></value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>4</value> +			<value>pm in no box</value> +			<value>pm in no box</value> +			<value>2</value> +			<value>2</value> +			<value></value> +			<value></value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>5</value> +			<value>no pms</value> +			<value>no pms</value> +			<value>0</value> +			<value>0</value> +			<value></value> +			<value></value> +			<value></value> +			<value></value> +		</row> +	</table> +	<table name="phpbb_privmsgs"> +		<column>msg_id</column> +		<column>root_level</column> +		<column>author_id</column> +		<column>message_subject</column> +		<column>message_text</column> +		<column>to_address</column> +		<column>bcc_address</column> +		<row> +			<value>1</value> +			<value>0</value> +			<value>2</value> +			<value>#1</value> +			<value> +				2 - outbox +				3 - inbox +				4 - nobox +			</value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>2</value> +			<value>0</value> +			<value>2</value> +			<value>#2</value> +			<value> +				2 - outbox +				4 - nobox +			</value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>3</value> +			<value>0</value> +			<value>2</value> +			<value>#3</value> +			<value> +				2 - outbox +			</value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>4</value> +			<value>0</value> +			<value>2</value> +			<value>#4</value> +			<value> +				3 - nobox +			</value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>5</value> +			<value>0</value> +			<value>2</value> +			<value>#5</value> +			<value> +				2 - outbox +				3 - nobox +				4 - nobox +			</value> +			<value></value> +			<value></value> +		</row> +	</table> +	<table name="phpbb_privmsgs_to"> +		<column>msg_id</column> +		<column>user_id</column> +		<column>author_id</column> +		<column>pm_new</column> +		<column>pm_unread</column> +		<column>folder_id</column> +		<row> +			<value>1</value> +			<value>2</value> +			<value>2</value> +			<value>0</value> +			<value>0</value> +			<value>-2</value> +		</row> +		<row> +			<value>1</value> +			<value>3</value> +			<value>2</value> +			<value>0</value> +			<value>0</value> +			<value>0</value> +		</row> +		<row> +			<value>1</value> +			<value>4</value> +			<value>2</value> +			<value>0</value> +			<value>0</value> +			<value>-3</value> +		</row> +		<row> +			<value>2</value> +			<value>2</value> +			<value>2</value> +			<value>0</value> +			<value>0</value> +			<value>-2</value> +		</row> +		<row> +			<value>2</value> +			<value>4</value> +			<value>2</value> +			<value>0</value> +			<value>0</value> +			<value>-3</value> +		</row> +		<row> +			<value>3</value> +			<value>2</value> +			<value>2</value> +			<value>0</value> +			<value>0</value> +			<value>-2</value> +		</row> +		<row> +			<value>4</value> +			<value>3</value> +			<value>2</value> +			<value>0</value> +			<value>0</value> +			<value>-3</value> +		</row> +		<row> +			<value>5</value> +			<value>2</value> +			<value>2</value> +			<value>0</value> +			<value>0</value> +			<value>-2</value> +		</row> +		<row> +			<value>5</value> +			<value>3</value> +			<value>2</value> +			<value>0</value> +			<value>0</value> +			<value>-3</value> +		</row> +		<row> +			<value>5</value> +			<value>4</value> +			<value>2</value> +			<value>0</value> +			<value>0</value> +			<value>-3</value> +		</row> +	</table> +</dataset> diff --git a/tests/request/request_var_test.php b/tests/request/request_var_test.php index 8e609c00af..0c07fe11a3 100644 --- a/tests/request/request_var_test.php +++ b/tests/request/request_var_test.php @@ -73,7 +73,7 @@ class phpbb_request_request_var_test extends phpbb_test_case  		unset($_GET[$var], $_POST[$var], $_REQUEST[$var], $_COOKIE[$var]);  	} -	public static function request_variables() +	static public function request_variables()  	{  		return array(  			// strings diff --git a/tests/security/extract_current_page_test.php b/tests/security/extract_current_page_test.php index 4911f7b452..0f5128884b 100644 --- a/tests/security/extract_current_page_test.php +++ b/tests/security/extract_current_page_test.php @@ -14,7 +14,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/session.php';  class phpbb_security_extract_current_page_test extends phpbb_security_test_base  { -	public static function security_variables() +	static public function security_variables()  	{  		return array(  			array('http://localhost/phpBB/index.php', 'mark=forums&x="><script>alert(/XSS/);</script>', 'mark=forums&x=%22%3E%3Cscript%3Ealert(/XSS/);%3C/script%3E'), diff --git a/tests/security/redirect_test.php b/tests/security/redirect_test.php index 4848a938c6..872a331dc7 100644 --- a/tests/security/redirect_test.php +++ b/tests/security/redirect_test.php @@ -14,7 +14,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/session.php';  class phpbb_security_redirect_test extends phpbb_security_test_base  { -	public static function provider() +	static public function provider()  	{  		// array(Input -> redirect(), expected triggered error (else false), expected returned result url (else false))  		return array( diff --git a/tests/template/template_test.php b/tests/template/template_test.php index aaee7bb4a0..9b3c6ac245 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -94,7 +94,7 @@ class phpbb_template_template_test extends phpbb_test_case  	/**  	 * @todo put test data into templates/xyz.test  	 */ -	public static function template_data() +	static public function template_data()  	{  		return array(  			/* @@ -419,7 +419,7 @@ class phpbb_template_template_test extends phpbb_test_case  		$GLOBALS['config']['tpl_allow_php'] = false;  	} -	public static function alter_block_array_data() +	static public function alter_block_array_data()  	{  		return array(  			array( diff --git a/tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php b/tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php new file mode 100644 index 0000000000..ec59fa3886 --- /dev/null +++ b/tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php @@ -0,0 +1,37 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +if (!class_exists('PDO')) +{ +	return; +} + +/** +* Used for passing in information about the PDO driver +* since the PDO class reveals nothing about the DSN that +* the user provided. +* +* This is used in the custom PHPUnit ODBC driver +*/ +class phpbb_database_connection_odbc_pdo_wrapper extends PDO +{ +	// Name of the driver being used (i.e. mssql, firebird) +	public $driver = ''; + +	// Version number of driver since PDO::getAttribute(PDO::ATTR_CLIENT_VERSION) is pretty useless for this +	public $version = 0; + +	function __construct($dbms, $version, $dsn, $user, $pass) +	{ +		$this->driver = $dbms; +		$this->version = (double) $version; + +		parent::__construct($dsn, $user, $pass); +	} +} diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index e742b543b0..75a3c0944b 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -28,6 +28,28 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test  		);  	} +	public function createXMLDataSet($path) +	{ +		$db_config = $this->get_database_config(); + +		// Firebird requires table and column names to be uppercase +		if ($db_config['dbms'] == 'firebird') +		{ +			$xml_data = file_get_contents($path); +			$xml_data = preg_replace_callback('/(?:(<table name="))([a-z_]+)(?:(">))/', 'phpbb_database_test_case::to_upper', $xml_data); +			$xml_data = preg_replace_callback('/(?:(<column>))([a-z_]+)(?:(<\/column>))/', 'phpbb_database_test_case::to_upper', $xml_data); + +			$new_fixture = tmpfile(); +			fwrite($new_fixture, $xml_data); +			fseek($new_fixture, 0); + +			$meta_data = stream_get_meta_data($new_fixture); +			$path = $meta_data['uri']; +		} + +		return parent::createXMLDataSet($path); +	} +  	public function get_test_case_helpers()  	{  		if (!$this->test_case_helpers) @@ -106,4 +128,17 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test  	{  		return new phpbb_database_test_connection_manager($config);  	} + +	/** +	* Converts a match in the middle of a string to uppercase. +	* This is necessary for transforming the fixture information for Firebird tests +	* +	* @param $matches The array of matches from a regular expression +	* +	* @return string The string with the specified match converted to uppercase +	*/ +	static public function to_upper($matches) +	{ +		return $matches[1] . strtoupper($matches[2]) . $matches[3]; +	}  } diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index ae21be6c34..25e0972f42 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -8,6 +8,7 @@  */  require_once dirname(__FILE__) . '/../../phpBB/includes/functions_install.php'; +require_once dirname(__FILE__) . '/phpbb_database_connection_odbc_pdo_wrapper.php';  class phpbb_database_test_connection_manager  { @@ -62,6 +63,13 @@ class phpbb_database_test_connection_manager  				// e.g. Driver={SQL Server Native Client 10.0};Server=(local)\SQLExpress;  				$dsn .= $this->config['dbhost']; +				// Primarily for MSSQL Native/Azure as ODBC needs it in $dbhost, attached to the Server param +				if ($this->config['dbport']) +				{ +					$port_delimiter = (defined('PHP_OS') && substr(PHP_OS, 0, 3) === 'WIN') ? ',' : ':'; +					$dsn .= $port_delimiter . $this->config['dbport']; +				} +  				if ($use_db)  				{  					$dsn .= ';Database=' . $this->config['dbname']; @@ -98,9 +106,34 @@ class phpbb_database_test_connection_manager  			break;  		} +		// These require different connection strings on the phpBB side than they do in PDO +		// so you must provide a DSN string for ODBC separately +		if (!empty($this->config['custom_dsn']) && ($this->config['dbms'] == 'mssql' || $this->config['dbms'] == 'firebird')) +		{ +			$dsn = 'odbc:' . $this->config['custom_dsn']; +		} +  		try  		{ -			$this->pdo = new PDO($dsn, $this->config['dbuser'], $this->config['dbpasswd']); +			switch ($this->config['dbms']) +			{ +				case 'mssql': +				case 'mssql_odbc': +					$this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('mssql', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']); +				break; + +				case 'firebird': +					if (!empty($this->config['custom_dsn'])) +					{ +						$this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('firebird', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']); +						break; +					} +					// Fall through if they're using the firebird PDO driver and not the generic ODBC driver + +				default: +					$this->pdo = new PDO($dsn, $this->config['dbuser'], $this->config['dbpasswd']); +				break; +			}  		}  		catch (PDOException $e)  		{ @@ -108,8 +141,7 @@ class phpbb_database_test_connection_manager  			throw new Exception("Unable do connect to $cleaned_dsn using PDO with error: {$e->getMessage()}");  		} -		// good for debug -		// $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +		$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);  	}  	/** @@ -140,12 +172,41 @@ class phpbb_database_test_connection_manager  				}  			break; +			case 'firebird': +				$this->connect(); +				// Drop all of the tables +				foreach ($this->get_tables() as $table) +				{ +					$this->pdo->exec('DROP TABLE ' . $table); +				} +				$this->purge_extras(); +			break; + +			case 'oracle': +				$this->connect(); +				// Drop all of the tables +				foreach ($this->get_tables() as $table) +				{ +					$this->pdo->exec('DROP TABLE ' . $table . ' CASCADE CONSTRAINTS'); +				} +				$this->purge_extras(); +			break; +  			default:  				$this->connect(false);  				try  				{  					$this->pdo->exec('DROP DATABASE ' . $this->config['dbname']); + +					try +					{ +						$this->pdo->exec('CREATE DATABASE ' . $this->config['dbname']); +					} +					catch (PDOException $e) +					{ +						throw new Exception("Unable to re-create database: {$e->getMessage()}"); +					}  				}  				catch (PDOException $e)  				{ @@ -154,9 +215,8 @@ class phpbb_database_test_connection_manager  					{  						$this->pdo->exec('DROP TABLE ' . $table);  					} +					$this->purge_extras();  				} - -				$this->pdo->exec('CREATE DATABASE ' . $this->config['dbname']);  			 break;  		}  	} @@ -258,7 +318,7 @@ class phpbb_database_test_connection_manager  		$filename = $directory . $schema . '_schema.sql';  		$queries = file_get_contents($filename); -		$sql = remove_comments($queries); +		$sql = phpbb_remove_comments($queries);  		$sql = split_sql_file($sql, $this->dbms['DELIM']); @@ -332,4 +392,44 @@ class phpbb_database_test_connection_manager  			throw new Exception($message);  		}  	} + +	/** +	* Removes extra objects from a database. This is for cases where dropping the database fails. +	*/ +	public function purge_extras() +	{ +		$this->ensure_connected(__METHOD__); +		$queries = array(); + +		switch ($this->config['dbms']) +		{ +			case 'firebird': +				$sql = 'SELECT RDB$GENERATOR_NAME +					FROM RDB$GENERATORS +					WHERE RDB$SYSTEM_FLAG = 0'; +				$result = $this->pdo->query($sql); + +				while ($row = $result->fetch(PDO::FETCH_NUM)) +				{ +					$queries[] = 'DROP GENERATOR ' . current($row); +				} +			break; + +			case 'oracle': +				$sql = 'SELECT sequence_name +					FROM USER_SEQUENCES'; +				$result = $this->pdo->query($sql); + +				while ($row = $result->fetch(PDO::FETCH_NUM)) +				{ +					$queries[] = 'DROP SEQUENCE ' . current($row); +				} +			break; +		} + +		foreach ($queries as $query) +		{ +			$this->pdo->exec($query); +		} +	}  } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 76fed76fae..d35913e415 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -30,16 +30,6 @@ class phpbb_functional_test_case extends phpbb_test_case  	static protected $config = array();  	static protected $already_installed = false; -	static public function setUpBeforeClass() -	{ -		if (!extension_loaded('phar')) -		{ -			self::markTestSkipped('phar extension is not loaded'); -		} - -		require_once 'phar://' . __DIR__ . '/../../vendor/goutte.phar'; -	} -  	public function setUp()  	{  		if (!isset(self::$config['phpbb_functional_url'])) @@ -48,7 +38,10 @@ class phpbb_functional_test_case extends phpbb_test_case  		}  		$this->cookieJar = new CookieJar; -		$this->client = new Goutte\Client(array(), array(), null, $this->cookieJar); +		$this->client = new Goutte\Client(array(), null, $this->cookieJar); +		// Reset the curl handle because it is 0 at this point and not a valid +		// resource +		$this->client->getClient()->getCurlMulti()->reset(true);  		$this->root_url = self::$config['phpbb_functional_url'];  		// Clear the language array so that things  		// that were added in other tests are gone @@ -146,13 +139,11 @@ class phpbb_functional_test_case extends phpbb_test_case  		$this->do_request('create_table', $data); -		file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], array(), true)); -  		$this->do_request('config_file', $data); - -		copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); +		file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], array(), true, true));  		$this->do_request('final', $data); +		copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx");  	}  	private function do_request($sub, $post_data = null) @@ -193,9 +184,9 @@ class phpbb_functional_test_case extends phpbb_test_case  		$cookies = $this->cookieJar->all();  		// The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie -		foreach ($cookies as $key => $cookie); +		foreach ($cookies as $cookie);  		{ -			if (substr($key, -4) == '_sid') +			if (substr($cookie->getName(), -4) == '_sid')  			{  				$this->sid = $cookie->getValue();  			} diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 2a3c27f9f9..29adfc6817 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -79,6 +79,7 @@ class phpbb_test_case_helpers  				'dbname'	=> $dbname,  				'dbuser'	=> $dbuser,  				'dbpasswd'	=> $dbpasswd, +				'custom_dsn'	=> isset($custom_dsn) ? $custom_dsn : '',  			));  			if (isset($phpbb_functional_url)) @@ -95,7 +96,8 @@ class phpbb_test_case_helpers  				'dbport'	=> isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '',  				'dbname'	=> isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '',  				'dbuser'	=> isset($_SERVER['PHPBB_TEST_DBUSER']) ? $_SERVER['PHPBB_TEST_DBUSER'] : '', -				'dbpasswd'	=> isset($_SERVER['PHPBB_TEST_DBPASSWD']) ? $_SERVER['PHPBB_TEST_DBPASSWD'] : '' +				'dbpasswd'	=> isset($_SERVER['PHPBB_TEST_DBPASSWD']) ? $_SERVER['PHPBB_TEST_DBPASSWD'] : '', +				'custom_dsn'	=> isset($_SERVER['PHPBB_TEST_CUSTOM_DSN']) ? $_SERVER['PHPBB_TEST_CUSTOM_DSN'] : '',  			));  		} diff --git a/tests/text_processing/censor_text_test.php b/tests/text_processing/censor_text_test.php index 8fcdb7ef85..f0e13638a5 100644 --- a/tests/text_processing/censor_text_test.php +++ b/tests/text_processing/censor_text_test.php @@ -9,7 +9,7 @@  require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';  require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; -require_once dirname(__FILE__) . '/../mock_user.php'; +require_once dirname(__FILE__) . '/../mock/user.php';  require_once dirname(__FILE__) . '/../mock/cache.php';  class phpbb_text_processing_censor_text_test extends phpbb_test_case diff --git a/tests/text_processing/make_clickable_test.php b/tests/text_processing/make_clickable_test.php index 8697907311..db0812319d 100644 --- a/tests/text_processing/make_clickable_test.php +++ b/tests/text_processing/make_clickable_test.php @@ -12,7 +12,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';  class phpbb_text_processing_make_clickable_test extends phpbb_test_case  { -	public static function make_clickable_data() +	static public function make_clickable_data()  	{  		// value => whether it should work  		$prefix_texts = array( diff --git a/tests/utf/utf8_clean_string_test.php b/tests/utf/utf8_clean_string_test.php index 70bd549d5b..5ebf6409af 100644 --- a/tests/utf/utf8_clean_string_test.php +++ b/tests/utf/utf8_clean_string_test.php @@ -11,7 +11,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';  class phpbb_utf_utf8_clean_string_test extends phpbb_test_case  { -	public static function cleanable_strings() +	static public function cleanable_strings()  	{  		return array(  			array('MiXed CaSe', 'mixed case', 'Checking case folding'),  | 
