1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Testing\Feature; |
4
|
|
|
|
5
|
|
|
use Hyde\Framework\Hyde; |
6
|
|
|
use Hyde\Framework\Models\Pages\DocumentationPage; |
7
|
|
|
use Hyde\Framework\Models\Pages\MarkdownPage; |
8
|
|
|
use Hyde\Testing\TestCase; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @covers \Hyde\Framework\Actions\PageModelConstructor |
12
|
|
|
*/ |
13
|
|
|
class PageModelConstructorTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
public function test_dynamic_data_constructor_can_find_title_from_front_matter() |
16
|
|
|
{ |
17
|
|
|
$this->markdown('_pages/foo.md', '# Foo Bar', ['title' => 'My Title']); |
18
|
|
|
$page = MarkdownPage::parse('foo'); |
19
|
|
|
$this->assertEquals('My Title', $page->title); |
|
|
|
|
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function test_dynamic_data_constructor_can_find_title_from_h1_tag() |
23
|
|
|
{ |
24
|
|
|
$this->markdown('_pages/foo.md', '# Foo Bar'); |
25
|
|
|
$page = MarkdownPage::parse('foo'); |
26
|
|
|
|
27
|
|
|
$this->assertEquals('Foo Bar', $page->title); |
|
|
|
|
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function test_dynamic_data_constructor_can_find_title_from_slug() |
31
|
|
|
{ |
32
|
|
|
$this->markdown('_pages/foo-bar.md'); |
33
|
|
|
$page = MarkdownPage::parse('foo-bar'); |
34
|
|
|
|
35
|
|
|
$this->assertEquals('Foo Bar', $page->title); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function test_documentation_page_parser_can_get_category_from_front_matter() |
39
|
|
|
{ |
40
|
|
|
$this->markdown('_docs/foo.md', '# Foo Bar', ['category' => 'foo']); |
41
|
|
|
|
42
|
|
|
$page = DocumentationPage::parse('foo'); |
43
|
|
|
$this->assertEquals('foo', $page->category); |
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function test_documentation_page_parser_can_get_category_automatically_from_nested_page() |
47
|
|
|
{ |
48
|
|
|
mkdir(Hyde::path('_docs/foo')); |
49
|
|
|
touch(Hyde::path('_docs/foo/bar.md')); |
50
|
|
|
|
51
|
|
|
/** @var DocumentationPage $page */ |
52
|
|
|
$page = DocumentationPage::parse('foo/bar'); |
53
|
|
|
$this->assertEquals('foo', $page->category); |
54
|
|
|
|
55
|
|
|
unlink(Hyde::path('_docs/foo/bar.md')); |
56
|
|
|
rmdir(Hyde::path('_docs/foo')); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|