2009-08-24 20:46:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
|
|
|
|
print "This script must be run from the command line\n";
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
|
|
|
|
define('LACONICA', true);
|
|
|
|
|
|
|
|
require_once INSTALLDIR . '/lib/common.php';
|
|
|
|
|
|
|
|
class URLDetectionTest extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider provider
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function testProduction($content, $expected)
|
|
|
|
{
|
|
|
|
$rendered = common_render_text($content);
|
|
|
|
$this->assertEquals($expected, $rendered);
|
|
|
|
}
|
|
|
|
|
|
|
|
static public function provider()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('example',
|
|
|
|
'example'),
|
|
|
|
array('http://example',
|
|
|
|
'http://example'),
|
|
|
|
array('http://example/',
|
|
|
|
'http://example/'),
|
|
|
|
array('http://example/path',
|
|
|
|
'http://example/path'),
|
|
|
|
array('http://example.com',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com" rel="external">http://example.com</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('https://example.com',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="https://example.com" rel="external">https://example.com</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('ftp://example.com',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="ftp://example.com" rel="external">ftp://example.com</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('ftps://example.com',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="ftps://example.com" rel="external">ftps://example.com</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://user@example.com',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://user@example.com" rel="external">http://user@example.com</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://user:pass@example.com',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://user:pass@example.com" rel="external">http://user:pass@example.com</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://example.com:8080',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com:8080" rel="external">http://example.com:8080</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://www.example.com',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://www.example.com" rel="external">http://www.example.com</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://example.com/',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com/" rel="external">http://example.com/</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://example.com/path',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com/path" rel="external">http://example.com/path</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://example.com/path.html',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com/path.html" rel="external">http://example.com/path.html</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://example.com/path.html#fragment',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com/path.html#fragment" rel="external">http://example.com/path.html#fragment</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://example.com/path.php?foo=bar&bar=foo',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com/path.php?foo=bar&bar=foo" rel="external">http://example.com/path.php?foo=bar&bar=foo</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://müllärör.de',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://müllärör.de" rel="external">http://müllärör.de</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://ﺱﺲﺷ.com',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://ﺱﺲﺷ.com" rel="external">http://ﺱﺲﺷ.com</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://сделаткартинки.com',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://сделаткартинки.com" rel="external">http://сделаткартинки.com</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://tūdaliņ.lv',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://tūdaliņ.lv" rel="external">http://tūdaliņ.lv</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://brændendekærlighed.com',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://brændendekærlighed.com" rel="external">http://brændendekærlighed.com</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://あーるいん.com',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://あーるいん.com" rel="external">http://あーるいん.com</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://예비교사.com',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://예비교사.com" rel="external">http://예비교사.com</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://example.com.',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com" rel="external">http://example.com</a>.'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://example.com?',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com" rel="external">http://example.com</a>?'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://example.com!',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com" rel="external">http://example.com</a>!'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://example.com,',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com" rel="external">http://example.com</a>,'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://example.com;',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com" rel="external">http://example.com</a>;'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://example.com:',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com" rel="external">http://example.com</a>:'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('\'http://example.com\'',
|
2009-08-24 22:48:24 +01:00
|
|
|
'\'<a href="http://example.com" rel="external">http://example.com</a>\''),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('"http://example.com"',
|
2009-08-24 22:48:24 +01:00
|
|
|
'"<a href="http://example.com" rel="external">http://example.com</a>"'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://example.com
',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com" rel="external">http://example.com</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('(http://example.com)',
|
2009-08-24 22:48:24 +01:00
|
|
|
'(<a href="http://example.com" rel="external">http://example.com</a>)'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('[http://example.com]',
|
2009-08-24 22:48:24 +01:00
|
|
|
'[<a href="http://example.com" rel="external">http://example.com</a>]'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('<http://example.com>',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<<a href="http://example.com" rel="external">http://example.com</a>>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://example.com/path/(foo)/bar',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com/path/(foo)/bar" rel="external">http://example.com/path/(foo)/bar</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://example.com/path/[foo]/bar',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com/path/[foo]/bar" rel="external">http://example.com/path/[foo]/bar</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://example.com/path/foo/(bar)',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com/path/foo/(bar)" rel="external">http://example.com/path/foo/(bar)</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('http://example.com/path/foo/[bar]',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com/path/foo/[bar]" rel="external">http://example.com/path/foo/[bar]</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('Hey, check out my cool site http://example.com okay?',
|
2009-08-24 22:48:24 +01:00
|
|
|
'Hey, check out my cool site <a href="http://example.com" rel="external">http://example.com</a> okay?'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('What about parens (e.g. http://example.com/path/foo/(bar))?',
|
2009-08-24 22:48:24 +01:00
|
|
|
'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" rel="external">http://example.com/path/foo/(bar)</a>)?'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('What about parens (e.g. http://example.com/path/foo/(bar)?',
|
2009-08-24 22:48:24 +01:00
|
|
|
'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" rel="external">http://example.com/path/foo/(bar)</a>?'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('What about parens (e.g. http://example.com/path/foo/(bar).)?',
|
2009-08-24 22:48:24 +01:00
|
|
|
'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" rel="external">http://example.com/path/foo/(bar)</a>.)?'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('What about parens (e.g. http://example.com/path/(foo,bar)?',
|
2009-08-24 22:48:24 +01:00
|
|
|
'What about parens (e.g. <a href="http://example.com/path/(foo,bar)" rel="external">http://example.com/path/(foo,bar)</a>?'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?',
|
2009-08-24 22:48:24 +01:00
|
|
|
'Unbalanced too (e.g. <a href="http://example.com/path/((((foo)/bar)" rel="external">http://example.com/path/((((foo)/bar)</a>?'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?',
|
2009-08-24 22:48:24 +01:00
|
|
|
'Unbalanced too (e.g. <a href="http://example.com/path/(foo))))/bar" rel="external">http://example.com/path/(foo))))/bar</a>)?'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('Unbalanced too (e.g. http://example.com/path/foo/((((bar)?',
|
2009-08-24 22:48:24 +01:00
|
|
|
'Unbalanced too (e.g. <a href="http://example.com/path/foo/((((bar)" rel="external">http://example.com/path/foo/((((bar)</a>?'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('Unbalanced too (e.g. http://example.com/path/foo/(bar))))?',
|
2009-08-24 22:48:24 +01:00
|
|
|
'Unbalanced too (e.g. <a href="http://example.com/path/foo/(bar)" rel="external">http://example.com/path/foo/(bar)</a>)))?'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('example.com',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com" rel="external">example.com</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('example.org',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.org" rel="external">example.org</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('example.co.uk',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.co.uk" rel="external">example.co.uk</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('www.example.co.uk',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://www.example.co.uk" rel="external">www.example.co.uk</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('farm1.images.example.co.uk',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://farm1.images.example.co.uk" rel="external">farm1.images.example.co.uk</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('example.museum',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.museum" rel="external">example.museum</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('example.travel',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.travel" rel="external">example.travel</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('example.com.',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com" rel="external">example.com</a>.'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('example.com?',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com" rel="external">example.com</a>?'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('example.com!',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com" rel="external">example.com</a>!'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('example.com,',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com" rel="external">example.com</a>,'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('example.com;',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com" rel="external">example.com</a>;'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('example.com:',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com" rel="external">example.com</a>:'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('\'example.com\'',
|
2009-08-24 22:48:24 +01:00
|
|
|
'\'<a href="http://example.com" rel="external">example.com</a>\''),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('"example.com"',
|
2009-08-24 22:48:24 +01:00
|
|
|
'"<a href="http://example.com" rel="external">example.com</a>"'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('example.com
',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<a href="http://example.com" rel="external">example.com</a>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('(example.com)',
|
2009-08-24 22:48:24 +01:00
|
|
|
'(<a href="http://example.com" rel="external">example.com</a>)'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('[example.com]',
|
2009-08-24 22:48:24 +01:00
|
|
|
'[<a href="http://example.com" rel="external">example.com</a>]'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('<example.com>',
|
2009-08-24 22:48:24 +01:00
|
|
|
'<<a href="http://example.com" rel="external">example.com</a>>'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('Hey, check out my cool site example.com okay?',
|
2009-08-24 22:48:24 +01:00
|
|
|
'Hey, check out my cool site <a href="http://example.com" rel="external">example.com</a> okay?'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('Hey, check out my cool site example.com.I made it.',
|
2009-08-24 22:48:24 +01:00
|
|
|
'Hey, check out my cool site <a href="http://example.com" rel="external">example.com</a>.I made it.'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('Hey, check out my cool site example.com.Funny thing...',
|
2009-08-24 22:48:24 +01:00
|
|
|
'Hey, check out my cool site <a href="http://example.com" rel="external">example.com</a>.Funny thing...'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('Hey, check out my cool site example.com.You will love it.',
|
2009-08-24 22:48:24 +01:00
|
|
|
'Hey, check out my cool site <a href="http://example.com" rel="external">example.com</a>.You will love it.'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('What about parens (e.g. example.com/path/foo/(bar))?',
|
2009-08-24 22:48:24 +01:00
|
|
|
'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" rel="external">example.com/path/foo/(bar)</a>)?'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('What about parens (e.g. example.com/path/foo/(bar)?',
|
2009-08-24 22:48:24 +01:00
|
|
|
'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" rel="external">example.com/path/foo/(bar)</a>?'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('What about parens (e.g. example.com/path/foo/(bar).)?',
|
2009-08-24 22:48:24 +01:00
|
|
|
'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" rel="external">example.com/path/foo/(bar)</a>.)?'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('What about parens (e.g. example.com/path/(foo,bar)?',
|
2009-08-24 22:48:24 +01:00
|
|
|
'What about parens (e.g. <a href="http://example.com/path/(foo,bar)" rel="external">example.com/path/(foo,bar)</a>?'),
|
2009-08-24 20:46:12 +01:00
|
|
|
array('file.ext',
|
|
|
|
'file.ext'),
|
|
|
|
array('file.html',
|
|
|
|
'file.html'),
|
|
|
|
array('file.php',
|
|
|
|
'file.php')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|