Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions src/Foundation/Kernel/Hyperlinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public function url(string $path = ''): string
{
$path = $this->formatLink(trim($path, '/'));

if (str_starts_with($path, 'http')) {
return $path;
}

if ($this->hasSiteUrl()) {
return rtrim(rtrim(Config::getString('hyde.url'), '/')."/$path", '/');
}
Expand Down
18 changes: 17 additions & 1 deletion tests/Feature/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,23 @@ public function testUrlFunctionWithLocalhostBaseUrlButNoPath()
/** @covers ::url */
public function testUrlFunctionWithAlreadyQualifiedUrl()
{
$this->markTestSkipped('The url function does not check if the URL is already qualified.');
$this->assertSame('https://example.com/foo', url('https://example.com/foo'));
$this->assertSame('http://localhost/foo', url('http://localhost/foo'));
}

/** @covers ::url */
public function testUrlFunctionWithAlreadyQualifiedUrlWhenSiteUrlIsSet()
{
$this->app['config']->set(['hyde.url' => 'https://example.com']);

$this->assertSame('https://example.com/foo', url('https://example.com/foo'));
$this->assertSame('http://localhost/foo', url('http://localhost/foo'));
}

/** @covers ::url */
public function testUrlFunctionWithAlreadyQualifiedUrlWhenSiteUrlIsSetToSomethingElse()
{
$this->app['config']->set(['hyde.url' => 'my-site.com']);

$this->assertSame('https://example.com/foo', url('https://example.com/foo'));
$this->assertSame('http://localhost/foo', url('http://localhost/foo'));
Expand Down
45 changes: 45 additions & 0 deletions tests/Unit/Foundation/HyperlinksUrlPathHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,51 @@ public function testQualifiedUrlAcceptsMultipleSchemes()
$this->assertSame('http://example.com', $this->class->url());
}

public function testQualifiedUrlHelperWithAlreadyQualifiedUrl()
{
$this->assertSame('https://example.com/foo', $this->class->url('https://example.com/foo'));
$this->assertSame('http://localhost/foo', $this->class->url('http://localhost/foo'));
}

public function testQualifiedUrlHelperWithAlreadyQualifiedUrlWhenSiteUrlIsSet()
{
$this->app['config']->set(['hyde.url' => 'https://example.com']);

$this->assertSame('https://example.com/foo', $this->class->url('https://example.com/foo'));
$this->assertSame('http://localhost/foo', $this->class->url('http://localhost/foo'));
}

public function testQualifiedUrlHelperWithAlreadyQualifiedUrlWhenSiteUrlIsSetToSomethingElse()
{
$this->app['config']->set(['hyde.url' => 'my-site.com']);

$this->assertSame('https://example.com/foo', $this->class->url('https://example.com/foo'));
$this->assertSame('http://localhost/foo', $this->class->url('http://localhost/foo'));
}

public function testQualifiedUrlHelperWithAlreadyQualifiedUrlStillFormatsPath()
{
$this->assertSame('https://example.com/foo/bar.html', $this->class->url('https://example.com/foo/bar.html'));
$this->assertSame('http://localhost/foo/bar.html', $this->class->url('http://localhost/foo/bar.html'));
$this->assertSame('http://localhost/foo/bar', $this->class->url('http://localhost/foo/bar/'));
}

public function testQualifiedUrlHelperWithAlreadyQualifiedUrlStillFormatsPathWhenSiteUrlIsSet()
{
$this->app['config']->set(['hyde.url' => 'https://example.com']);
$this->assertSame('https://example.com/foo/bar.html', $this->class->url('https://example.com/foo/bar.html'));
$this->assertSame('http://localhost/foo/bar.html', $this->class->url('http://localhost/foo/bar.html'));
$this->assertSame('http://localhost/foo/bar', $this->class->url('http://localhost/foo/bar/'));
}

public function testQualifiedUrlHelperWithAlreadyQualifiedUrlStillFormatsPathWithPrettyUrls()
{
$this->app['config']->set(['hyde.url' => 'https://example.com', 'hyde.pretty_urls' => true]);
$this->assertSame('https://example.com/foo/bar', $this->class->url('https://example.com/foo/bar.html'));
$this->assertSame('http://localhost/foo/bar', $this->class->url('http://localhost/foo/bar.html'));
$this->assertSame('http://localhost/foo/bar', $this->class->url('http://localhost/foo/bar/'));
}

public function testQualifiedUrlThrowsExceptionWhenNoSiteUrlIsSet()
{
$this->withSiteUrl(null);
Expand Down