-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Improve behaviour when a site URL is not explicitly set #1726
Merged
caendesilva
merged 16 commits into
master
from
ensure-a-better-state-when-a-site-url-is-not-set
Jun 13, 2024
Merged
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b3e93bf
Introduce local variable
caendesilva 3cfa8a5
Method `Hyde::url()` now resolves relative paths instead of throwing
caendesilva ef6598e
Method `Hyde::hasSiteUrl()` now returns false when URL is for localhost
caendesilva 4e7c28a
Create SitesWithoutBaseUrlAreHandledGracefullyTest.php
caendesilva 3da6869
Document test abstract
caendesilva f5649f6
Merge branch 'master' into ensure-a-better-state-when-a-site-url-is-n…
caendesilva aa0e007
Create initial test
caendesilva 099e8cb
Add more test cases
caendesilva 11d4030
Refactor tests to use PHPUnit data provider for multiple page classes
caendesilva 9f79f4e
Add green path state test
caendesilva 31c202f
Cleanup test code
caendesilva d2286f2
Merge branch 'master' into ensure-a-better-state-when-a-site-url-is-n…
caendesilva 8fbcd10
Update RELEASE_NOTES.md
caendesilva a6a1ac0
Update RELEASE_NOTES.md
caendesilva b33407b
Update method documentation
caendesilva 0bcb9f7
Simplify check to use evaluated conditions by called method
caendesilva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
packages/framework/tests/Feature/SitesWithoutBaseUrlAreHandledGracefullyTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Hyde\Framework\Testing\Feature; | ||
|
||
use Hyde\Hyde; | ||
use Hyde\Testing\TestCase; | ||
use Hyde\Pages\MarkdownPage; | ||
use Hyde\Pages\MarkdownPost; | ||
use Hyde\Pages\DocumentationPage; | ||
|
||
/** | ||
* High level test to ensure that sites without a base URL are handled gracefully. | ||
* | ||
* For example: In case a user forgot to set a base URL, we don't want their site | ||
* to have localhost links in the compiled HTML output since that would break | ||
* things when deployed to production. So we fall back to relative links. | ||
* | ||
* Some things like sitemaps and RSS feeds cannot be generated without a base URL, | ||
* as their schemas generally do not allow relative URLs. In those cases, we | ||
* don't generate files at all, and we don't add any links to them either. | ||
* | ||
* @coversNothing This test is not testing a specific class, but a general feature of the framework. | ||
*/ | ||
class SitesWithoutBaseUrlAreHandledGracefullyTest extends TestCase | ||
{ | ||
public static function pageClassProvider(): array | ||
{ | ||
return [ | ||
[MarkdownPage::class], | ||
[MarkdownPost::class], | ||
[DocumentationPage::class], | ||
]; | ||
} | ||
|
||
/** @dataProvider pageClassProvider */ | ||
public function testLocalhostLinksAreNotAddedToCompiledHtmlWhenBaseUrlIsNull(string $class) | ||
{ | ||
config(['hyde.url' => null]); | ||
|
||
$this->assertStringNotContainsString('http://localhost', $this->getHtml($class)); | ||
} | ||
|
||
/** @dataProvider pageClassProvider */ | ||
public function testLocalhostLinksAreNotAddedToCompiledHtmlWhenBaseUrlIsNotSet(string $class) | ||
{ | ||
config(['hyde.url' => '']); | ||
|
||
$this->assertStringNotContainsString('http://localhost', $this->getHtml($class)); | ||
} | ||
|
||
/** @dataProvider pageClassProvider */ | ||
public function testLocalhostLinksAreNotAddedToCompiledHtmlWhenBaseUrlIsSetToLocalhost(string $class) | ||
{ | ||
config(['hyde.url' => 'http://localhost']); | ||
|
||
$this->assertStringNotContainsString('http://localhost', $this->getHtml($class)); | ||
} | ||
|
||
/** @dataProvider pageClassProvider */ | ||
public function testSiteUrlLinksAreAddedToCompiledHtmlWhenBaseUrlIsSetToValidUrl(string $class) | ||
{ | ||
config(['hyde.url' => 'https://example.com']); | ||
|
||
$this->assertStringNotContainsString('http://localhost', $this->getHtml($class)); | ||
} | ||
|
||
protected function getHtml(string $class): string | ||
{ | ||
$page = new $class('foo'); | ||
|
||
Hyde::shareViewData($page); | ||
|
||
return $page->compile(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might consider this for deprecation