Passed
Push — master ( 421bfc...8e1cd9 )
by Caen
03:38 queued 13s
created

PageModelConstructorTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 44
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A test_documentation_page_parser_can_get_category_automatically_from_nested_page() 0 11 1
A test_dynamic_data_constructor_can_find_title_from_slug() 0 6 1
A test_documentation_page_parser_can_get_category_from_front_matter() 0 6 1
A test_dynamic_data_constructor_can_find_title_from_h1_tag() 0 6 1
A test_dynamic_data_constructor_can_find_title_from_front_matter() 0 5 1
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);
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...
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);
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...
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);
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...
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);
0 ignored issues
show
Bug introduced by
Accessing category on the interface Hyde\Framework\Contracts\PageContract suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
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