diff options
Diffstat (limited to 'tests/functions')
32 files changed, 1293 insertions, 156 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 index ef2f5744d3..14cb4b9a94 100644 --- a/tests/functions/build_hidden_fields_for_query_params_test.php +++ b/tests/functions/build_hidden_fields_for_query_params_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/build_url_test.php b/tests/functions/build_url_test.php new file mode 100644 index 0000000000..3e19b51f02 --- /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\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/convert_30_dbms_to_31_test.php b/tests/functions/convert_30_dbms_to_31_test.php index 4d210d7b29..729c0a82f0 100644 --- a/tests/functions/convert_30_dbms_to_31_test.php +++ b/tests/functions/convert_30_dbms_to_31_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. * */ @@ -14,7 +18,6 @@ class phpbb_convert_30_dbms_to_31_test extends phpbb_test_case public function convert_30_dbms_to_31_data() { return array( - array('firebird'), array('mssql'), array('mssql_odbc'), array('mssqlnative'), @@ -33,7 +36,8 @@ class phpbb_convert_30_dbms_to_31_test extends phpbb_test_case { $expected = "phpbb\\db\\driver\\$input"; - $output = phpbb_convert_30_dbms_to_31($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/user_delete.xml b/tests/functions/fixtures/user_delete.xml new file mode 100644 index 0000000000..4c4479d29b --- /dev/null +++ b/tests/functions/fixtures/user_delete.xml @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_users"> + <column>user_id</column> + <column>username_clean</column> + <column>username</column> + <column>user_permissions</column> + <column>user_sig</column> + <row> + <value>1</value> + <value>anonymous</value> + <value>anonymous</value> + <value></value> + <value></value> + </row> + <row> + <value>2</value> + <value>2</value> + <value>2</value> + <value></value> + <value></value> + </row> + </table> + <table name="phpbb_oauth_accounts"> + <column>user_id</column> + <column>provider</column> + <column>oauth_provider_id</column> + <row> + <value>2</value> + <value>google</value> + <value>1234567890123456789</value> + </row> + </table> + <table name="phpbb_oauth_tokens"> + <column>user_id</column> + <column>session_id</column> + <column>provider</column> + <column>oauth_token</column> + <row> + <value>2</value> + <value>897a897b797c8789997d7979879</value> + <value>auth.provider.oauth.service.google</value> + <value>{"accessToken":"ya29.YPHwCWVkrvwu1kgbYKiDNYaQ451ZuHy9OEQAGVME8if-WBzR-v7a9ftxbx41kaL)5VLEXB-6qJEvri","endOfLife":1429959670,"extraParams":{"token_type":"Bearer","id_token":"eyJhbGciOiJSUzI1NiIsImupZCI6IjE0YuRjNzc2MDQwYjUyNDZmNTI5OWFkZDVlMmQ1NWNOPTdjMDdlZTAifQ.eyJpc3MiOiJhY2NvdW90cy5nb78nbGUuY29tIiwic3ViIjoiMTExMDMwNwerNjM4MTM5NTQwMTM1IiwiYXpwIjoiOTk3MzUwMTY0NzE0LWhwOXJrYjZpcjM4MW80YjV1NjRpaGtmM29zMnRvbWxhLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwiZW1haWwiOiJtYXJjLmFsZXhhbmRlci4zN0BnbWFpbC5jb20iLCJhdF9oYXNoIjoiWHk2b1JabnVZUWRfRTZDeDV0RkItdyIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJhdWQiOiI5OTczNTAxNjQ3MTQtaHA5cmtiNmlyMzgxbzRiNXU2NGloa2Yzb3MydG9tbGEuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJpYXQiOjE0Mjk5NTYwNzEsImV4cCI6MTQyOTk1OTY3MX0.C5gfSzjqwlRRvVMuTP6jfWIuEHMXn55oYHsSA3eh97n2BZL0TZHhUm4K206Fgucd6ufAphan4l0J7y6tMAHLZPr-kk6KDINxWnPG-up99reblGutay0lRYjMCcrhJAOql8EI1bi84GyliZFYHL67pE0ZtSf-CMb1CeH18TFe-Fk"},"refreshToken":null,"token_class":"OAuth\\\\OAuth2\\\\Token\\\\StdOAuth2Token"}</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..bcf0c09fe4 --- /dev/null +++ b/tests/functions/generate_string_list.php @@ -0,0 +1,69 @@ +<?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(); + + global $phpbb_root_path, $phpEx; + + $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); + $lang = new \phpbb\language\language($lang_loader); + $user = new \phpbb\user($lang, '\phpbb\datetime'); + $this->user = $user; + $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..781a73a462 100644 --- a/tests/functions/get_remote_file_test.php +++ b/tests/functions/get_remote_file_test.php @@ -1,14 +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_admin.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_compatibility.php'; /** * @group slow @@ -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 deleted file mode 100644 index 6d26793d82..0000000000 --- a/tests/functions/is_absolute_test.php +++ /dev/null @@ -1,56 +0,0 @@ -<?php -/** -* -* @package testing -* @copyright (c) 2013 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_functions_is_absolute_test extends phpbb_test_case -{ - static public function is_absolute_data() - { - return array( - // Empty - array('', false), - - // Absolute unix style - array('/etc/phpbb', true), - // Unix does not support \ so that is not an absolute path - array('\etc\phpbb', false), - - // Absolute windows style - array('c:\windows', true), - array('C:\Windows', true), - array('c:/windows', true), - array('C:/Windows', true), - - // Executable - array('etc/phpbb', false), - array('explorer.exe', false), - - // Relative subdir - array('Windows\System32', false), - array('Windows\System32\explorer.exe', false), - array('Windows/System32', false), - array('Windows/System32/explorer.exe', false), - - // Relative updir - array('..\Windows\System32', false), - array('..\Windows\System32\explorer.exe', false), - array('../Windows/System32', false), - array('../Windows/System32/explorer.exe', false), - ); - } - - /** - * @dataProvider is_absolute_data - */ - public function test_is_absolute($path, $expected) - { - $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 cf42fd5b58..e793a4eb82 100644 --- a/tests/functions/obtain_online_test.php +++ b/tests/functions/obtain_online_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. * */ @@ -124,19 +128,19 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case { return array( array(0, false, array( - 'online_userlist' => 'REGISTERED_USERS 2, 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', + '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', + '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_GUESTS 1 3', + '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( diff --git a/tests/functions/parse_cfg_file_test.php b/tests/functions/parse_cfg_file_test.php new file mode 100644 index 0000000000..b47e25fbc1 --- /dev/null +++ b/tests/functions/parse_cfg_file_test.php @@ -0,0 +1,110 @@ +<?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_parse_cfg_file extends phpbb_test_case +{ + public function parse_cfg_file_data() + { + return array( + array( + array( + '#', + '# phpBB Style Configuration File', + '#', + '# 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', + '# For on/off options the valid values are on, off, 1, 0, true and false', + '#', + '# Values get trimmed, if you want to add a space in front or at the end of', + '# the value, then enclose the value with single or double quotes.', + '# Single and double quotes do not need to be escaped.', + '#', + '', + '# General Information about this style', + 'name = prosilver', + 'copyright = © phpBB Limited, 2007', + 'version = 3.0.12', + ), + array( + 'name' => 'prosilver', + 'copyright' => '© phpBB Limited, 2007', + 'version' => '3.0.12', + ), + ), + array( + array( + 'name = subsilver2', + 'copyright = © 2005 phpBB Limited', + 'version = 3.0.12', + ), + array( + 'name' => 'subsilver2', + 'copyright' => '© 2005 phpBB Limited', + 'version' => '3.0.12', + ), + ), + array( + array( + 'foo = on', + 'foo1 = true', + 'foo2 = 1', + 'bar = off', + 'bar1 = false', + 'bar2 = 0', + 'foobar =', + 'foobar1 = "asdf"', + 'foobar2 = \'qwer\'', + ), + array( + 'foo' => true, + 'foo1' => true, + 'foo2' => true, + 'bar' => false, + 'bar1' => false, + 'bar2' => false, + 'foobar' => '', + 'foobar1' => 'asdf', + 'foobar2' => 'qwer', + ), + ), + array( + array( + 'foo = & bar', + 'bar = <a href="test">Test</a>', + ), + array( + 'foo' => '&amp; bar', + 'bar' => '<a href="test">Test</a>', + ), + ), + ); + } + + /** + * @dataProvider parse_cfg_file_data + */ + public function test_parse_cfg_file($file_contents, $expected) + { + $this->assertEquals($expected, parse_cfg_file(false, $file_contents)); + } +} 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 index 9d2a7d470e..6e191f9610 100644 --- a/tests/functions/quoteattr_test.php +++ b/tests/functions/quoteattr_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/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/user_delete_test.php b/tests/functions/user_delete_test.php new file mode 100644 index 0000000000..bd6b53c59f --- /dev/null +++ b/tests/functions/user_delete_test.php @@ -0,0 +1,114 @@ +<?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'; + +class phpbb_functions_user_delete_test extends phpbb_database_test_case +{ + /** @var \phpbb\db\driver\driver_interface */ + protected $db; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/user_delete.xml'); + } + + protected function setUp() + { + parent::setUp(); + + global $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user, $phpbb_root_path, $phpEx; + + $this->db = $db = $this->new_dbal(); + $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); + $lang = new \phpbb\language\language($lang_loader); + $user = new \phpbb\user($lang, '\phpbb\datetime'); + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $phpbb_container = new phpbb_mock_container_builder(); + $config = new \phpbb\config\config(array( + 'auth_method' => 'oauth', + 'auth_oauth_google_key' => 'foo', + 'auth_oauth_google_secret' => 'bar', + )); + $cache = new \phpbb\cache\driver\dummy(); + $request = new phpbb_mock_request(); + $notification_manager = new phpbb_mock_notification_manager(); + $provider_collection = new \phpbb\auth\provider_collection($phpbb_container, $config); + $oauth_provider_google = new \phpbb\auth\provider\oauth\service\google($config, $request); + $oauth_provider_collection = new \phpbb\di\service_collection($phpbb_container); + $oauth_provider_collection->offsetSet('auth.provider.oauth.service.google', $oauth_provider_google); + + $driver_helper = new \phpbb\passwords\driver\helper($config); + $passwords_drivers = array( + 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper), + 'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $driver_helper), + 'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $driver_helper), + 'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $driver_helper), + ); + + $passwords_helper = new \phpbb\passwords\helper; + // Set up passwords manager + $passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers)); + + $oauth_provider = new \phpbb\auth\provider\oauth\oauth( + $db, + $config, + $passwords_manager, + $request, + $user, + 'phpbb_oauth_tokens', + 'phpbb_oauth_states', + 'phpbb_oauth_accounts', + $oauth_provider_collection, + 'phpbb_users', + $phpbb_container, + $this->phpbb_root_path, + $this->php_ext + ); + $provider_collection->offsetSet('auth.provider.oauth', $oauth_provider); + + $phpbb_container->set('auth.provider.oauth', $oauth_provider); + $phpbb_container->set('auth.provider.oauth.service.google', $oauth_provider_google); + $phpbb_container->set('auth.provider_collection', $provider_collection); + $phpbb_container->set('notification_manager', $notification_manager); + } + + public function test_user_delete() + { + // Check that user is linked + $sql = 'SELECT ot.user_id AS user_id + FROM phpbb_oauth_accounts oa, phpbb_oauth_tokens ot + WHERE oa.user_id = 2 + AND ot.user_id = oa.user_id'; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $this->assertEquals(array('user_id' => '2'), $row); + + // user_delete() should return false + $this->assertFalse(user_delete('remove', array(2))); + + // Make sure user link was removed + $sql = 'SELECT ot.user_id AS user_id + FROM phpbb_oauth_accounts oa, phpbb_oauth_tokens ot + WHERE oa.user_id = 2 + AND ot.user_id = oa.user_id'; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $this->assertEmpty($row); + } +} 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 82c5fa03c1..c5942e79bf 100644 --- a/tests/functions/validate_password_test.php +++ b/tests/functions/validate_password_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_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; + } +} |