Skip to content

Commit 52a8589

Browse files
committed
test: add tests for base_url() and site_url() with $allowedHostnames
1 parent 9bc43d0 commit 52a8589

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/system/Helpers/URLHelper/SiteUrlTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,42 @@ public function testBaseURLService()
294294
base_url('controller/method', null)
295295
);
296296
}
297+
298+
public function testSiteURLWithAllowedHostname()
299+
{
300+
$_SERVER['HTTP_HOST'] = 'www.example.jp';
301+
$_SERVER['REQUEST_URI'] = '/public';
302+
$_SERVER['SCRIPT_NAME'] = '/public/index.php';
303+
304+
$this->config->baseURL = 'http://example.com/public/';
305+
$this->config->allowedHostnames = ['www.example.jp'];
306+
307+
// URI object and Config\App::$baseURL are updated in IncomingRequest constructor.
308+
$request = Services::incomingrequest($this->config);
309+
Services::injectMock('request', $request);
310+
311+
$this->assertSame(
312+
'http://www.example.jp/public/index.php/controller/method',
313+
site_url('controller/method', null, $this->config)
314+
);
315+
}
316+
317+
public function testBaseURLWithAllowedHostname()
318+
{
319+
$_SERVER['HTTP_HOST'] = 'www.example.jp';
320+
$_SERVER['REQUEST_URI'] = '/public';
321+
$_SERVER['SCRIPT_NAME'] = '/public/index.php';
322+
323+
$this->config->baseURL = 'http://example.com/public/';
324+
$this->config->allowedHostnames = ['www.example.jp'];
325+
326+
// URI object and Config\App::$baseURL are updated in IncomingRequest constructor.
327+
$request = Services::incomingrequest($this->config);
328+
Services::injectMock('request', $request);
329+
330+
$this->assertSame(
331+
'http://www.example.jp/public/controller/method',
332+
base_url('controller/method', null)
333+
);
334+
}
297335
}

0 commit comments

Comments
 (0)