]> git.wh0rd.org Git - tt-rss.git/commitdiff
add unit tests for fix_url() and fix a bug I discovered because of them - protocols...
authorChristian Weiske <cweiske@cweiske.de>
Wed, 10 Nov 2010 21:18:41 +0000 (22:18 +0100)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Thu, 11 Nov 2010 06:41:51 +0000 (09:41 +0300)
functions.php
tests/FunctionsTest.php [new file with mode: 0644]

index 715d29deef6dd36c57f560d37497aa0aeed1ee37..e73c0d16e277efaf29788ac4e0ef7914e93bafee 100644 (file)
 
                //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 (file)
index 0000000..61264ac
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+require_once dirname(__FILE__) . '/../functions.php';
+/**
+ * Unit tests for functions.php
+ *
+ * @author Christian Weiske <cweiske@php.net>
+ */
+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