-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Frontmatter now parses with empty body (#278)
- Loading branch information
1 parent
da0e8d1
commit dcc27bf
Showing
4 changed files
with
64 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Tapestry\Tests; | ||
|
||
use Symfony\Component\Finder\SplFileInfo; | ||
use Tapestry\Entities\File; | ||
use Tapestry\Modules\Content\FrontMatter; | ||
|
||
class FrontmatterTest extends CommandTestBase | ||
{ | ||
/** | ||
* Written for issue #148 | ||
* @link https://github.com/carbontwelve/tapestry/issues/148 | ||
*/ | ||
function testFrontmatterParsedWhenBodyEmpty() | ||
{ | ||
$file = new File(new SplFileInfo(__DIR__ . '/Mocks/TestFileNoBody.md', '', '')); | ||
$frontMatter = new FrontMatter($file->getFileContent()); | ||
$this->assertSame('', $frontMatter->getContent()); | ||
$this->assertSame([ | ||
'title' => 'Test File Title', | ||
'draft' => false, | ||
'date' => 507600000 | ||
], $frontMatter->getData()); | ||
} | ||
|
||
function testFrontMatterAndBodyParsedCorrectly() | ||
{ | ||
$file = new File(new SplFileInfo(__DIR__ . '/Mocks/TestFile.md', '', '')); | ||
$frontMatter = new FrontMatter($file->getFileContent()); | ||
$this->assertSame('This is a test file...', $frontMatter->getContent()); | ||
$this->assertSame([ | ||
'title' => 'Test File Title', | ||
'draft' => false, | ||
'date' => 507600000 | ||
], $frontMatter->getData()); | ||
} | ||
|
||
function testFrontMatterParsedWhenEmpty() | ||
{ | ||
$frontMatter = new FrontMatter("---\n---\nHello World"); | ||
$this->assertSame('Hello World', $frontMatter->getContent()); | ||
$this->assertSame([], $frontMatter->getData()); | ||
|
||
$frontMatter = new FrontMatter("---\n---\n\n\nHello World"); | ||
$this->assertSame('Hello World', $frontMatter->getContent()); | ||
$this->assertSame([], $frontMatter->getData()); | ||
|
||
$frontMatter = new FrontMatter("---\r\n---\r\nHello World"); | ||
$this->assertSame('Hello World', $frontMatter->getContent()); | ||
$this->assertSame([], $frontMatter->getData()); | ||
} | ||
} |
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,5 @@ | ||
--- | ||
title: Test File Title | ||
draft: false | ||
date: 1986-02-01 | ||
--- |