Skip to content

Commit

Permalink
Merge branch 'master' into 2.x-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Jun 29, 2024
2 parents 786d81e + 44678c2 commit 3f06280
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/framework/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 packages/framework/tests/Feature/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,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
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

0 comments on commit 3f06280

Please sign in to comment.