Skip to content

Commit

Permalink
Merge pull request #140 from hydephp/fix-139-error-caused-in-generate…
Browse files Browse the repository at this point in the history
…snavigationmenu-when-having-a-page-file-starting-with-an-underscore-after-updating-to-v044x

Fix bug causing files starting with underscores to add empty values to the file collection array hydephp/develop@a6aada7
  • Loading branch information
github-actions committed Jul 2, 2022
1 parent 1f3da75 commit 718329b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/Services/CollectionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ public static function getSourceFileListForModel(string $model): array|false
return false;
}

return array_map(function ($filepath) use ($model) {
$files = [];
foreach (glob(Hyde::path($model::qualifyBasename('*'))) as $filepath) {
if (! str_starts_with(basename($filepath), '_')) {
return basename($filepath, $model::getFileExtension());
$files[] = basename($filepath, $model::getFileExtension());
}
}, glob(Hyde::path($model::qualifyBasename('*'))));
}

return $files;
}

/**
Expand Down
15 changes: 15 additions & 0 deletions tests/Feature/GeneratesNavigationMenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public function test_generated_links_include_documentation_pages()
$this->assertIsArray($generator->links);

$this->assertContains('docs/index.html', Arr::flatten($generator->links));

unlink(Hyde::path('_docs/index.md'));
}

public function test_get_links_from_config_method()
Expand Down Expand Up @@ -60,4 +62,17 @@ public function test_get_links_from_config_method()
'priority' => 999,
], $result[1]);
}

public function test_files_starting_with_underscores_are_ignored()
{
touch(Hyde::path('_pages/_foo.md'));
touch(Hyde::path('_pages/_foo.blade.php'));

$array = GeneratesNavigationMenu::getNavigationLinks();
$this->assertIsArray($array);
$this->assertCount(1, $array);

unlink(Hyde::path('_pages/_foo.md'));
unlink(Hyde::path('_pages/_foo.blade.php'));
}
}
29 changes: 26 additions & 3 deletions tests/Feature/Services/CollectionServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,37 @@ public function test_get_media_asset_files_discovers_custom_file_types()
unlink($path);
}

public function test_files_starting_with_underscore_are_ignored()
public function test_blade_page_files_starting_with_underscore_are_ignored()
{
touch(Hyde::path('_pages/_foo.blade.php'));
$this->assertEquals([
'404',
'index',
], CollectionService::getBladePageList());
unlink(Hyde::path('_pages/_foo.blade.php'));
}

public function test_markdown_page_files_starting_with_underscore_are_ignored()
{
touch(Hyde::path('_pages/_foo.md'));
$this->assertEquals([], CollectionService::getMarkdownPageList());
unlink(Hyde::path('_pages/_foo.md'));
}

public function test_post_files_starting_with_underscore_are_ignored()
{
touch(Hyde::path('_posts/_foo.md'));
$this->assertNotContains('_foo', CollectionService::getMarkdownPostList());
$this->assertNotContains('foo', CollectionService::getMarkdownPostList());
$this->assertEquals([], CollectionService::getMarkdownPostList());
unlink(Hyde::path('_posts/_foo.md'));
}

public function test_documentation_page_files_starting_with_underscore_are_ignored()
{
touch(Hyde::path('_docs/_foo.md'));
$this->assertEquals([], CollectionService::getDocumentationPageList());
unlink(Hyde::path('_docs/_foo.md'));
}

protected function unitTestMarkdownBasedPageList(string $model, string $path, ?string $expected = null)
{
touch(Hyde::path($path));
Expand Down

0 comments on commit 718329b

Please sign in to comment.