From 69c1c629927cd78286fc6c8d61b5b5ad78245508 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 24 Oct 2023 22:27:27 +0300 Subject: add a workaround for make_self_url() when invoked off /api/ endpoint, add unit tests for this method --- tests/SelfUrlPathTest.php | 106 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 tests/SelfUrlPathTest.php (limited to 'tests/SelfUrlPathTest.php') diff --git a/tests/SelfUrlPathTest.php b/tests/SelfUrlPathTest.php new file mode 100644 index 000000000..b8892f84b --- /dev/null +++ b/tests/SelfUrlPathTest.php @@ -0,0 +1,106 @@ +assertEquals( + 'http://example.com/tt-rss', + Config::get_self_url(true) + ); + + } + + public function test_b(): void { + $_SERVER = []; + + $_SERVER["HTTP_X_FORWARDED_PROTO"] = "https"; + $_SERVER["HTTP_HOST"] = "example.com"; + $_SERVER["REQUEST_URI"] = "/api/"; + + $this->assertEquals( + 'https://example.com', + Config::get_self_url(true) + ); + } + + public function test_c(): void { + $_SERVER = []; + + $_SERVER["HTTP_X_FORWARDED_PROTO"] = "https"; + $_SERVER["HTTP_HOST"] = "example.com"; + $_SERVER["REQUEST_URI"] = "/api/index.php"; + + $this->assertEquals( + 'https://example.com', + Config::get_self_url(true) + ); + } + + public function test_d(): void { + $_SERVER = []; + + $_SERVER["HTTP_X_FORWARDED_PROTO"] = "https"; + $_SERVER["HTTP_HOST"] = "example.com"; + $_SERVER["REQUEST_URI"] = "/api//"; + + $this->assertEquals( + 'https://example.com', + Config::get_self_url(true) + ); + } + + public function test_e(): void { + $_SERVER = []; + + $_SERVER["HTTP_X_FORWARDED_PROTO"] = "https"; + $_SERVER["HTTP_HOST"] = "example.com"; + $_SERVER["REQUEST_URI"] = "/"; + + $this->assertEquals( + 'https://example.com', + Config::get_self_url(true) + ); + } + + public function test_f(): void { + $_SERVER = []; + + $_SERVER["HTTP_HOST"] = "example.com"; + $_SERVER["REQUEST_URI"] = "/tt-rss/index.php"; + + $this->assertEquals( + 'http://example.com/tt-rss', + Config::get_self_url(true) + ); + } + + public function test_g(): void { + $_SERVER = []; + + $_SERVER["HTTP_HOST"] = "example.com"; + $_SERVER["REQUEST_URI"] = "/tt-rss/"; + + $this->assertEquals( + 'http://example.com/tt-rss', + Config::get_self_url(true) + ); + } + + public function test_h(): void { + $_SERVER = []; + + $_SERVER["HTTP_HOST"] = "example.com"; + $_SERVER["REQUEST_URI"] = "/tt-rss"; + + $this->assertEquals( + 'http://example.com/tt-rss', + Config::get_self_url(true) + ); + } +} -- cgit v1.2.3-54-g00ecf