diff options
49 files changed, 829 insertions, 38 deletions
| diff --git a/phpBB/includes/acp/acp_inactive.php b/phpBB/includes/acp/acp_inactive.php index 78d6a0b2f3..f098b772ee 100644 --- a/phpBB/includes/acp/acp_inactive.php +++ b/phpBB/includes/acp/acp_inactive.php @@ -136,6 +136,8 @@ class acp_inactive  								add_log('admin', 'LOG_USER_ACTIVE', $row['username']);  								add_log('user', $row['user_id'], 'LOG_USER_ACTIVE_USER');  							} + +							trigger_error(sprintf($user->lang['LOG_INACTIVE_ACTIVATE'], implode($user->lang['COMMA_SEPARATOR'], $user_affected) . ' ' . adm_back_link($this->u_action)));  						}  						// For activate we really need to redirect, else a refresh can result in users being deactivated again @@ -159,6 +161,8 @@ class acp_inactive  							}  							add_log('admin', 'LOG_INACTIVE_' . strtoupper($action), implode(', ', $user_affected)); + +							trigger_error(sprintf($user->lang['LOG_INACTIVE_DELETE'], implode($user->lang['COMMA_SEPARATOR'], $user_affected) . ' ' . adm_back_link($this->u_action)));  						}  						else  						{ @@ -230,7 +234,8 @@ class acp_inactive  						$db->sql_query($sql);  						add_log('admin', 'LOG_INACTIVE_REMIND', implode(', ', $usernames)); -						unset($usernames); + +						trigger_error(sprintf($user->lang['LOG_INACTIVE_REMIND'], implode($user->lang['COMMA_SEPARATOR'], $usernames) . ' ' . adm_back_link($this->u_action)));  					}  					$db->sql_freeresult($result); diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php index cf54d455f7..159703d3be 100644 --- a/phpBB/includes/db/dbal.php +++ b/phpBB/includes/db/dbal.php @@ -284,6 +284,37 @@ class dbal  	}  	/** +	* Build a case expression +	* +	* Note: The two statements action_true and action_false must have the same data type (int, vchar, ...) in the database! +	* +	* @param	string	$condition		The condition which must be true, to use action_true rather then action_else +	* @param	string	$action_true	SQL expression that is used, if the condition is true +	* @param	string	$action_else	SQL expression that is used, if the condition is false, optional +	* @return	string			CASE expression including the condition and statements +	*/ +	public function sql_case($condition, $action_true, $action_false = false) +	{ +		$sql_case = 'CASE WHEN ' . $condition; +		$sql_case .= ' THEN ' . $action_true; +		$sql_case .= ($action_false !== false) ? ' ELSE ' . $action_false : ''; +		$sql_case .= ' END'; +		return $sql_case; +	} + +	/** +	* Build a concatenated expression +	* +	* @param	string	$expr1		Base SQL expression where we append the second one +	* @param	string	$expr2		SQL expression that is appended to the first expression +	* @return	string		Concatenated string +	*/ +	public function sql_concatenate($expr1, $expr2) +	{ +		return $expr1 . ' || ' . $expr2; +	} + +	/**  	* Returns whether results of a query need to be buffered to run a transaction while iterating over them.  	*  	* @return bool Whether buffering is required. diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php index abeabc389f..fb044b492f 100644 --- a/phpBB/includes/db/mssql.php +++ b/phpBB/includes/db/mssql.php @@ -92,6 +92,14 @@ class dbal_mssql extends dbal  	}  	/** +	* {@inheritDoc} +	*/ +	public function sql_concatenate($expr1, $expr2) +	{ +		return $expr1 . ' + ' . $expr2; +	} + +	/**  	* SQL Transaction  	* @access private  	*/ diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index 6e24f4e9e8..64fa9634d1 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -110,6 +110,14 @@ class dbal_mssql_odbc extends dbal  	}  	/** +	* {@inheritDoc} +	*/ +	public function sql_concatenate($expr1, $expr2) +	{ +		return $expr1 . ' + ' . $expr2; +	} + +	/**  	* SQL Transaction  	* @access private  	*/ diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php index 8a4503f111..1f37d54ecb 100644 --- a/phpBB/includes/db/mssqlnative.php +++ b/phpBB/includes/db/mssqlnative.php @@ -260,6 +260,14 @@ class dbal_mssqlnative extends dbal  	/**  	* {@inheritDoc}  	*/ +	public function sql_concatenate($expr1, $expr2) +	{ +		return $expr1 . ' + ' . $expr2; +	} + +	/** +	* {@inheritDoc} +	*/  	function sql_buffer_nested_transactions()  	{  		return true; @@ -435,7 +443,7 @@ class dbal_mssqlnative extends dbal  				unset($row['line2'], $row['line3']);  			}  		} -		return $row; +		return (sizeof($row)) ? $row : false;  	}  	/** diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index eb38e3e913..8d1f805870 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -120,6 +120,14 @@ class dbal_mysql extends dbal  	}  	/** +	* {@inheritDoc} +	*/ +	public function sql_concatenate($expr1, $expr2) +	{ +		return 'CONCAT(' . $expr1 . ', ' . $expr2 . ')'; +	} + +	/**  	* SQL Transaction  	* @access private  	*/ diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php index 4210a58002..e07cd35e24 100644 --- a/phpBB/includes/db/mysqli.php +++ b/phpBB/includes/db/mysqli.php @@ -123,6 +123,14 @@ class dbal_mysqli extends dbal  	}  	/** +	* {@inheritDoc} +	*/ +	public function sql_concatenate($expr1, $expr2) +	{ +		return 'CONCAT(' . $expr1 . ', ' . $expr2 . ')'; +	} + +	/**  	* SQL Transaction  	* @access private  	*/ diff --git a/phpBB/styles/prosilver/template/ucp_groups_membership.html b/phpBB/styles/prosilver/template/ucp_groups_membership.html index a312911ae4..5cb238082a 100644 --- a/phpBB/styles/prosilver/template/ucp_groups_membership.html +++ b/phpBB/styles/prosilver/template/ucp_groups_membership.html @@ -93,7 +93,7 @@  				<!-- IF pending.GROUP_DESC --><br />{pending.GROUP_DESC}<!-- ENDIF -->  				<!-- IF not pending.GROUP_SPECIAL --><br /><i>{pending.GROUP_STATUS}</i><!-- ENDIF -->  				</dt> -				<dd class="mark"><input type="radio" name="selected" value="{pending.GROUP_ID}" <!-- IF pending.GROUP_SPECIAL -->disabled="diabled"<!-- ENDIF --> /></dd> +				<dd class="mark"><input type="radio" name="selected" value="{pending.GROUP_ID}" <!-- IF pending.GROUP_SPECIAL -->disabled="disabled"<!-- ENDIF --> /></dd>  			</dl>  		</li>  		<!-- END pending --> diff --git a/phpBB/styles/prosilver/template/ucp_pm_viewmessage_print.html b/phpBB/styles/prosilver/template/ucp_pm_viewmessage_print.html index bafb64dbc8..43e7de2e12 100644 --- a/phpBB/styles/prosilver/template/ucp_pm_viewmessage_print.html +++ b/phpBB/styles/prosilver/template/ucp_pm_viewmessage_print.html @@ -17,10 +17,9 @@  	<div id="page-header">  		<h1>{SITENAME}</h1> -		<p>{SITE_DESCRIPTION}<br /><a href="{U_FORUM}">{U_FORUM}</a></p> +		<p>{SITE_DESCRIPTION}</p> -		<h2>{TOPIC_TITLE}</h2> -		<p><a href="{U_TOPIC}">{U_TOPIC}</a></p> +		<h2>{L_PRIVATE_MESSAGING}</h2>  	</div>  	<div id="page-body"> diff --git a/tests/bbcode/url_bbcode_test.php b/tests/bbcode/url_bbcode_test.php index b944b6135d..d5df386714 100644 --- a/tests/bbcode/url_bbcode_test.php +++ b/tests/bbcode/url_bbcode_test.php @@ -11,8 +11,6 @@ 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/request.php';  class phpbb_url_bbcode_test extends phpbb_test_case  { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index f103d8f15a..1017e0c72f 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -16,6 +16,8 @@ $table_prefix = 'phpbb_';  require_once $phpbb_root_path . 'includes/constants.php';  require_once $phpbb_root_path . 'includes/class_loader.' . $phpEx; +$phpbb_class_loader_mock = new phpbb_class_loader('phpbb_mock_', $phpbb_root_path . '../tests/mock/', ".php"); +$phpbb_class_loader_mock->register();  $phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path . 'ext/', ".php");  $phpbb_class_loader_ext->register();  $phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', ".php"); diff --git a/tests/class_loader/class_loader_test.php b/tests/class_loader/class_loader_test.php index 80f0b38095..76af4dde37 100644 --- a/tests/class_loader/class_loader_test.php +++ b/tests/class_loader/class_loader_test.php @@ -7,8 +7,6 @@  *  */ -require_once dirname(__FILE__) . '/../mock/cache.php'; -  class phpbb_class_loader_test extends PHPUnit_Framework_TestCase  {  	public function setUp() diff --git a/tests/config/db_test.php b/tests/config/db_test.php index a9a53541a5..0b8f73d53a 100644 --- a/tests/config/db_test.php +++ b/tests/config/db_test.php @@ -7,8 +7,6 @@  *  */ -require_once dirname(__FILE__) . '/../mock/cache.php'; -  class phpbb_config_db_test extends phpbb_database_test_case  {  	private $cache; diff --git a/tests/cron/manager_test.php b/tests/cron/manager_test.php index f433fc9a9b..3e40a6d338 100644 --- a/tests/cron/manager_test.php +++ b/tests/cron/manager_test.php @@ -7,7 +7,6 @@  *  */ -require_once dirname(__FILE__) . '/../mock/extension_manager.php';  require_once dirname(__FILE__) . '/includes/cron/task/core/dummy_task.php';  require_once dirname(__FILE__) . '/includes/cron/task/core/second_dummy_task.php';  require_once dirname(__FILE__) . '/ext/testext/cron/dummy_task.php'; diff --git a/tests/cron/task_provider_test.php b/tests/cron/task_provider_test.php index 4547c61a55..b42f40bb4a 100644 --- a/tests/cron/task_provider_test.php +++ b/tests/cron/task_provider_test.php @@ -7,8 +7,6 @@  *  */ -require_once dirname(__FILE__) . '/../mock/extension_manager.php'; -  class phpbb_cron_task_provider_test extends PHPUnit_Framework_TestCase  {  	public function setUp() diff --git a/tests/dbal/case_test.php b/tests/dbal/case_test.php new file mode 100644 index 0000000000..57a1729a39 --- /dev/null +++ b/tests/dbal/case_test.php @@ -0,0 +1,69 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_dbal_case_test extends phpbb_database_test_case +{ +	public function getDataSet() +	{ +		return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); +	} + +	public function test_case_int() +	{ +		$db = $this->new_dbal(); + +		$sql = 'SELECT ' . $db->sql_case('1 = 1', '1', '2') . ' AS test_num +			FROM phpbb_config'; +		$result = $db->sql_query_limit($sql, 1); + +		$this->assertEquals(1, (int) $db->sql_fetchfield('test_num')); + +		$sql = 'SELECT ' . $db->sql_case('1 = 0', '1', '2') . ' AS test_num +			FROM phpbb_config'; +		$result = $db->sql_query_limit($sql, 1); + +		$this->assertEquals(2, (int) $db->sql_fetchfield('test_num')); +	} + +	public function test_case_string() +	{ +		$db = $this->new_dbal(); + +		$sql = 'SELECT ' . $db->sql_case('1 = 1', "'foo'", "'bar'") . ' AS test_string +			FROM phpbb_config'; +		$result = $db->sql_query_limit($sql, 1); + +		$this->assertEquals('foo', $db->sql_fetchfield('test_string')); + +		$sql = 'SELECT ' . $db->sql_case('1 = 0', "'foo'", "'bar'") . ' AS test_string +			FROM phpbb_config'; +		$result = $db->sql_query_limit($sql, 1); + +		$this->assertEquals('bar', $db->sql_fetchfield('test_string')); +	} + +	public function test_case_column() +	{ +		$db = $this->new_dbal(); + +		$sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS test_string +			FROM phpbb_config +			WHERE config_name = 'config1'"; +		$result = $db->sql_query_limit($sql, 1); + +		$this->assertEquals('config1', $db->sql_fetchfield('test_string')); + +		$sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS test_string +			FROM phpbb_config +			WHERE config_value = 'bar'"; +		$result = $db->sql_query_limit($sql, 1); + +		$this->assertEquals('bar', $db->sql_fetchfield('test_string')); +	} +} diff --git a/tests/dbal/concatenate_test.php b/tests/dbal/concatenate_test.php new file mode 100644 index 0000000000..0891fa58a0 --- /dev/null +++ b/tests/dbal/concatenate_test.php @@ -0,0 +1,64 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_dbal_concatenate_test extends phpbb_database_test_case +{ +	public function getDataSet() +	{ +		return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); +	} + +	public function test_concatenate_string() +	{ +		$db = $this->new_dbal(); + +		$sql = 'SELECT config_name, ' . $db->sql_concatenate('config_name', "'" . $db->sql_escape('append') . "'") . ' AS string +			FROM phpbb_config'; +		$result = $db->sql_query($sql); + +		$db->sql_return_on_error(false); + +		$this->assertEquals(array( +				array( +					'config_name'	=> 'config1', +					'string'		=> 'config1append', +				), +				array( +					'config_name'	=> 'config2', +					'string'		=> 'config2append', +				), +			), +			$db->sql_fetchrowset($result) +		); +	} + +	public function test_concatenate_statement() +	{ +		$db = $this->new_dbal(); + +		$sql = 'SELECT config_name, ' . $db->sql_concatenate('config_name', 'config_value') . ' AS string +			FROM phpbb_config'; +		$result = $db->sql_query($sql); + +		$db->sql_return_on_error(false); + +		$this->assertEquals(array( +				array( +					'config_name'	=> 'config1', +					'string'		=> 'config1foo', +				), +				array( +					'config_name'	=> 'config2', +					'string'		=> 'config2bar', +				), +			), +			$db->sql_fetchrowset($result) +		); +	} +} diff --git a/tests/dbal/order_lower_test.php b/tests/dbal/order_lower_test.php index e16c0c20ee..84d454742f 100644 --- a/tests/dbal/order_lower_test.php +++ b/tests/dbal/order_lower_test.php @@ -14,7 +14,7 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case  		return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/styles.xml');  	} -	public function test_cross_join() +	public function test_order_lower()  	{  		$db = $this->new_dbal(); diff --git a/tests/download/http_byte_range_test.php b/tests/download/http_byte_range_test.php index b93c1b630c..23b9169fe3 100644 --- a/tests/download/http_byte_range_test.php +++ b/tests/download/http_byte_range_test.php @@ -8,7 +8,6 @@  */  require_once dirname(__FILE__) . '/../../phpBB/includes/functions_download.php'; -require_once dirname(__FILE__) . '/../mock/request.php';  class phpbb_download_http_byte_range_test extends phpbb_test_case  { diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index f7e9bd57bb..622f404786 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -7,9 +7,6 @@  *  */ -require_once dirname(__FILE__) . '/../mock/cache.php'; -require_once dirname(__FILE__) . '/../mock/extension_manager.php'; -  class phpbb_extension_finder_test extends phpbb_test_case  {  	protected $extension_manager; diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index 0a689916c7..45bed247ae 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -7,7 +7,6 @@  *  */ -require_once dirname(__FILE__) . '/../mock/cache.php';  require_once dirname(__FILE__) . '/ext/bar/ext.php';  require_once dirname(__FILE__) . '/ext/foo/ext.php';  require_once dirname(__FILE__) . '/ext/vendor/moo/ext.php'; diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php new file mode 100644 index 0000000000..6ba55eeba7 --- /dev/null +++ b/tests/functional/fileupload_form_test.php @@ -0,0 +1,62 @@ +<?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_fileupload_form_test extends phpbb_functional_test_case +{ +	private $path; + +	public function setUp() +	{ +		parent::setUp(); +		$this->path = __DIR__ . '/fixtures/files/'; +		$this->add_lang('posting'); +		$this->login(); +	} + +	public function test_empty_file() +	{ +		$crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); +		$form = $crawler->selectButton('add_file')->form(); +		$form['fileupload']->upload($this->path . 'empty.png'); +		$crawler = $this->client->submit($form); +		$this->assertEquals($this->lang('ATTACHED_IMAGE_NOT_IMAGE'), $crawler->filter('div#message p')->text()); +	} + +	public function test_invalid_extension() +	{ +		$crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); +		$form = $crawler->selectButton('add_file')->form(); +		$form['fileupload']->upload($this->path . 'illegal-extension.bif'); +		$crawler = $this->client->submit($form); +		$this->assertEquals($this->lang('DISALLOWED_EXTENSION', 'bif'), $crawler->filter('p.error')->text()); +	} + +	public function test_too_large() +	{ +		$this->markTestIncomplete('Functional tests use an admin account which ignores maximum upload size.'); +		$crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); +		$form = $crawler->selectButton('add_file')->form(); +		$form['fileupload']->upload($this->path . 'too-large.png'); +		$crawler = $this->client->submit($form); +		$this->assertEquals($this->lang('WRONG_FILESIZE', '256', 'KiB'), $crawler->filter('p.error')->text()); +	} + +	public function test_valid_file() +	{ +		$crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); +		$form = $crawler->selectButton('add_file')->form(); +		$form['fileupload']->upload($this->path . 'valid.jpg'); +		$crawler = $this->client->submit($form); +		$this->assertEquals(0, $crawler->filter('p.error')->count()); +		$this->assertContains($this->lang('POSTED_ATTACHMENTS'), $crawler->filter('#postform h3')->eq(1)->text()); +	} +} diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php new file mode 100644 index 0000000000..0deb79acf6 --- /dev/null +++ b/tests/functional/fileupload_remote_test.php @@ -0,0 +1,72 @@ +<?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_fileupload_remote_test extends phpbb_functional_test_case +{ +	public function setUp() +	{ +		parent::setUp(); +		// Only doing this within the functional framework because we need a +		// URL + +		// Global $config required by unique_id +		// Global $user required by fileupload::remote_upload +		global $config, $user; + +		if (!is_array($config)) +		{ +			$config = array(); +		} + +		$config['rand_seed'] = ''; +		$config['rand_seed_last_update'] = time() + 600; + +		$user = new phpbb_mock_user(); +		$user->lang = new phpbb_mock_lang(); +	} + +	public function tearDown() +	{ +		global $config, $user; +		$user = null; +		$config = array(); +	} + +	public function test_invalid_extension() +	{ +		$upload = new fileupload('', array('jpg'), 100); +		$file = $upload->remote_upload('http://example.com/image.gif'); +		$this->assertEquals('URL_INVALID', $file->error[0]); +	} + +	public function test_non_existant() +	{ +		$upload = new fileupload('', array('jpg'), 100); +		$file = $upload->remote_upload('http://example.com/image.jpg'); +		$this->assertEquals('EMPTY_REMOTE_DATA', $file->error[0]); +	} + +	public function test_successful_upload() +	{ +		$upload = new fileupload('', array('gif'), 1000); +		$file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); +		$this->assertEquals(0, sizeof($file->error)); +		$this->assertTrue(file_exists($file->filename)); +	} + +	public function test_too_large() +	{ +		$upload = new fileupload('', array('gif'), 100); +		$file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); +		$this->assertEquals('WRONG_FILESIZE', $file->error[0]); +	} +} diff --git a/tests/functional/fixtures/files/empty.png b/tests/functional/fixtures/files/empty.png new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/functional/fixtures/files/empty.png diff --git a/tests/functional/fixtures/files/illegal-extension.bif b/tests/functional/fixtures/files/illegal-extension.bifBinary files differ new file mode 100644 index 0000000000..3cd5038e38 --- /dev/null +++ b/tests/functional/fixtures/files/illegal-extension.bif diff --git a/tests/functional/fixtures/files/too-large.png b/tests/functional/fixtures/files/too-large.pngBinary files differ new file mode 100644 index 0000000000..ed4b0abd80 --- /dev/null +++ b/tests/functional/fixtures/files/too-large.png diff --git a/tests/functional/fixtures/files/valid.jpg b/tests/functional/fixtures/files/valid.jpgBinary files differ new file mode 100644 index 0000000000..95a87ddbdf --- /dev/null +++ b/tests/functional/fixtures/files/valid.jpg diff --git a/tests/functions_acp/build_cfg_template_test.php b/tests/functions_acp/build_cfg_template_test.php index bb479ffac9..12121f6678 100644 --- a/tests/functions_acp/build_cfg_template_test.php +++ b/tests/functions_acp/build_cfg_template_test.php @@ -7,7 +7,6 @@  *  */ -require_once dirname(__FILE__) . '/../mock/lang.php';  require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php';  class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case diff --git a/tests/functions_acp/build_select_test.php b/tests/functions_acp/build_select_test.php index 782acae1fa..aca49b7655 100644 --- a/tests/functions_acp/build_select_test.php +++ b/tests/functions_acp/build_select_test.php @@ -7,7 +7,6 @@  *  */ -require_once dirname(__FILE__) . '/../mock/lang.php';  require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php';  class phpbb_functions_acp_built_select_test extends phpbb_test_case diff --git a/tests/functions_acp/h_radio_test.php b/tests/functions_acp/h_radio_test.php index 02b2444a9e..a61f2e8975 100644 --- a/tests/functions_acp/h_radio_test.php +++ b/tests/functions_acp/h_radio_test.php @@ -7,7 +7,6 @@  *  */ -require_once dirname(__FILE__) . '/../mock/lang.php';  require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php';  class phpbb_functions_acp_h_radio_test extends phpbb_test_case diff --git a/tests/functions_acp/validate_config_vars_test.php b/tests/functions_acp/validate_config_vars_test.php index 55441561a6..7cd7fa3892 100644 --- a/tests/functions_acp/validate_config_vars_test.php +++ b/tests/functions_acp/validate_config_vars_test.php @@ -7,7 +7,6 @@  *  */ -require_once dirname(__FILE__) . '/../mock/lang.php';  require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php';  class phpbb_functions_acp_validate_config_vars_test extends phpbb_test_case diff --git a/tests/functions_acp/validate_range_test.php b/tests/functions_acp/validate_range_test.php index 34ce848e76..8606158251 100644 --- a/tests/functions_acp/validate_range_test.php +++ b/tests/functions_acp/validate_range_test.php @@ -7,7 +7,6 @@  *  */ -require_once dirname(__FILE__) . '/../mock/lang.php';  require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';  require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php'; diff --git a/tests/mock/filespec.php b/tests/mock/filespec.php new file mode 100644 index 0000000000..9d2a5c84de --- /dev/null +++ b/tests/mock/filespec.php @@ -0,0 +1,32 @@ +<?php +/** + * + * @package testing + * @copyright (c) 2012 phpBB Group + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 + * + */ + +/** + * Mock filespec class with some basic values to help with testing the + * fileupload class + */ +class phpbb_mock_filespec +{ +	public $filesize; +	public $realname; +	public $extension; +	public $width; +	public $height; +	public $error = array(); + +	public function check_content($disallowed_content) +	{ +		return true; +	} + +	public function get($property) +	{ +		return $this->$property; +	} +} diff --git a/tests/mock/fileupload.php b/tests/mock/fileupload.php new file mode 100644 index 0000000000..409036ba63 --- /dev/null +++ b/tests/mock/fileupload.php @@ -0,0 +1,52 @@ +<?php +/** + * + * @package testing + * @copyright (c) 2012 phpBB Group + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 + * + */ + +/** + * Mock fileupload class with some basic values to help with testing the + * filespec class + */ +class phpbb_mock_fileupload +{ +	public $max_filesize = 100; +	public $error_prefix = ''; + +	public function valid_dimensions($filespec) +	{ +		return true; +	} + +	/** +	 * Copied verbatim from phpBB/includes/functions_upload.php's fileupload +	 * class to ensure the correct behaviour of filespec::move_file. +	 * +	 * Maps file extensions to the constant in second index of the array +	 * returned by getimagesize() +	 */ +	public function image_types() +	{ +		return array( +			IMAGETYPE_GIF		=> array('gif'), +			IMAGETYPE_JPEG		=> array('jpg', 'jpeg'), +			IMAGETYPE_PNG		=> array('png'), +			IMAGETYPE_SWF		=> array('swf'), +			IMAGETYPE_PSD		=> array('psd'), +			IMAGETYPE_BMP		=> array('bmp'), +			IMAGETYPE_TIFF_II	=> array('tif', 'tiff'), +			IMAGETYPE_TIFF_MM	=> array('tif', 'tiff'), +			IMAGETYPE_JPC		=> array('jpg', 'jpeg'), +			IMAGETYPE_JP2		=> array('jpg', 'jpeg'), +			IMAGETYPE_JPX		=> array('jpg', 'jpeg'), +			IMAGETYPE_JB2		=> array('jpg', 'jpeg'), +			IMAGETYPE_SWC		=> array('swc'), +			IMAGETYPE_IFF		=> array('iff'), +			IMAGETYPE_WBMP		=> array('wbmp'), +			IMAGETYPE_XBM		=> array('xbm'), +		); +	} +} 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/security/base.php b/tests/security/base.php index 82e4dda9d0..08878ad60d 100644 --- a/tests/security/base.php +++ b/tests/security/base.php @@ -7,8 +7,6 @@  *  */ -require_once dirname(__FILE__) . '/../mock/request.php'; -  abstract class phpbb_security_test_base extends phpbb_test_case  {  	/** diff --git a/tests/session/continue_test.php b/tests/session/continue_test.php index c4f7f8d75b..ad78d92299 100644 --- a/tests/session/continue_test.php +++ b/tests/session/continue_test.php @@ -7,7 +7,6 @@  *  */ -require_once dirname(__FILE__) . '/../mock/cache.php';  require_once dirname(__FILE__) . '/testable_factory.php';  class phpbb_session_continue_test extends phpbb_database_test_case diff --git a/tests/session/init_test.php b/tests/session/init_test.php index 2ce6c4a4ac..830de34ed0 100644 --- a/tests/session/init_test.php +++ b/tests/session/init_test.php @@ -7,7 +7,6 @@  *  */ -require_once dirname(__FILE__) . '/../mock/cache.php';  require_once dirname(__FILE__) . '/testable_factory.php';  class phpbb_session_init_test extends phpbb_database_test_case diff --git a/tests/session/testable_factory.php b/tests/session/testable_factory.php index a042085908..cb85a01c5c 100644 --- a/tests/session/testable_factory.php +++ b/tests/session/testable_factory.php @@ -7,9 +7,6 @@  *  */ -require_once dirname(__FILE__) . '/../mock/request.php'; -require_once dirname(__FILE__) . '/../mock/session_testable.php'; -  /**  * This class exists to setup an instance of phpbb's session class for testing.  * diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index dd0acba6cd..6f76cb049d 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -8,7 +8,6 @@  */  require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../mock/extension_manager.php';  class phpbb_template_template_test_case extends phpbb_test_case  { diff --git a/tests/text_processing/censor_text_test.php b/tests/text_processing/censor_text_test.php index 8fcdb7ef85..043d8eb27d 100644 --- a/tests/text_processing/censor_text_test.php +++ b/tests/text_processing/censor_text_test.php @@ -9,8 +9,6 @@  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/cache.php';  class phpbb_text_processing_censor_text_test extends phpbb_test_case  { @@ -19,7 +17,7 @@ class phpbb_text_processing_censor_text_test extends phpbb_test_case  		global $cache, $user;  		$cache = new phpbb_mock_cache;  		$user = new phpbb_mock_user; -		 +  		$user->optionset('viewcensors', false);  		return array( @@ -61,7 +59,7 @@ class phpbb_text_processing_censor_text_test extends phpbb_test_case  			array('badword1 badword2 badword3 badword4', 'replacement1 replacement2 replacement3 replacement4'),  			array('badword1 badword2 badword3 badword4d', 'replacement1 replacement2 replacement3 badword4d'),  			array('abadword1 badword2 badword3 badword4', 'replacement1 replacement2 replacement3 replacement4'), -			 +  			array("new\nline\ntest", "new\nline\ntest"),  			array("tab\ttest\t", "tab\ttest\t"),  			array('öäü', 'öäü'), diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php new file mode 100644 index 0000000000..c7ff2e78e0 --- /dev/null +++ b/tests/upload/filespec_test.php @@ -0,0 +1,275 @@ +<?php +/** + * + * @package testing + * @copyright (c) 2012 phpBB Group + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 + * + */ + +require_once __DIR__ . '/../../phpBB/includes/functions.php'; +require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php'; +require_once __DIR__ . '/../../phpBB/includes/functions_upload.php'; + +class phpbb_filespec_test extends phpbb_test_case +{ +	const TEST_COUNT = 100; +	const PREFIX = 'phpbb_'; +	const MAX_STR_LEN = 50; +	const UPLOAD_MAX_FILESIZE = 1000; + +	private $config; +	public $path; + +	protected function setUp() +	{ +		// Global $config required by unique_id +		// Global $user required by filespec::additional_checks and +		// filespec::move_file +		global $config, $user; + +		if (!is_array($config)) +		{ +			$config = array(); +		} + +		$config['rand_seed'] = ''; +		$config['rand_seed_last_update'] = time() + 600; +		// This config value is normally pulled from the database which is set +		// to this value at install time. +		// See: phpBB/install/schemas/schema_data.sql +		$config['mime_triggers'] = 'body|head|html|img|plaintext|a href|pre|script|table|title'; + +		$user = new phpbb_mock_user(); +		$user->lang = new phpbb_mock_lang(); + +		$this->config = &$config; +		$this->path = __DIR__ . '/fixture/'; + +		// Create copies of the files for use in testing move_file +		$iterator = new DirectoryIterator($this->path); +		foreach ($iterator as $fileinfo) +		{ +			if ($fileinfo->isDot() || $fileinfo->isDir()) +			{ +				continue; +			} + +			copy($fileinfo->getPathname(), $this->path . 'copies/' . $fileinfo->getFilename() . '_copy'); +			if ($fileinfo->getFilename() === 'txt') +			{ +				copy($fileinfo->getPathname(), $this->path . 'copies/' . $fileinfo->getFilename() . '_copy_2'); +			} +		} +	} + +	private function get_filespec($override = array()) +	{ +		// Initialise a blank filespec object for use with trivial methods +		$upload_ary = array( +			'name' => '', +			'type' => '', +			'size' => '', +			'tmp_name' => '', +			'error' => '', +		); + +		return new filespec(array_merge($upload_ary, $override), null); +	} + +	protected function tearDown() +	{ +		global $user; +		$this->config = array(); +		$user = null; + +		$iterator = new DirectoryIterator($this->path . 'copies'); +		foreach ($iterator as $fileinfo) +		{ +			$name = $fileinfo->getFilename(); +			if ($name[0] !== '.') +			{ +				unlink($fileinfo->getPathname()); +			} +		} +	} + +	public function additional_checks_variables() +	{ +		// False here just indicates the file is too large and fails the +		// filespec::additional_checks method because of it. All other code +		// paths in that method are covered elsewhere. +		return array( +			array('gif', true), +			array('jpg', false), +			array('png', true), +			array('tif', false), +			array('txt', false), +		); +	} + +	/** +	 * @dataProvider additional_checks_variables +	 */ +	public function test_additional_checks($filename, $expected) +	{ +		$upload = new phpbb_mock_fileupload(); +		$filespec = $this->get_filespec(); +		$filespec->upload = $upload; +		$filespec->file_moved = true; +		$filespec->filesize = $filespec->get_filesize($this->path . $filename); + +		$this->assertEquals($expected, $filespec->additional_checks()); +	} + +	public function check_content_variables() +	{ +		// False here indicates that a file is non-binary and contains +		// disallowed content that makes IE report the mimetype incorrectly. +		return array( +			array('gif', true), +			array('jpg', true), +			array('png', true), +			array('tif', true), +			array('txt', false), +		); +	} + +	/** +	 * @dataProvider check_content_variables +	 */ +	public function test_check_content($filename, $expected) +	{ +		$disallowed_content = explode('|', $this->config['mime_triggers']); +		$filespec = $this->get_filespec(array('tmp_name' => $this->path . $filename)); +		$this->assertEquals($expected, $filespec->check_content($disallowed_content)); +	} + +	public function clean_filename_variables() +	{ +		$chunks = str_split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\'\\" /:*?<>|[];(){},#+=-_`', 8); +		return array( +			array($chunks[0] . $chunks[7]), +			array($chunks[1] . $chunks[8]), +			array($chunks[2] . $chunks[9]), +			array($chunks[3] . $chunks[4]), +			array($chunks[5] . $chunks[6]), +		); +	} + +	/** +	 * @dataProvider clean_filename_variables +	 */ +	public function test_clean_filename_real($filename) +	{ +		$bad_chars = array("'", "\\", ' ', '/', ':', '*', '?', '"', '<', '>', '|'); +		$filespec = $this->get_filespec(array('name' => $filename)); +		$filespec->clean_filename('real', self::PREFIX); +		$name = $filespec->realname; + +		$this->assertEquals(0, preg_match('/%(\w{2})/', $name)); +		foreach ($bad_chars as $char) +		{ +			$this->assertFalse(strpos($name, $char)); +		} +	} + +	public function test_clean_filename_unique() +	{ +		$filenames = array(); +		for ($tests = 0; $tests < self::TEST_COUNT; $tests++) +		{ +			$filespec = $this->get_filespec(); +			$filespec->clean_filename('unique', self::PREFIX); +			$name = $filespec->realname; +			 +			$this->assertEquals(strlen($name), 32 + strlen(self::PREFIX)); +			$this->assertRegExp('#^[A-Za-z0-9]+$#', substr($name, strlen(self::PREFIX))); +			$this->assertFalse(isset($filenames[$name])); +			$filenames[$name] = true; +		} +	} + +	public function get_extension_variables() +	{ +		return array( +			array('file.png', 'png'), +			array('file.phpbb.gif', 'gif'), +			array('file..', ''), +			array('.file..jpg.webp', 'webp'), +		); +	} + +	/** +	 * @dataProvider get_extension_variables +	 */ +	public function test_get_extension($filename, $expected) +	{ +		$filespec = $this->get_filespec(); +		$this->assertEquals($expected, $filespec->get_extension($filename)); +	} + +	public function is_image_variables() +	{ +		return array( +			array('gif', 'image/gif', true), +			array('jpg', 'image/jpg', true), +			array('png', 'image/png', true), +			array('tif', 'image/tif', true), +			array('txt', 'text/plain', false), +		); +	} + +	/** +	 * @dataProvider is_image_variables +	 */ +	public function test_is_image($filename, $mimetype, $expected) +	{ +		$filespec = $this->get_filespec(array('tmp_name' => $this->path . $filename, 'type' => $mimetype)); +		$this->assertEquals($expected, $filespec->is_image()); +	} + +	public function move_file_variables() +	{ +		return array( +			array('gif_copy', 'gif_moved', 'image/gif', 'gif', false, true), +			array('non_existant', 'still_non_existant', 'text/plain', 'txt', 'GENERAL_UPLOAD_ERROR', false), +			array('txt_copy', 'txt_as_img', 'image/jpg', 'txt', false, true), +			array('txt_copy_2', 'txt_moved', 'text/plain', 'txt', false, true), +			array('jpg_copy', 'jpg_moved', 'image/png', 'jpg', false, true), +			array('png_copy', 'png_moved', 'image/png', 'jpg', 'IMAGE_FILETYPE_MISMATCH', true), +		); +	} + +	/** +	 * @dataProvider move_file_variables +	 */ +	public function test_move_file($tmp_name, $realname, $mime_type, $extension, $error, $expected) +	{ +		// Global $phpbb_root_path and $phpEx are required by phpbb_chmod +		global $phpbb_root_path, $phpEx; +		$phpbb_root_path = ''; +		$phpEx = 'php'; + +		$upload = new phpbb_mock_fileupload(); +		$upload->max_filesize = self::UPLOAD_MAX_FILESIZE; + +		$filespec = $this->get_filespec(array( +			'tmp_name' => $this->path . 'copies/' . $tmp_name, +			'name' => $realname, +			'type' => $mime_type, +		)); +		$filespec->extension = $extension; +		$filespec->upload = $upload; +		$filespec->local = true; + +		$this->assertEquals($expected, $filespec->move_file($this->path . 'copies')); +		$this->assertEquals($filespec->file_moved, file_exists($this->path . 'copies/' . $realname)); +		if ($error) +		{ +			$this->assertEquals($error, $filespec->error[0]); +		} + +		$phpEx = ''; +	} +} diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php new file mode 100644 index 0000000000..076855ab56 --- /dev/null +++ b/tests/upload/fileupload_test.php @@ -0,0 +1,115 @@ +<?php +/** + * + * @package testing + * @copyright (c) 2012 phpBB Group + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 + * + */ + +require_once __DIR__ . '/../../phpBB/includes/functions.php'; +require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php'; +require_once __DIR__ . '/../../phpBB/includes/functions_upload.php'; + +class phpbb_fileupload_test extends phpbb_test_case +{ +	private $path; + +	protected function setUp() +	{ +		// Global $config required by unique_id +		// Global $user required by several functions dealing with translations +		global $config, $user; + +		if (!is_array($config)) +		{ +			$config = array(); +		} + +		$config['rand_seed'] = ''; +		$config['rand_seed_last_update'] = time() + 600; + +		$user = new phpbb_mock_user(); +		$user->lang = new phpbb_mock_lang(); +		$this->path = __DIR__ . '/fixture/'; +	} + +	private function gen_valid_filespec() +	{ +		$filespec = new phpbb_mock_filespec(); +		$filespec->filesize = 1; +		$filespec->extension = 'jpg'; +		$filespec->realname = 'valid'; +		$filespec->width = 2; +		$filespec->height = 2; + +		return $filespec; +	} + +	protected function tearDown() +	{ +		// Clear globals +		global $config, $user; +		$config = array(); +		$user = null; +	} + +	public function test_common_checks_invalid_extension() +	{ +		$upload = new fileupload('', array('png'), 100); +		$file = $this->gen_valid_filespec(); +		$upload->common_checks($file); +		$this->assertEquals('DISALLOWED_EXTENSION', $file->error[0]); +	} + +	public function test_common_checks_invalid_filename() +	{ +		$upload = new fileupload('', array('jpg'), 100); +		$file = $this->gen_valid_filespec(); +		$file->realname = 'invalid?'; +		$upload->common_checks($file); +		$this->assertEquals('INVALID_FILENAME', $file->error[0]); +	} + +	public function test_common_checks_too_large() +	{ +		$upload = new fileupload('', array('jpg'), 100); +		$file = $this->gen_valid_filespec(); +		$file->filesize = 1000; +		$upload->common_checks($file); +		$this->assertEquals('WRONG_FILESIZE', $file->error[0]); +	} + +	public function test_common_checks_valid_file() +	{ +		$upload = new fileupload('', array('jpg'), 1000); +		$file = $this->gen_valid_filespec(); +		$upload->common_checks($file); +		$this->assertEquals(0, sizeof($file->error)); +	} + +	public function test_local_upload() +	{ +		$upload = new fileupload('', array('jpg'), 1000); + +		copy($this->path . 'jpg', $this->path . 'jpg.jpg'); +		$file = $upload->local_upload($this->path . 'jpg.jpg'); +		$this->assertEquals(0, sizeof($file->error)); +		unlink($this->path . 'jpg.jpg'); +	} + +	public function test_valid_dimensions() +	{ +		$upload = new fileupload('', false, false, 1, 1, 100, 100); + +		$file1 = $this->gen_valid_filespec(); +		$file2 = $this->gen_valid_filespec(); +		$file2->height = 101; +		$file3 = $this->gen_valid_filespec(); +		$file3->width = 0; + +		$this->assertTrue($upload->valid_dimensions($file1)); +		$this->assertFalse($upload->valid_dimensions($file2)); +		$this->assertFalse($upload->valid_dimensions($file3)); +	} +} diff --git a/tests/upload/fixture/copies/.gitkeep b/tests/upload/fixture/copies/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/upload/fixture/copies/.gitkeep diff --git a/tests/upload/fixture/gif b/tests/upload/fixture/gifBinary files differ new file mode 100644 index 0000000000..b636f4b8df --- /dev/null +++ b/tests/upload/fixture/gif diff --git a/tests/upload/fixture/jpg b/tests/upload/fixture/jpgBinary files differ new file mode 100644 index 0000000000..3cd5038e38 --- /dev/null +++ b/tests/upload/fixture/jpg diff --git a/tests/upload/fixture/png b/tests/upload/fixture/pngBinary files differ new file mode 100644 index 0000000000..5514ad40e9 --- /dev/null +++ b/tests/upload/fixture/png diff --git a/tests/upload/fixture/tif b/tests/upload/fixture/tifBinary files differ new file mode 100644 index 0000000000..248b50f9cb --- /dev/null +++ b/tests/upload/fixture/tif diff --git a/tests/upload/fixture/txt b/tests/upload/fixture/txt new file mode 100644 index 0000000000..a78c858f5c --- /dev/null +++ b/tests/upload/fixture/txt @@ -0,0 +1,2 @@ +<HTML>mime trigger</HTML> +The HTML tags should remain uppercase so that case-insensitivity can be checked. | 
