Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

site_url tests #4063

Merged
merged 1 commit into from
Jan 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
211 changes: 124 additions & 87 deletions tests/system/Helpers/URLHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,112 +42,149 @@ public function tearDown(): void
}

//--------------------------------------------------------------------
// Test site_url

public function testSiteURLBasics()
{
$request = Services::request($this->config);
$request->uri = new URI('http://example.com/');

Services::injectMock('request', $request);

$this->assertEquals('http://example.com/index.php', site_url('', null, $this->config));
}

public function testSiteURLHTTPS()
{
$_SERVER['HTTPS'] = 'on';

$request = Services::request($this->config);
$request->uri = new URI('http://example.com/');

Services::injectMock('request', $request);

$this->assertEquals('https://example.com/index.php', site_url('', null, $this->config));
}

public function testSiteURLNoTrailingSlash()
{
$this->config->baseURL = 'http://example.com';
$request = Services::request($this->config);
$request->uri = new URI('http://example.com/index.php');

Services::injectMock('request', $request);

$this->assertEquals('http://example.com/index.php', site_url('', null, $this->config));
}

public function testSiteURLNoIndex()
{
$this->config->indexPage = '';
$request = Services::request($this->config);
$request->uri = new URI('http://example.com/');

Services::injectMock('request', $request);

$this->assertEquals('http://example.com/', site_url('', null, $this->config));
}

public function testSiteURLDifferentIndex()
{
$this->config->indexPage = 'banana.php';
$request = Services::request($this->config);
$request->uri = new URI('http://example.com/');

Services::injectMock('request', $request);

$this->assertEquals('http://example.com/banana.php', site_url('', null, $this->config));
}

public function testSiteURLNoIndexButPath()
/**
* @dataProvider siteUrlProvider
*/
public function testSiteUrl($baseURL, $indexPage, $param, $protocol, $expected)
{
$this->config->indexPage = '';
$request = Services::request($this->config);
$request->uri = new URI('http://example.com/');

Services::injectMock('request', $request);
// Set the config
$this->config->baseURL = $baseURL;
$this->config->indexPage = $indexPage;

$this->assertEquals('http://example.com/abc', site_url('abc', null, $this->config));
}

public function testSiteURLAttachesPath()
{
// Mock the Request
$request = Services::request($this->config);
$request->uri = new URI('http://example.com/');

Services::injectMock('request', $request);

$this->assertEquals('http://example.com/index.php/foo', site_url('foo', null, $this->config));
$this->assertEquals($expected, site_url($param, $protocol, $this->config));
}

public function testSiteURLAttachesScheme()
public function siteUrlProvider()
{
$request = Services::request($this->config);
$request->uri = new URI('http://example.com/');

Services::injectMock('request', $request);

$this->assertEquals('ftp://example.com/index.php/foo', site_url('foo', 'ftp', $this->config));
// baseURL, indexPage, param, protocol, expected
return [
[
'http://example.com/',
'index.php',
'',
null,
'http://example.com/index.php',
],
[
'http://example.com',
'index.php',
'',
null,
'http://example.com/index.php',
],
[
'http://example.com/',
'',
'',
null,
'http://example.com/',
],
[
'http://example.com/',
'banana.php',
'',
null,
'http://example.com/banana.php',
],
[
'http://example.com/',
'',
'abc',
null,
'http://example.com/abc',
],
[
'http://example.com/public/',
'index.php',
'',
null,
'http://example.com/public/index.php',
],
[
'http://example.com/public/',
'',
'',
null,
'http://example.com/public/',
],
[
'http://example.com/public',
'',
'',
null,
'http://example.com/public/',
],
[
'http://example.com/public',
'index.php',
'/',
null,
'http://example.com/public/index.php/',
],
[
'http://example.com/public/',
'index.php',
'/',
null,
'http://example.com/public/index.php/',
],
[
'http://example.com/',
'index.php',
'foo',
null,
'http://example.com/index.php/foo',
],
[
'http://example.com/public',
'index.php',
'foo',
null,
'http://example.com/public/index.php/foo',
],
[
'http://example.com/',
'index.php',
'foo',
'ftp',
'ftp://example.com/index.php/foo',
],
[
'http://example.com/',
'index.php',
'news/local/123',
null,
'http://example.com/index.php/news/local/123',
],
[
'http://example.com/',
'index.php',
[
'news',
'local',
'123',
], null,
'http://example.com/index.php/news/local/123',
],
];
}

public function testSiteURLExample()
public function testSiteURLHTTPS()
{
$request = Services::request($this->config);
$request->uri = new URI('http://example.com/');

Services::injectMock('request', $request);

$this->assertEquals('http://example.com/index.php/news/local/123', site_url('news/local/123', null, $this->config));
}
$_SERVER['HTTPS'] = 'on';

public function testSiteURLSegments()
{
$request = Services::request($this->config);
$request->uri = new URI('http://example.com/');

Services::injectMock('request', $request);

$this->assertEquals('http://example.com/index.php/news/local/123', site_url(['news', 'local', '123'], null, $this->config));
$this->assertEquals('https://example.com/index.php', site_url('', null, $this->config));
}

/**
Expand Down