Skip to content

Commit 5e518fa

Browse files
committed
feat: added tests for the fix on the SiteURIFactory
- I wrote some tests for the fixes I made to the SiteURIFactory - I reverted the retrieval of the config from the App class within SiteURIFactory, the reason is explained in the pull request: https://github.com/codeigniter4/CodeIgniter4/pull/9607/files/f60db2cf341e98d4cc3250d8eb0fbefab2cf660f#diff-2bdcab9f3781f203b6582279dec4886d261349628487f14baed6e8b53f3e772e
1 parent e588cd6 commit 5e518fa

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

system/HTTP/SiteURIFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function detectRoutePath(string $protocol = ''): string
111111
*/
112112
private function parseRequestURI(): string
113113
{
114-
$appConfig = $this->appConfig;
114+
$appConfig = config(App::class);
115115
$baseUrl = $appConfig->baseURL;
116116
$indexPage = $appConfig->indexPage;
117117
$baseUri = false;

tests/system/HTTP/SiteURIFactoryTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,44 @@ public static function provideCreateFromStringWithoutIndexPage(): iterable
171171
],
172172
];
173173
}
174+
175+
public function testCreateFromStringWithIndexPageSubDirCombinations(){
176+
$standardUrl = "http://localhost:8080";
177+
$subDirectoryAppsOptions = array(
178+
array(
179+
"subDir" => "",
180+
"indexPage" => ""
181+
),
182+
array(
183+
"subDir" => "",
184+
"indexPage" => "index.php"
185+
),
186+
array(
187+
"subDir" => "/subdir",
188+
"indexPage" => ""
189+
),
190+
array(
191+
"subDir" => "/subdir",
192+
"indexPage" => "index.php"
193+
),
194+
array(
195+
"subDir" => "/subdir/subsubdir",
196+
"indexPage" => "index.php"
197+
),
198+
);
199+
foreach($subDirectoryAppsOptions as $option){
200+
$route = "woot";
201+
config(App::class)->baseURL = $standardUrl . $option["subDir"];
202+
config(App::class)->indexPage = $option["indexPage"];
203+
204+
$_SERVER['PATH_INFO'] = '/' . $route;
205+
$_SERVER['REQUEST_URI'] = $option["subDir"] . "/" . $option["indexPage"] . $_SERVER['PATH_INFO'];
206+
$_SERVER['SCRIPT_NAME'] = $option["subDir"] . "/" .$option["indexPage"];
207+
$_SERVER['HTTP_HOST'] = $standardUrl;
208+
209+
$factory = $this->createSiteURIFactory();
210+
$detectedRoutePath = $factory->detectRoutePath();
211+
$this->assertSame($route, $detectedRoutePath);
212+
}
213+
}
174214
}

0 commit comments

Comments
 (0)