|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Testing\Feature\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Hyde\Framework\Commands\HydeRebuildStaticSiteCommand; |
|
6
|
|
|
use Hyde\Framework\Hyde; |
|
7
|
|
|
use Hyde\Testing\TestCase; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @covers \Hyde\Framework\Commands\HydeRebuildStaticSiteCommand |
|
11
|
|
|
*/ |
|
12
|
|
|
class HydeRebuildStaticSiteCommandTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function test_handle_is_successful_with_valid_path() |
|
15
|
|
|
{ |
|
16
|
|
|
file_put_contents(Hyde::path('_pages/test-page.md'), 'foo'); |
|
17
|
|
|
|
|
18
|
|
|
$this->artisan('rebuild '.'_pages/test-page.md') |
|
19
|
|
|
->assertExitCode(0); |
|
20
|
|
|
|
|
21
|
|
|
$outputPath = '_site/test-page.html'; |
|
22
|
|
|
$this->assertFileExists(Hyde::path($outputPath)); |
|
23
|
|
|
|
|
24
|
|
|
unlink(Hyde::path('_pages/test-page.md')); |
|
25
|
|
|
unlink(Hyde::path($outputPath)); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function test_media_files_can_be_transferred() |
|
29
|
|
|
{ |
|
30
|
|
|
backupDirectory(Hyde::path('_site/media')); |
|
31
|
|
|
deleteDirectory(Hyde::path('_site/media')); |
|
32
|
|
|
mkdir(Hyde::path('_site/media')); |
|
33
|
|
|
|
|
34
|
|
|
Hyde::touch(('_media/test.jpg')); |
|
35
|
|
|
|
|
36
|
|
|
$this->artisan('rebuild _media') |
|
37
|
|
|
->assertExitCode(0); |
|
38
|
|
|
|
|
39
|
|
|
$this->assertFileExists(Hyde::path('_site/media/test.jpg')); |
|
40
|
|
|
unlink(Hyde::path('_media/test.jpg')); |
|
41
|
|
|
unlink(Hyde::path('_site/media/test.jpg')); |
|
42
|
|
|
|
|
43
|
|
|
restoreDirectory(Hyde::path('_site/media')); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function test_validate_catches_bad_source_directory() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->artisan('rebuild foo/bar') |
|
49
|
|
|
->expectsOutput('Path [foo/bar] is not in a valid source directory.') |
|
50
|
|
|
->assertExitCode(400); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function test_validate_catches_missing_file() |
|
54
|
|
|
{ |
|
55
|
|
|
$this->artisan('rebuild _pages/foo.md') |
|
56
|
|
|
->expectsOutput('File [_pages/foo.md] not found.') |
|
57
|
|
|
->assertExitCode(404); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function test_rebuild_documentation_page() |
|
61
|
|
|
{ |
|
62
|
|
|
Hyde::touch(('_docs/foo.md')); |
|
63
|
|
|
|
|
64
|
|
|
$this->artisan('rebuild _docs/foo.md') |
|
65
|
|
|
->assertExitCode(0); |
|
66
|
|
|
|
|
67
|
|
|
$this->assertFileExists(Hyde::path('_site/docs/foo.html')); |
|
68
|
|
|
|
|
69
|
|
|
unlink(Hyde::path('_docs/foo.md')); |
|
70
|
|
|
unlink(Hyde::path('_site/docs/foo.html')); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function test_rebuild_blog_post() |
|
74
|
|
|
{ |
|
75
|
|
|
Hyde::touch(('_posts/foo.md')); |
|
76
|
|
|
|
|
77
|
|
|
$this->artisan('rebuild _posts/foo.md') |
|
78
|
|
|
->assertExitCode(0); |
|
79
|
|
|
|
|
80
|
|
|
$this->assertFileExists(Hyde::path('_site/posts/foo.html')); |
|
81
|
|
|
|
|
82
|
|
|
unlink(Hyde::path('_posts/foo.md')); |
|
83
|
|
|
unlink(Hyde::path('_site/posts/foo.html')); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function test_get_output_path_returns_same_input_for_out_of_bounds_page() |
|
87
|
|
|
{ |
|
88
|
|
|
$this->assertEquals('test-page.html', |
|
89
|
|
|
(new HydeRebuildStaticSiteCommand)->getOutputPath(('test-page.html'))); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|