Passed
Push — master ( a0ff31...47a9f8 )
by Caen
03:50 queued 14s
created

test_documentation_page_parser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 10
rs 10
1
<?php
2
3
namespace Hyde\Framework\Testing\Feature;
4
5
use Hyde\Framework\Actions\SourceFileParser;
6
use Hyde\Framework\Hyde;
7
use Hyde\Framework\Models\Pages\BladePage;
8
use Hyde\Framework\Models\Pages\DocumentationPage;
9
use Hyde\Framework\Models\Pages\MarkdownPage;
10
use Hyde\Framework\Models\Pages\MarkdownPost;
11
use Hyde\Testing\TestCase;
12
13
/**
14
 * @covers \Hyde\Framework\Actions\SourceFileParser
15
 */
16
class SourceFileParserTest extends TestCase
17
{
18
    public function test_blade_page_parser()
19
    {
20
        $this->file('_pages/foo.blade.php');
21
22
        $parser = new SourceFileParser(BladePage::class, 'foo');
23
        $page = $parser->get();
24
        $this->assertInstanceOf(BladePage::class, $page);
25
        $this->assertEquals('foo', $page->slug);
0 ignored issues
show
Bug introduced by
Accessing slug on the interface Hyde\Framework\Contracts\PageContract suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
26
    }
27
28
    public function test_markdown_page_parser()
29
    {
30
        $this->markdown('_pages/foo.md', '# Foo Bar', ['title' => 'Foo Bar Baz']);
31
32
        $parser = new SourceFileParser(MarkdownPage::class, 'foo');
33
        $page = $parser->get();
34
        $this->assertInstanceOf(MarkdownPage::class, $page);
35
        $this->assertEquals('foo', $page->slug);
0 ignored issues
show
Bug introduced by
Accessing slug on the interface Hyde\Framework\Contracts\PageContract suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
36
        $this->assertEquals('# Foo Bar', $page->body);
0 ignored issues
show
Bug introduced by
Accessing body on the interface Hyde\Framework\Contracts\PageContract suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
37
        $this->assertEquals('Foo Bar Baz', $page->title);
0 ignored issues
show
Bug introduced by
Accessing title on the interface Hyde\Framework\Contracts\PageContract suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
38
    }
39
40
    public function test_markdown_post_parser()
41
    {
42
        $this->markdown('_posts/foo.md', '# Foo Bar', ['title' => 'Foo Bar Baz']);
43
44
        $parser = new SourceFileParser(MarkdownPost::class, 'foo');
45
        $page = $parser->get();
46
        $this->assertInstanceOf(MarkdownPost::class, $page);
47
        $this->assertEquals('foo', $page->slug);
0 ignored issues
show
Bug introduced by
Accessing slug on the interface Hyde\Framework\Contracts\PageContract suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
48
        $this->assertEquals('# Foo Bar', $page->body);
0 ignored issues
show
Bug introduced by
Accessing body on the interface Hyde\Framework\Contracts\PageContract suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
49
        $this->assertEquals('Foo Bar Baz', $page->title);
0 ignored issues
show
Bug introduced by
Accessing title on the interface Hyde\Framework\Contracts\PageContract suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
50
    }
51
52
    public function test_documentation_page_parser()
53
    {
54
        $this->markdown('_docs/foo.md', '# Foo Bar', ['title' => 'Foo Bar Baz']);
55
56
        $parser = new SourceFileParser(DocumentationPage::class, 'foo');
57
        $page = $parser->get();
58
        $this->assertInstanceOf(DocumentationPage::class, $page);
59
        $this->assertEquals('foo', $page->slug);
0 ignored issues
show
Bug introduced by
Accessing slug on the interface Hyde\Framework\Contracts\PageContract suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
60
        $this->assertEquals('# Foo Bar', $page->body);
0 ignored issues
show
Bug introduced by
Accessing body on the interface Hyde\Framework\Contracts\PageContract suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
61
        $this->assertEquals('Foo Bar Baz', $page->title);
0 ignored issues
show
Bug introduced by
Accessing title on the interface Hyde\Framework\Contracts\PageContract suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
62
    }
63
64
    public function test_documentation_page_parser_can_get_category_from_front_matter()
65
    {
66
        $this->markdown('_docs/foo.md', '# Foo Bar', ['category' => 'foo']);
67
68
        $parser = new SourceFileParser(DocumentationPage::class, 'foo');
69
70
        /** @var DocumentationPage $page */
71
        $page = $parser->get();
72
        $this->assertEquals('foo', $page->category);
73
    }
74
75
    public function test_documentation_page_parser_can_get_category_automatically_from_nested_page()
76
    {
77
        mkdir(Hyde::path('_docs/foo'));
78
        touch(Hyde::path('_docs/foo/bar.md'));
79
80
        $parser = new SourceFileParser(DocumentationPage::class, 'foo/bar');
81
82
        /** @var DocumentationPage $page */
83
        $page = $parser->get();
84
        $this->assertEquals('foo', $page->category);
85
86
        unlink(Hyde::path('_docs/foo/bar.md'));
87
        rmdir(Hyde::path('_docs/foo'));
88
    }
89
}
90