diff options
Diffstat (limited to 'tests/functions')
35 files changed, 1204 insertions, 202 deletions
| diff --git a/tests/functions/build_hidden_fields_for_query_params_test.php b/tests/functions/build_hidden_fields_for_query_params_test.php new file mode 100644 index 0000000000..14cb4b9a94 --- /dev/null +++ b/tests/functions/build_hidden_fields_for_query_params_test.php @@ -0,0 +1,75 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_build_hidden_fields_for_query_params_test extends phpbb_test_case +{ +	public function build_hidden_fields_for_query_params_test_data() +	{ +		return array( +			// get +			// post +			// exclude +			// expected +			array( +				array('foo' => 'bar'), +				array(), +				array(), +				"<input type='hidden' name=\"foo\" value=\"bar\" />", +			), +			array( +				array('foo' => 'bar', 'a' => 'b'), +				array(), +				array(), +				"<input type='hidden' name=\"foo\" value=\"bar\" /><input type='hidden' name=\"a\" value=\"b\" />", +			), +			array( +				array('a' => 'quote"', 'b' => '<less>'), +				array(), +				array(), +				"<input type='hidden' name=\"a\" value='quote\"' /><input type='hidden' name=\"b\" value=\"<less>\" />", +			), +			array( +				array('a' => "quotes'\""), +				array(), +				array(), +				"<input type='hidden' name=\"a\" value=\"quotes'"\" />", +			), +			array( +				array('foo' => 'bar', 'a' => 'b'), +				array('a' => 'c'), +				array(), +				"<input type='hidden' name=\"foo\" value=\"bar\" />", +			), +			// strict equality check +			array( +				array('foo' => 'bar', 'a' => '0'), +				array('a' => ''), +				array(), +				"<input type='hidden' name=\"foo\" value=\"bar\" />", +			), +		); +	} + +	/** +	* @dataProvider build_hidden_fields_for_query_params_test_data +	*/ +	public function test_build_hidden_fields_for_query_params($get, $post, $exclude, $expected) +	{ +		$request = new phpbb_mock_request($get, $post); +		$result = phpbb_build_hidden_fields_for_query_params($request, $exclude); + +		$this->assertEquals($expected, $result); +	} +} diff --git a/tests/functions/build_url_test.php b/tests/functions/build_url_test.php new file mode 100644 index 0000000000..a59b94c744 --- /dev/null +++ b/tests/functions/build_url_test.php @@ -0,0 +1,92 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_build_url_test extends phpbb_test_case +{ +	protected function setUp() +	{ +		global $user, $phpbb_dispatcher, $phpbb_container, $phpbb_root_path, $phpbb_path_helper; + +		parent::setUp(); + +		$phpbb_container = new phpbb_mock_container_builder(); +		$user = new phpbb_mock_user(); +		$phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + +		$phpbb_path_helper = new \phpbb\path_helper( +			new \phpbb\symfony_request( +				new phpbb_mock_request() +			), +			new \phpbb\filesystem(), +			$this->getMock('\phpbb\request\request'), +			$phpbb_root_path, +			'php' +		); +		$phpbb_container->set('path_helper', $phpbb_path_helper); +	} +	public function build_url_test_data() +	{ +		return array( +			array( +				'index.php', +				false, +				'phpBB/index.php?', +			), +			array( +				'index.php', +				't', +				'phpBB/index.php?', +			), +			array( +				'viewtopic.php?t=5&f=4', +				false, +				'phpBB/viewtopic.php?t=5&f=4', +			), +			array( +				'viewtopic.php?f=2&style=1&t=6', +				'f', +				'phpBB/viewtopic.php?style=1&t=6', +			), +			array( +				'viewtopic.php?f=2&style=1&t=6', +				array('f', 'style', 't'), +				'phpBB/viewtopic.php?', +			), +			array( +				'http://test.phpbb.com/viewtopic.php?f=2&style=1&t=6', +				array('f', 'style', 't'), +				'http://test.phpbb.com/viewtopic.php?', +			), +			array( +				'posting.php?f=2&mode=delete&p=20%22%3Cscript%3Ealert%281%29%3B%3C%2Fscript%3E', +				false, +				'phpBB/posting.php?f=2&mode=delete&p=20%22%3Cscript%3Ealert%281%29%3B%3C%2Fscript%3E', +			) +		); +	} + +	/** +	* @dataProvider build_url_test_data +	*/ +	public function test_build_url($page, $strip_vars, $expected) +	{ +		global $user, $phpbb_root_path; + +		$user->page['page'] = $page; +		$output = build_url($strip_vars); + +		$this->assertEquals($expected, $output); +	} +} diff --git a/tests/functions/clean_path_test.php b/tests/functions/clean_path_test.php deleted file mode 100644 index bcbe9838d9..0000000000 --- a/tests/functions/clean_path_test.php +++ /dev/null @@ -1,44 +0,0 @@ -<?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/functions/convert_30_dbms_to_31_test.php b/tests/functions/convert_30_dbms_to_31_test.php new file mode 100644 index 0000000000..729c0a82f0 --- /dev/null +++ b/tests/functions/convert_30_dbms_to_31_test.php @@ -0,0 +1,44 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_convert_30_dbms_to_31_test extends phpbb_test_case +{ +	public function convert_30_dbms_to_31_data() +	{ +		return array( +			array('mssql'), +			array('mssql_odbc'), +			array('mssqlnative'), +			array('mysql'), +			array('mysqli'), +			array('oracle'), +			array('postgres'), +			array('sqlite'), +		); +	} + +	/** +	* @dataProvider convert_30_dbms_to_31_data +	*/ +	public function test_convert_30_dbms_to_31($input) +	{ +		$expected = "phpbb\\db\\driver\\$input"; + +		$config_php_file = new \phpbb\config_php_file('', ''); +		$output = $config_php_file->convert_30_dbms_to_31($input); + +		$this->assertEquals($expected, $output); +	} +} diff --git a/tests/functions/fixtures/banned_users.xml b/tests/functions/fixtures/banned_users.xml new file mode 100644 index 0000000000..cec3f4e51f --- /dev/null +++ b/tests/functions/fixtures/banned_users.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_banlist"> +		<column>ban_userid</column> +		<column>ban_exclude</column> +		<column>ban_end</column> +		<row> +			<value>1</value> +			<value>1</value> +			<value>0</value> +		</row> +		<row> +			<value>2</value> +			<value>0</value> +			<value>0</value> +		</row> +		<row> +			<value>3</value> +			<value>0</value> +			<value>0</value> +		</row> +		<row> +			<value>4</value> +			<value>0</value> +			<value>2</value> +		</row> +		<row> +			<value>5</value> +			<value>0</value> +			<value>999999999999999999999</value> +		</row> +		<row> +			<value>6</value> +			<value>0</value> +			<value>3</value> +		</row> +	</table> +</dataset> diff --git a/tests/functions/fixtures/obtain_online.xml b/tests/functions/fixtures/obtain_online.xml index 05bbe6a05e..14621a3287 100644 --- a/tests/functions/fixtures/obtain_online.xml +++ b/tests/functions/fixtures/obtain_online.xml @@ -15,8 +15,6 @@  		<column>user_allow_viewonline</column>  		<column>user_permissions</column>  		<column>user_sig</column> -		<column>user_occ</column> -		<column>user_interests</column>  		<row>  			<value>1</value>  			<value>anonymous</value> @@ -24,8 +22,6 @@  			<value>1</value>  			<value></value>  			<value></value> -			<value></value> -			<value></value>  		</row>  		<row>  			<value>2</value> @@ -34,8 +30,6 @@  			<value>1</value>  			<value></value>  			<value></value> -			<value></value> -			<value></value>  		</row>  		<row>  			<value>3</value> @@ -44,8 +38,6 @@  			<value>1</value>  			<value></value>  			<value></value> -			<value></value> -			<value></value>  		</row>  		<row>  			<value>4</value> @@ -54,8 +46,6 @@  			<value>1</value>  			<value></value>  			<value></value> -			<value></value> -			<value></value>  		</row>  		<row>  			<value>5</value> @@ -64,8 +54,6 @@  			<value>1</value>  			<value></value>  			<value></value> -			<value></value> -			<value></value>  		</row>  		<row>  			<value>6</value> @@ -74,8 +62,6 @@  			<value>0</value>  			<value></value>  			<value></value> -			<value></value> -			<value></value>  		</row>  		<row>  			<value>7</value> @@ -84,8 +70,6 @@  			<value>0</value>  			<value></value>  			<value></value> -			<value></value> -			<value></value>  		</row>  		<row>  			<value>8</value> @@ -94,8 +78,6 @@  			<value>0</value>  			<value></value>  			<value></value> -			<value></value> -			<value></value>  		</row>  		<row>  			<value>9</value> @@ -104,8 +86,6 @@  			<value>0</value>  			<value></value>  			<value></value> -			<value></value> -			<value></value>  		</row>  		<row>  			<value>10</value> @@ -114,8 +94,6 @@  			<value>0</value>  			<value></value>  			<value></value> -			<value></value> -			<value></value>  		</row>  	</table>  </dataset> diff --git a/tests/functions/fixtures/style_select.xml b/tests/functions/fixtures/style_select.xml index 12d6392ab5..ca95f94461 100644 --- a/tests/functions/fixtures/style_select.xml +++ b/tests/functions/fixtures/style_select.xml @@ -4,20 +4,24 @@  		<column>style_id</column>  		<column>style_name</column>  		<column>style_active</column> +		<column>style_parent_tree</column>  		<row>  			<value>1</value>  			<value>prosilver</value>  			<value>1</value> +			<value></value>  		</row>  		<row>  			<value>2</value>  			<value>subsilver2</value>  			<value>1</value> +			<value></value>  		</row>  		<row>  			<value>3</value>  			<value>zoo</value>  			<value>0</value> +			<value></value>  		</row>  	</table>  </dataset> diff --git a/tests/functions/fixtures/validate_email.xml b/tests/functions/fixtures/validate_email.xml index de7fce8a08..eb4fd90217 100644 --- a/tests/functions/fixtures/validate_email.xml +++ b/tests/functions/fixtures/validate_email.xml @@ -6,8 +6,6 @@  		<column>username_clean</column>  		<column>user_permissions</column>  		<column>user_sig</column> -		<column>user_occ</column> -		<column>user_interests</column>  		<column>user_email_hash</column>  		<row>  			<value>1</value> @@ -15,8 +13,6 @@  			<value>admin</value>  			<value></value>  			<value></value> -			<value></value> -			<value></value>  			<value>143317126117</value>  		</row>  	</table> diff --git a/tests/functions/fixtures/validate_username.xml b/tests/functions/fixtures/validate_username.xml index fbe398469c..1b85a2f06d 100644 --- a/tests/functions/fixtures/validate_username.xml +++ b/tests/functions/fixtures/validate_username.xml @@ -14,16 +14,12 @@  		<column>username_clean</column>  		<column>user_permissions</column>  		<column>user_sig</column> -		<column>user_occ</column> -		<column>user_interests</column>  		<row>  			<value>1</value>  			<value>admin</value>  			<value>admin</value>  			<value></value>  			<value></value> -			<value></value> -			<value></value>  		</row>  		<row>  			<value>2</value> @@ -31,8 +27,6 @@  			<value>moderator</value>  			<value></value>  			<value></value> -			<value></value> -			<value></value>  		</row>  	</table>  </dataset> diff --git a/tests/functions/generate_string_list.php b/tests/functions/generate_string_list.php new file mode 100644 index 0000000000..cd1e37618a --- /dev/null +++ b/tests/functions/generate_string_list.php @@ -0,0 +1,64 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_generate_string_list_test extends phpbb_test_case +{ +	public $user; + +	public function setUp() +	{ +		parent::setUp(); + +		$this->user = new \phpbb\user('\phpbb\datetime'); +		$this->user->data = array('user_lang' => 'en'); +		$this->user->add_lang('common'); +	} + +	public function generate_string_list_data() +	{ +		return array( +			array( +				array(), +				'', +			), +			array( +				array('A'), +				'A',	 +			), +			array( +				array(2 => 'A', 3 => 'B'), +				'A and B', +			), +			array( +				array('A' => 'A', 'B' => 'B', 'C' => 'C'), +				'A, B, and C', +			), +			array( +				array('A', 'B', 'C', 'D'), +				'A, B, C, and D', +			) +		); +	} + +	/** +	* @dataProvider generate_string_list_data +	*/ +	public function test_generate_string_list($items, $expected_result) +	{ +		$result = phpbb_generate_string_list($items, $this->user); +		$this->assertEquals($expected_result, $result); +	} +} diff --git a/tests/functions/get_formatted_filesize_test.php b/tests/functions/get_formatted_filesize_test.php index 96ea2be132..635753d737 100644 --- a/tests/functions/get_formatted_filesize_test.php +++ b/tests/functions/get_formatted_filesize_test.php @@ -1,9 +1,13 @@  <?php  /**  * -* @package testing -* @copyright (c) 2012 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */ diff --git a/tests/functions/get_preg_expression_test.php b/tests/functions/get_preg_expression_test.php new file mode 100644 index 0000000000..e74017d315 --- /dev/null +++ b/tests/functions/get_preg_expression_test.php @@ -0,0 +1,40 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_functions_get_preg_expression_test extends phpbb_test_case +{ +	public function data_path_remove_dot_trailing_slash() +	{ +		return array( +			array('./../', '$2', '/..'), +			array('/../', '$2', '/..'), +			array('', '$2', ''), +			array('./', '$2', ''), +			array('/', '$2', ''), +			array('./../../', '$2', '/../..'), +			array('/../../', '$2', '/../..'), +			array('./dir/', '$2', '/dir'), +			array('./../dir/', '$2', '/../dir'), +		); +	} + +	/** +	 * @dataProvider data_path_remove_dot_trailing_slash +	 */ +	public function test_path_remove_dot_trailing_slash($input, $replace, $expected) +	{ +		$this->assertSame($expected, preg_replace(get_preg_expression('path_remove_dot_trailing_slash'), $replace, $input)); +	} +} diff --git a/tests/functions/get_remote_file_test.php b/tests/functions/get_remote_file_test.php index 4032ca5b58..612d82273e 100644 --- a/tests/functions/get_remote_file_test.php +++ b/tests/functions/get_remote_file_test.php @@ -1,9 +1,13 @@  <?php  /**  * -* @package testing -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */ @@ -17,6 +21,10 @@ class phpbb_functions_get_remote_file extends phpbb_test_case  {  	public function test_version_phpbb_com()  	{ +		global $phpbb_container; +		$phpbb_container = new phpbb_mock_container_builder(); +		$phpbb_container->set('file_downloader', new \phpbb\file_downloader()); +  		$hostname = 'version.phpbb.com';  		if (!phpbb_checkdnsrr($hostname, 'A')) diff --git a/tests/functions/is_absolute_test.php b/tests/functions/is_absolute_test.php index 7630b7c58c..afa4b9b59f 100644 --- a/tests/functions/is_absolute_test.php +++ b/tests/functions/is_absolute_test.php @@ -1,9 +1,13 @@  <?php  /**  * -* @package testing -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */ @@ -51,6 +55,6 @@ class phpbb_functions_is_absolute_test extends phpbb_test_case  	*/  	public function test_is_absolute($path, $expected)  	{ -		$this->assertEquals($expected, is_absolute($path)); +		$this->assertEquals($expected, phpbb_is_absolute($path));  	}  } diff --git a/tests/functions/language_select_test.php b/tests/functions/language_select_test.php index 3341e2a256..6762ead5a1 100644 --- a/tests/functions/language_select_test.php +++ b/tests/functions/language_select_test.php @@ -1,9 +1,13 @@  <?php  /**  * -* @package testing -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */ diff --git a/tests/functions/make_clickable_email_test.php b/tests/functions/make_clickable_email_test.php new file mode 100644 index 0000000000..4c802d0487 --- /dev/null +++ b/tests/functions/make_clickable_email_test.php @@ -0,0 +1,222 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; + +class phpbb_functions_make_clickable_email_test extends phpbb_test_case +{ +	protected function setUp() +	{ +		parent::setUp(); + +		global $config, $user, $request; +		$user = new phpbb_mock_user(); +		$request = new phpbb_mock_request(); +	} + +	/** +	* 'e' tag for email addresses html +	**/ +	public function data_test_make_clickable_email_positive() +	{ +		return array( +			array( +				'nobody@phpbb.com', +				'<!-- e --><a href="mailto:nobody@phpbb.com">nobody@phpbb.com</a><!-- e -->' +			), +			array( +				'Nobody@sub.phpbb.com', +				'<!-- e --><a href="mailto:Nobody@sub.phpbb.com">Nobody@sub.phpbb.com</a><!-- e -->' +			), +			array( +				'alice.bob@foo.phpbb.com', +				'<!-- e --><a href="mailto:alice.bob@foo.phpbb.com">alice.bob@foo.phpbb.com</a><!-- e -->' +			), +			array( +				'alice-foo@bar.phpbb.com', +				'<!-- e --><a href="mailto:alice-foo@bar.phpbb.com">alice-foo@bar.phpbb.com</a><!-- e -->' +			), +			array( +				'alice_foo@bar.phpbb.com', +				'<!-- e --><a href="mailto:alice_foo@bar.phpbb.com">alice_foo@bar.phpbb.com</a><!-- e -->' +			), +			array( +				'alice+tag@foo.phpbb.com', +				'<!-- e --><a href="mailto:alice+tag@foo.phpbb.com">alice+tag@foo.phpbb.com</a><!-- e -->' +			), +			array( +				'alice&tag@foo.phpbb.com', +				'<!-- e --><a href="mailto:alice&tag@foo.phpbb.com">alice&tag@foo.phpbb.com</a><!-- e -->' +			), +			array( +				'alice@phpbb.australia', +				'<!-- e --><a href="mailto:alice@phpbb.australia">alice@phpbb.australia</a><!-- e -->' +			), + +			// Test shortened text for email > 55 characters long +			// Email text should be turned into: first 39 chars + ' ... ' + last 10 chars +			array( +				'alice@phpbb.topZlevelZdomainZnamesZcanZbeZupZtoZsixtyZthreeZcharactersZlong', +				'<!-- e --><a href="mailto:alice@phpbb.topZlevelZdomainZnamesZcanZbeZupZtoZsixtyZthreeZcharactersZlong">alice@phpbb.topZlevelZdomainZnamesZcanZ ... ctersZlong</a><!-- e -->' +			), +			array( +				'l3tt3rsAndNumb3rs@domain.com', +				'<!-- e --><a href="mailto:l3tt3rsAndNumb3rs@domain.com">l3tt3rsAndNumb3rs@domain.com</a><!-- e -->' +			), +			array( +				'has-dash@domain.com', +				'<!-- e --><a href="mailto:has-dash@domain.com">has-dash@domain.com</a><!-- e -->' +			), +			array( +				'hasApostrophe.o\'leary@domain.org', +				'<!-- e --><a href="mailto:hasApostrophe.o\'leary@domain.org">hasApostrophe.o\'leary@domain.org</a><!-- e -->' +			), +			array( +				'uncommonTLD@domain.museum', +				'<!-- e --><a href="mailto:uncommonTLD@domain.museum">uncommonTLD@domain.museum</a><!-- e -->' +			), +			array( +				'uncommonTLD@domain.travel', +				'<!-- e --><a href="mailto:uncommonTLD@domain.travel">uncommonTLD@domain.travel</a><!-- e -->' +			), +			array( +				'uncommonTLD@domain.mobi', +				'<!-- e --><a href="mailto:uncommonTLD@domain.mobi">uncommonTLD@domain.mobi</a><!-- e -->' +			), +			array( +				'countryCodeTLD@domain.uk', +				'<!-- e --><a href="mailto:countryCodeTLD@domain.uk">countryCodeTLD@domain.uk</a><!-- e -->' +			), +			array( +				'countryCodeTLD@domain.rw', +				'<!-- e --><a href="mailto:countryCodeTLD@domain.rw">countryCodeTLD@domain.rw</a><!-- e -->' +			), +			array( +				'numbersInDomain@911.com', +				'<!-- e --><a href="mailto:numbersInDomain@911.com">numbersInDomain@911.com</a><!-- e -->' +			), +			array( +				'underscore_inLocal@domain.net', +				'<!-- e --><a href="mailto:underscore_inLocal@domain.net">underscore_inLocal@domain.net</a><!-- e -->' +			), +			array( +				'IPInsteadOfDomain@127.0.0.1', +				'<!-- e --><a href="mailto:IPInsteadOfDomain@127.0.0.1">IPInsteadOfDomain@127.0.0.1</a><!-- e -->' +			), +			array( +				'IPAndPort@127.0.0.1:25', +				'<!-- e --><a href="mailto:IPAndPort@127.0.0.1:25">IPAndPort@127.0.0.1:25</a><!-- e -->' +			), +			array( +				'subdomain@sub.domain.com', +				'<!-- e --><a href="mailto:subdomain@sub.domain.com">subdomain@sub.domain.com</a><!-- e -->' +			), +			array( +				'local@dash-inDomain.com', +				'<!-- e --><a href="mailto:local@dash-inDomain.com">local@dash-inDomain.com</a><!-- e -->' +			), +			array( +				'dot.inLocal@foo.com', +				'<!-- e --><a href="mailto:dot.inLocal@foo.com">dot.inLocal@foo.com</a><!-- e -->' +			), +			array( +				'a@singleLetterLocal.org', +				'<!-- e --><a href="mailto:a@singleLetterLocal.org">a@singleLetterLocal.org</a><!-- e -->' +			), +			array( +				'singleLetterDomain@x.org', +				'<!-- e --><a href="mailto:singleLetterDomain@x.org">singleLetterDomain@x.org</a><!-- e -->' +			), +			array( +				'&*=?^+{}\'~@validCharsInLocal.net', +				'<!-- e --><a href="mailto:&*=?^+{}\'~@validCharsInLocal.net">&*=?^+{}\'~@validCharsInLocal.net</a><!-- e -->' +			), +			array( +				'foor@bar.newTLD', +				'<!-- e --><a href="mailto:foor@bar.newTLD">foor@bar.newTLD</a><!-- e -->' +			), +		); +	} + +	public function data_test_make_clickable_email_negative() +	{ +		return array( +			array('foo.example.com'),			// @ is missing +			array('.foo.example.com'),			// . as first character +			array('Foo.@example.com'),			// . is last in local part +			array('foo..123@example.com'),		// . doubled +			array('a@b@c@example.com'),			// @ doubled + +			// Emails with invalid characters +			// (only 'valid' pieces having localparts prepended with one of the \n \t ( > chars should parsed if any) +			array('()[]\;:,<>@example.com'),	// invalid characters +			array('abc(def@example.com', 'abc(<!-- e --><a href="mailto:def@example.com">def@example.com</a><!-- e -->'),		// invalid character ( +			array('abc)def@example.com'),		// invalid character ) +			array('abc[def@example.com'),		// invalid character [ +			array('abc]def@example.com'),		// invalid character ] +			array('abc\def@example.com'),		// invalid character \ +			array('abc;def@example.com'),		// invalid character ; +			array('abc:def@example.com'),		// invalid character : +			array('abc,def@example.com'),		// invalid character , +			array('abc<def@example.com'),		// invalid character < +			array('abc>def@example.com', 'abc><!-- e --><a href="mailto:def@example.com">def@example.com</a><!-- e -->'),		// invalid character > +			 +			// http://fightingforalostcause.net/misc/2006/compare-email-regex.php +			array('missingDomain@.com'), +			array('@missingLocal.org'), +			array('missingatSign.net'), +			array('missingDot@com'), +			array('two@@signs.com'), +			// Trailing colon is ignored +			array('colonButNoPort@127.0.0.1:', '<!-- e --><a href="mailto:colonButNoPort@127.0.0.1">colonButNoPort@127.0.0.1</a><!-- e -->:'), + +			array(''), +			// Trailing part after the 3rd dot is ignored +			array('someone-else@127.0.0.1.26', '<!-- e --><a href="mailto:someone-else@127.0.0.1">someone-else@127.0.0.1</a><!-- e -->.26'), + +			array('.localStartsWithDot@domain.com'), +			array('localEndsWithDot.@domain.com'), +			array('two..consecutiveDots@domain.com'), +			array('domainStartsWithDash@-domain.com'), +			array('domainEndsWithDash@domain-.com'), +			array('numbersInTLD@domain.c0m'), +			array('missingTLD@domain.'), +			array('! "#$%(),/;<>[]`|@invalidCharsInLocal.org'), +			array('invalidCharsInDomain@! "#$%(),/;<>_[]`|.org'), +			array('local@SecondLevelDomainNamesAreInvalidIfTheyAreLongerThan64Charactersss.org'), +			// The domain zone name part after the 63rd char is ignored +			array( +				'alice@phpbb.topZlevelZdomainZnamesZcanZbeZupZtoZsixtyZthreeZcharactersZlongZ', +				'<!-- e --><a href="mailto:alice@phpbb.topZlevelZdomainZnamesZcanZbeZupZtoZsixtyZthreeZcharactersZlong">alice@phpbb.topZlevelZdomainZnamesZcanZ ... ctersZlong</a><!-- e -->Z' +			), +		); +	} + +	/** +	 * @dataProvider data_test_make_clickable_email_positive +	 */ +	public function test_email_matching_positive($email, $expected) +	{ +		$this->assertSame($expected, make_clickable($email)); +	} + +	/** +	 * @dataProvider data_test_make_clickable_email_negative +	 */ +	public function test_email_matching_negative($email, $expected = null) +	{ +		$expected = ($expected) ?: $email; +		$this->assertSame($expected, make_clickable($email)); +	} +} diff --git a/tests/functions/make_clickable_test.php b/tests/functions/make_clickable_test.php new file mode 100644 index 0000000000..63beeb06b2 --- /dev/null +++ b/tests/functions/make_clickable_test.php @@ -0,0 +1,180 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; + +class phpbb_functions_make_clickable_test extends phpbb_test_case +{ +	/** +	* Tags: +	* 'm' - full URL like xxxx://aaaaa.bbb.cccc. +	* 'l' - local relative board URL like http://domain.tld/path/to/board/index.php +	* 'w' - URL without http/https protocol like www.xxxx.yyyy[/zzzz] aka 'lazy' URLs +	* 'e' - email@domain type address +	* +	* Classes: +	* "postlink-local" for 'l' URLs +	* "postlink" for the rest of URLs +	* empty for email addresses +	**/ +	public function data_test_make_clickable_url_positive() +	{ +		return array( +			array( +				'http://www.phpbb.com/community/', +				'<!-- m --><a class="postlink" href="http://www.phpbb.com/community/">http://www.phpbb.com/community/</a><!-- m -->' +			), +			array( +				'http://www.phpbb.com/path/file.ext#section', +				'<!-- m --><a class="postlink" href="http://www.phpbb.com/path/file.ext#section">http://www.phpbb.com/path/file.ext#section</a><!-- m -->' +			), +			array( +				'ftp://ftp.phpbb.com/', +				'<!-- m --><a class="postlink" href="ftp://ftp.phpbb.com/">ftp://ftp.phpbb.com/</a><!-- m -->' +			), +			array( +				'sip://bantu@phpbb.com', +				'<!-- m --><a class="postlink" href="sip://bantu@phpbb.com">sip://bantu@phpbb.com</a><!-- m -->' +			), +			array( +				'www.phpbb.com/community/', +				'<!-- w --><a class="postlink" href="http://www.phpbb.com/community/">www.phpbb.com/community/</a><!-- w -->' +			), +			array( +				'http://testhost/viewtopic.php?t=1', +				'<!-- l --><a class="postlink-local" href="http://testhost/viewtopic.php?t=1">viewtopic.php?t=1</a><!-- l -->' +			), +			array( +				'email@domain.com', +				'<!-- e --><a href="mailto:email@domain.com">email@domain.com</a><!-- e -->' +			), +			// Test appending punctuation mark to the URL +			array( +				'http://testhost/viewtopic.php?t=1!', +				'<!-- l --><a class="postlink-local" href="http://testhost/viewtopic.php?t=1">viewtopic.php?t=1</a><!-- l -->!' +			), +			array( +				'www.phpbb.com/community/?', +				'<!-- w --><a class="postlink" href="http://www.phpbb.com/community/">www.phpbb.com/community/</a><!-- w -->?' +			), +			// Test shortened text for URL > 55 characters long +			// URL text should be turned into: first 39 chars + ' ... ' + last 10 chars +			array( +				'http://www.phpbb.com/community/path/to/long/url/file.ext#section', +				'<!-- m --><a class="postlink" href="http://www.phpbb.com/community/path/to/long/url/file.ext#section">http://www.phpbb.com/community/path/to/ ... xt#section</a><!-- m -->' +			), +		); +	} + +	public function data_test_make_clickable_url_idn() +	{ +		return array( +			array( +				'http://www.täst.de/community/', +				'<!-- m --><a class="postlink" href="http://www.täst.de/community/">http://www.täst.de/community/</a><!-- m -->' +			), +			array( +				'http://www.täst.de/path/file.ext#section', +				'<!-- m --><a class="postlink" href="http://www.täst.de/path/file.ext#section">http://www.täst.de/path/file.ext#section</a><!-- m -->' +			), +			array( +				'ftp://ftp.täst.de/', +				'<!-- m --><a class="postlink" href="ftp://ftp.täst.de/">ftp://ftp.täst.de/</a><!-- m -->' +			), +			array( +				'sip://bantu@täst.de', +				'<!-- m --><a class="postlink" href="sip://bantu@täst.de">sip://bantu@täst.de</a><!-- m -->' +			), +			array( +				'www.täst.de/community/', +				'<!-- w --><a class="postlink" href="http://www.täst.de/community/">www.täst.de/community/</a><!-- w -->' +			), +			// Test appending punctuation mark to the URL +			array( +				'http://домен.рф/viewtopic.php?t=1!', +				'<!-- m --><a class="postlink" href="http://домен.рф/viewtopic.php?t=1">http://домен.рф/viewtopic.php?t=1</a><!-- m -->!' +			), +			array( +				'www.домен.рф/сообщество/?', +				'<!-- w --><a class="postlink" href="http://www.домен.рф/сообщество/">www.домен.рф/сообщество/</a><!-- w -->?' +			), +			// Test shortened text for URL > 55 characters long +			// URL text should be turned into: first 39 chars + ' ... ' + last 10 chars +			array( +				'http://www.домен.рф/сообщество/путь/по/длинной/ссылке/file.ext#section', +				'<!-- m --><a class="postlink" href="http://www.домен.рф/сообщество/путь/по/длинной/ссылке/file.ext#section">http://www.домен.рф/сообщество/путь/по/ ... xt#section</a><!-- m -->' +			), + +			// IDN with invalid characters shouldn't be parsed correctly (only 'valid' part) +			array( +				'http://www.täst╫.de', +				'<!-- m --><a class="postlink" href="http://www.täst">http://www.täst</a><!-- m -->╫.de' +			), +			// IDN in emails is unsupported yet +			array('почта@домен.рф', 'почта@домен.рф'), +		); +	} + +	public function data_test_make_clickable_local_url_idn() +	{ +		return array( +			array( +				'http://www.домен.рф/viewtopic.php?t=1', +				'<!-- l --><a class="postlink-local" href="http://www.домен.рф/viewtopic.php?t=1">viewtopic.php?t=1</a><!-- l -->' +			), +			// Test appending punctuation mark to the URL +			array( +				'http://www.домен.рф/viewtopic.php?t=1!', +				'<!-- l --><a class="postlink-local" href="http://www.домен.рф/viewtopic.php?t=1">viewtopic.php?t=1</a><!-- l -->!' +			), +			array( +				'http://www.домен.рф/сообщество/?', +				'<!-- l --><a class="postlink-local" href="http://www.домен.рф/сообщество/">сообщество/</a><!-- l -->?' +			), +		); +	} + +	protected function setUp() +	{ +		parent::setUp(); + +		global $config, $user, $request; +		$user = new phpbb_mock_user(); +		$request = new phpbb_mock_request(); +	} + +	/** +	 * @dataProvider data_test_make_clickable_url_positive +	 */ +	public function test_urls_matching_positive($url, $expected) +	{ +		$this->assertSame($expected, make_clickable($url)); +	} + +	/** +	 * @dataProvider data_test_make_clickable_url_idn +	 */ +	public function test_urls_matching_idn($url, $expected) +	{ +		$this->assertSame($expected, make_clickable($url)); +	} + +	/** +	 * @dataProvider data_test_make_clickable_local_url_idn +	 */ +	public function test_local_urls_matching_idn($url, $expected) +	{ +		$this->assertSame($expected, make_clickable($url, "http://www.домен.рф")); +	} +} diff --git a/tests/functions/obtain_online_test.php b/tests/functions/obtain_online_test.php index de6451a0db..e793a4eb82 100644 --- a/tests/functions/obtain_online_test.php +++ b/tests/functions/obtain_online_test.php @@ -1,15 +1,18 @@  <?php  /**  * -* @package testing -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */  require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';  require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/auth.php';  class phpbb_functions_obtain_online_test extends phpbb_database_test_case  { @@ -125,28 +128,28 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case  	{  		return array(  			array(0, false, array( -				'online_userlist'	=> 'REGISTERED_USERS 2, 3', -				'l_online_users'	=> 'ONLINE_USERS_TOTAL 5REG_USERS_TOTAL_AND 2HIDDEN_USERS_TOTAL 3', +				'online_userlist'	=> 'REGISTERED_USERS <span class="username">2</span>, <span class="username">3</span>', +				'l_online_users'	=> 'ONLINE_USERS_TOTAL 5 REG_USERS_TOTAL 2 HIDDEN_USERS_TOTAL 3',  			)),  			array(0, true, array( -				'online_userlist'	=> 'REGISTERED_USERS 2, 3', -				'l_online_users'	=> 'ONLINE_USERS_TOTAL 7REG_USERS_TOTAL 2HIDDEN_USERS_TOTAL_AND 3GUEST_USERS_TOTAL 2', +				'online_userlist'	=> 'REGISTERED_USERS <span class="username">2</span>, <span class="username">3</span>', +				'l_online_users'	=> 'ONLINE_USERS_TOTAL_GUESTS 7 REG_USERS_TOTAL 2 HIDDEN_USERS_TOTAL 3 GUEST_USERS_TOTAL 2',  			)),  			array(1, false, array( -				'online_userlist'	=> 'BROWSING_FORUM 3', -				'l_online_users'	=> 'ONLINE_USERS_TOTAL 2REG_USER_TOTAL_AND 1HIDDEN_USER_TOTAL 1', +				'online_userlist'	=> 'BROWSING_FORUM <span class="username">3</span>', +				'l_online_users'	=> 'ONLINE_USERS_TOTAL 2 REG_USERS_TOTAL 1 HIDDEN_USERS_TOTAL 1',  			)),  			array(1, true, array( -				'online_userlist'	=> 'BROWSING_FORUM_GUEST 3 1', -				'l_online_users'	=> 'ONLINE_USERS_TOTAL 3REG_USER_TOTAL 1HIDDEN_USER_TOTAL_AND 1GUEST_USER_TOTAL 1', +				'online_userlist'	=> 'BROWSING_FORUM_GUESTS 1 <span class="username">3</span>', +				'l_online_users'	=> 'ONLINE_USERS_TOTAL_GUESTS 3 REG_USERS_TOTAL 1 HIDDEN_USERS_TOTAL 1 GUEST_USERS_TOTAL 1',  			)),  			array(2, false, array(  				'online_userlist'	=> 'BROWSING_FORUM NO_ONLINE_USERS', -				'l_online_users'	=> 'ONLINE_USERS_ZERO_TOTAL 0REG_USERS_ZERO_TOTAL_AND 0HIDDEN_USERS_ZERO_TOTAL 0', +				'l_online_users'	=> 'ONLINE_USERS_TOTAL 0 REG_USERS_TOTAL 0 HIDDEN_USERS_TOTAL 0',  			)),  			array(2, true, array( -				'online_userlist'	=> 'BROWSING_FORUM_GUESTS NO_ONLINE_USERS 0', -				'l_online_users'	=> 'ONLINE_USERS_ZERO_TOTAL 0REG_USERS_ZERO_TOTAL 0HIDDEN_USERS_ZERO_TOTAL_AND 0GUEST_USERS_ZERO_TOTAL 0', +				'online_userlist'	=> 'BROWSING_FORUM_GUESTS 0 NO_ONLINE_USERS', +				'l_online_users'	=> 'ONLINE_USERS_TOTAL_GUESTS 0 REG_USERS_TOTAL 0 HIDDEN_USERS_TOTAL 0 GUEST_USERS_TOTAL 0',  			)),  		);  	} @@ -158,18 +161,21 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case  	{  		$this->db->sql_query('DELETE FROM phpbb_sessions'); -		global $config, $user, $auth; +		global $config, $user, $auth, $phpbb_dispatcher;  		$config['load_online_guests'] = $display_guests; +		$user = new phpbb_mock_lang();  		$user->lang = $this->load_language(); -		$auth = $this->getMock('auth'); +		$auth = $this->getMock('\phpbb\auth\auth');  		$acl_get_map = array(  			array('u_viewonline', true), +			array('u_viewprofile', true),  		);  		$auth->expects($this->any())  			->method('acl_get')  			->with($this->stringContains('_'),  				$this->anything())  			->will($this->returnValueMap($acl_get_map)); +		$phpbb_dispatcher = new phpbb_mock_event_dispatcher();  		$time = time();  		$this->create_guest_sessions($time); @@ -215,25 +221,12 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case  	protected function load_language()  	{ -		$lang = array( +		return array(  			'NO_ONLINE_USERS'	=> 'NO_ONLINE_USERS',  			'REGISTERED_USERS'	=> 'REGISTERED_USERS',  			'BROWSING_FORUM'	=> 'BROWSING_FORUM %s',  			'BROWSING_FORUM_GUEST'	=> 'BROWSING_FORUM_GUEST %s %d',  			'BROWSING_FORUM_GUESTS'	=> 'BROWSING_FORUM_GUESTS %s %d',  		); -		$vars_online = array('ONLINE', 'REG', 'HIDDEN', 'GUEST'); -		foreach ($vars_online as $online) -		{ -			$lang = array_merge($lang, array( -				$online . '_USERS_ZERO_TOTAL'	=> $online . '_USERS_ZERO_TOTAL %d', -				$online . '_USER_TOTAL'			=> $online . '_USER_TOTAL %d', -				$online . '_USERS_TOTAL'		=> $online . '_USERS_TOTAL %d', -				$online . '_USERS_ZERO_TOTAL_AND'	=> $online . '_USERS_ZERO_TOTAL_AND %d', -				$online . '_USER_TOTAL_AND'			=> $online . '_USER_TOTAL_AND %d', -				$online . '_USERS_TOTAL_AND'		=> $online . '_USERS_TOTAL_AND %d', -			)); -		} -		return $lang;  	}  } diff --git a/tests/functions/parse_cfg_file_test.php b/tests/functions/parse_cfg_file_test.php index 69000ddf72..b47e25fbc1 100644 --- a/tests/functions/parse_cfg_file_test.php +++ b/tests/functions/parse_cfg_file_test.php @@ -1,9 +1,13 @@  <?php  /**  * -* @package testing -* @copyright (c) 2014 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */ @@ -19,10 +23,13 @@ class phpbb_functions_parse_cfg_file extends phpbb_test_case  					'#',  					'# phpBB Style Configuration File',  					'#', -					'# @package phpBB3', -					'# @copyright (c) 2005 phpBB Group', -					'# @license http://opensource.org/licenses/gpl-license.php GNU Public License', +					'# This file is part of the phpBB Forum Software package.', +					'#', +					'# @copyright (c) phpBB Limited <https://www.phpbb.com>', +					'# @license GNU General Public License, version 2 (GPL-2.0)',  					'#', +					'# For full copyright and license information, please see', +					'# the docs/CREDITS.txt file.',  					'#',  					'# At the left is the name, please do not change this',  					'# At the right the value is entered', @@ -35,24 +42,24 @@ class phpbb_functions_parse_cfg_file extends phpbb_test_case  					'',  					'# General Information about this style',  					'name = prosilver', -					'copyright = © phpBB Group, 2007', +					'copyright = © phpBB Limited, 2007',  					'version = 3.0.12',  				),  				array(  					'name'		=> 'prosilver', -					'copyright'	=> '© phpBB Group, 2007', +					'copyright'	=> '© phpBB Limited, 2007',  					'version'	=> '3.0.12',  				),  			),  			array(  				array(  					'name = subsilver2', -					'copyright = © 2005 phpBB Group', +					'copyright = © 2005 phpBB Limited',  					'version = 3.0.12',  				),  				array(  					'name'		=> 'subsilver2', -					'copyright'	=> '© 2005 phpBB Group', +					'copyright'	=> '© 2005 phpBB Limited',  					'version'	=> '3.0.12',  				),  			), diff --git a/tests/functions/phpbb_get_banned_user_ids.php b/tests/functions/phpbb_get_banned_user_ids.php new file mode 100644 index 0000000000..6f7607132e --- /dev/null +++ b/tests/functions/phpbb_get_banned_user_ids.php @@ -0,0 +1,62 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php'; + +class phpbb_get_banned_user_ids_test extends phpbb_database_test_case +{ +	public function getDataSet() +	{ +		return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/banned_users.xml'); +	} + +	public function phpbb_get_banned_user_ids_data() +	{ +		return array( +			// Input to phpbb_get_banned_user_ids (user_id list, ban_end) +			// Expected output +			array( +				// True to get users currently banned +				array(array(1, 2, 4, 5, 6), true), +				array(2 => 2, 5 => 5), +			), +			array( +				// False to only get permanently banned users +				array(array(1, 2, 4, 5, 6), false), +				array(2 => 2), +			), +			array( +				// Unix timestamp to get users banned until that time +				array(array(1, 2, 4, 5, 6), 2), +				array(2 => 2, 5 => 5, 6 => 6), +			), +		); +	} + +	public function setUp() +	{ +		global $db; + +		$db = $this->new_dbal(); + +		return parent::setUp(); +	} + +	/** +	* @dataProvider phpbb_get_banned_user_ids_data +	*/ +	public function test_phpbb_get_banned_user_ids($input, $expected) +	{ +		$this->assertEquals($expected, call_user_func_array('phpbb_get_banned_user_ids', $input)); +	} +} diff --git a/tests/functions/quoteattr_test.php b/tests/functions/quoteattr_test.php new file mode 100644 index 0000000000..6e191f9610 --- /dev/null +++ b/tests/functions/quoteattr_test.php @@ -0,0 +1,48 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_quoteattr_test extends phpbb_test_case +{ +	public function quoteattr_test_data() +	{ +		return array( +			array('foo', null, '"foo"'), +			array('', null, '""'), +			array(' ', null, '" "'), +			array('<a>', null, '"<a>"'), +			array('&', null, '"&amp;"'), +			array('"hello"', null, "'\"hello\"'"), +			array("'hello'", null, "\"'hello'\""), +			array("\"'", null, "\""'\""), +			array("a\nb", null, '"a
b"'), +			array("a\r\nb", null, '"a
b"'), +			array("a\tb", null, '"a	b"'), +			array('a b', null, '"a b"'), +			array('"a<b"', null, "'\"a<b\"'"), +			array('foo', array('f' => 'z'), '"zoo"'), +			array('<a>', array('a' => '&'), '"<&>"'), +		); +	} + +	/** +	* @dataProvider quoteattr_test_data +	*/ +	public function test_quoteattr($input, $entities, $expected) +	{ +		$output = phpbb_quoteattr($input, $entities); + +		$this->assertEquals($expected, $output); +	} +} diff --git a/tests/functions/style_select_test.php b/tests/functions/style_select_test.php index 1e44f3c2cb..a918f83155 100644 --- a/tests/functions/style_select_test.php +++ b/tests/functions/style_select_test.php @@ -1,9 +1,13 @@  <?php  /**  * -* @package testing -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */ diff --git a/tests/functions/validate_data_helper.php b/tests/functions/validate_data_helper.php index b92a3aa5eb..448d029d3f 100644 --- a/tests/functions/validate_data_helper.php +++ b/tests/functions/validate_data_helper.php @@ -1,9 +1,13 @@  <?php  /**  * -* @package testing -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */ diff --git a/tests/functions/validate_date_test.php b/tests/functions/validate_date_test.php index 1dcd1361a2..9dc0db46d6 100644 --- a/tests/functions/validate_date_test.php +++ b/tests/functions/validate_date_test.php @@ -1,9 +1,13 @@  <?php  /**  * -* @package testing -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */ diff --git a/tests/functions/validate_email_test.php b/tests/functions/validate_email_test.php index 9a6ce39251..b46509fda7 100644 --- a/tests/functions/validate_email_test.php +++ b/tests/functions/validate_email_test.php @@ -2,7 +2,7 @@  /**  *  * @package testing -* @copyright (c) 2013 phpBB Group +* @copyright (c) 2014 phpBB Group  * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2  *  */ @@ -47,60 +47,54 @@ class phpbb_functions_validate_email_test extends phpbb_database_test_case  		$user->optionset('banned_users', array('banned@example.com'));  	} -	public function test_validate_email() +	public static function validate_email_data() +	{ +		return array( +			array('empty', array('EMAIL_INVALID'), ''),		// email does not allow empty +			array('allowed', array(), 'foobar@example.com'), +			array('valid_complex', array(), "'%$~test@example.com"), +			array('invalid', array('EMAIL_INVALID'), 'fööbar@example.com'), +			array('taken', array(), 'admin@example.com'),	// email does not check taken, should use user_email instead +			array('banned', array(), 'banned@example.com'),	// email does not check ban, should use user_email instead +		); +	} + +	/** +	* @dataProvider validate_email_data +	*/ +	public function test_validate_email($case, $errors, $email)  	{  		$this->set_validation_prerequisites(false);  		$this->helper->assert_valid_data(array( -			'empty' => array( -				array(), -				'', -				array('email'), -			), -			'allowed' => array( -				array(), -				'foobar@example.com', -				array('email', 'foobar@example.com'), -			), -			'invalid' => array( -				array('EMAIL_INVALID'), -				'fööbar@example.com', -				array('email'), -			), -			'valid_complex' => array( -				array(), -				"'%$~test@example.com", -				array('email'), -			), -			'taken' => array( -				array('EMAIL_TAKEN'), -				'admin@example.com', -				array('email'), -			), -			'banned' => array( -				array('EMAIL_BANNED'), -				'banned@example.com', +			$case => array( +				$errors, +				$email,  				array('email'),  			),  		));  	} +	public static function validate_email_mx_data() +	{ +		return array( +			array('valid', array(), 'foobar@phpbb.com'), +			array('no_mx', array('DOMAIN_NO_MX_RECORD'), 'test@does-not-exist.phpbb.com'), +		); +	} +  	/** +	* @dataProvider validate_email_mx_data  	* @group slow  	*/ -	public function test_validate_email_mx() +	public function test_validate_email_mx($case, $errors, $email)  	{  		$this->set_validation_prerequisites(true);  		$this->helper->assert_valid_data(array( -			'valid' => array( -				array(), -				'foobar@phpbb.com', -				array('email'), -			), -			'no_mx' => array( -				array('DOMAIN_NO_MX_RECORD'), -				'test@does-not-exist.phpbb.com', +			$case => array( +				$errors, +				$email,  				array('email'),  			),  		)); diff --git a/tests/functions/validate_hex_colour_test.php b/tests/functions/validate_hex_colour_test.php index 812ebe5eeb..b2c4862458 100644 --- a/tests/functions/validate_hex_colour_test.php +++ b/tests/functions/validate_hex_colour_test.php @@ -1,9 +1,13 @@  <?php  /**  * -* @package testing -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */ diff --git a/tests/functions/validate_jabber_test.php b/tests/functions/validate_jabber_test.php index 5a53c963bd..23811a94c0 100644 --- a/tests/functions/validate_jabber_test.php +++ b/tests/functions/validate_jabber_test.php @@ -1,9 +1,13 @@  <?php  /**  * -* @package testing -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */ diff --git a/tests/functions/validate_lang_iso_test.php b/tests/functions/validate_lang_iso_test.php index c8a5b71021..81b56055e6 100644 --- a/tests/functions/validate_lang_iso_test.php +++ b/tests/functions/validate_lang_iso_test.php @@ -1,9 +1,13 @@  <?php  /**  * -* @package testing -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */ diff --git a/tests/functions/validate_match_test.php b/tests/functions/validate_match_test.php index 73a363e003..811bed3e33 100644 --- a/tests/functions/validate_match_test.php +++ b/tests/functions/validate_match_test.php @@ -1,9 +1,13 @@  <?php  /**  * -* @package testing -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */ diff --git a/tests/functions/validate_num_test.php b/tests/functions/validate_num_test.php index 4deac02ebc..798468759c 100644 --- a/tests/functions/validate_num_test.php +++ b/tests/functions/validate_num_test.php @@ -1,9 +1,13 @@  <?php  /**  * -* @package testing -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */ diff --git a/tests/functions/validate_password_test.php b/tests/functions/validate_password_test.php index 4639f6cc89..c5942e79bf 100644 --- a/tests/functions/validate_password_test.php +++ b/tests/functions/validate_password_test.php @@ -1,12 +1,17 @@  <?php  /**  * -* @package testing -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */ +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';  require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php';  require_once dirname(__FILE__) . '/validate_data_helper.php'; diff --git a/tests/functions/validate_string_test.php b/tests/functions/validate_string_test.php index ab44c28541..24026e4c9f 100644 --- a/tests/functions/validate_string_test.php +++ b/tests/functions/validate_string_test.php @@ -1,9 +1,13 @@  <?php  /**  * -* @package testing -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */ diff --git a/tests/functions/validate_user_email_test.php b/tests/functions/validate_user_email_test.php new file mode 100644 index 0000000000..951d5794e6 --- /dev/null +++ b/tests/functions/validate_user_email_test.php @@ -0,0 +1,106 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php'; +require_once dirname(__FILE__) . '/../mock/user.php'; +require_once dirname(__FILE__) . '/validate_data_helper.php'; + +class phpbb_functions_validate_user_email_test extends phpbb_database_test_case +{ +	protected $db; +	protected $user; +	protected $helper; + +	public function getDataSet() +	{ +		return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/validate_email.xml'); +	} + +	protected function setUp() +	{ +		parent::setUp(); + +		$this->db = $this->new_dbal(); +		$this->user = new phpbb_mock_user; +		$this->helper = new phpbb_functions_validate_data_helper($this); +	} + +	/** +	* Get validation prerequesites +	* +	* @param bool $check_mx Whether mx records should be checked +	*/ +	protected function set_validation_prerequisites($check_mx) +	{ +		global $config, $db, $user; + +		$config['email_check_mx'] = $check_mx; +		$db = $this->db; +		$user = $this->user; +		$user->optionset('banned_users', array('banned@example.com')); +	} + +	public static function validate_user_email_data() +	{ +		return array( +			array('empty', array(), ''), +			array('allowed', array(), 'foobar@example.com'), +			array('valid_complex', array(), "'%$~test@example.com"), +			array('invalid', array('EMAIL_INVALID'), 'fööbar@example.com'), +			array('taken', array('EMAIL_TAKEN'), 'admin@example.com'), +			array('banned', array('EMAIL_BANNED'), 'banned@example.com'), +		); +	} + +	/** +	* @dataProvider validate_user_email_data +	*/ +	public function test_validate_user_email($case, $errors, $email) +	{ +		$this->set_validation_prerequisites(false); + +		$this->helper->assert_valid_data(array( +			$case => array( +				$errors, +				$email, +				array('user_email'), +			), +		)); +	} + +	public static function validate_user_email_mx_data() +	{ +		return array( +			array('valid', array(), 'foobar@phpbb.com'), +			array('no_mx', array('DOMAIN_NO_MX_RECORD'), 'test@does-not-exist.phpbb.com'), +		); +	} + +	/** +	* @dataProvider validate_user_email_mx_data +	* @group slow +	*/ +	public function test_validate_user_email_mx($case, $errors, $email) +	{ +		$this->set_validation_prerequisites(true); + +		$this->helper->assert_valid_data(array( +			$case => array( +				$errors, +				$email, +				array('user_email'), +			), +		)); +	} +} diff --git a/tests/functions/validate_username_test.php b/tests/functions/validate_username_test.php index 0819974e54..4fa5af7ff3 100644 --- a/tests/functions/validate_username_test.php +++ b/tests/functions/validate_username_test.php @@ -1,12 +1,17 @@  <?php  /**  * -* @package testing -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */ +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';  require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php';  require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';  require_once dirname(__FILE__) . '/../mock/cache.php'; diff --git a/tests/functions/validate_with_method_test.php b/tests/functions/validate_with_method_test.php new file mode 100644 index 0000000000..37e05d412a --- /dev/null +++ b/tests/functions/validate_with_method_test.php @@ -0,0 +1,43 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php'; +require_once dirname(__FILE__) . '/validate_data_helper.php'; + +class phpbb_functions_validate_with_method_test extends phpbb_test_case +{ +	protected $helper; + +	protected function setUp() +	{ +		parent::setUp(); + +		$this->helper = new phpbb_functions_validate_data_helper($this); +	} + +	public function test_validate_date() +	{ +		$this->helper->assert_valid_data(array( +			'method_call' => array( +				array(), +				true, +				array(array(array($this, 'with_method'), false)), +			), +		)); +	} + +	public function validate_with_method($bool, $optional = false) +	{ +		return ! $bool; +	} +} | 
