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

HydePHP v1.0.0 - Release Candidate Two #563

Merged
merged 7 commits into from
Mar 10, 2023
Prev Previous commit
Next Next commit
Merge pull request #1238 from hydephp/bugfixes
Update pretty relative index links to rewrite to `./` instead of `/` hydephp/develop@d15496b
  • Loading branch information
github-actions committed Mar 8, 2023
commit 6832e69302016c3e2f5b52af7bb658167fc912a5
2 changes: 1 addition & 1 deletion resources/views/pages/404.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
Sorry, the page you are looking for could not be found.
</p>

<a href="{{ config('hyde.url') ?? '/' }}">
<a href="{{ config('hyde.url') ?? './' }}">
<button
class="bg-transparent text-grey-darkest font-bold uppercase tracking-wide py-3 px-6 border-2 border-grey-light hover:border-grey rounded-lg">
Go Home
Expand Down
4 changes: 4 additions & 0 deletions src/Foundation/Kernel/Hyperlinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public function relativeLink(string $destination): string
}
$route .= $this->formatLink($destination);

if (Config::getBool('hyde.pretty_urls', false) === true && $route === '/') {
return './';
}

return str_replace('//', '/', $route);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/BreadcrumbsComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function testCanGenerateBreadcrumbsForIndexPageWithPrettyUrls()
self::mockConfig(['hyde.pretty_urls' => true]);
$this->mockPage(new MarkdownPage('index'));

$this->assertSame(['/' => 'Home'], (new BreadcrumbsComponent())->breadcrumbs);
$this->assertSame(['./' => 'Home'], (new BreadcrumbsComponent())->breadcrumbs);
}

public function testCanGenerateBreadcrumbsForNestedPageWithPrettyUrls()
Expand Down
69 changes: 43 additions & 26 deletions tests/Unit/Foundation/HyperlinkFileHelperRelativeLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,99 +5,116 @@
namespace Hyde\Framework\Testing\Unit\Foundation;

use Hyde\Hyde;
use Hyde\Testing\TestCase;
use Hyde\Support\Facades\Render;
use Hyde\Support\Models\RenderData;
use Hyde\Testing\InteractsWithPages;
use Hyde\Testing\UnitTestCase;
use Illuminate\Support\Facades\View;
use Illuminate\View\Factory;
use Mockery;

