[1] | 1 | <?php |
---|
| 2 | /** |
---|
[362] | 3 | * The Strangecode Codebase - a general application development framework for PHP |
---|
| 4 | * For details visit the project site: <http://trac.strangecode.com/codebase/> |
---|
[396] | 5 | * Copyright 2001-2012 Strangecode, LLC |
---|
[541] | 6 | * |
---|
[362] | 7 | * This file is part of The Strangecode Codebase. |
---|
[42] | 8 | * |
---|
[362] | 9 | * The Strangecode Codebase is free software: you can redistribute it and/or |
---|
| 10 | * modify it under the terms of the GNU General Public License as published by the |
---|
| 11 | * Free Software Foundation, either version 3 of the License, or (at your option) |
---|
| 12 | * any later version. |
---|
[541] | 13 | * |
---|
[362] | 14 | * The Strangecode Codebase is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
---|
| 17 | * details. |
---|
[541] | 18 | * |
---|
[362] | 19 | * You should have received a copy of the GNU General Public License along with |
---|
| 20 | * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | /** |
---|
| 24 | * PHPUnit test case for codebase/lib/Utilities.inc.php |
---|
| 25 | * |
---|
[42] | 26 | * The method skeletons below need to be filled in with |
---|
| 27 | * real data so that the tests will run correctly. Replace |
---|
| 28 | * all EXPECTED_VAL and PARAM strings with real data. |
---|
| 29 | * |
---|
[1] | 30 | * Created with PHPUnit_Skeleton on 2005-08-09 |
---|
| 31 | */ |
---|
| 32 | |
---|
[468] | 33 | class UtilitiesTest extends PHPUnit_Framework_TestCase { |
---|
| 34 | |
---|
[1] | 35 | function setUp() |
---|
| 36 | { |
---|
[541] | 37 | define('_CLI', true); |
---|
[1] | 38 | require dirname(__FILE__) . '/_config.inc.php'; |
---|
| 39 | require_once '../lib/Utilities.inc.php'; |
---|
[541] | 40 | // $this->Utilities =& new Utilities(PARAM); |
---|
[1] | 41 | } |
---|
| 42 | |
---|
| 43 | function tearDown() |
---|
| 44 | { |
---|
[541] | 45 | $app =& App::getInstance(); |
---|
| 46 | $app->stop(); |
---|
[1] | 47 | } |
---|
| 48 | |
---|
[541] | 49 | function test_hyperlinkTxt() |
---|
| 50 | { |
---|
| 51 | $urls = [ |
---|
| 52 | ' http://www.asdf.com/ ' => ' <a href="http://www.asdf.com/">www.asdf.com/</a> ', |
---|
| 53 | ' www.asdf.com/ ' => ' <a href="http://www.asdf.com/">www.asdf.com/</a> ', |
---|
| 54 | ' www.asdf.com/? ' => ' <a href="http://www.asdf.com/">www.asdf.com/</a>? ', |
---|
| 55 | ' www.asdf.com/?x=y+z ' => ' <a href="http://www.asdf.com/?x=y+z">www.asdf.com/?x=y+z</a> ', |
---|
| 56 | ' www.asdf.com/?x=y+ ' => ' <a href="http://www.asdf.com/?x=y+">www.asdf.com/?x=y+</a> ', |
---|
| 57 | ' www.asdf.com/?x= ' => ' <a href="http://www.asdf.com/?x=">www.asdf.com/?x=</a> ', |
---|
| 58 | ' www.asdf.com/?x ' => ' <a href="http://www.asdf.com/?x">www.asdf.com/?x</a> ', |
---|
| 59 | ' www.asdf.com/?â€ïž=ð¥ ' => ' <a href="http://www.asdf.com/?â€ïž=ð¥">www.asdf.com/?â€ïž=ð¥</a> ', |
---|
| 60 | ' www.asdf.com? ' => ' <a href="http://www.asdf.com">www.asdf.com</a>? ', |
---|
| 61 | ' www.asdf.com! ' => ' <a href="http://www.asdf.com">www.asdf.com</a>! ', |
---|
| 62 | ' www.asdf.com. ' => ' <a href="http://www.asdf.com">www.asdf.com</a>. ', |
---|
| 63 | ' `www.asdf.com` ' => ' `www.asdf.com` ', |
---|
| 64 | ' "www.asdf.com" ' => ' "www.asdf.com" ', |
---|
| 65 | ' <www.asdf.com> ' => ' <<a href="http://www.asdf.com">www.asdf.com</a>> ', |
---|
| 66 | ' <http://www.asdf.com> ' => ' <<a href="http://www.asdf.com">www.asdf.com</a>> ', |
---|
| 67 | ' (http://www.asdf.com) ' => ' (<a href="http://www.asdf.com">www.asdf.com</a>) ', |
---|
| 68 | ' (URL: http://www.asdf.com#1) ' => ' (URL: <a href="http://www.asdf.com#1">www.asdf.com#1</a>) ', |
---|
| 69 | ' <a href="http://www.example.com/">Click Here</a> ' => ' <a href="http://www.example.com/">Click Here</a> ', |
---|
| 70 | ' <a href="http://www.example.com/">http://www.example.com/</a> ' => ' <a href="http://www.example.com/">http://www.example.com/</a> ', |
---|
| 71 | ' <a href=http://www.example.com/>http://www.example.com/</a> ' => ' <a href=http://www.example.com/>http://www.example.com/</a> ', |
---|
| 72 | ' <a href=\'http://www.example.com/\' >http://www.example.com/</a> ' => ' <a href=\'http://www.example.com/\' >http://www.example.com/</a> ', |
---|
| 73 | ' http://foo.com/blah_blah ' => ' <a href="http://foo.com/blah_blah">foo.com/blah_blah</a> ', |
---|
| 74 | ' http://foo.com/blah_blah/ ' => ' <a href="http://foo.com/blah_blah/">foo.com/blah_blah/</a> ', |
---|
| 75 | ' http://foo.com/blah_blah_(wikipedia) ' => ' <a href="http://foo.com/blah_blah_(wikipedia">foo.com/blah_blah_(wikipedia</a>) ', |
---|
| 76 | ' http://foo.com/blah_blah_(wikipedia)_(again) ' => ' <a href="http://foo.com/blah_blah_(wikipedia)_(again">foo.com/blah_blah_(wikipedia)_(again</a>) ', |
---|
| 77 | ' http://www.example.com/wpstyle/?p=364 ' => ' <a href="http://www.example.com/wpstyle/?p=364">www.example.com/wpstyle/?p=364</a> ', |
---|
| 78 | ' https://www.example.com/foo/?bar=baz&inga=42&quux ' => ' <a href="https://www.example.com/foo/?bar=baz&inga=42&quux">www.example.com/foo/?bar=baz&inga=42&quux</a> ', |
---|
| 79 | ' http://âªdf.ws/123 ' => ' <a href="http://âªdf.ws/123">âªdf.ws/123</a> ', |
---|
| 80 | ' http://userid:password@example.com:8080 ' => ' <a href="http://userid:password@example.com:8080">userid:password@example.com:8080</a> ', |
---|
| 81 | ' http://userid:password@example.com:8080/ ' => ' <a href="http://userid:password@example.com:8080/">userid:password@example.com:8080/</a> ', |
---|
| 82 | ' http://userid@example.com ' => ' <a href="http://userid@example.com">userid@example.com</a> ', |
---|
| 83 | ' http://userid@example.com/ ' => ' <a href="http://userid@example.com/">userid@example.com/</a> ', |
---|
| 84 | ' http://userid@example.com:8080 ' => ' <a href="http://userid@example.com:8080">userid@example.com:8080</a> ', |
---|
| 85 | ' http://userid@example.com:8080/ ' => ' <a href="http://userid@example.com:8080/">userid@example.com:8080/</a> ', |
---|
| 86 | ' http://userid:password@example.com ' => ' <a href="http://userid:password@example.com">userid:password@example.com</a> ', |
---|
| 87 | ' http://userid:password@example.com/ ' => ' <a href="http://userid:password@example.com/">userid:password@example.com/</a> ', |
---|
| 88 | ' http://142.42.1.1/ ' => ' <a href="http://142.42.1.1/">142.42.1.1/</a> ', |
---|
| 89 | ' http://142.42.1.1:8080/ ' => ' <a href="http://142.42.1.1:8080/">142.42.1.1:8080/</a> ', |
---|
| 90 | ' http://â¡.ws/äš¹ ' => ' <a href="http://â¡.ws/äš¹">â¡.ws/äš¹</a> ', |
---|
| 91 | ' http://â.ws ' => ' <a href="http://â.ws">â.ws</a> ', |
---|
| 92 | ' http://â.ws/ ' => ' <a href="http://â.ws/">â.ws/</a> ', |
---|
| 93 | ' http://foo.com/blah_(wikipedia)#cite-1 ' => ' <a href="http://foo.com/blah_(wikipedia)#cite-1">foo.com/blah_(wikipedia)#cite-1</a> ', |
---|
| 94 | ' http://foo.com/blah_(wikipedia)_blah#cite-1 ' => ' <a href="http://foo.com/blah_(wikipedia)_blah#cite-1">foo.com/blah_(wikipedia)_blah#cite-1</a> ', |
---|
| 95 | ' http://foo.com/unicode_(âª)_in_parens ' => ' <a href="http://foo.com/unicode_(âª)_in_parens">foo.com/unicode_(âª)_in_parens</a> ', |
---|
| 96 | ' http://foo.com/(something)?after=parens ' => ' <a href="http://foo.com/(something)?after=parens">foo.com/(something)?after=parens</a> ', |
---|
| 97 | ' http://âº.damowmow.com/ ' => ' <a href="http://âº.damowmow.com/">âº.damowmow.com/</a> ', |
---|
| 98 | ' http://code.google.com/events/#&product=browser ' => ' <a href="http://code.google.com/events/#&product=browser">code.google.com/events/#&product=browser</a> ', |
---|
| 99 | ' http://j.mp ' => ' <a href="http://j.mp">j.mp</a> ', |
---|
| 100 | ' ftp://foo.bar/baz ' => ' <a href="ftp://foo.bar/baz">foo.bar/baz</a> ', |
---|
| 101 | ' http://foo.bar/?q=Test%20URL-encoded%20stuff ' => ' <a href="http://foo.bar/?q=Test%20URL-encoded%20stuff">foo.bar/?q=Test%20URL-encoded%20stuff</a> ', |
---|
| 102 | ' http://Ù
ثاÙ.إختؚار ' => ' <a href="http://Ù
ثاÙ.إختؚار">Ù
ثاÙ.إختؚار</a> ', |
---|
| 103 | ' http://äŸå.æµè¯ ' => ' <a href="http://äŸå.æµè¯">äŸå.æµè¯</a> ', |
---|
| 104 | ' http://à€à€Šà€Ÿà€¹à€°à€£.à€ªà€°à¥à€à¥à€·à€Ÿ ' => ' <a href="http://à€à€Šà€Ÿà€¹à€°à€£.à€ªà€°à¥à€à¥à€·à€Ÿ">à€à€Šà€Ÿà€¹à€°à€£.à€ªà€°à¥à€à¥à€·à€Ÿ</a> ', |
---|
| 105 | ' http://-.~_!$&\'()*+,;=:%40:80%2f::::::@example.com ' => ' <a href="http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com">-.~_!$&\'()*+,;=:%40:80%2f::::::@example.com</a> ', |
---|
| 106 | ' http://1337.net ' => ' <a href="http://1337.net">1337.net</a> ', |
---|
| 107 | ' http://a.b-c.de ' => ' <a href="http://a.b-c.de">a.b-c.de</a> ', |
---|
| 108 | ' http://223.255.255.254 ' => ' <a href="http://223.255.255.254">223.255.255.254</a> ', |
---|
| 109 | ' http://x and.co OK?' => ' http://x and.co OK?', |
---|
| 110 | ' http://foo.bar?q=Spaces should be encoded ' => ' <a href="http://foo.bar?q=Spaces">foo.bar?q=Spaces</a> should be encoded ', |
---|
| 111 | ' https://github.com/search?utf8=â&q=gif ' => ' <a href="https://github.com/search?utf8=â&q=gif">github.com/search?utf8=â&q=gif</a> ', |
---|
| 112 | ' https://github.com/search?q=gif&utf8=* ' => ' <a href="https://github.com/search?q=gif&utf8=*">github.com/search?q=gif&utf8=*</a> ', |
---|
| 113 | ' https://github.com/search?q=gif&utf8=â ' => ' <a href="https://github.com/search?q=gif&utf8=â">github.com/search?q=gif&utf8=â</a> ', |
---|
| 114 | |
---|
| 115 | // These are allowed to fuckup due to limitations in our ability to be omnipotent. |
---|
| 116 | ' <a href=http://www.example.com/ > http://www.example.com/</a> ' => ' <a href=http://www.example.com/ > <a href="http://www.example.com/">www.example.com/</a></a> ', |
---|
| 117 | ]; |
---|
| 118 | foreach ($urls as $input => $expected) { |
---|
| 119 | $result = hyperlinkTxt($input, false); |
---|
| 120 | $this->assertEquals($expected, $result, sprintf('Failed with input: %s', $input)); |
---|
| 121 | } |
---|
| 122 | } |
---|
| 123 | |
---|
[1] | 124 | } |
---|