]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/URLDetectionTest.php
Merge branch 'i18n-work' into i18n-0.9.x
[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/&quot;test" title="http://127.0.0.1/&quot;test" rel="external">127.0.0.1/&quot;test</a>'),
51                      array('127.0.0.1/-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>'),
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%20stuff',
60                            '<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>'),
61                      array('http://[::1]:99/test.php',
62                            '<a href="http://[::1]:99/test.php" title="http://[::1]:99/test.php" rel="external">http://[::1]:99/test.php</a>'),
63                      array('http://::1/test.php',
64                            '<a href="http://::1/test.php" title="http://::1/test.php" rel="external">http://::1/test.php</a>'),
65                      array('http://::1',
66                            '<a href="http://::1/" title="http://::1/" rel="external">http://::1</a>'),
67                      array('2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php',
68                            '<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>'),
69                      array('[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php',
70                            '<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>'),
71                      array('2001:4978:1b5:0:21d:e0ff:fe66:59ab',
72                            '<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>'),
73                      array('http://127.0.0.1',
74                            '<a href="http://127.0.0.1/" title="http://127.0.0.1/" rel="external">http://127.0.0.1</a>'),
75                      array('example.com',
76                            '<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>'),
77                      array('example.com',
78                            '<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>'),
79                      array('http://example.com',
80                            '<a href="http://example.com/" title="http://example.com/" rel="external">http://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('/var/lib/example.so',
84                            '/var/lib/example.so'),
85                      array('example',
86                            'example'),
87                      array('user@example.com',
88                            '<a href="mailto:user@example.com" title="mailto:user@example.com" rel="external">user@example.com</a>'),
89                      array('user_name+other@example.com',
90                            '<a href="mailto:user_name+other@example.com" title="mailto:user_name+other@example.com" rel="external">user_name+other@example.com</a>'),
91                      array('mailto:user@example.com',
92                            '<a href="mailto:user@example.com" title="mailto:user@example.com" rel="external">mailto:user@example.com</a>'),
93                      array('mailto:user@example.com?subject=test',
94                            '<a href="mailto:user@example.com?subject=test" title="mailto:user@example.com?subject=test" rel="external">mailto:user@example.com?subject=test</a>'),
95                      array('xmpp:user@example.com',
96                            '<a href="xmpp:user@example.com" title="xmpp:user@example.com" rel="external">xmpp:user@example.com</a>'),
97                      array('#example',
98                            '#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('example'))) . '" rel="tag">example</a></span>'),
99                      array('#example.com',
100                            '#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('example.com'))) . '" rel="tag">example.com</a></span>'),
101                      array('#.net',
102                            '#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('.net'))) . '" rel="tag">.net</a></span>'),
103                      array('http://example',
104                            '<a href="http://example/" title="http://example/" rel="external">http://example</a>'),
105                      array('http://3xampl3',
106                            '<a href="http://3xampl3/" title="http://3xampl3/" rel="external">http://3xampl3</a>'),
107                      array('http://example/',
108                            '<a href="http://example/" title="http://example/" rel="external">http://example/</a>'),
109                      array('http://example/path',
110                            '<a href="http://example/path" title="http://example/path" rel="external">http://example/path</a>'),
111                      array('http://example.com',
112                            '<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a>'),
113                      array('https://example.com',
114                            '<a href="https://example.com/" title="https://example.com/" rel="external">https://example.com</a>'),
115                      array('ftp://example.com',
116                            '<a href="ftp://example.com/" title="ftp://example.com/" rel="external">ftp://example.com</a>'),
117                      array('ftps://example.com',
118                            '<a href="ftps://example.com/" title="ftps://example.com/" rel="external">ftps://example.com</a>'),
119                      array('http://user@example.com',
120                            '<a href="http://user@example.com/" title="http://user@example.com/" rel="external">http://user@example.com</a>'),
121                      array('http://user:pass@example.com',
122                            '<a href="http://user:pass@example.com/" title="http://user:pass@example.com/" rel="external">http://user:pass@example.com</a>'),
123                      array('http://example.com:8080',
124                            '<a href="http://example.com:8080/" title="http://example.com:8080/" rel="external">http://example.com:8080</a>'),
125                      array('http://example.com:8080/test.php',
126                            '<a href="http://example.com:8080/test.php" title="http://example.com:8080/test.php" rel="external">http://example.com:8080/test.php</a>'),
127                      array('example.com:8080/test.php',
128                            '<a href="http://example.com:8080/test.php" title="http://example.com:8080/test.php" rel="external">example.com:8080/test.php</a>'),
129                      array('http://www.example.com',
130                            '<a href="http://www.example.com/" title="http://www.example.com/" rel="external">http://www.example.com</a>'),
131                      array('http://example.com/',
132                            '<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com/</a>'),
133                      array('http://example.com/path',
134                            '<a href="http://example.com/path" title="http://example.com/path" rel="external">http://example.com/path</a>'),
135                      array('http://example.com/path.html',
136                            '<a href="http://example.com/path.html" title="http://example.com/path.html" rel="external">http://example.com/path.html</a>'),
137                      array('http://example.com/path.html#fragment',
138                            '<a href="http://example.com/path.html#fragment" title="http://example.com/path.html#fragment" rel="external">http://example.com/path.html#fragment</a>'),
139                      array('http://example.com/path.php?foo=bar&bar=foo',
140                            '<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>'),
141                      array('http://example.com.',
142                            '<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a>.'),
143                      array('http://müllärör.de',
144                            '<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>'),
145                      array('http://ﺱﺲﺷ.com',
146                            '<a href="http://&#xFEB1;&#xFEB2;&#xFEB7;.com/" title="http://&#xFEB1;&#xFEB2;&#xFEB7;.com/" rel="external">http://ﺱﺲﺷ.com</a>'),
147                      array('http://сделаткартинки.com',
148                            '<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>'),
149                      array('http://tūdaliņ.lv',
150                            '<a href="http://t&#x16B;dali&#x146;.lv/" title="http://t&#x16B;dali&#x146;.lv/" rel="external">http://tūdaliņ.lv</a>'),
151                      array('http://brændendekærlighed.com',
152                            '<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>'),
153                      array('http://あーるいん.com',
154                            '<a href="http://&#x3042;&#x30FC;&#x308B;&#x3044;&#x3093;.com/" title="http://&#x3042;&#x30FC;&#x308B;&#x3044;&#x3093;.com/" rel="external">http://あーるいん.com</a>'),
155                      array('http://예비교사.com',
156                            '<a href="http://&#xC608;&#xBE44;&#xAD50;&#xC0AC;.com/" title="http://&#xC608;&#xBE44;&#xAD50;&#xC0AC;.com/" rel="external">http://예비교사.com</a>'),
157                      array('http://example.com.',
158                            '<a href="http://example.com/" title="http://example.com/" rel="external">http://example.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                            '&quot;<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a>&quot;'),
173                      array('http://example.com',
174                            '<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a>'),
175                      array('(http://example.com)',
176                            '(<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a>)'),
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                            '&lt;<a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a>&gt;'),
181                      array('http://example.com/path/(foo)/bar',
182                            '<a href="http://example.com/path/(foo)/bar" title="http://example.com/path/(foo)/bar" rel="external">http://example.com/path/(foo)/bar</a>'),
183                      array('http://example.com/path/[foo]/bar',
184                            '<a href="http://example.com/path/[foo]/bar" title="http://example.com/path/[foo]/bar" rel="external">http://example.com/path/[foo]/bar</a>'),
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                      //Not a valid url - urls cannot contain unencoded square brackets
188                      array('http://example.com/path/foo/[bar]',
189                            '<a href="http://example.com/path/foo/[bar]" title="http://example.com/path/foo/[bar]" rel="external">http://example.com/path/foo/[bar]</a>'),
190                      array('Hey, check out my cool site http://example.com okay?',
191                            'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="external">http://example.com</a> okay?'),
192                      array('What about parens (e.g. http://example.com/path/foo/(bar))?',
193                            '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>)?'),
194                      array('What about parens (e.g. http://example.com/path/foo/(bar)?',
195                            '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>?'),
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                      //Not a valid url - urls cannot contain unencoded commas
199                      array('What about parens (e.g. http://example.com/path/(foo,bar)?',
200                            '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>?'),
201                      array('Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?',
202                            '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>?'),
203                      array('Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?',
204                            '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>)?'),
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('example.com',
210                            '<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>'),
211                      array('example.org',
212                            '<a href="http://example.org/" title="http://example.org/" rel="external">example.org</a>'),
213                      array('example.co.uk',
214                            '<a href="http://example.co.uk/" title="http://example.co.uk/" rel="external">example.co.uk</a>'),
215                      array('www.example.co.uk',
216                            '<a href="http://www.example.co.uk/" title="http://www.example.co.uk/" rel="external">www.example.co.uk</a>'),
217                      array('farm1.images.example.co.uk',
218                            '<a href="http://farm1.images.example.co.uk/" title="http://farm1.images.example.co.uk/" rel="external">farm1.images.example.co.uk</a>'),
219                      array('example.museum',
220                            '<a href="http://example.museum/" title="http://example.museum/" rel="external">example.museum</a>'),
221                      array('example.travel',
222                            '<a href="http://example.travel/" title="http://example.travel/" rel="external">example.travel</a>'),
223                      array('example.com.',
224                            '<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>.'),
225                      array('example.com?',
226                            '<a href="http://example.com/" title="http://example.com/" rel="external">example.com</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                            '&quot;<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>&quot;'),
239                      array('example.com',
240                            '<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>'),
241                      array('(example.com)',
242                            '(<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>)'),
243                      array('[example.com]',
244                            '[<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>]'),
245                      array('<example.com>',
246                            '&lt;<a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>&gt;'),
247                      array('Hey, check out my cool site example.com okay?',
248                            'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="external">example.com</a> okay?'),
249                      array('Hey, check out my cool site example.com.I made it.',
250                            'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>.I made it.'),
251                      array('Hey, check out my cool site example.com.Funny thing...',
252                            'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>.Funny thing...'),
253                      array('Hey, check out my cool site example.com.You will love it.',
254                            'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="external">example.com</a>.You will love it.'),
255                      array('What about parens (e.g. example.com/path/foo/(bar))?',
256                            '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>)?'),
257                      array('What about parens (e.g. example.com/path/foo/(bar)?',
258                            '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>?'),
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('file.ext',
264                            'file.ext'),
265                      array('file.html',
266                            'file.html'),
267                      array('file.php',
268                            'file.php')
269                      );
270     }
271 }
272