diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/functional/common_avatar_test_case.php | 2 | ||||
-rw-r--r-- | tests/functional/download_test.php | 15 | ||||
-rw-r--r-- | tests/functions/make_clickable_email_test.php | 222 | ||||
-rw-r--r-- | tests/test_framework/phpbb_functional_test_case.php | 12 | ||||
-rw-r--r-- | tests/upload/filespec_test.php | 5 |
5 files changed, 255 insertions, 1 deletions
diff --git a/tests/functional/common_avatar_test_case.php b/tests/functional/common_avatar_test_case.php index 7278f23bcc..924eb1273c 100644 --- a/tests/functional/common_avatar_test_case.php +++ b/tests/functional/common_avatar_test_case.php @@ -62,7 +62,7 @@ abstract class phpbb_functional_common_avatar_test_case extends phpbb_functional { if (is_array($value)) { - $form[$key]->$value[0]($value[1]); + $form[$key]->{$value[0]}($value[1]); } else { diff --git a/tests/functional/download_test.php b/tests/functional/download_test.php index 4e4995c21e..1e863210e6 100644 --- a/tests/functional/download_test.php +++ b/tests/functional/download_test.php @@ -66,6 +66,11 @@ class phpbb_functional_download_test extends phpbb_functional_test_case public function test_download_accessible() { + if (!class_exists('finfo')) + { + $this->markTestSkipped('Unable to run test with fileinfo disabled'); + } + $this->load_ids(array( 'forums' => array( 'Download #1', @@ -118,6 +123,11 @@ class phpbb_functional_download_test extends phpbb_functional_test_case public function test_download_softdeleted_post() { + if (!class_exists('finfo')) + { + $this->markTestSkipped('Unable to run test with fileinfo disabled'); + } + $this->load_ids(array( 'forums' => array( 'Download #1', @@ -180,6 +190,11 @@ class phpbb_functional_download_test extends phpbb_functional_test_case public function test_download_softdeleted_topic() { + if (!class_exists('finfo')) + { + $this->markTestSkipped('Unable to run test with fileinfo disabled'); + } + $this->load_ids(array( 'forums' => array( 'Download #1', 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/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index b6769f08d0..844caa8f54 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -410,6 +410,18 @@ class phpbb_functional_test_case extends phpbb_test_case $form = $crawler->selectButton('Enable')->form(); $crawler = self::submit($form); $this->add_lang('acp/extensions'); + + $meta_refresh = $crawler->filter('meta[http-equiv="refresh"]'); + + // Wait for extension to be fully enabled + while (sizeof($meta_refresh)) + { + preg_match('#url=.+/(adm+.+)#', $meta_refresh->attr('content'), $match); + $url = $match[1]; + $crawler = self::request('POST', $url); + $meta_refresh = $crawler->filter('meta[http-equiv="refresh"]'); + } + $this->assertContainsLang('EXTENSION_ENABLE_SUCCESS', $crawler->filter('div.successbox')->text()); $this->logout(); diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index d8fa82e2b5..05547dcd00 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -266,6 +266,11 @@ class phpbb_filespec_test extends phpbb_test_case */ public function test_is_image_get_mimetype($filename, $mimetype, $expected) { + if (!class_exists('finfo') && strtolower(substr(PHP_OS, 0, 3)) === 'win') + { + $this->markTestSkipped('Unable to test mimetype guessing without fileinfo support on Windows'); + } + $filespec = $this->get_filespec(array('tmp_name' => $this->path . $filename, 'type' => $mimetype)); $filespec->get_mimetype($this->path . $filename); $this->assertEquals($expected, $filespec->is_image()); |