assertContains('index.md', $pages->column('Filename'), 'The tests/docs/en folder should contain a index file'); $this->assertContains('subfolder/', $pages->column('Filename'), 'The tests/docs/en folder should contain a subfolder called subfolder'); $this->assertContains('test.md', $pages->column('Filename'), 'The tests/docs/en folder should contain a test file'); $this->assertNotContains('_images', $pages->column('Filename'), 'It should not include hidden files'); $this->assertNotContains('.svn', $pages->column('Filename'), 'It should not include hidden files'); // test the order of pages $pages = DocumentationService::get_pages_from_folder($entity, 'sort'); $this->assertEquals( array('Basic', 'Intermediate', 'Advanced', 'Some page', 'Another page'), $pages->column('Title') ); } function testGetPagesFromFolderRecursive() { $entity = DocumentationService::register('testdocsrecursive', BASE_PATH . '/sapphiredocs/tests/docs-recursive/'); $pages = DocumentationService::get_pages_from_folder($entity, null, true); // check to see all the pages are found, we don't care about order $this->assertEquals($pages->Count(), 9); $pages = $pages->column('Title'); foreach(array('Index', 'SubFolder TestFile', 'SubSubFolder TestFile', 'TestFile') as $expected) { $this->assertContains($expected, $pages); } } function testFindPath() { DocumentationService::register("DocumentationViewerTests", BASE_PATH . "/sapphiredocs/tests/docs/"); // file $path = DocumentationService::find_page('DocumentationViewerTests', array('test')); $this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/test.md", $path); // the home page. The path finder should go to the index.md file in the default language $path = DocumentationService::find_page('DocumentationViewerTests', array('')); $this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/index.md", $path); // second level $path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subpage')); $this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/subfolder/subpage.md", $path); $path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subsubfolder')); $this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/subfolder/subsubfolder/", $path); // third level $path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subsubfolder', 'subsubpage')); $this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/subfolder/subsubfolder/subsubpage.md", $path); // with trailing slash $path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subsubfolder', 'subsubpage')); $this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/subfolder/subsubfolder/subsubpage.md", $path); } function testCleanPageNames() { $names = array( 'documentation-Page', 'documentation_Page', 'documentation.md', 'documentation.pdf', 'documentation.file.txt', '.hidden' ); $should = array( 'Documentation Page', 'Documentation Page', 'Documentation', 'Documentation.pdf', // do not remove an extension we don't know 'Documentation.file', // .txt we do know about '.hidden' // don't display something without a title ); foreach($names as $key => $value) { $this->assertEquals(DocumentationService::clean_page_name($value), $should[$key]); } } }