-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into realtime-compiler-dashboard-improvements
- Loading branch information
Showing
7 changed files
with
196 additions
and
10 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
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
104 changes: 104 additions & 0 deletions
104
packages/framework/tests/Unit/CreatesNewMarkdownPostFileTest.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,104 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Hyde\Framework\Testing\Unit; | ||
|
||
use Hyde\Hyde; | ||
use Hyde\Testing\TestCase; | ||
use Illuminate\Support\Carbon; | ||
use Hyde\Framework\Actions\CreatesNewMarkdownPostFile; | ||
|
||
/** | ||
* @covers \Hyde\Framework\Actions\CreatesNewMarkdownPostFile | ||
* | ||
* @see \Hyde\Framework\Testing\Feature\Commands\MakePostCommandTest | ||
*/ | ||
class CreatesNewMarkdownPostFileTest extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
Carbon::setTestNow(Carbon::create(2024)); | ||
} | ||
|
||
public function testWithDefaultData() | ||
{ | ||
$action = new CreatesNewMarkdownPostFile('Example Title', null, null, null); | ||
|
||
$this->assertSame([ | ||
'title' => 'Example Title', | ||
'description' => 'A short description used in previews and SEO', | ||
'category' => 'blog', | ||
'author' => 'default', | ||
'date' => '2024-01-01 00:00', | ||
], $action->toArray()); | ||
} | ||
|
||
public function testWithCustomData() | ||
{ | ||
$action = new CreatesNewMarkdownPostFile('foo', 'bar', 'baz', 'qux', '2024-06-01 12:20'); | ||
|
||
$this->assertSame([ | ||
'title' => 'foo', | ||
'description' => 'bar', | ||
'category' => 'baz', | ||
'author' => 'qux', | ||
'date' => '2024-06-01 12:20', | ||
], $action->toArray()); | ||
} | ||
|
||
public function testSave() | ||
{ | ||
$action = new CreatesNewMarkdownPostFile('Example Post', null, null, null); | ||
$action->save(); | ||
|
||
$path = Hyde::path('_posts/example-post.md'); | ||
|
||
$this->assertSame(<<<'MARKDOWN' | ||
--- | ||
title: 'Example Post' | ||
description: 'A short description used in previews and SEO' | ||
category: blog | ||
author: default | ||
date: '2024-01-01 00:00' | ||
--- | ||
## Write something awesome. | ||
|
||
MARKDOWN, file_get_contents($path)); | ||
|
||
unlink($path); | ||
} | ||
|
||
public function testSaveWithCustomContent() | ||
{ | ||
$action = new CreatesNewMarkdownPostFile('Example Post', null, null, null, null, 'Hello World!'); | ||
$action->save(); | ||
|
||
$path = Hyde::path('_posts/example-post.md'); | ||
|
||
$this->assertSame(<<<'MARKDOWN' | ||
--- | ||
title: 'Example Post' | ||
description: 'A short description used in previews and SEO' | ||
category: blog | ||
author: default | ||
date: '2024-01-01 00:00' | ||
--- | ||
Hello World! | ||
|
||
MARKDOWN, file_get_contents($path)); | ||
|
||
unlink($path); | ||
} | ||
|
||
public function testCustomDateNormalisation() | ||
{ | ||
$action = new CreatesNewMarkdownPostFile('Example Post', null, null, null, 'Jan 1 2024 8am'); | ||
|
||
$this->assertSame('2024-01-01 08:00', $action->toArray()['date']); | ||
} | ||
} |