|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Testing\Feature\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Hyde\Framework\Hyde; |
|
6
|
|
|
use Hyde\Framework\Models\Pages\MarkdownPost; |
|
7
|
|
|
use Hyde\Framework\StaticPageBuilder; |
|
8
|
|
|
use Hyde\Testing\TestCase; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Test the post compiler module. |
|
12
|
|
|
* |
|
13
|
|
|
* @see \Hyde\Framework\Testing\Unit\MarkdownPostParserTest for the Markdown parser test. |
|
14
|
|
|
*/ |
|
15
|
|
|
class StaticSiteBuilderPostModuleTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
protected MarkdownPost $post; |
|
18
|
|
|
|
|
19
|
|
|
protected function setUp(): void |
|
20
|
|
|
{ |
|
21
|
|
|
parent::setUp(); |
|
22
|
|
|
|
|
23
|
|
|
$this->post = MarkdownPost::make('test-post', [ |
|
24
|
|
|
'title' => 'Adventures in Wonderland', |
|
25
|
|
|
'description' => 'All in the golden afternoon, full leisurely we glide.', |
|
26
|
|
|
'category' => 'novels', |
|
27
|
|
|
'author' => 'Lewis Carroll', |
|
28
|
|
|
'date' => '1865-11-18 18:52', |
|
29
|
|
|
], "## CHAPTER I. DOWN THE RABBIT-HOLE. \n\nSo she was considering in her own mind, as well as she could, for the hot day made her feel very sleepy and stupid.", 'Test Title'); |
|
30
|
|
|
|
|
31
|
|
|
// Make sure no file exists which could cause unintended results. |
|
32
|
|
|
unlinkIfExists(Hyde::path('_site/posts/test-post.html')); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
protected function tearDown(): void |
|
36
|
|
|
{ |
|
37
|
|
|
unlink(Hyde::path('_site/posts/test-post.html')); |
|
38
|
|
|
|
|
39
|
|
|
parent::tearDown(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function inspectHtml(array $expectedStrings) |
|
43
|
|
|
{ |
|
44
|
|
|
new StaticPageBuilder($this->post, true); |
|
45
|
|
|
$stream = file_get_contents(Hyde::path('_site/posts/test-post.html')); |
|
46
|
|
|
|
|
47
|
|
|
foreach ($expectedStrings as $expectedString) { |
|
48
|
|
|
$this->assertStringContainsString($expectedString, $stream); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function test_can_create_post() |
|
53
|
|
|
{ |
|
54
|
|
|
$builder = new StaticPageBuilder($this->post); |
|
55
|
|
|
|
|
56
|
|
|
$builder->__invoke(); |
|
57
|
|
|
|
|
58
|
|
|
$this->assertFileExists(Hyde::path('_site/posts/test-post.html')); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function test_post_contains_expected_content() |
|
62
|
|
|
{ |
|
63
|
|
|
$this->inspectHtml([ |
|
64
|
|
|
'Adventures in Wonderland', |
|
65
|
|
|
'Saturday Nov 18th, 1865, at 6:52pm', |
|
66
|
|
|
'Lewis Carroll', |
|
67
|
|
|
'in the category "novels"', |
|
68
|
|
|
'<h2>CHAPTER I. DOWN THE RABBIT-HOLE.</h2>', |
|
69
|
|
|
'<p>So she was considering in her own mind, as well as she could', |
|
70
|
|
|
]); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function test_post_contains_expected_elements() |
|
74
|
|
|
{ |
|
75
|
|
|
$this->inspectHtml([ |
|
76
|
|
|
'<!DOCTYPE html>', |
|
77
|
|
|
'<html', |
|
78
|
|
|
'<head', |
|
79
|
|
|
'<body', |
|
80
|
|
|
'<main', |
|
81
|
|
|
'<article', |
|
82
|
|
|
'<meta', |
|
83
|
|
|
'<header', |
|
84
|
|
|
'<h1', |
|
85
|
|
|
'<time', |
|
86
|
|
|
'<address', |
|
87
|
|
|
]); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function test_post_contains_expected_meta_tags() |
|
91
|
|
|
{ |
|
92
|
|
|
$this->inspectHtml([ |
|
93
|
|
|
'<meta name="description" content="All in the golden afternoon, full leisurely we glide.">', |
|
94
|
|
|
'<meta name="author" content="Lewis Carroll">', |
|
95
|
|
|
'<meta name="keywords" content="novels">', |
|
96
|
|
|
'<meta property="og:type" content="article">', |
|
97
|
|
|
'<meta property="og:title" content="Adventures in Wonderland">', |
|
98
|
|
|
'<meta property="og:article:published_time" content="1865-11-18T18:52:00+00:00">', |
|
99
|
|
|
]); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function test_post_contains_expected_itemprops() |
|
103
|
|
|
{ |
|
104
|
|
|
$this->inspectHtml([ |
|
105
|
|
|
'itemtype="http://schema.org/Article"', |
|
106
|
|
|
'itemtype="http://schema.org/Person"', |
|
107
|
|
|
'itemprop="identifier"', |
|
108
|
|
|
'itemprop="headline"', |
|
109
|
|
|
'itemprop="dateCreated datePublished"', |
|
110
|
|
|
'itemprop="author"', |
|
111
|
|
|
'itemprop="name"', |
|
112
|
|
|
'itemprop="articleBody"', |
|
113
|
|
|
]); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function test_post_contains_expected_aria_support() |
|
117
|
|
|
{ |
|
118
|
|
|
$this->inspectHtml([ |
|
119
|
|
|
'role="doc-pageheader"', |
|
120
|
|
|
'role="doc-introduction"', |
|
121
|
|
|
'aria-label="About the post"', |
|
122
|
|
|
]); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|