forked from phpbb/phpbb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ticket/13433] Add make_clickable() test for emails
PHPBB3-13433
- Loading branch information
Showing
1 changed file
with
222 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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( | ||
'[email protected]', | ||
'<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'[email protected]', | ||
'<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'[email protected]', | ||
'<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'[email protected]', | ||
'<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'[email protected]', | ||
'<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'[email protected]', | ||
'<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'alice&[email protected]', | ||
'<!-- e --><a href="mailto:alice&[email protected]">alice&[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'[email protected]', | ||
'<!-- e --><a href="mailto:[email protected]">[email protected]</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">[email protected] ... ctersZlong</a><!-- e -->' | ||
), | ||
array( | ||
'[email protected]', | ||
'<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'[email protected]', | ||
'<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'hasApostrophe.o\'[email protected]', | ||
'<!-- e --><a href="mailto:hasApostrophe.o\'[email protected]">hasApostrophe.o\'[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'[email protected]', | ||
'<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'[email protected]', | ||
'<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'[email protected]', | ||
'<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'[email protected]', | ||
'<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'[email protected]', | ||
'<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'[email protected]', | ||
'<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'[email protected]', | ||
'<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'[email protected]', | ||
'<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'[email protected]:25', | ||
'<!-- e --><a href="mailto:[email protected]:25">[email protected]:25</a><!-- e -->' | ||
), | ||
array( | ||
'[email protected]', | ||
'<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'[email protected]', | ||
'<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'[email protected]', | ||
'<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'[email protected]', | ||
'<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'[email protected]', | ||
'<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'&*=?^+{}\'[email protected]', | ||
'<!-- e --><a href="mailto:&*=?^+{}\'[email protected]">&*=?^+{}\'[email protected]</a><!-- e -->' | ||
), | ||
array( | ||
'[email protected]', | ||
'<!-- e --><a href="mailto:[email protected]">[email protected]</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('[email protected]'), // . is last in local part | ||
array('[email protected]'), // . doubled | ||
array('a@b@[email protected]'), // @ 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([email protected]', 'abc(<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->'), // invalid character ( | ||
array('abc)[email protected]'), // invalid character ) | ||
array('abc[[email protected]'), // invalid character [ | ||
array('abc][email protected]'), // invalid character ] | ||
array('abc\[email protected]'), // invalid character \ | ||
array('abc;[email protected]'), // invalid character ; | ||
array('abc:[email protected]'), // invalid character : | ||
array('abc,[email protected]'), // invalid character , | ||
array('abc<[email protected]'), // invalid character < | ||
array('abc>[email protected]', 'abc><!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->'), // invalid character > | ||
|
||
// http://fightingforalostcause.net/misc/2006/compare-email-regex.php | ||
array('[email protected]'), | ||
array('@missingLocal.org'), | ||
array('missingatSign.net'), | ||
array('missingDot@com'), | ||
array('two@@signs.com'), | ||
// Trailing colon is ignored | ||
array('[email protected]:', '<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->:'), | ||
|
||
array(''), | ||
// Trailing part after the 3rd dot is ignored | ||
array('[email protected]', '<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->.26'), | ||
|
||
array('[email protected]'), | ||
array('[email protected]'), | ||
array('[email protected]'), | ||
array('[email protected]'), | ||
array('[email protected]'), | ||
array('[email protected]'), | ||
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">[email protected] ... 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)); | ||
} | ||
} |