44
55namespace Hyde \Framework \Testing \Feature \Actions ;
66
7+ use Hyde \Facades \Filesystem ;
78use Hyde \Framework \Actions \CreatesNewPageSourceFile ;
89use Hyde \Framework \Exceptions \FileConflictException ;
910use Hyde \Framework \Exceptions \UnsupportedPageTypeException ;
1011use Hyde \Hyde ;
1112use Hyde \Pages \BladePage ;
1213use Hyde \Pages \DocumentationPage ;
1314use Hyde \Testing \TestCase ;
14- use Illuminate \Support \Facades \File ;
1515
1616/**
1717 * @covers \Hyde\Framework\Actions\CreatesNewPageSourceFile
1818 */
1919class CreatesNewPageSourceFileTest extends TestCase
2020{
21- protected function tearDown (): void
22- {
23- if (file_exists (Hyde::path ('_pages/test-page.md ' ))) {
24- unlink (Hyde::path ('_pages/test-page.md ' ));
25- }
26-
27- if (file_exists (Hyde::path ('_pages/test-page.blade.php ' ))) {
28- unlink (Hyde::path ('_pages/test-page.blade.php ' ));
29- }
30-
31- parent ::tearDown ();
32- }
33-
3421 public function test_class_can_be_instantiated ()
3522 {
3623 $ this ->assertInstanceOf (
3724 CreatesNewPageSourceFile::class,
38- new CreatesNewPageSourceFile ('Test Page ' )
25+ ( new CreatesNewPageSourceFile ('Test Page ' ) )
3926 );
4027 }
4128
@@ -49,113 +36,112 @@ public function test_that_an_exception_is_thrown_for_invalid_page_type()
4936
5037 public function test_that_an_exception_is_thrown_if_file_already_exists_and_overwrite_is_false ()
5138 {
52- $ path = Hyde::path ('_pages/foo.md ' );
53- file_put_contents ($ path , 'foo ' );
39+ $ this ->file ('_pages/foo.md ' , 'foo ' );
5440
5541 $ this ->expectException (FileConflictException::class);
56- $ this ->expectExceptionMessage (" File already exists: $ path" );
42+ $ this ->expectExceptionMessage (' File already exists: ' .Hyde:: path ( ' _pages/foo.md ' ) );
5743 $ this ->expectExceptionCode (409 );
5844
59- new CreatesNewPageSourceFile ('foo ' );
60-
61- unlink ($ path );
45+ ( new CreatesNewPageSourceFile ('foo ' ) );
46+ $ this -> assertSame ( ' foo ' , file_get_contents (Hyde:: path ( ' _pages/foo.md ' )));
47+ Filesystem:: unlink (' _pages/foo.md ' );
6248 }
6349
6450 public function test_that_can_save_file_returns_true_if_file_already_exists_and_overwrite_is_true ()
6551 {
66- $ path = Hyde::path ('_pages/foo.md ' );
67- file_put_contents ($ path , 'foo ' );
68-
69- new CreatesNewPageSourceFile ('foo ' , force: true );
52+ $ this ->file ('_pages/foo.md ' , 'foo ' );
7053
71- $ this ->assertTrue (true );
72- unlink ($ path );
54+ (new CreatesNewPageSourceFile ('foo ' , force: true ));
55+ $ this ->assertSame ("--- \ntitle: foo \n--- \n\n# foo \n" , file_get_contents (Hyde::path ('_pages/foo.md ' )));
56+ Filesystem::unlink ('_pages/foo.md ' );
7357 }
7458
7559 public function test_that_a_markdown_file_can_be_created_and_contains_expected_content ()
7660 {
61+ Filesystem::unlink ('_pages/test-page.md ' );
7762 (new CreatesNewPageSourceFile ('Test Page ' ));
7863
79- $ this ->assertFileExists (
80- Hyde::path ('_pages/test-page.md ' )
81- );
64+ $ this ->assertFileExists (Hyde::path ('_pages/test-page.md ' ));
8265
83- $ this ->assertEquals (
66+ $ this ->assertSame (
8467 "--- \ntitle: Test Page \n--- \n\n# Test Page \n" ,
8568 file_get_contents (Hyde::path ('_pages/test-page.md ' ))
8669 );
70+ Filesystem::unlink ('_pages/test-page.md ' );
8771 }
8872
8973 public function test_that_a_blade_file_can_be_created_and_contains_expected_content ()
9074 {
9175 (new CreatesNewPageSourceFile ('Test Page ' , BladePage::class));
9276
93- $ this ->assertFileExists (
94- Hyde::path ('_pages/test-page.blade.php ' )
95- );
77+ $ this ->assertFileExists (Hyde::path ('_pages/test-page.blade.php ' ));
78+
79+ $ this ->assertEquals (
80+ <<<'BLADE'
81+ @extends('hyde::layouts.app')
82+ @section('content')
83+ @php($title = "Test Page")
9684
97- $ fileContent = file_get_contents (Hyde::path ('_pages/test-page.blade.php ' ));
98- $ this ->assertEqualsIgnoringLineEndingType (
99- '@extends( \'hyde::layouts.app \')
100- @section( \'content \')
101- @php($title = "Test Page")
85+ <main class="mx-auto max-w-7xl py-16 px-8">
86+ <h1 class="text-center text-3xl font-bold">Test Page</h1>
87+ </main>
10288
103- <main class="mx-auto max-w-7xl py-16 px-8">
104- <h1 class="text-center text-3xl font-bold">Test Page</h1>
105- </main>
89+ @endsection
10690
107- @endsection
108- ' , $ fileContent
91+ BLADE, file_get_contents (Hyde::path ('_pages/test-page.blade.php ' ))
10992 );
93+
94+ Filesystem::unlink ('_pages/test-page.blade.php ' );
11095 }
11196
11297 public function test_that_a_documentation_file_can_be_created_and_contains_expected_content ()
11398 {
11499 (new CreatesNewPageSourceFile ('Test Page ' , DocumentationPage::class));
115100
116- $ this ->assertFileExists (
117- Hyde::path ('_docs/test-page.md ' )
118- );
101+ $ this ->assertFileExists (Hyde::path ('_docs/test-page.md ' ));
119102
120- $ this ->assertEquals (
103+ $ this ->assertSame (
121104 "# Test Page \n" ,
122105 file_get_contents (Hyde::path ('_docs/test-page.md ' ))
123106 );
124107
125- Hyde ::unlink ('_docs/test-page.md ' );
108+ Filesystem ::unlink ('_docs/test-page.md ' );
126109 }
127110
128111 public function test_that_the_file_path_can_be_returned ()
129112 {
130- $ this ->assertEquals (
113+ $ this ->assertSame (
131114 Hyde::path ('_pages/test-page.md ' ),
132115 (new CreatesNewPageSourceFile ('Test Page ' ))->getOutputPath ()
133116 );
134117
135- $ this ->assertEquals (
118+ $ this ->assertSame (
136119 Hyde::path ('_pages/test-page.blade.php ' ),
137120 (new CreatesNewPageSourceFile ('Test Page ' , BladePage::class))->getOutputPath ()
138121 );
122+
123+ Filesystem::unlink ('_pages/test-page.md ' );
124+ Filesystem::unlink ('_pages/test-page.blade.php ' );
139125 }
140126
141127 public function test_file_is_created_using_slug_generated_from_title ()
142128 {
143- new CreatesNewPageSourceFile ('Foo Bar ' );
129+ ( new CreatesNewPageSourceFile ('Foo Bar ' ) );
144130 $ this ->assertFileExists (Hyde::path ('_pages/foo-bar.md ' ));
145- Hyde ::unlink ('_pages/foo-bar.md ' );
131+ Filesystem ::unlink ('_pages/foo-bar.md ' );
146132 }
147133
148134 public function test_action_can_generate_nested_pages ()
149135 {
150- new CreatesNewPageSourceFile ('foo/bar ' );
136+ ( new CreatesNewPageSourceFile ('foo/bar ' ) );
151137 $ this ->assertFileExists (Hyde::path ('_pages/foo/bar.md ' ));
152- File ::deleteDirectory (Hyde:: path ( '_pages/foo ' ) );
138+ Filesystem ::deleteDirectory ('_pages/foo ' );
153139 }
154140
155141 public function test_can_create_deeply_nested_pages ()
156142 {
157- new CreatesNewPageSourceFile ('/foo/bar/Foo Bar ' );
143+ ( new CreatesNewPageSourceFile ('/foo/bar/Foo Bar ' ) );
158144 $ this ->assertFileExists (Hyde::path ('_pages/foo/bar/foo-bar.md ' ));
159- File ::deleteDirectory (Hyde:: path ( '_pages/foo ' ) );
145+ Filesystem ::deleteDirectory ('_pages/foo ' );
160146 }
161147}
0 commit comments