From 483af1d036aadf8bd7d3b4c76a1fe97409238547 Mon Sep 17 00:00:00 2001 From: rxu Date: Thu, 6 Nov 2014 12:25:36 +0700 Subject: [ticket/13297] Add unicode modifier to url/email regular expression patterns. PHPBB3-13297 --- tests/functions/make_clickable_test.php | 100 ++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 tests/functions/make_clickable_test.php (limited to 'tests/functions/make_clickable_test.php') diff --git a/tests/functions/make_clickable_test.php b/tests/functions/make_clickable_test.php new file mode 100644 index 0000000000..e61cb2c30e --- /dev/null +++ b/tests/functions/make_clickable_test.php @@ -0,0 +1,100 @@ + +* @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/', + 'http://www.phpbb.com/community/' + ), + array( + 'http://www.phpbb.com/path/file.ext#section', + 'http://www.phpbb.com/path/file.ext#section' + ), + array( + 'ftp://ftp.phpbb.com/', + 'ftp://ftp.phpbb.com/' + ), + array( + 'sip://bantu@phpbb.com', + 'sip://bantu@phpbb.com' + ), + array( + 'www.phpbb.com/community/', + 'www.phpbb.com/community/' + ), + array( + 'http://testhost/viewtopic.php?t=1', + 'viewtopic.php?t=1' + ), + array( + 'email@domain.com', + 'email@domain.com' + ), + // Test appending punctuation mark to the URL + array( + 'http://testhost/viewtopic.php?t=1!', + 'viewtopic.php?t=1!' + ), + array( + 'www.phpbb.com/community/?', + 'www.phpbb.com/community/?' + ), + // 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', + 'http://www.phpbb.com/community/path/to/ ... xt#section' + ), + + // IDN is not parsed and returned as is + array('http://домен.рф', 'http://домен.рф'), + array('почта@домен.рф', 'почта@домен.рф'), + ); + } + + 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)); + } +} -- cgit v1.2.1 From a8c62e707af0971a62b7601f4ac6ea46f57b16c2 Mon Sep 17 00:00:00 2001 From: rxu Date: Tue, 25 Nov 2014 22:16:30 +0700 Subject: [ticket/12926] Support for IDN (IRI) Add international domain name support for URLs. PHPBB3-12926 --- tests/functions/make_clickable_test.php | 84 ++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 2 deletions(-) (limited to 'tests/functions/make_clickable_test.php') diff --git a/tests/functions/make_clickable_test.php b/tests/functions/make_clickable_test.php index e61cb2c30e..63beeb06b2 100644 --- a/tests/functions/make_clickable_test.php +++ b/tests/functions/make_clickable_test.php @@ -74,13 +74,77 @@ class phpbb_functions_make_clickable_test extends phpbb_test_case 'http://www.phpbb.com/community/path/to/long/url/file.ext#section', 'http://www.phpbb.com/community/path/to/ ... xt#section' ), + ); + } - // IDN is not parsed and returned as is - array('http://домен.рф', 'http://домен.рф'), + public function data_test_make_clickable_url_idn() + { + return array( + array( + 'http://www.täst.de/community/', + 'http://www.täst.de/community/' + ), + array( + 'http://www.täst.de/path/file.ext#section', + 'http://www.täst.de/path/file.ext#section' + ), + array( + 'ftp://ftp.täst.de/', + 'ftp://ftp.täst.de/' + ), + array( + 'sip://bantu@täst.de', + 'sip://bantu@täst.de' + ), + array( + 'www.täst.de/community/', + 'www.täst.de/community/' + ), + // Test appending punctuation mark to the URL + array( + 'http://домен.рф/viewtopic.php?t=1!', + 'http://домен.рф/viewtopic.php?t=1!' + ), + array( + 'www.домен.рф/сообщество/?', + 'www.домен.рф/сообщество/?' + ), + // 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', + 'http://www.домен.рф/сообщество/путь/по/ ... xt#section' + ), + + // IDN with invalid characters shouldn't be parsed correctly (only 'valid' part) + array( + 'http://www.täst╫.de', + 'http://www.täst╫.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', + 'viewtopic.php?t=1' + ), + // Test appending punctuation mark to the URL + array( + 'http://www.домен.рф/viewtopic.php?t=1!', + 'viewtopic.php?t=1!' + ), + array( + 'http://www.домен.рф/сообщество/?', + 'сообщество/?' + ), + ); + } + protected function setUp() { parent::setUp(); @@ -97,4 +161,20 @@ class phpbb_functions_make_clickable_test extends phpbb_test_case { $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.домен.рф")); + } } -- cgit v1.2.1