mirror of
https://github.com/silverstripe/doc.silverstripe.org
synced 2024-10-22 17:05:50 +02:00
a0eab442a3
git-svn-id: http://svn.silverstripe.com/projects/ss2doc/branches/v2@116225 467b73ca-7a2a-4603-9d3b-597d59a354a9
99 lines
3.8 KiB
PHP
99 lines
3.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @package sapphiredocs
|
|
* @subpackage tests
|
|
*/
|
|
|
|
class DocumentationServiceTest extends SapphireTest {
|
|
|
|
function testGetPagesFromFolder() {
|
|
$entity = DocumentationService::register('testdocs', BASE_PATH . '/sapphiredocs/tests/docs/');
|
|
$pages = DocumentationService::get_pages_from_folder($entity);
|
|
|
|
// check folders and files exist as their filenames
|
|
$this->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);
|
|
|
|
// subsubfolder has no index file. It should fail instead the viewer should pick up on this
|
|
// and display the listing of the folder
|
|
$path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subsubfolder'));
|
|
$this->assertFalse($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]);
|
|
}
|
|
}
|
|
} |