diff options
author | rxu <rxu@mail.ru> | 2014-11-25 22:16:30 +0700 |
---|---|---|
committer | rxu <rxu@mail.ru> | 2014-11-27 01:18:49 +0700 |
commit | a8c62e707af0971a62b7601f4ac6ea46f57b16c2 (patch) | |
tree | 48ccc14a1f33f722b2f3524ca3a4187e964de09c /tests | |
parent | ee90d227c2b041df85fbbdc9cd1f99b23a858687 (diff) | |
download | forums-a8c62e707af0971a62b7601f4ac6ea46f57b16c2.tar forums-a8c62e707af0971a62b7601f4ac6ea46f57b16c2.tar.gz forums-a8c62e707af0971a62b7601f4ac6ea46f57b16c2.tar.bz2 forums-a8c62e707af0971a62b7601f4ac6ea46f57b16c2.tar.xz forums-a8c62e707af0971a62b7601f4ac6ea46f57b16c2.zip |
[ticket/12926] Support for IDN (IRI)
Add international domain name support for URLs.
PHPBB3-12926
Diffstat (limited to 'tests')
-rw-r--r-- | tests/functions/make_clickable_test.php | 84 | ||||
-rw-r--r-- | tests/profilefields/type_url_test.php | 40 | ||||
-rw-r--r-- | tests/regex/url_test.php | 2 |
3 files changed, 123 insertions, 3 deletions
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', '<!-- 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 -->' ), + ); + } - // 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/', + '<!-- 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(); @@ -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.домен.рф")); + } } diff --git a/tests/profilefields/type_url_test.php b/tests/profilefields/type_url_test.php index 372c07418f..cc37f04f30 100644 --- a/tests/profilefields/type_url_test.php +++ b/tests/profilefields/type_url_test.php @@ -89,6 +89,32 @@ class phpbb_profilefield_type_url_test extends phpbb_test_case 'FIELD_INVALID_URL-field', 'Field should reject invalid URL having multi value parameters', ), + + // IDN url type profilefields + array( + 'http://www.täst.de', + array(), + false, + 'Field should accept valid IDN', + ), + array( + 'http://täst.de/index.html?param1=test¶m2=awesome', + array(), + false, + 'Field should accept valid IDN URL with params', + ), + array( + 'http://домен.рф/index.html/тест/path?document=get', + array(), + false, + 'Field should accept valid IDN URL', + ), + array( + 'http://домен.рф/index.html/тест/path?document[]=DocType%20test&document[]=AnotherDoc', + array(), + 'FIELD_INVALID_URL-field', + 'Field should reject invalid IDN URL having multi value parameters', + ), ); } @@ -119,6 +145,20 @@ class phpbb_profilefield_type_url_test extends phpbb_test_case 'http://example.com', 'Field should return correct raw value', ), + + // IDN tests + array( + 'http://täst.de', + array('field_show_novalue' => true), + 'http://täst.de', + 'Field should return the correct raw value', + ), + array( + 'http://домен.рф', + array('field_show_novalue' => false), + 'http://домен.рф', + 'Field should return correct raw value', + ), ); } diff --git a/tests/regex/url_test.php b/tests/regex/url_test.php index d3487a9c16..e5d7c3256a 100644 --- a/tests/regex/url_test.php +++ b/tests/regex/url_test.php @@ -32,6 +32,6 @@ class phpbb_regex_url_test extends phpbb_test_case */ public function test_url($url, $expected) { - $this->assertEquals($expected, preg_match('#^' . get_preg_expression('url') . '$#i', $url)); + $this->assertEquals($expected, preg_match('#^' . get_preg_expression('url') . '$#iu', $url)); } } |