From 444537736be8625a5f2ba15de6c284d91666c011 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 10 Nov 2010 22:18:41 +0100 Subject: add unit tests for fix_url() and fix a bug I discovered because of them - protocols longer than "http" broke url fixing --- functions.php | 2 +- tests/FunctionsTest.php | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 tests/FunctionsTest.php diff --git a/functions.php b/functions.php index 715d29dee..e73c0d16e 100644 --- a/functions.php +++ b/functions.php @@ -6622,7 +6622,7 @@ //prepend slash if the URL has no slash in it // "http://www.example" -> "http://www.example/" - if (strpos($url, '/', 7) === false) { + if (strpos($url, '/', strpos($url, ':') + 3) === false) { $url .= '/'; } return $url; diff --git a/tests/FunctionsTest.php b/tests/FunctionsTest.php new file mode 100644 index 000000000..61264ac50 --- /dev/null +++ b/tests/FunctionsTest.php @@ -0,0 +1,61 @@ + + */ +class FunctionsTest extends PHPUnit_Framework_TestCase +{ + /** + * Test fix_url with feed:// urls + */ + public function testFixUrlFeed() + { + $this->assertEquals('http://tt-rss.org/', fix_url('feed://tt-rss.org')); + $this->assertEquals('http://tt-rss.org/', fix_url('feed://tt-rss.org/')); + } + + /** + * Test fix_url with non-http protocols + */ + public function testFixUrlProtocols() + { + $this->assertEquals('https://tt-rss.org/', fix_url('https://tt-rss.org')); + $this->assertEquals('ftp://tt-rss.org/', fix_url('ftp://tt-rss.org/')); + $this->assertEquals( + 'reallylongprotocolisthat://tt-rss.org/', + fix_url('reallylongprotocolisthat://tt-rss.org') + ); + } + + /** + * Test fix_url with domain names only + */ + public function testFixUrlDomainOnly() + { + $this->assertEquals('http://tt-rss.org/', fix_url('tt-rss.org')); + $this->assertEquals('http://tt-rss.org/', fix_url('tt-rss.org/')); + $this->assertEquals('http://tt-rss.org/', fix_url('http://tt-rss.org')); + $this->assertEquals('http://tt-rss.org/', fix_url('http://tt-rss.org/')); + } + + /** + * Test fix_url with domain + paths + */ + public function testFixUrlWithPaths() + { + $this->assertEquals('http://tt-rss.org/foo', fix_url('tt-rss.org/foo')); + + $this->assertEquals( + 'http://tt-rss.org/foo/bar/baz', + fix_url('tt-rss.org/foo/bar/baz') + ); + $this->assertEquals( + 'http://tt-rss.org/foo/bar/baz/', + fix_url('tt-rss.org/foo/bar/baz/') + ); + } +} + +?> \ No newline at end of file -- cgit v1.2.3