From f679105cb2adc6de3e41527830fa0bfde36324d1 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 10 Nov 2010 23:09:03 +0100 Subject: add unit tests for rewrite_relative_url and fix a number of bugs in it --- tests/FunctionsTest.php | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'tests') diff --git a/tests/FunctionsTest.php b/tests/FunctionsTest.php index 163e985d0..f1bfa7451 100644 --- a/tests/FunctionsTest.php +++ b/tests/FunctionsTest.php @@ -177,6 +177,69 @@ HTM ); $this->assertFalse(url_is_html($this->tmpFile)); } + + + + /** + * Test rewrite_relative_url() with a relative path + */ + public function testRewriteRelativeUrlRelative() + { + $this->assertEquals( + 'http://tt-rss.org/foo/bar', + rewrite_relative_url('http://tt-rss.org', 'foo/bar') + ); + $this->assertEquals( + 'http://tt-rss.org/foo/bar', + rewrite_relative_url('http://tt-rss.org/', 'foo/bar') + ); + $this->assertEquals( + 'http://tt-rss.org/bar', + rewrite_relative_url('http://tt-rss.org/foo', 'bar') + ); + $this->assertEquals( + 'http://tt-rss.org/foo/bar', + rewrite_relative_url('http://tt-rss.org/foo/', 'bar') + ); + $this->assertEquals( + 'http://tt-rss.org/f/o/bar', + rewrite_relative_url('http://tt-rss.org/f/o/o', 'bar') + ); + $this->assertEquals( + 'http://tt-rss.org/f/o/o/bar', + rewrite_relative_url('http://tt-rss.org/f/o/o/', 'bar') + ); + } + + /** + * Test rewrite_relative_url() with an absolute path + */ + public function testRewriteRelativeUrlAbsolutePath() + { + $this->assertEquals( + 'http://tt-rss.org/bar/', + rewrite_relative_url('http://tt-rss.org/foo/', '/bar/') + ); + $this->assertEquals( + 'http://tt-rss.org/bar/', + rewrite_relative_url('http://tt-rss.org/so/what/is/next', '/bar/') + ); + $this->assertEquals( + 'http://tt-rss.org/bar/', + rewrite_relative_url('http://tt-rss.org/so/what/is/next/', '/bar/') + ); + } + + /** + * Test rewrite_relative_url() with an absolute URL + */ + public function testRewriteRelativeUrlAbsoluteUrl() + { + $this->assertEquals( + 'http://example.org/bar/', + rewrite_relative_url('http://tt-rss.org/foo/', 'http://example.org/bar/') + ); + } } ?> \ No newline at end of file -- cgit v1.2.3