|
4 | 4 |
|
5 | 5 | use Hyde\Framework\Foundation\Filesystem;
|
6 | 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; |
7 | 11 | use Hyde\Testing\TestCase;
|
8 | 12 |
|
9 | 13 | /**
|
| 14 | + * @covers \Hyde\Framework\HydeKernel |
10 | 15 | * @covers \Hyde\Framework\Foundation\Filesystem
|
11 |
| - * |
12 |
| - * @see \Hyde\Framework\Testing\Unit\Foundation\FluentFilesystemModelPathHelpersTest |
13 | 16 | */
|
14 | 17 | class FilesystemTest extends TestCase
|
15 | 18 | {
|
@@ -146,4 +149,163 @@ public function test_unlink_helper_deletes_multiple_files_at_given_paths()
|
146 | 149 | $this->assertFileDoesNotExist(Hyde::path('foo'));
|
147 | 150 | $this->assertFileDoesNotExist(Hyde::path('bar'));
|
148 | 151 | }
|
| 152 | + |
| 153 | + public function test_get_model_source_path_method_returns_path_for_model_classes() |
| 154 | + { |
| 155 | + $this->assertEquals( |
| 156 | + Hyde::path('_posts'), |
| 157 | + Hyde::getModelSourcePath(MarkdownPost::class) |
| 158 | + ); |
| 159 | + |
| 160 | + $this->assertEquals( |
| 161 | + Hyde::path('_pages'), |
| 162 | + Hyde::getModelSourcePath(MarkdownPage::class) |
| 163 | + ); |
| 164 | + |
| 165 | + $this->assertEquals( |
| 166 | + Hyde::path('_docs'), |
| 167 | + Hyde::getModelSourcePath(DocumentationPage::class) |
| 168 | + ); |
| 169 | + |
| 170 | + $this->assertEquals( |
| 171 | + Hyde::path('_pages'), |
| 172 | + Hyde::getModelSourcePath(BladePage::class) |
| 173 | + ); |
| 174 | + } |
| 175 | + |
| 176 | + public function test_get_model_source_path_method_returns_path_to_file_for_model_classes() |
| 177 | + { |
| 178 | + $this->assertEquals( |
| 179 | + Hyde::path('_posts'.DIRECTORY_SEPARATOR.'foo.md'), |
| 180 | + Hyde::getModelSourcePath(MarkdownPost::class, 'foo.md') |
| 181 | + ); |
| 182 | + |
| 183 | + $this->assertEquals( |
| 184 | + Hyde::path('_pages'.DIRECTORY_SEPARATOR.'foo.md'), |
| 185 | + Hyde::getModelSourcePath(MarkdownPage::class, 'foo.md') |
| 186 | + ); |
| 187 | + |
| 188 | + $this->assertEquals( |
| 189 | + Hyde::path('_docs'.DIRECTORY_SEPARATOR.'foo.md'), |
| 190 | + Hyde::getModelSourcePath(DocumentationPage::class, 'foo.md') |
| 191 | + ); |
| 192 | + |
| 193 | + $this->assertEquals( |
| 194 | + Hyde::path('_pages'.DIRECTORY_SEPARATOR.'foo.md'), |
| 195 | + Hyde::getModelSourcePath(BladePage::class, 'foo.md') |
| 196 | + ); |
| 197 | + } |
| 198 | + |
| 199 | + public function test_helper_for_blade_pages() |
| 200 | + { |
| 201 | + $this->assertEquals( |
| 202 | + Hyde::path('_pages'), |
| 203 | + Hyde::getBladePagePath() |
| 204 | + ); |
| 205 | + } |
| 206 | + |
| 207 | + public function test_helper_for_markdown_pages() |
| 208 | + { |
| 209 | + $this->assertEquals( |
| 210 | + Hyde::path('_pages'), |
| 211 | + Hyde::getMarkdownPagePath() |
| 212 | + ); |
| 213 | + } |
| 214 | + |
| 215 | + public function test_helper_for_markdown_posts() |
| 216 | + { |
| 217 | + $this->assertEquals( |
| 218 | + Hyde::path('_posts'), |
| 219 | + Hyde::getMarkdownPostPath() |
| 220 | + ); |
| 221 | + } |
| 222 | + |
| 223 | + public function test_helper_for_documentation_pages() |
| 224 | + { |
| 225 | + $this->assertEquals( |
| 226 | + Hyde::path('_docs'), |
| 227 | + Hyde::getDocumentationPagePath() |
| 228 | + ); |
| 229 | + } |
| 230 | + |
| 231 | + public function test_helper_for_site_output_path() |
| 232 | + { |
| 233 | + $this->assertEquals( |
| 234 | + Hyde::path('_site'), |
| 235 | + Hyde::getSiteOutputPath() |
| 236 | + ); |
| 237 | + } |
| 238 | + |
| 239 | + public function test_helper_for_site_output_path_returns_path_to_file_within_the_directory() |
| 240 | + { |
| 241 | + $this->assertEquals( |
| 242 | + Hyde::path('_site'.DIRECTORY_SEPARATOR.'foo.html'), |
| 243 | + Hyde::getSiteOutputPath('foo.html') |
| 244 | + ); |
| 245 | + } |
| 246 | + |
| 247 | + public function test_get_site_output_path_returns_absolute_path() |
| 248 | + { |
| 249 | + $this->assertEquals( |
| 250 | + Hyde::path('_site'), |
| 251 | + Hyde::getSiteOutputPath() |
| 252 | + ); |
| 253 | + } |
| 254 | + |
| 255 | + public function test_site_output_path_helper_ignores_trailing_slashes() |
| 256 | + { |
| 257 | + $this->assertEquals( |
| 258 | + Hyde::path('_site'.DIRECTORY_SEPARATOR.'foo.html'), |
| 259 | + Hyde::getSiteOutputPath('/foo.html/') |
| 260 | + ); |
| 261 | + } |
| 262 | + |
| 263 | + public function test_path_to_relative_helper_decodes_hyde_path_into_relative() |
| 264 | + { |
| 265 | + $s = DIRECTORY_SEPARATOR; |
| 266 | + $this->assertEquals('foo', Hyde::pathToRelative(Hyde::path('foo'))); |
| 267 | + $this->assertEquals('foo', Hyde::pathToRelative(Hyde::path('/foo/'))); |
| 268 | + $this->assertEquals('foo.md', Hyde::pathToRelative(Hyde::path('foo.md'))); |
| 269 | + $this->assertEquals("foo{$s}bar", Hyde::pathToRelative(Hyde::path("foo{$s}bar"))); |
| 270 | + $this->assertEquals("foo{$s}bar.md", Hyde::pathToRelative(Hyde::path("foo{$s}bar.md"))); |
| 271 | + } |
| 272 | + |
| 273 | + public function test_path_to_relative_helper_does_not_modify_already_relative_paths() |
| 274 | + { |
| 275 | + $this->assertEquals('foo', Hyde::pathToRelative('foo')); |
| 276 | + $this->assertEquals('foo/', Hyde::pathToRelative('foo/')); |
| 277 | + $this->assertEquals('../foo', Hyde::pathToRelative('../foo')); |
| 278 | + $this->assertEquals('../foo/', Hyde::pathToRelative('../foo/')); |
| 279 | + $this->assertEquals('foo.md', Hyde::pathToRelative('foo.md')); |
| 280 | + $this->assertEquals('foo/bar', Hyde::pathToRelative('foo/bar')); |
| 281 | + $this->assertEquals('foo/bar.md', Hyde::pathToRelative('foo/bar.md')); |
| 282 | + } |
| 283 | + |
| 284 | + public function test_path_to_relative_helper_does_not_modify_non_project_paths() |
| 285 | + { |
| 286 | + $testStrings = [ |
| 287 | + 'C:\Documents\Newsletters\Summer2018.pdf', |
| 288 | + '\Program Files\Custom Utilities\StringFinder.exe', |
| 289 | + '2018\January.xlsx', |
| 290 | + '..\Publications\TravelBrochure.pdf', |
| 291 | + 'C:\Projects\library\library.sln', |
| 292 | + 'C:Projects\library\library.sln', |
| 293 | + '/home/seth/Pictures/penguin.jpg', |
| 294 | + '~/Pictures/penguin.jpg', |
| 295 | + ]; |
| 296 | + |
| 297 | + foreach ($testStrings as $testString) { |
| 298 | + $this->assertEquals( |
| 299 | + $this->systemPath(($testString)), |
| 300 | + Hyde::pathToRelative( |
| 301 | + $this->systemPath($testString) |
| 302 | + ) |
| 303 | + ); |
| 304 | + } |
| 305 | + } |
| 306 | + |
| 307 | + protected function systemPath(string $path): string |
| 308 | + { |
| 309 | + return str_replace('/', DIRECTORY_SEPARATOR, $path); |
| 310 | + } |
149 | 311 | }
|
0 commit comments