]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/URLDetectionTest.php
merge from testing
[quix0rs-gnu-social.git] / tests / URLDetectionTest.php
1 <?php
2
3 if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
4     print "This script must be run from the command line\n";
5     exit();
6 }
7
8 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
9 define('STATUSNET', true);
10 define('LACONICA', true);
11
12 require_once INSTALLDIR . '/lib/common.php';
13
14 class URLDetectionTest extends PHPUnit_Framework_TestCase
15 {
16     /**
17      * @dataProvider provider
18      *
19      */
20     public function testProduction($content, $expected)
21     {
22         $rendered = common_render_text($content);
23         $this->assertEquals($expected, $rendered);
24     }
25
26     static public function provider()
27     {
28         return array(
29                      array('not a link :: no way',
30                            'not a link :: no way'),
31                      array('link http://www.somesite.com/xyz/35637563@N00/52803365/ link',
32                            'link <a href="http://www.somesite.com/xyz/35637563@N00/52803365/" title="http://www.somesite.com/xyz/35637563@N00/52803365/" rel="external">http://www.somesite.com/xyz/35637563@N00/52803365/</a> link'),
33                      array('http://127.0.0.1',
34                            '<a href="http://127.0.0.1/" title="http://127.0.0.1/" rel="external">http://127.0.0.1</a>'),
35                      array('127.0.0.1',
36                            '<a href="http://127.0.0.1/" title="http://127.0.0.1/" rel="external">127.0.0.1</a>'),
37                      array('127.0.0.1:99',
38                            '<a href="http://127.0.0.1:99/" title="http://127.0.0.1:99/" rel="external">127.0.0.1:99</a>'),
39                      array('127.0.0.1/Name:test.php',
40                            '<a href="http://127.0.0.1/Name:test.php" title="http://127.0.0.1/Name:test.php" rel="external">127.0.0.1/Name:test.php</a>'),
41                      array('127.0.0.1/~test',
42                            '<a href="http://127.0.0.1/~test" title="http://127.0.0.1/~test" rel="external">127.0.0.1/~test</a>'),
43                      array('127.0.0.1/+test',
44                            '<a href="http://127.0.0.1/+test" title="http://127.0.0.1/+test" rel="external">127.0.0.1/+test</a>'),
45                      array('127.0.0.1/$test',
46                            '<a href="http://127.0.0.1/$test" title="http://127.0.0.1/$test" rel="external">127.0.0.1/$test</a>'),
47                      array('127.0.0.1/\'test',
48                            '<a href="http://127.0.0.1/\'test" title="http://127.0.0.1/\'test" rel="external">127.0.0.1/\'test</a>'),
49                      array('127.0.0.1/"test',
50                            '<a href="http://127.0.0.1/" title="http://127.0.0.1/" rel="external">127.0.0.1/</a>&quot;test'),
51                      array('127.0.0.1/test"test',
52                            '<a href="http://127.0.0.1/test" title="http://127.0.0.1/test" rel="external">127.0.0.1/test</a>&quot;test'),
53                      array('127.0.0.1/-test',
54                            '<a href="http://127.0.0.1/-test" title="http://127.0.0.1/-test" rel="external">127.0.0.1/-test</a>'),
55                      array('127.0.0.1/_test',
56                            '<a href="http://127.0.0.1/_test" title="http://127.0.0.1/_test" rel="external">127.0.0.1/_test</a>'),
57                      array('127.0.0.1/!test',
58                            '<a href="http://127.0.0.1/!test" title="http://127.0.0.1/!test" rel="external">127.0.0.1/!test</a>'),
59                      array('127.0.0.1/*test',
60                            '<a href="http://127.0.0.1/*test" title="http://127.0.0.1/*test" rel="external">127.0.0.1/*test</a>'),
61                      array('127.0.0.1/test%20stuff',
62                            '<a href="http://127.0.0.1/test%20stuff" title="http://127.0.0.1/test%20stuff" rel="external">127.0.0.1/test%20stuff</a>'),
63                      array('http://[::1]:99/test.php',
64                            '<a href="http://[::1]:99/test.php" title="http://[::1]:99/test.php" rel="external">http://[::1]:99/test.php</a>'),
65                      array('http://::1/test.php',
66                            '<a href="http://::1/test.php" title="http://::1/test.php" rel="external">http://::1/test.php</a>'),
67                      array('http://::1',
68                            '<a href="http://::1/" title="http://::1/" rel="external">http://::1</a>'),
69                      array('2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php',
70                            '<a href="http://2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php" title="http://2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php" rel="external">2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php</a>'),
71                      array('[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php',
72                            '<a href="http://[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php" title="http://[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php" rel="external">[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php</a>'),
73                      array('2001:4978:1b5:0:21d:e0ff:fe66:59ab',
74                            '<a href="http://2001:4978:1b5:0:21d:e0ff:fe66:59ab/" title="http://2001:4978:1b5:0:21d:e0ff:fe66:59ab/" rel="external">2001:4978:1b5:0:21d:e0ff:fe66:59ab</a>'),
75                      array('http://127.0.0.1',
76                            '<a href="http://127.0.0.1/" title="http://127.0.0.1/" rel="external">http://127.0.0.1</a>'),
77                      array('example.com',
78                            '<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>'),
79                      array('example.com',
80                            '<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>'),
81                      array('http://example.com',
82                            '<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a>'),
83                      array('http://example.com.',
84                            '<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a>.'),
85                      array('/var/lib/example.so',
86                            '/var/lib/example.so'),
87                      array('example',
88                            'example'),
89                      array('user@example.com',
90                            '<a href="mailto:user@example.com" title="mailto:user@example.com" rel="external">user@example.com</a>'),
91                      array('user_name+other@example.com',
92                            '<a href="mailto:user_name+other@example.com" title="mailto:user_name+other@example.com" rel="external">user_name+other@example.com</a>'),
93                      array('mailto:user@example.com',
94                            '<a href="mailto:user@example.com" title="mailto:user@example.com" rel="external">mailto:user@example.com</a>'),
95                      array('mailto:user@example.com?subject=test',
96                            '<a href="mailto:user@example.com?subject=test" title="mailto:user@example.com?subject=test" rel="external">mailto:user@example.com?subject=test</a>'),
97                      array('xmpp:user@example.com',
98                            '<a href="xmpp:user@example.com" title="xmpp:user@example.com" rel="external">xmpp:user@example.com</a>'),
99                      array('#example',
100                            '#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('example'))) . '" rel="tag">example</a></span>'),
101                      array('#example.com',
102                            '#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('example.com'))) . '" rel="tag">example.com</a></span>'),
103                      array('#.net',
104                            '#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('.net'))) . '" rel="tag">.net</a></span>'),
105                      array('http://example',
106                            '<a href="http://example/" title="http://example/" rel="external">http://example</a>'),
107                      array('http://3xampl3',
108                            '<a href="http://3xampl3/" title="http://3xampl3/" rel="external">http://3xampl3</a>'),
109                      array('http://example/',
110                            '<a href="http://example/" title="http://example/" rel="external">http://example/</a>'),
111                      array('http://example/path',
112                            '<a href="http://example/path" title="http://example/path" rel="external">http://example/path</a>'),
113                      array('http://example.com',
114                            '<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a>'),
115                      array('https://example.com',
116                            '<a href="https://example.com/" title="https://example.com/" rel="external">https://example.com</a>'),
117                      array('ftp://example.com',
118                            '<a href="ftp://example.com/" title="ftp://example.com/" rel="external">ftp://example.com</a>'),
119                      array('ftps://example.com',
120                            '<a href="ftps://example.com/" title="ftps://example.com/" rel="external">ftps://example.com</a>'),
121                      array('http://user@example.com',
122                            '<a href="http://user@example.com/" title="http://user@example.com/" rel="external">http://user@example.com</a>'),
123                      array('http://user:pass@example.com',
124                            '<a href="http://user:pass@example.com/" title="http://user:pass@example.com/" rel="external">http://user:pass@example.com</a>'),
125                      array('http://example.com:8080',
126                            '<a href="http://example.com:8080/" title="http://example.com:8080/" rel="external">http://example.com:8080</a>'),
127                      array('http://example.com:8080/test.php',
128                            '<a href="http://example.com:8080/test.php" title="http://example.com:8080/test.php" rel="external">http://example.com:8080/test.php</a>'),
129                      array('example.com:8080/test.php',
130                            '<a href="http://example.com:8080/test.php" title="http://example.com:8080/test.php" rel="external">example.com:8080/test.php</a>'),
131                      array('http://www.example.com',
132                            '<a href="http://www.example.com/" title="http://www.example.com/" rel="external">http://www.example.com</a>'),
133                      array('http://example.com/',
134                            '<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com/</a>'),
135                      array('http://example.com/path',
136                            '<a href="http://example.com/path" title="http://example.com/path" rel="external">http://example.com/path</a>'),
137                      array('http://example.com/path.html',
138                            '<a href="http://example.com/path.html" title="http://example.com/path.html" rel="external">http://example.com/path.html</a>'),
139                      array('http://example.com/path.html#fragment',
140                            '<a href="http://example.com/path.html#fragment" title="http://example.com/path.html#fragment" rel="external">http://example.com/path.html#fragment</a>'),
141                      array('http://example.com/path.php?foo=bar&bar=foo',
142                            '<a href="http://example.com/path.php?foo=bar&amp;bar=foo" title="http://example.com/path.php?foo=bar&amp;bar=foo" rel="external">http://example.com/path.php?foo=bar&amp;bar=foo</a>'),
143                      array('http://example.com.',
144                            '<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a>.'),
145                      array('http://müllärör.de',
146                            '<a href="http://m&#xFC;ll&#xE4;r&#xF6;r.de/" title="http://m&#xFC;ll&#xE4;r&#xF6;r.de/" rel="external">http://müllärör.de</a>'),
147                      array('http://ﺱﺲﺷ.com',
148                            '<a href="http://&#xFEB1;&#xFEB2;&#xFEB7;.com/" title="http://&#xFEB1;&#xFEB2;&#xFEB7;.com/" rel="external">http://ﺱﺲﺷ.com</a>'),
149                      array('http://сделаткартинки.com',
150                            '<a href="http://&#x441;&#x434;&#x435;&#x43B;&#x430;&#x442;&#x43A;&#x430;&#x440;&#x442;&#x438;&#x43D;&#x43A;&#x438;.com/" title="http://&#x441;&#x434;&#x435;&#x43B;&#x430;&#x442;&#x43A;&#x430;&#x440;&#x442;&#x438;&#x43D;&#x43A;&#x438;.com/" rel="external">http://сделаткартинки.com</a>'),
151                      array('http://tūdaliņ.lv',
152                            '<a href="http://t&#x16B;dali&#x146;.lv/" title="http://t&#x16B;dali&#x146;.lv/" rel="external">http://tūdaliņ.lv</a>'),
153                      array('http://brændendekærlighed.com',
154                            '<a href="http://br&#xE6;ndendek&#xE6;rlighed.com/" title="http://br&#xE6;ndendek&#xE6;rlighed.com/" rel="external">http://brændendekærlighed.com</a>'),
155                      array('http://あーるいん.com',
156                            '<a href="http://&#x3042;&#x30FC;&#x308B;&#x3044;&#x3093;.com/" title="http://&#x3042;&#x30FC;&#x308B;&#x3044;&#x3093;.com/" rel="external">http://あーるいん.com</a>'),
157                      array('http://예비교사.com',
158                            '<a href="http://&#xC608;&#xBE44;&#xAD50;&#xC0AC;.com/" title="http://&#xC608;&#xBE44;&#xAD50;&#xC0AC;.com/" rel="external">http://예비교사.com</a>'),
159                      array('http://example.com.',
160                            '<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a>.'),
161                      array('http://example.com?',
162                            '<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a>?'),
163                      array('http://example.com!',
164                            '<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a>!'),
165                      array('http://example.com,',
166                            '<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a>,'),
167                      array('http://example.com;',
168                            '<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a>;'),
169                      array('http://example.com:',
170                            '<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a>:'),
171                      array('\'http://example.com\'',
172                            '\'<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a>\''),
173                      array('"http://example.com"',
174                            '&quot;<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a>&quot;'),
175                      array('"http://example.com/"',
176                            '&quot;<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com/</a>&quot;'),
177                      array('http://example.com',
178                            '<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a>'),
179                      array('(http://example.com)',
180                            '(<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a>)'),
181                      array('[http://example.com]',
182                            '[<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a>]'),
183                      array('<http://example.com>',
184                            '&lt;<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a>&gt;'),
185                      array('http://example.com/path/(foo)/bar',
186                            '<a href="http://example.com/path/(foo)/bar" title="http://example.com/path/(foo)/bar" rel="external">http://example.com/path/(foo)/bar</a>'),
187                      array('http://example.com/path/[foo]/bar',
188                            '<a href="http://example.com/path/[foo]/bar" title="http://example.com/path/[foo]/bar" rel="external">http://example.com/path/[foo]/bar</a>'),
189                      array('http://example.com/path/foo/(bar)',
190                            '<a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="external">http://example.com/path/foo/(bar)</a>'),
191                      //Not a valid url - urls cannot contain unencoded square brackets
192                      array('http://example.com/path/foo/[bar]',
193                            '<a href="http://example.com/path/foo/[bar]" title="http://example.com/path/foo/[bar]" rel="external">http://example.com/path/foo/[bar]</a>'),
194                      array('Hey, check out my cool site http://example.com okay?',
195                            'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a> okay?'),
196                      array('What about parens (e.g. http://example.com/path/foo/(bar))?',
197                            'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="external">http://example.com/path/foo/(bar)</a>)?'),
198                      array('What about parens (e.g. http://example.com/path/foo/(bar)?',
199                            'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="external">http://example.com/path/foo/(bar)</a>?'),
200                      array('What about parens (e.g. http://example.com/path/foo/(bar).)?',
201                            'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="external">http://example.com/path/foo/(bar)</a>.)?'),
202                      //Not a valid url - urls cannot contain unencoded commas
203                      array('What about parens (e.g. http://example.com/path/(foo,bar)?',
204                            'What about parens (e.g. <a href="http://example.com/path/(foo,bar)" title="http://example.com/path/(foo,bar)" rel="external">http://example.com/path/(foo,bar)</a>?'),
205                      array('Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?',
206                            'Unbalanced too (e.g. <a href="http://example.com/path/((((foo)/bar)" title="http://example.com/path/((((foo)/bar)" rel="external">http://example.com/path/((((foo)/bar)</a>?'),
207                      array('Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?',
208                            'Unbalanced too (e.g. <a href="http://example.com/path/(foo))))/bar" title="http://example.com/path/(foo))))/bar" rel="external">http://example.com/path/(foo))))/bar</a>)?'),
209                      array('Unbalanced too (e.g. http://example.com/path/foo/((((bar)?',
210                            'Unbalanced too (e.g. <a href="http://example.com/path/foo/((((bar)" title="http://example.com/path/foo/((((bar)" rel="external">http://example.com/path/foo/((((bar)</a>?'),
211                      array('Unbalanced too (e.g. http://example.com/path/foo/(bar))))?',
212                            'Unbalanced too (e.g. <a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="external">http://example.com/path/foo/(bar)</a>)))?'),
213                      array('example.com',
214                            '<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>'),
215                      array('example.org',
216                            '<a href="http://example.org/" title="http://example.org/" rel="external">example.org</a>'),
217                      array('example.co.uk',
218                            '<a href="http://example.co.uk/" title="http://example.co.uk/" rel="external">example.co.uk</a>'),
219                      array('www.example.co.uk',
220                            '<a href="http://www.example.co.uk/" title="http://www.example.co.uk/" rel="external">www.example.co.uk</a>'),
221                      array('farm1.images.example.co.uk',
222                            '<a href="http://farm1.images.example.co.uk/" title="http://farm1.images.example.co.uk/" rel="external">farm1.images.example.co.uk</a>'),
223                      array('example.museum',
224                            '<a href="http://example.museum/" title="http://example.museum/" rel="external">example.museum</a>'),
225                      array('example.travel',
226                            '<a href="http://example.travel/" title="http://example.travel/" rel="external">example.travel</a>'),
227                      array('example.com.',
228                            '<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>.'),
229                      array('example.com?',
230                            '<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>?'),
231                      array('example.com!',
232                            '<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>!'),
233                      array('example.com,',
234                            '<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>,'),
235                      array('example.com;',
236                            '<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>;'),
237                      array('example.com:',
238                            '<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>:'),
239                      array('\'example.com\'',
240                            '\'<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>\''),
241                      array('"example.com"',
242                            '&quot;<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>&quot;'),
243                      array('example.com',
244                            '<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>'),
245                      array('(example.com)',
246                            '(<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>)'),
247                      array('[example.com]',
248                            '[<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>]'),
249                      array('<example.com>',
250                            '&lt;<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>&gt;'),
251                      array('Hey, check out my cool site example.com okay?',
252                            'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="external">example.com</a> okay?'),
253                      array('Hey, check out my cool site example.com.I made it.',
254                            'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>.I made it.'),
255                      array('Hey, check out my cool site example.com.Funny thing...',
256                            'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>.Funny thing...'),
257                      array('Hey, check out my cool site example.com.You will love it.',
258                            'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>.You will love it.'),
259                      array('What about parens (e.g. example.com/path/foo/(bar))?',
260                            'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="external">example.com/path/foo/(bar)</a>)?'),
261                      array('What about parens (e.g. example.com/path/foo/(bar)?',
262                            'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="external">example.com/path/foo/(bar)</a>?'),
263                      array('What about parens (e.g. example.com/path/foo/(bar).)?',
264                            'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="external">example.com/path/foo/(bar)</a>.)?'),
265                      array('What about parens (e.g. example.com/path/(foo,bar)?',
266                            'What about parens (e.g. <a href="http://example.com/path/(foo,bar)" title="http://example.com/path/(foo,bar)" rel="external">example.com/path/(foo,bar)</a>?'),
267                      array('file.ext',
268                            'file.ext'),
269                      array('file.html',
270                            'file.html'),
271                      array('file.php',
272                            'file.php')
273                      );
274     }
275 }
276