Passed
Push — master ( 2a3d19...5e9e4e )
by Caen
05:36 queued 13s
created

PublicationListPageTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 47
dl 0
loc 88
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A test_listing_page_can_be_compiled() 0 11 1
A test_list_page_is_not_added_to_navigation_when_publication_identifier_is_set_in_config() 0 11 1
A test_source_path_mappings() 0 11 1
A test_list_page_can_show_up_in_navigation() 0 9 1
A getPublicationType() 0 3 1
A createPublicationFiles() 0 7 1
A getTestData() 0 14 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Publications\Testing\Feature;
6
7
use Hyde\Hyde;
8
use Hyde\Testing\TestCase;
9
use Illuminate\Support\Facades\File;
10
use Hyde\Publications\Models\PublicationType;
11
use Hyde\Publications\Pages\PublicationListPage;
12
13
/**
14
 * @covers \Hyde\Publications\Pages\PublicationListPage
15
 */
16
class PublicationListPageTest extends TestCase
17
{
18
    public function test_source_path_mappings()
19
    {
20
        $this->createPublicationFiles();
21
22
        $page = new PublicationListPage($this->getPublicationType());
23
        $this->assertSame('test-publication/index', $page->getIdentifier());
24
        $this->assertSame('test-publication/index', $page->getRouteKey());
25
        $this->assertSame('test-publication/index.html', $page->getOutputPath());
26
        $this->assertSame('test-publication/index', $page->getSourcePath());
27
28
        File::deleteDirectory(Hyde::path('test-publication'));
29
    }
30
31
    public function test_listing_page_can_be_compiled()
32
    {
33
        $this->createPublicationFiles();
34
35
        file_put_contents(Hyde::path('test-publication/list.blade.php'), 'Listing Page');
36
37
        $page = new PublicationListPage($this->getPublicationType());
38
39
        Hyde::shareViewData($page);
40
        $this->assertStringContainsString('Listing Page', $page->compile());
41
        File::deleteDirectory(Hyde::path('test-publication'));
42
    }
43
44
    public function test_list_page_can_show_up_in_navigation()
45
    {
46
        $this->createPublicationFiles();
47
48
        $page = new PublicationListPage($this->getPublicationType());
49
50
        $this->assertTrue($page->showInNavigation());
51
52
        File::deleteDirectory(Hyde::path('test-publication'));
53
    }
54
55
    public function test_list_page_is_not_added_to_navigation_when_publication_identifier_is_set_in_config()
56
    {
57
        config(['hyde.navigation.exclude' => ['test-publication']]);
58
59
        $this->createPublicationFiles();
60
61
        $page = new PublicationListPage($this->getPublicationType());
62
63
        $this->assertFalse($page->showInNavigation());
64
65
        File::deleteDirectory(Hyde::path('test-publication'));
66
    }
67
68
    protected function createPublicationFiles(): void
69
    {
70
        mkdir(Hyde::path('test-publication'));
71
        file_put_contents(Hyde::path('test-publication/schema.json'), json_encode($this->getTestData()));
72
        file_put_contents(
73
            Hyde::path('test-publication/foo.md'),
74
            '---
75
__canonical: canonical
76
__createdAt: 2022-11-16 11:32:52
77
foo: bar
78
---
79
80
Hello World!
81
'
82
        );
83
    }
84
85
    protected function getPublicationType(): PublicationType
86
    {
87
        return PublicationType::fromFile('test-publication/schema.json');
88
    }
89
90
    protected function getTestData(): array
91
    {
92
        return [
93
            'name'           => 'test',
94
            'canonicalField' => 'canonical',
95
            'detailTemplate' => 'detail.blade.php',
96
            'listTemplate'   => 'list.blade.php',
97
            'sortField'      => 'sort',
98
            'sortAscending'  => true,
99
            'pageSize'       => 10,
100
            'fields'         => [
101
                [
102
                    'type' => 'string',
103
                    'name' => 'Foo',
104
                ],
105
            ],
106
        ];
107
    }
108
}
109