|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Testing\Feature; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
use Hyde\Framework\Hyde; |
|
7
|
|
|
use Hyde\Framework\Models\Pages\DocumentationPage; |
|
8
|
|
|
use Hyde\Framework\Models\Parsers\DocumentationPageParser; |
|
9
|
|
|
use Hyde\Framework\Services\CollectionService; |
|
10
|
|
|
use Hyde\Testing\TestCase; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @covers \Hyde\Framework\Models\Parsers\DocumentationPageParser |
|
14
|
|
|
*/ |
|
15
|
|
|
class DocumentationPageParserTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
public function test_can_parse_markdown_file() |
|
18
|
|
|
{ |
|
19
|
|
|
file_put_contents(Hyde::path('_docs/test.md'), "# Title Heading \n\nMarkdown Content"); |
|
20
|
|
|
$page = (new DocumentationPageParser('test'))->get(); |
|
21
|
|
|
$this->assertInstanceOf(DocumentationPage::class, $page); |
|
22
|
|
|
unlink(Hyde::path('_docs/test.md')); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function test_can_get_collection_of_slugs() |
|
26
|
|
|
{ |
|
27
|
|
|
$this->resetDocs(); |
|
28
|
|
|
|
|
29
|
|
|
file_put_contents(Hyde::path('_docs/phpunit-test.md'), "# PHPUnit Test File \n Hello World!"); |
|
30
|
|
|
|
|
31
|
|
|
$array = CollectionService::getDocumentationPageFiles(); |
|
32
|
|
|
|
|
33
|
|
|
$this->assertIsArray($array); |
|
34
|
|
|
$this->assertCount(1, $array); |
|
35
|
|
|
$this->assertArrayHasKey('phpunit-test', array_flip($array)); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function test_exception_is_thrown_for_missing_slug() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->expectException(Exception::class); |
|
41
|
|
|
$this->expectExceptionMessage('File _docs/invalid-file.md not found.'); |
|
42
|
|
|
new DocumentationPageParser('invalid-file'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function test_can_parse_documentation_page() |
|
46
|
|
|
{ |
|
47
|
|
|
$parser = new DocumentationPageParser('phpunit-test'); |
|
48
|
|
|
$this->assertInstanceOf(DocumentationPageParser::class, $parser); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function test_title_was_inferred_from_heading() |
|
52
|
|
|
{ |
|
53
|
|
|
$parser = new DocumentationPageParser('phpunit-test'); |
|
54
|
|
|
$object = $parser->get(); |
|
55
|
|
|
$this->assertIsString($object->title); |
|
56
|
|
|
$this->assertEquals('PHPUnit Test File', $object->title); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function test_parser_contains_body_text() |
|
60
|
|
|
{ |
|
61
|
|
|
$parser = new DocumentationPageParser('phpunit-test'); |
|
62
|
|
|
$this->assertIsString($parser->body); |
|
63
|
|
|
$this->assertEquals("# PHPUnit Test File \n Hello World!", $parser->body); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function test_can_get_page_model_object() |
|
67
|
|
|
{ |
|
68
|
|
|
$parser = new DocumentationPageParser('phpunit-test'); |
|
69
|
|
|
$object = $parser->get(); |
|
70
|
|
|
$this->assertInstanceOf(DocumentationPage::class, $object); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function test_created_model_contains_expected_data() |
|
74
|
|
|
{ |
|
75
|
|
|
$parser = new DocumentationPageParser('phpunit-test'); |
|
76
|
|
|
$object = $parser->get(); |
|
77
|
|
|
$this->assertEquals('PHPUnit Test File', $object->title); |
|
78
|
|
|
$this->assertEquals("# PHPUnit Test File \n Hello World!", $object->body); |
|
79
|
|
|
$this->assertEquals('phpunit-test', $object->slug); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function test_cleanup() |
|
83
|
|
|
{ |
|
84
|
|
|
unlink(Hyde::path('_docs/phpunit-test.md')); |
|
85
|
|
|
$this->assertTrue(true); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function test_can_get_category_from_front_matter() |
|
89
|
|
|
{ |
|
90
|
|
|
file_put_contents(Hyde::path('_docs/foo.md'), "---\ncategory: foo\n---\n"); |
|
91
|
|
|
$parser = new DocumentationPageParser('foo'); |
|
92
|
|
|
$this->assertEquals('foo', $parser->getCategory()); |
|
93
|
|
|
unlink(Hyde::path('_docs/foo.md')); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function test_can_get_category_automatically_from_nested_page() |
|
97
|
|
|
{ |
|
98
|
|
|
mkdir(Hyde::path('_docs/foo')); |
|
99
|
|
|
touch(Hyde::path('_docs/foo/bar.md')); |
|
100
|
|
|
$parser = new DocumentationPageParser('foo/bar'); |
|
101
|
|
|
$this->assertEquals('foo', $parser->getCategory()); |
|
102
|
|
|
|
|
103
|
|
|
unlink(Hyde::path('_docs/foo/bar.md')); |
|
104
|
|
|
rmdir(Hyde::path('_docs/foo')); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|