Skip to content

Commit

Permalink
Add test to ensure that post front matter can be omitted
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed May 2, 2022
1 parent e0ed6f2 commit 875c6d4
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/Unit/BlogPostFrontMatterIsOptionalTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Tests\Unit;

use Hyde\Framework\Hyde;
use Illuminate\Support\Facades\Artisan;
use PHPUnit\Framework\TestCase;

class BlogPostFrontMatterIsOptionalTest extends TestCase
{
// Test blog posts can be created without having any front matter
public function testBlogPostCanBeCreatedWithoutFrontMatter()
{
file_put_contents(Hyde::path('_posts/test-post.md'), '# My New Post');

Artisan::call('rebuild _posts/test-post.md');

$this->assertFileExists(Hyde::path('_site/posts/test-post.html'));

unlink(Hyde::path('_posts/test-post.md'));
unlink(Hyde::path('_site/posts/test-post.html'));
}

// Test blog post feed can be rendered when having post without front matter
public function testBlogPostFeedCanBeRenderedWhenPostHasNoFrontMatter()
{
file_put_contents(Hyde::path('_posts/test-post.md'), '# My New Post');

// Create a temporary page to test the feed
file_put_contents(Hyde::path('_pages/feed-test.blade.php'),
'@foreach(Hyde::getLatestPosts() as $post)
@include(\'hyde::components.article-excerpt\')
@endforeach'
);

Artisan::call('rebuild _pages/feed-test.blade.php');

$this->assertFileExists(Hyde::path('_site/feed-test.html'));

unlink(Hyde::path('_posts/test-post.md'));
unlink(Hyde::path('_pages/feed-test.blade.php'));
unlink(Hyde::path('_site/feed-test.html'));
}
}

0 comments on commit 875c6d4

Please sign in to comment.