Skip to content

Commit

Permalink
[ticket/13433] Add make_clickable() test for emails
Browse files Browse the repository at this point in the history
PHPBB3-13433
  • Loading branch information
rxu committed Feb 17, 2015
1 parent fa1c61f commit 950c72a
Showing 1 changed file with 222 additions and 0 deletions.
222 changes: 222 additions & 0 deletions tests/functions/make_clickable_email_test.php
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&amp;[email protected]',
'<!-- e --><a href="mailto:alice&amp;[email protected]">alice&amp;[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(
'&amp;*=?^+{}\'[email protected]',
'<!-- e --><a href="mailto:&amp;*=?^+{}\'[email protected]">&amp;*=?^+{}\'[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));
}
}

0 comments on commit 950c72a

Please sign in to comment.