1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Sculpin\Tests\Functional; |
6
|
|
|
|
7
|
|
|
class GenerateFromMarkdownTest extends FunctionalTestCase |
8
|
|
|
{ |
9
|
|
|
/** @test */ |
10
|
1 |
|
public function shouldGenerateAnHtmlFileFromMarkdown(): void |
11
|
|
|
{ |
12
|
1 |
|
$this->copyFixtureToProject(__DIR__ . '/Fixture/source/hello_world.md', '/source/hello_world.md'); |
13
|
|
|
|
14
|
1 |
|
$this->executeSculpin('generate'); |
15
|
|
|
|
16
|
1 |
|
$this->assertProjectHasGeneratedFile('/hello_world/index.html'); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** @test */ |
20
|
1 |
|
public function shouldGenerateHtmlContentFromMarkdown(): void |
21
|
|
|
{ |
22
|
1 |
|
$this->copyFixtureToProject(__DIR__ . '/Fixture/source/hello_world.md', '/source/hello_world.md'); |
23
|
|
|
|
24
|
1 |
|
$this->executeSculpin('generate'); |
25
|
|
|
|
26
|
1 |
|
$crawler = $this->crawlGeneratedProjectFile('/hello_world/index.html'); |
27
|
|
|
|
28
|
1 |
|
$this->assertContains('Hello World', $crawler->filter('h1')->text()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** @test */ |
32
|
1 |
|
public function shouldGenerateIntoNestedDirectories(): void |
33
|
|
|
{ |
34
|
1 |
|
$this->copyFixtureToProject(__DIR__ . '/Fixture/source/hello_world.md', '/source/hello/world.md'); |
35
|
|
|
|
36
|
1 |
|
$this->executeSculpin('generate'); |
37
|
|
|
|
38
|
1 |
|
$this->assertProjectHasGeneratedFile('/hello/world/index.html'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** @test */ |
42
|
1 |
|
public function shouldGenerateHtmlUsingALayout() |
43
|
|
|
{ |
44
|
1 |
|
$this->addProjectFile('/source/_layouts/my_layout.html.twig', <<<EOT |
45
|
1 |
|
<body> |
46
|
|
|
<div class="page-content">{% block content %}{% endblock content %}</div> |
47
|
|
|
</body> |
48
|
|
|
EOT |
49
|
|
|
); |
50
|
|
|
|
51
|
1 |
|
$this->addProjectFile('/source/my_page_with_layout.md', <<<EOT |
52
|
1 |
|
--- |
53
|
|
|
layout: my_layout.html.twig |
54
|
|
|
--- |
55
|
|
|
Hello World |
56
|
|
|
EOT |
57
|
|
|
); |
58
|
|
|
|
59
|
1 |
|
$this->executeSculpin('generate'); |
60
|
|
|
|
61
|
1 |
|
$crawler = $this->crawlGeneratedProjectFile('/my_page_with_layout/index.html'); |
62
|
|
|
|
63
|
1 |
|
$pageContentEl = $crawler->filter('.page-content'); |
64
|
1 |
|
$this->assertEquals( |
65
|
1 |
|
1, |
66
|
1 |
|
$pageContentEl->count(), |
67
|
1 |
|
"Expected generated file to have a single .page-content element." |
68
|
|
|
); |
69
|
1 |
|
$this->assertContains('Hello World', $pageContentEl->text()); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** @test */ |
73
|
1 |
|
public function shouldRefreshGeneratedHtmlAfterFilesystemChange(): void |
74
|
|
|
{ |
75
|
1 |
|
$layoutFile = '/source/_layouts/my_layout.html.twig'; |
76
|
1 |
|
$pageFile = '/source/my_page_with_layout.md'; |
77
|
1 |
|
$pageGenerated = '/my_page_with_layout/index.html'; |
78
|
|
|
|
79
|
1 |
|
$expectedHeader = 'ORIGINAL_HEADER'; |
80
|
1 |
|
$expectedContent = 'Hello World'; |
81
|
|
|
|
82
|
|
|
$layoutContent = <<<EOT |
83
|
|
|
<body> |
84
|
1 |
|
<h1 class="header">{$expectedHeader}</h1> |
85
|
|
|
<div class="page-content">{% block content %}{% endblock content %}</div> |
86
|
|
|
</body> |
87
|
|
|
EOT; |
88
|
|
|
|
89
|
|
|
$pageContent = <<<EOT |
90
|
|
|
--- |
91
|
|
|
layout: my_layout.html.twig |
92
|
|
|
--- |
93
|
1 |
|
{$expectedContent} |
94
|
|
|
EOT; |
95
|
|
|
|
96
|
1 |
|
$this->addProjectFile($layoutFile, $layoutContent); |
97
|
1 |
|
$this->addProjectFile($pageFile, $pageContent); |
98
|
|
|
|
99
|
|
|
// start our async sculpin watcher/server |
100
|
1 |
|
$process = $this->executeSculpinAsync('generate --watch'); |
101
|
|
|
|
102
|
1 |
|
sleep(1); // wait until our file exists |
103
|
1 |
|
$crawler = $this->crawlGeneratedProjectFile($pageGenerated); |
104
|
|
|
|
105
|
1 |
|
$pageContentEl = $crawler->filter('.page-content'); |
106
|
1 |
|
$this->assertEquals( |
107
|
1 |
|
1, |
108
|
1 |
|
$pageContentEl->count(), |
109
|
1 |
|
"Expected generated file to have a single .page-content element." |
110
|
|
|
); |
111
|
|
|
|
112
|
1 |
|
$pageHeaderEl = $crawler->filter('.header'); |
113
|
1 |
|
$this->assertEquals( |
114
|
1 |
|
1, |
115
|
1 |
|
$pageHeaderEl->count(), |
116
|
1 |
|
"Expected generated file to have a single .header element." |
117
|
|
|
); |
118
|
|
|
|
119
|
1 |
|
$this->assertContains($expectedHeader, $pageHeaderEl->text()); |
120
|
1 |
|
$this->assertContains($expectedContent, $pageContentEl->text()); |
121
|
|
|
|
122
|
|
|
// update the content |
123
|
1 |
|
$originalHeader = $expectedHeader; |
124
|
1 |
|
$originalContent = $expectedContent; |
125
|
|
|
|
126
|
1 |
|
$expectedHeader = 'FRESH HEADER'; |
127
|
1 |
|
$expectedContent = 'HELLO WORLD!'; |
128
|
|
|
|
129
|
1 |
|
$layoutContent = str_replace($originalHeader, $expectedHeader, $layoutContent); |
130
|
1 |
|
$pageContent = str_replace($originalContent, $expectedContent, $pageContent); |
131
|
|
|
|
132
|
|
|
// test that page content refreshes properly |
133
|
1 |
|
$this->addProjectFile($pageFile, $pageContent); |
134
|
|
|
|
135
|
1 |
|
sleep(2); |
136
|
1 |
|
$crawler = $this->crawlGeneratedProjectFile($pageGenerated); |
137
|
|
|
|
138
|
1 |
|
$pageContentEl = $crawler->filter('.page-content'); |
139
|
1 |
|
$this->assertEquals( |
140
|
1 |
|
1, |
141
|
1 |
|
$pageContentEl->count(), |
142
|
1 |
|
"Expected generated file to have a single .page-content element." |
143
|
|
|
); |
144
|
|
|
|
145
|
1 |
|
$this->assertContains($expectedContent, $pageContentEl->text()); |
146
|
|
|
|
147
|
|
|
// test that layouts/views refresh properly |
148
|
1 |
|
$this->addProjectFile($layoutFile, $layoutContent); |
149
|
|
|
|
150
|
1 |
|
sleep(2); |
151
|
1 |
|
$crawler = $this->crawlGeneratedProjectFile($pageGenerated); |
152
|
|
|
|
153
|
1 |
|
$pageHeaderEl = $crawler->filter('.header'); |
154
|
1 |
|
$this->assertEquals( |
155
|
1 |
|
1, |
156
|
1 |
|
$pageHeaderEl->count(), |
157
|
1 |
|
"Expected generated file to have a single .header element." |
158
|
|
|
); |
159
|
|
|
|
160
|
1 |
|
$this->assertContains($expectedHeader, $pageHeaderEl->text()); // I don't get it. This should be failing. |
161
|
|
|
|
162
|
1 |
|
$process->stop(0); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** @test */ |
166
|
1 |
|
public function shouldPassThruFilesWithNoExtension(): void |
167
|
|
|
{ |
168
|
1 |
|
$this->copyFixtureToProject(__DIR__ . '/Fixture/source/hello_world.md', '/source/hello_world'); |
169
|
1 |
|
$this->copyFixtureToProject(__DIR__ . '/Fixture/source/hello_world.md', '/source/hello_world2'); |
170
|
|
|
|
171
|
1 |
|
$this->executeSculpin('generate'); |
172
|
|
|
|
173
|
1 |
|
$this->assertProjectHasGeneratedFile('/hello_world'); |
174
|
1 |
|
$this->assertProjectHasGeneratedFile('/hello_world2'); |
175
|
|
|
|
176
|
1 |
|
$this->assertGeneratedFileHasContent('/hello_world', '# Hello World'); |
177
|
1 |
|
$this->assertGeneratedFileHasContent('/hello_world2', '# Hello World'); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** @test */ |
181
|
1 |
|
public function shouldSkipContentTypeFilesWithNoExtension(): void |
182
|
|
|
{ |
183
|
1 |
|
$this->addProjectDirectory(__DIR__ . '/Fixture/source/_posts'); |
184
|
1 |
|
$this->writeToProjectFile( |
185
|
1 |
|
'/app/config/sculpin_kernel.yml', |
186
|
|
|
<<<EOF |
187
|
1 |
|
sculpin_content_types: |
188
|
|
|
posts: |
189
|
|
|
permalink: blog/:basename |
190
|
|
|
EOF |
191
|
|
|
); |
192
|
|
|
|
193
|
1 |
|
$this->copyFixtureToProject(__DIR__ . '/Fixture/source/hello_world.md', '/source/_posts/hello_world'); |
194
|
1 |
|
$this->copyFixtureToProject(__DIR__ . '/Fixture/source/hello_world.md', '/source/_posts/hello_world2'); |
195
|
1 |
|
$this->copyFixtureToProject(__DIR__ . '/Fixture/source/hello_world.md', '/source/_posts/hello_world3.md'); |
196
|
|
|
|
197
|
1 |
|
$this->executeSculpin('generate'); |
198
|
|
|
|
199
|
1 |
|
$actualOutput = implode("\n", $this->executeOutput); |
200
|
1 |
|
$this->assertContains('Skipping empty or unknown file: _posts/hello_world' . PHP_EOL, $actualOutput); |
201
|
1 |
|
$this->assertContains('Skipping empty or unknown file: _posts/hello_world2', $actualOutput); |
202
|
1 |
|
$this->assertNotContains('Skipping empty or unknown file: _posts/hello_world3.md', $actualOutput); |
203
|
|
|
|
204
|
1 |
|
$this->assertProjectLacksFile('/output_test/_posts/hello_world'); |
205
|
1 |
|
$this->assertProjectLacksFile('/output_test/_posts/hello_world2'); |
206
|
1 |
|
$this->assertProjectHasGeneratedFile('/blog/hello_world3/index.html'); |
207
|
|
|
|
208
|
1 |
|
$this->assertGeneratedFileHasContent( |
209
|
1 |
|
'/blog/hello_world3/index.html', |
210
|
1 |
|
'<h1 id="hello-world">Hello World</h1>' |
211
|
|
|
); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** @test */ |
215
|
1 |
|
public function shouldSkipHiddenFilesSilently(): void |
216
|
|
|
{ |
217
|
1 |
|
$this->addProjectDirectory(__DIR__ . '/Fixture/source/_posts'); |
218
|
1 |
|
$this->writeToProjectFile( |
219
|
1 |
|
'/app/config/sculpin_kernel.yml', |
220
|
|
|
<<<EOF |
221
|
1 |
|
sculpin_content_types: |
222
|
|
|
posts: |
223
|
|
|
permalink: blog/:basename |
224
|
|
|
EOF |
225
|
|
|
); |
226
|
|
|
|
227
|
1 |
|
$this->addProjectFile('/source/_posts/.DS_Store'); |
228
|
1 |
|
$this->addProjectFile('/source/_posts/.hello_world2.swp'); |
229
|
1 |
|
$this->copyFixtureToProject(__DIR__ . '/Fixture/source/hello_world.md', '/source/_posts/hello_world3.md'); |
230
|
|
|
|
231
|
1 |
|
$this->executeSculpin('generate'); |
232
|
|
|
|
233
|
1 |
|
$actualOutput = implode("\n", $this->executeOutput); |
234
|
1 |
|
$this->assertNotContains('.DS_Store', $actualOutput); |
235
|
1 |
|
$this->assertNotContains('.hello_world2.swp', $actualOutput); |
236
|
1 |
|
$this->assertNotContains('Skipping empty or unknown file:', $actualOutput); |
237
|
|
|
|
238
|
1 |
|
$this->assertProjectLacksFile('/output_test/_posts/.DS_Store'); |
239
|
1 |
|
$this->assertProjectLacksFile('/output_test/_posts/.hello_world2.swp'); |
240
|
1 |
|
$this->assertProjectHasGeneratedFile('/blog/hello_world3/index.html'); |
241
|
|
|
|
242
|
1 |
|
$this->assertGeneratedFileHasContent( |
243
|
1 |
|
'/blog/hello_world3/index.html', |
244
|
1 |
|
'<h1 id="hello-world">Hello World</h1>' |
245
|
|
|
); |
246
|
|
|
} |
247
|
|
|
} |
248
|
|
|
|