Skip to content

Commit f317b2d

Browse files
committed
Test configured post author fields can be set customized in front matter
1 parent 6c3f56d commit f317b2d

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

packages/framework/tests/Feature/PostsAuthorIntegrationTest.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,81 @@ public function testAllPostAuthorFieldsCanBeSetInFrontMatter()
132132
], $page->author->toArray());
133133
}
134134

135+
public function testConfiguredPostAuthorFieldsCanBeSetCustomizedInFrontMatter()
136+
{
137+
Config::set('hyde.authors', [
138+
'mr_hyde' => Author::create(
139+
name: 'Mr. Hyde',
140+
website: 'https://hydephp.com',
141+
bio: 'The mysterious author of HydePHP',
142+
avatar: 'avatar.png',
143+
socials: [
144+
'twitter' => '@HydeFramework',
145+
'github' => 'hydephp',
146+
],
147+
),
148+
]);
149+
150+
$this->file('_posts/literal.md', <<<'MD'
151+
---
152+
author: mr_hyde
153+
---
154+
155+
# Using the configured author
156+
MD
157+
);
158+
159+
$this->file('_posts/changed.md', <<<'MD'
160+
---
161+
author:
162+
username: mr_hyde
163+
name: Dr. Jekyll
164+
---
165+
166+
# Modifying the configured author
167+
MD
168+
);
169+
170+
$this->artisan('rebuild _posts/literal.md')->assertExitCode(0);
171+
$this->artisan('rebuild _posts/changed.md')->assertExitCode(0);
172+
$this->assertFileExists(Hyde::path('_site/posts/literal.html'));
173+
$this->assertFileExists(Hyde::path('_site/posts/changed.html'));
174+
$this->cleanUpWhenDone('_site/posts/literal.html');
175+
$this->cleanUpWhenDone('_site/posts/changed.html');
176+
177+
$page = MarkdownPost::get('literal');
178+
$this->assertNotNull($page);
179+
$this->assertNotNull($page->author);
180+
181+
$this->assertSame([
182+
'username' => 'mr_hyde',
183+
'name' => 'Mr. Hyde',
184+
'website' => 'https://hydephp.com',
185+
'bio' => 'The mysterious author of HydePHP',
186+
'avatar' => 'avatar.png',
187+
'socials' => [
188+
'twitter' => '@HydeFramework',
189+
'github' => 'hydephp',
190+
],
191+
], $page->author->toArray());
192+
193+
$page = MarkdownPost::get('changed');
194+
$this->assertNotNull($page);
195+
$this->assertNotNull($page->author);
196+
197+
$this->assertSame([
198+
'username' => 'mr_hyde',
199+
'name' => 'Dr. Jekyll',
200+
'website' => 'https://hydephp.com',
201+
'bio' => 'The mysterious author of HydePHP',
202+
'avatar' => 'avatar.png',
203+
'socials' => [
204+
'twitter' => '@HydeFramework',
205+
'github' => 'hydephp',
206+
],
207+
], $page->author->toArray());
208+
}
209+
135210
protected function createPostFile(string $title, string $author): void
136211
{
137212
(new CreatesNewMarkdownPostFile($title, '', '', $author))->save();

0 commit comments

Comments
 (0)