From 935a529092f3d230a354195f92df19b265d24a47 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 14 Oct 2022 09:51:18 +0900 Subject: [PATCH 1/2] test: remove $request->uri and fix incorrect assertions --- tests/system/HTTP/URITest.php | 28 ++++++++++++++-------------- tests/system/Pager/PagerTest.php | 4 ++-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/system/HTTP/URITest.php b/tests/system/HTTP/URITest.php index 8e6bcb95ede9..30e74decbb69 100644 --- a/tests/system/HTTP/URITest.php +++ b/tests/system/HTTP/URITest.php @@ -863,56 +863,56 @@ public function testSetBadSegmentSilent() public function testBasedNoIndex() { - $this->resetServices(); - $_SERVER['HTTP_HOST'] = 'example.com'; $_SERVER['REQUEST_URI'] = '/ci/v4/controller/method'; + $this->resetServices(); + $config = new App(); - $config->baseURL = 'http://example.com/ci/v4'; + $config->baseURL = 'http://example.com/ci/v4/'; $config->indexPage = 'index.php'; - $request = Services::request($config); - $request->uri = new URI('http://example.com/ci/v4/controller/method'); + Factories::injectMock('config', 'App', $config); + $request = Services::request($config); Services::injectMock('request', $request); // going through request $this->assertSame('http://example.com/ci/v4/controller/method', (string) $request->getUri()); - $this->assertSame('/ci/v4/controller/method', $request->getUri()->getPath()); + $this->assertSame('ci/v4/controller/method', $request->getUri()->getPath()); // standalone $uri = new URI('http://example.com/ci/v4/controller/method'); $this->assertSame('http://example.com/ci/v4/controller/method', (string) $uri); $this->assertSame('/ci/v4/controller/method', $uri->getPath()); - $this->assertSame($uri->getPath(), $request->getUri()->getPath()); + $this->assertSame($uri->getPath(), '/' . $request->getUri()->getPath()); } public function testBasedWithIndex() { - $this->resetServices(); - $_SERVER['HTTP_HOST'] = 'example.com'; $_SERVER['REQUEST_URI'] = '/ci/v4/index.php/controller/method'; + $this->resetServices(); + $config = new App(); - $config->baseURL = 'http://example.com/ci/v4'; + $config->baseURL = 'http://example.com/ci/v4/'; $config->indexPage = 'index.php'; - $request = Services::request($config); - $request->uri = new URI('http://example.com/ci/v4/index.php/controller/method'); + Factories::injectMock('config', 'App', $config); + $request = Services::request($config); Services::injectMock('request', $request); // going through request $this->assertSame('http://example.com/ci/v4/index.php/controller/method', (string) $request->getUri()); - $this->assertSame('/ci/v4/index.php/controller/method', $request->getUri()->getPath()); + $this->assertSame('ci/v4/index.php/controller/method', $request->getUri()->getPath()); // standalone $uri = new URI('http://example.com/ci/v4/index.php/controller/method'); $this->assertSame('http://example.com/ci/v4/index.php/controller/method', (string) $uri); $this->assertSame('/ci/v4/index.php/controller/method', $uri->getPath()); - $this->assertSame($uri->getPath(), $request->getUri()->getPath()); + $this->assertSame($uri->getPath(), '/' . $request->getUri()->getPath()); } public function testForceGlobalSecureRequests() diff --git a/tests/system/Pager/PagerTest.php b/tests/system/Pager/PagerTest.php index 573911ffa7af..554df08ec5d0 100644 --- a/tests/system/Pager/PagerTest.php +++ b/tests/system/Pager/PagerTest.php @@ -467,9 +467,9 @@ public function testBasedURI() $config = new App(); $config->baseURL = 'http://example.com/ci/v4/'; $config->indexPage = 'fc.php'; - $request = Services::request($config); - $request->uri = new URI('http://example.com/ci/v4/x/y'); + Factories::injectMock('config', 'App', $config); + $request = Services::request($config); Services::injectMock('request', $request); $this->config = new PagerConfig(); From 027e9e68b65b29aac7b6de6ef5da4ad0f60e964d Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 14 Oct 2022 09:59:17 +0900 Subject: [PATCH 2/2] test: fix incorrect config The test is when BaseURL does not have `index.php`, so $config->indexPage should be empty string. --- tests/system/HTTP/URITest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/HTTP/URITest.php b/tests/system/HTTP/URITest.php index 30e74decbb69..44ebb67e5e85 100644 --- a/tests/system/HTTP/URITest.php +++ b/tests/system/HTTP/URITest.php @@ -870,7 +870,7 @@ public function testBasedNoIndex() $config = new App(); $config->baseURL = 'http://example.com/ci/v4/'; - $config->indexPage = 'index.php'; + $config->indexPage = ''; Factories::injectMock('config', 'App', $config); $request = Services::request($config);