/**
* @covers \Hyde\Foundation\Kernel\Hyperlinks::relativeLink
*/
class HyperlinkFileHelperRelativeLinkTest extends TestCase
class HyperlinkFileHelperRelativeLinkTest extends UnitTestCase
{
public function test_helper_returns_string_as_is_if_current_is_not_set()
use InteractsWithPages;

protected static bool $needsKernel = true;
protected static bool $needsConfig = true;

protected function setUp(): void
{
Render::swap(new RenderData());
View::swap(Mockery::mock(Factory::class)->makePartial());
}

public function testHelperReturnsStringAsIsIfCurrentIsNotSet()
{
$this->assertEquals('foo/bar.html', Hyde::relativeLink('foo/bar.html'));
}

public function test_helper_injects_proper_number_of_doubles_slash()
public function testHelperInjectsProperNumberOfDoublesSlash()
{
$this->mockCurrentPage('foo/bar.html');
$this->assertEquals('../foo.html', Hyde::relativeLink('foo.html'));
}

public function test_helper_injects_proper_number_of_doubles_slash_for_deeply_nested_paths()
public function testHelperInjectsProperNumberOfDoublesSlashForDeeplyNestedPaths()
{
$this->mockCurrentPage('foo/bar/baz/qux.html');
$this->assertEquals('../../../foo.html', Hyde::relativeLink('foo.html'));
}

public function test_helper_handles_destination_without_file_extension()
public function testHelperHandlesDestinationWithoutFileExtension()
{
$this->mockCurrentPage('foo/bar.html');
$this->assertEquals('../foo', Hyde::relativeLink('foo'));
}

public function test_helper_handles_current_without_file_extension()
public function testHelperHandlesCurrentWithoutFileExtension()
{
$this->mockCurrentPage('foo/bar');
$this->assertEquals('../foo.html', Hyde::relativeLink('foo.html'));
}

public function test_helper_handles_case_without_any_file_extensions()
public function testHelperHandlesCaseWithoutAnyFileExtensions()
{
$this->mockCurrentPage('foo/bar');
$this->assertEquals('../foo', Hyde::relativeLink('foo'));
}

public function test_helper_handles_case_with_mixed_file_extensions()
public function testHelperHandlesCaseWithMixedFileExtensions()
{
$this->mockCurrentPage('foo/bar.md');
$this->assertEquals('../foo.md', Hyde::relativeLink('foo.md'));
$this->mockCurrentPage('foo/bar.txt');
$this->assertEquals('../foo.txt', Hyde::relativeLink('foo.txt'));
}

public function test_helper_handles_different_file_extensions()
public function testHelperHandlesDifferentFileExtensions()
{
$this->mockCurrentPage('foo/bar');
$this->assertEquals('../foo.png', Hyde::relativeLink('foo.png'));
$this->assertEquals('../foo.css', Hyde::relativeLink('foo.css'));
$this->assertEquals('../foo.js', Hyde::relativeLink('foo.js'));
}

public function test_helper_returns_pretty_url_if_enabled_and_destination_is_a_html_file()
public function testHelperReturnsPrettyUrlIfEnabledAndDestinationIsAHtmlFile()
{
config(['hyde.pretty_urls' => true]);
self::mockConfig(['hyde.pretty_urls' => true]);
$this->mockCurrentPage('foo/bar.html');
$this->assertEquals('../foo', Hyde::relativeLink('foo.html'));
}

public function test_helper_method_does_not_require_current_path_to_be_html_to_use_pretty_urls()
public function testHelperMethodDoesNotRequireCurrentPathToBeHtmlToUsePrettyUrls()
{
config(['hyde.pretty_urls' => true]);
self::mockConfig(['hyde.pretty_urls' => true]);
$this->mockCurrentPage('foo/bar');
$this->assertEquals('../foo', Hyde::relativeLink('foo.html'));
}

public function test_helper_returns_does_not_return_pretty_url_if_when_enabled_but_and_destination_is_not_a_html_file()
public function testHelperReturnsDoesNotReturnPrettyUrlIfWhenEnabledButAndDestinationIsNotAHtmlFile()
{
config(['hyde.pretty_urls' => true]);
self::mockConfig(['hyde.pretty_urls' => true]);
$this->mockCurrentPage('foo/bar.html');
$this->assertEquals('../foo.png', Hyde::relativeLink('foo.png'));
}

public function test_helper_rewrites_index_when_using_pretty_urls()
public function testHelperRewritesIndexWhenUsingPrettyUrls()
{
config(['hyde.pretty_urls' => true]);
self::mockConfig(['hyde.pretty_urls' => true]);
$this->mockCurrentPage('foo.html');
$this->assertEquals('/', Hyde::relativeLink('index.html'));
$this->assertEquals('./', Hyde::relativeLink('index.html'));
$this->mockCurrentPage('foo/bar.html');
$this->assertEquals('../', Hyde::relativeLink('index.html'));
$this->mockCurrentPage('foo/bar/baz.html');
$this->assertEquals('../../', Hyde::relativeLink('index.html'));
}

public function test_helper_does_not_rewrite_index_when_not_using_pretty_urls()
public function testHelperDoesNotRewriteIndexWhenNotUsingPrettyUrls()
{
config(['hyde.pretty_urls' => false]);
self::mockConfig(['hyde.pretty_urls' => false]);
$this->mockCurrentPage('foo.html');
$this->assertEquals('index.html', Hyde::relativeLink('index.html'));
$this->mockCurrentPage('foo/bar.html');
Expand All @@ -106,9 +123,9 @@ public function test_helper_does_not_rewrite_index_when_not_using_pretty_urls()
$this->assertEquals('../../index.html', Hyde::relativeLink('index.html'));
}

public function test_helper_rewrites_documentation_page_index_when_using_pretty_urls()
public function testHelperRewritesDocumentationPageIndexWhenUsingPrettyUrls()
{
config(['hyde.pretty_urls' => true]);
self::mockConfig(['hyde.pretty_urls' => true]);
$this->mockCurrentPage('foo.html');
$this->assertEquals('docs/', Hyde::relativeLink('docs/index.html'));
$this->mockCurrentPage('docs.html');
Expand All @@ -119,9 +136,9 @@ public function test_helper_rewrites_documentation_page_index_when_using_pretty_
$this->assertEquals('../docs/', Hyde::relativeLink('docs/index.html'));
}

public function test_helper_does_not_rewrite_documentation_page_index_when_not_using_pretty_urls()
public function testHelperDoesNotRewriteDocumentationPageIndexWhenNotUsingPrettyUrls()
{
config(['hyde.pretty_urls' => false]);
self::mockConfig(['hyde.pretty_urls' => false]);
$this->mockCurrentPage('foo.html');
$this->assertEquals('docs/index.html', Hyde::relativeLink('docs/index.html'));
$this->mockCurrentPage('docs.html');
Expand All @@ -132,7 +149,7 @@ public function test_helper_does_not_rewrite_documentation_page_index_when_not_u
$this->assertEquals('../docs/index.html', Hyde::relativeLink('docs/index.html'));
}

public function test_helper_does_not_rewrite_already_processed_links()
public function testHelperDoesNotRewriteAlreadyProcessedLinks()
{
$this->assertEquals('../foo', Hyde::relativeLink('../foo'));
}
Expand Down