3 if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
4 print "This script must be run from the command line\n";
8 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
9 define('LACONICA', true);
11 require_once INSTALLDIR . '/lib/common.php';
13 class URLDetectionTest extends PHPUnit_Framework_TestCase
16 * @dataProvider provider
19 public function testProduction($content, $expected)
21 $rendered = common_render_text($content);
22 $this->assertEquals($expected, $rendered);
25 static public function provider()
30 array('http://example',
31 '<a href="http://example/" rel="external">http://example</a>'),
32 array('http://example/',
33 '<a href="http://example/" rel="external">http://example/</a>'),
34 array('http://example/path',
35 '<a href="http://example/path" rel="external">http://example/path</a>'),
36 array('http://example.com',
37 '<a href="http://example.com/" rel="external">http://example.com</a>'),
38 array('https://example.com',
39 '<a href="https://example.com/" rel="external">https://example.com</a>'),
40 array('ftp://example.com',
41 '<a href="ftp://example.com/" rel="external">ftp://example.com</a>'),
42 array('ftps://example.com',
43 '<a href="ftps://example.com/" rel="external">ftps://example.com</a>'),
44 array('http://user@example.com',
45 '<a href="http://user@example.com/" rel="external">http://user@example.com</a>'),
46 array('http://user:pass@example.com',
47 '<a href="http://user:pass@example.com/" rel="external">http://user:pass@example.com</a>'),
48 array('http://example.com:8080',
49 '<a href="http://example.com:8080/" rel="external">http://example.com:8080</a>'),
50 array('http://www.example.com',
51 '<a href="http://www.example.com/" rel="external">http://www.example.com</a>'),
52 array('http://example.com/',
53 '<a href="http://example.com/" rel="external">http://example.com/</a>'),
54 array('http://example.com/path',
55 '<a href="http://example.com/path" rel="external">http://example.com/path</a>'),
56 array('http://example.com/path.html',
57 '<a href="http://example.com/path.html" rel="external">http://example.com/path.html</a>'),
58 array('http://example.com/path.html#fragment',
59 '<a href="http://example.com/path.html#fragment" rel="external">http://example.com/path.html#fragment</a>'),
60 array('http://example.com/path.php?foo=bar&bar=foo',
61 '<a href="http://example.com/path.php?foo=bar&bar=foo" rel="external">http://example.com/path.php?foo=bar&bar=foo</a>'),
62 array('http://müllärör.de',
63 '<a href="http://müllärör.de" rel="external">http://müllärör.de</a>'),
64 array('http://ﺱﺲﺷ.com',
65 '<a href="http://ﺱﺲﺷ.com" rel="external">http://ﺱﺲﺷ.com</a>'),
66 array('http://сделаткартинки.com',
67 '<a href="http://сделаткартинки.com" rel="external">http://сделаткартинки.com</a>'),
68 array('http://tūdaliņ.lv',
69 '<a href="http://tūdaliņ.lv" rel="external">http://tūdaliņ.lv</a>'),
70 array('http://brændendekærlighed.com',
71 '<a href="http://brændendekærlighed.com" rel="external">http://brændendekærlighed.com</a>'),
72 array('http://あーるいん.com',
73 '<a href="http://あーるいん.com" rel="external">http://あーるいん.com</a>'),
74 array('http://예비교사.com',
75 '<a href="http://예비교사.com" rel="external">http://예비교사.com</a>'),
76 array('http://example.com.',
77 '<a href="http://example.com" rel="external">http://example.com</a>.'),
78 array('http://example.com?',
79 '<a href="http://example.com" rel="external">http://example.com</a>?'),
80 array('http://example.com!',
81 '<a href="http://example.com" rel="external">http://example.com</a>!'),
82 array('http://example.com,',
83 '<a href="http://example.com" rel="external">http://example.com</a>,'),
84 array('http://example.com;',
85 '<a href="http://example.com" rel="external">http://example.com</a>;'),
86 array('http://example.com:',
87 '<a href="http://example.com" rel="external">http://example.com</a>:'),
88 array('\'http://example.com\'',
89 '\'<a href="http://example.com" rel="external">http://example.com</a>\''),
90 array('"http://example.com"',
91 '"<a href="http://example.com" rel="external">http://example.com</a>"'),
92 array('http://example.com
\r',
93 '<a href="http://example.com" rel="external">http://example.com</a>'),
94 array('(http://example.com)',
95 '(<a href="http://example.com" rel="external">http://example.com</a>)'),
96 array('[http://example.com]',
97 '[<a href="http://example.com" rel="external">http://example.com</a>]'),
98 array('<http://example.com>',
99 '<<a href="http://example.com" rel="external">http://example.com</a>>'),
100 array('http://example.com/path/(foo)/bar',
101 '<a href="http://example.com/path/(foo)/bar" rel="external">http://example.com/path/(foo)/bar</a>'),
102 array('http://example.com/path/[foo]/bar',
103 '<a href="http://example.com/path/[foo]/bar" rel="external">http://example.com/path/[foo]/bar</a>'),
104 array('http://example.com/path/foo/(bar)',
105 '<a href="http://example.com/path/foo/(bar)" rel="external">http://example.com/path/foo/(bar)</a>'),
106 array('http://example.com/path/foo/[bar]',
107 '<a href="http://example.com/path/foo/[bar]" rel="external">http://example.com/path/foo/[bar]</a>'),
108 array('Hey, check out my cool site http://example.com okay?',
109 'Hey, check out my cool site <a href="http://example.com" rel="external">http://example.com</a> okay?'),
110 array('What about parens (e.g. http://example.com/path/foo/(bar))?',
111 'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" rel="external">http://example.com/path/foo/(bar)</a>)?'),
112 array('What about parens (e.g. http://example.com/path/foo/(bar)?',
113 'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" rel="external">http://example.com/path/foo/(bar)</a>?'),
114 array('What about parens (e.g. http://example.com/path/foo/(bar).)?',
115 'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" rel="external">http://example.com/path/foo/(bar)</a>.)?'),
116 array('What about parens (e.g. http://example.com/path/(foo,bar)?',
117 'What about parens (e.g. <a href="http://example.com/path/(foo,bar)" rel="external">http://example.com/path/(foo,bar)</a>?'),
118 array('Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?',
119 'Unbalanced too (e.g. <a href="http://example.com/path/((((foo)/bar)" rel="external">http://example.com/path/((((foo)/bar)</a>?'),
120 array('Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?',
121 'Unbalanced too (e.g. <a href="http://example.com/path/(foo))))/bar" rel="external">http://example.com/path/(foo))))/bar</a>)?'),
122 array('Unbalanced too (e.g. http://example.com/path/foo/((((bar)?',
123 'Unbalanced too (e.g. <a href="http://example.com/path/foo/((((bar)" rel="external">http://example.com/path/foo/((((bar)</a>?'),
124 array('Unbalanced too (e.g. http://example.com/path/foo/(bar))))?',
125 'Unbalanced too (e.g. <a href="http://example.com/path/foo/(bar)" rel="external">http://example.com/path/foo/(bar)</a>)))?'),
127 '<a href="http://example.com" rel="external">example.com</a>'),
129 '<a href="http://example.org" rel="external">example.org</a>'),
130 array('example.co.uk',
131 '<a href="http://example.co.uk" rel="external">example.co.uk</a>'),
132 array('www.example.co.uk',
133 '<a href="http://www.example.co.uk" rel="external">www.example.co.uk</a>'),
134 array('farm1.images.example.co.uk',
135 '<a href="http://farm1.images.example.co.uk" rel="external">farm1.images.example.co.uk</a>'),
136 array('example.museum',
137 '<a href="http://example.museum" rel="external">example.museum</a>'),
138 array('example.travel',
139 '<a href="http://example.travel" rel="external">example.travel</a>'),
140 array('example.com.',
141 '<a href="http://example.com" rel="external">example.com</a>.'),
142 array('example.com?',
143 '<a href="http://example.com" rel="external">example.com</a>?'),
144 array('example.com!',
145 '<a href="http://example.com" rel="external">example.com</a>!'),
146 array('example.com,',
147 '<a href="http://example.com" rel="external">example.com</a>,'),
148 array('example.com;',
149 '<a href="http://example.com" rel="external">example.com</a>;'),
150 array('example.com:',
151 '<a href="http://example.com" rel="external">example.com</a>:'),
152 array('\'example.com\'',
153 '\'<a href="http://example.com" rel="external">example.com</a>\''),
154 array('"example.com"',
155 '"<a href="http://example.com" rel="external">example.com</a>"'),
156 array('example.com
\r',
157 '<a href="http://example.com" rel="external">example.com</a>'),
158 array('(example.com)',
159 '(<a href="http://example.com" rel="external">example.com</a>)'),
160 array('[example.com]',
161 '[<a href="http://example.com" rel="external">example.com</a>]'),
162 array('<example.com>',
163 '<<a href="http://example.com" rel="external">example.com</a>>'),
164 array('Hey, check out my cool site example.com okay?',
165 'Hey, check out my cool site <a href="http://example.com" rel="external">example.com</a> okay?'),
166 array('Hey, check out my cool site example.com.I made it.',
167 'Hey, check out my cool site <a href="http://example.com" rel="external">example.com</a>.I made it.'),
168 array('Hey, check out my cool site example.com.Funny thing...',
169 'Hey, check out my cool site <a href="http://example.com" rel="external">example.com</a>.Funny thing...'),
170 array('Hey, check out my cool site example.com.You will love it.',
171 'Hey, check out my cool site <a href="http://example.com" rel="external">example.com</a>.You will love it.'),
172 array('What about parens (e.g. example.com/path/foo/(bar))?',
173 'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" rel="external">example.com/path/foo/(bar)</a>)?'),
174 array('What about parens (e.g. example.com/path/foo/(bar)?',
175 'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" rel="external">example.com/path/foo/(bar)</a>?'),
176 array('What about parens (e.g. example.com/path/foo/(bar).)?',
177 'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" rel="external">example.com/path/foo/(bar)</a>.)?'),
178 array('What about parens (e.g. example.com/path/(foo,bar)?',
179 'What about parens (e.g. <a href="http://example.com/path/(foo,bar)" rel="external">example.com/path/(foo,bar)</a>?'),