From 7699c850a4b38d9242576640079ca55185b0ea82 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 20 Feb 2023 16:46:29 +0900 Subject: [PATCH] test: add test cases for path starting with slash --- tests/system/HTTP/SiteURITest.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/system/HTTP/SiteURITest.php b/tests/system/HTTP/SiteURITest.php index 807ac03f6ced..e00c65b0c89e 100644 --- a/tests/system/HTTP/SiteURITest.php +++ b/tests/system/HTTP/SiteURITest.php @@ -50,6 +50,17 @@ public function testConstructorRelativePath() $this->assertSame('/index.php/one/two', $uri->getPath()); } + public function testConstructorRelativePathStartWithSlash() + { + $config = new App(); + + $uri = new SiteURI($config, '/one/two'); + + $this->assertSame('http://example.com/index.php/one/two', (string) $uri); + $this->assertSame('one/two', $uri->getRoutePath()); + $this->assertSame('/index.php/one/two', $uri->getPath()); + } + public function testConstructorRelativePathWithQuery() { $config = new App(); @@ -190,6 +201,22 @@ public function testSetPath() $this->assertSame(2, $uri->getTotalSegments()); } + public function testSetPathStartWithSlash() + { + $config = new App(); + + $uri = new SiteURI($config); + + $uri->setPath('/test/method'); + + $this->assertSame('http://example.com/index.php/test/method', (string) $uri); + $this->assertSame('test/method', $uri->getRoutePath()); + $this->assertSame('/index.php/test/method', $uri->getPath()); + $this->assertSame(['test', 'method'], $uri->getSegments()); + $this->assertSame('test', $uri->getSegment(1)); + $this->assertSame(2, $uri->getTotalSegments()); + } + public function testSetPathSubfolder() { $config = new App();