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

Breaking: Reorder AbstractMarkdownPage constructor argument positions, putting the identifier first #329

Merged
merged 1 commit into from
Aug 3, 2022
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
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The identifier property is closely related to the page model's route key propert
### Changed
- Breaking: Rename AbstractMarkdownPage constructor parameter `slug` to `identifier`
- Breaking: Rename AbstractPage property `slug` to `identifier`
- Breaking: Change `AbstractMarkdownPage` constructor argument positions, putting `identifier` first
- Begin changing references to slugs to identifiers, see motivation above

### Deprecated
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/Contracts/AbstractMarkdownPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract class AbstractMarkdownPage extends AbstractPage

public static string $fileExtension = '.md';

public function __construct(array $matter = [], string $body = '', ?string $title = null, string $identifier = '', ?MarkdownDocument $markdownDocument = null)
public function __construct(string $identifier = '', array $matter = [], string $body = '', ?string $title = null, ?MarkdownDocument $markdownDocument = null)
{
$this->matter = $matter;
$this->body = $body;
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/Models/Pages/DocumentationPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DocumentationPage extends AbstractMarkdownPage

public function __construct(array $matter = [], string $body = '', string $title = '', string $identifier = '')
{
parent::__construct($matter, $body, $title, $identifier);
parent::__construct($identifier, $matter, $body, $title);
}

/** @inheritDoc */
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/Models/Pages/MarkdownPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MarkdownPost extends AbstractMarkdownPage

public function __construct(array $matter = [], string $body = '', string $title = '', string $identifier = '')
{
parent::__construct($matter, $body, $title, $identifier);
parent::__construct($identifier, $matter, $body, $title);

$this->constructAuthor();
$this->constructMetadata();
Expand Down
18 changes: 9 additions & 9 deletions packages/framework/tests/Feature/AbstractPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function test_all_returns_collection_of_all_source_files_parsed_into_the_
{
Hyde::touch(('_pages/foo.md'));
$this->assertEquals(
collect([new MarkdownPage([], '', 'Foo', 'foo')]),
collect([new MarkdownPage('foo', [], '', 'Foo')]),
MarkdownPage::all()
);
unlink(Hyde::path('_pages/foo.md'));
Expand Down Expand Up @@ -132,35 +132,35 @@ public function test_get_output_location_trims_trailing_slashes_from_basename()

public function test_get_current_page_path_returns_output_directory_and_basename()
{
$page = new MarkdownPage([], '', '', 'foo');
$page = new MarkdownPage('foo', [], '', '');
$this->assertEquals('foo', $page->getCurrentPagePath());
}

public function test_get_current_page_path_returns_output_directory_and_basename_for_configured_directory()
{
MarkdownPage::$outputDirectory = 'foo';
$page = new MarkdownPage([], '', '', 'bar');
$page = new MarkdownPage('bar', [], '', '');
$this->assertEquals('foo/bar', $page->getCurrentPagePath());
}

public function test_get_current_page_path_trims_trailing_slashes_from_directory_setting()
{
MarkdownPage::$outputDirectory = '/foo/\\';
$page = new MarkdownPage([], '', '', 'bar');
$page = new MarkdownPage('bar', [], '', '');
$this->assertEquals('foo/bar', $page->getCurrentPagePath());
}

public function test_get_output_path_returns_current_page_path_with_html_extension_appended()
{
$page = new MarkdownPage([], '', '', 'foo');
$page = new MarkdownPage('foo', [], '', '');
$this->assertEquals('foo.html', $page->getOutputPath());
}

public function test_get_source_path_returns_qualified_basename()
{
$this->assertEquals(
MarkdownPage::qualifyBasename('foo'),
(new MarkdownPage(identifier: 'foo'))->getSourcePath()
(new MarkdownPage('foo'))->getSourcePath()
);
}

Expand Down Expand Up @@ -285,7 +285,7 @@ public function test_abstract_markdown_page_markdown_helper_returns_the_configur

public function test_abstract_markdown_page_constructor_constructs_dynamic_title_automatically()
{
$page = new MarkdownPage(['title' => 'Foo']);
$page = new MarkdownPage('', ['title' => 'Foo']);
$this->assertEquals('Foo', $page->title);
}

Expand Down Expand Up @@ -315,12 +315,12 @@ public function test_get_route_returns_page_route()

public function test_html_title_returns_site_name_plus_page_title()
{
$this->assertEquals('HydePHP - Foo', (new MarkdownPage(['title' => 'Foo']))->htmlTitle());
$this->assertEquals('HydePHP - Foo', (new MarkdownPage('', ['title' => 'Foo']))->htmlTitle());
}

public function test_html_title_can_be_overridden()
{
$this->assertEquals('HydePHP - Bar', (new MarkdownPage(['title' => 'Foo']))->htmlTitle('Bar'));
$this->assertEquals('HydePHP - Bar', (new MarkdownPage('', ['title' => 'Foo']))->htmlTitle('Bar'));
}

public function test_html_title_returns_site_name_if_no_page_title()
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/tests/Feature/StaticPageBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function test_can_build_markdown_post()

public function test_can_build_markdown_page()
{
$page = new MarkdownPage([], '# Body', 'Title', 'foo');
$page = new MarkdownPage('foo', [], '# Body', 'Title');

new StaticPageBuilder($page, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function test_can_use_rss_feed_link_adds_meta_link_for_markdown_posts()

public function test_can_use_rss_feed_link_adds_meta_link_for_post_related_pages()
{
$page = new MarkdownPage([], '', identifier: 'posts');
$page = new MarkdownPage(identifier: 'posts', matter: [], body: '', title: 'posts');

$this->assertStringContainsString(
'<link rel="alternate" type="application/rss+xml" title="HydePHP RSS Feed" href="foo/feed.xml" />',
Expand All @@ -41,7 +41,7 @@ public function test_can_use_rss_feed_link_adds_meta_link_for_post_related_pages

public function test_can_use_rss_feed_link_adds_meta_link_for_markdown_index_page()
{
$page = new MarkdownPage([], '', identifier: 'index');
$page = new MarkdownPage(identifier: 'index', matter: [], body: '', title: 'index');

$this->assertStringContainsString(
'<link rel="alternate" type="application/rss+xml" title="HydePHP RSS Feed" href="foo/feed.xml" />',
Expand Down