| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Hyde\Framework\Testing\Unit; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Hyde\Framework\Hyde; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Hyde\Framework\HydeServiceProvider; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Hyde\Framework\Models\Pages\DocumentationPage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Hyde\Framework\Models\Route; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Hyde\Testing\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Illuminate\Support\Facades\Config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @covers \Hyde\Framework\Models\Pages\DocumentationPage | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 14 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  | class DocumentationPageTest extends TestCase | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     public function test_can_generate_table_of_contents() | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |         $page = (new DocumentationPage([], '# Foo')); | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |         $this->assertIsString($page->getTableOfContents()); | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |     public function test_can_get_current_page_path() | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |         $page = (new DocumentationPage([], '', '', 'foo')); | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |         $this->assertEquals('docs/foo', $page->getCurrentPagePath()); | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |         config(['docs.output_directory' => 'documentation/latest/']); | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |         (new HydeServiceProvider($this->app))->register(); | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         $this->assertEquals('documentation/latest/foo', $page->getCurrentPagePath()); | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     public function test_can_get_online_source_path() | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |         $page = (new DocumentationPage([], '')); | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |         $this->assertFalse($page->getOnlineSourcePath()); | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |     public function test_can_get_online_source_path_with_source_file_location_base() | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |         config(['docs.source_file_location_base' => 'docs.example.com/edit']); | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |         $page = (new DocumentationPage([], '', '', 'foo')); | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |         $this->assertEquals('docs.example.com/edit/foo.md', $page->getOnlineSourcePath()); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |     public function test_can_get_online_source_path_with_trailing_slash() | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |         $page = (new DocumentationPage([], '', '', 'foo')); | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |         config(['docs.source_file_location_base' => 'edit/']); | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |         $this->assertEquals('edit/foo.md', $page->getOnlineSourcePath()); | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |         config(['docs.source_file_location_base' => 'edit']); | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |         $this->assertEquals('edit/foo.md', $page->getOnlineSourcePath()); | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |     public function test_can_get_documentation_output_path() | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |         $this->assertEquals('docs', DocumentationPage::getOutputDirectory()); | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     public function test_can_get_documentation_output_path_with_custom_output_directory() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         config(['docs.output_directory' => 'foo']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         (new HydeServiceProvider($this->app))->register(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 66 |  |  |         $this->assertEquals('foo', DocumentationPage::getOutputDirectory()); | 
            
                                                                        
                                                                
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     public function test_can_get_documentation_output_path_with_trailing_slashes() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $tests = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             'foo', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             'foo/', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             'foo//', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             'foo\\', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             '/foo/', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         foreach ($tests as $test) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             config(['docs.output_directory' => $test]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             (new HydeServiceProvider($this->app))->register(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 82 |  |  |             $this->assertEquals('foo', DocumentationPage::getOutputDirectory()); | 
            
                                                                        
                                                                
            
                                    
            
            
                | 83 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |     public function test_get_source_path_returns_qualified_basename() | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |         $this->assertEquals( | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |             DocumentationPage::qualifyBasename('foo'), | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |             (new DocumentationPage(slug: 'foo'))->getSourcePath() | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |     public function test_get_source_path_returns_qualified_basename_for_nested_page() | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |         $this->assertEquals( | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |             DocumentationPage::qualifyBasename('foo/bar'), | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |             (new DocumentationPage(slug: 'foo/bar'))->getSourcePath() | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     public function test_home_method_returns_null_when_there_is_no_index_page() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 104 |  |  |         $this->assertNull(DocumentationPage::home()); | 
            
                                                                        
                                                                
            
                                    
            
            
                | 105 |  |  |     } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                        
                                                                
            
                                    
            
            
                | 107 |  |  |     public function test_home_method_returns_docs_index_route_when_it_exists() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         Hyde::touch('_docs/index.md'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         $this->assertInstanceOf(Route::class, DocumentationPage::home()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         $this->assertEquals(Route::get('docs/index'), DocumentationPage::home()); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 112 |  |  |         Hyde::unlink('_docs/index.md'); | 
            
                                                                        
                                                                
            
                                    
            
            
                | 113 |  |  |     } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     public function test_has_table_of_contents() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         $this->assertIsBool(DocumentationPage::hasTableOfContents()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         Config::set('docs.table_of_contents.enabled', true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         $this->assertTrue(DocumentationPage::hasTableOfContents()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         Config::set('docs.table_of_contents.enabled', false); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 123 |  |  |         $this->assertFalse(DocumentationPage::hasTableOfContents()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 125 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 126 |  |  |  |