2010-12-21 10:42:44 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2012-04-08 11:36:16 +02:00
|
|
|
* @package docsviewer
|
2010-12-21 10:42:44 +01:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
|
|
|
|
class DocumentationServiceTest extends SapphireTest {
|
|
|
|
|
2010-12-22 09:21:49 +01:00
|
|
|
function testGetPagesFromFolder() {
|
2012-04-08 11:36:16 +02:00
|
|
|
$entity = DocumentationService::register('testdocs', DOCSVIEWER_PATH . '/tests/docs/');
|
2010-12-22 09:21:49 +01:00
|
|
|
$pages = DocumentationService::get_pages_from_folder($entity);
|
|
|
|
|
|
|
|
$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() {
|
2012-04-08 11:36:16 +02:00
|
|
|
$entity = DocumentationService::register('testdocsrecursive', DOCSVIEWER_PATH . '/tests/docs-recursive/');
|
2010-12-22 09:21:49 +01:00
|
|
|
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-21 10:42:44 +01:00
|
|
|
function testFindPath() {
|
2012-04-08 11:36:16 +02:00
|
|
|
DocumentationService::register("DocumentationViewerTests", DOCSVIEWER_PATH . "/tests/docs/");
|
2010-12-21 10:42:44 +01:00
|
|
|
|
|
|
|
// file
|
|
|
|
$path = DocumentationService::find_page('DocumentationViewerTests', array('test'));
|
2012-04-08 11:36:16 +02:00
|
|
|
$this->assertEquals(DOCSVIEWER_PATH . "/tests/docs/en/test.md", $path);
|
2010-12-21 10:42:44 +01:00
|
|
|
|
|
|
|
// the home page. The path finder should go to the index.md file in the default language
|
|
|
|
$path = DocumentationService::find_page('DocumentationViewerTests', array(''));
|
2012-04-08 11:36:16 +02:00
|
|
|
$this->assertEquals(DOCSVIEWER_PATH . "/tests/docs/en/index.md", $path);
|
2010-12-21 10:42:44 +01:00
|
|
|
|
|
|
|
// second level
|
|
|
|
$path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subpage'));
|
2012-04-08 11:36:16 +02:00
|
|
|
$this->assertEquals(DOCSVIEWER_PATH . "/tests/docs/en/subfolder/subpage.md", $path);
|
2011-01-14 02:48:36 +01:00
|
|
|
|
2011-01-14 03:16:03 +01:00
|
|
|
// subsubfolder has no index file. It should fail instead the viewer should pick up on this
|
|
|
|
// and display the listing of the folder
|
2010-12-21 10:42:44 +01:00
|
|
|
$path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subsubfolder'));
|
2011-01-14 03:16:03 +01:00
|
|
|
$this->assertFalse($path);
|
2010-12-21 10:42:44 +01:00
|
|
|
|
|
|
|
// third level
|
|
|
|
$path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subsubfolder', 'subsubpage'));
|
2012-04-08 11:36:16 +02:00
|
|
|
$this->assertEquals(DOCSVIEWER_PATH . "/tests/docs/en/subfolder/subsubfolder/subsubpage.md", $path);
|
2010-12-21 10:42:44 +01:00
|
|
|
|
|
|
|
// with trailing slash
|
|
|
|
$path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subsubfolder', 'subsubpage'));
|
2012-04-08 11:36:16 +02:00
|
|
|
$this->assertEquals(DOCSVIEWER_PATH . "/tests/docs/en/subfolder/subsubfolder/subsubpage.md", $path);
|
2010-12-21 10:42:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-22 09:21:49 +01:00
|
|
|
function testCleanPageNames() {
|
|
|
|
$names = array(
|
|
|
|
'documentation-Page',
|
|
|
|
'documentation_Page',
|
|
|
|
'documentation.md',
|
|
|
|
'documentation.pdf',
|
|
|
|
'documentation.file.txt',
|
|
|
|
'.hidden'
|
|
|
|
);
|
2010-12-21 10:42:44 +01:00
|
|
|
|
2010-12-22 09:21:49 +01:00
|
|
|
$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
|
|
|
|
);
|
2010-12-21 10:42:44 +01:00
|
|
|
|
2010-12-22 09:21:49 +01:00
|
|
|
foreach($names as $key => $value) {
|
|
|
|
$this->assertEquals(DocumentationService::clean_page_name($value), $should[$key]);
|
2010-12-21 10:42:44 +01:00
|
|
|
}
|
|
|
|
}
|
2011-07-04 06:58:15 +02:00
|
|
|
|
|
|
|
function testIsValidExtension() {
|
|
|
|
$this->assertTrue(DocumentationService::is_valid_extension('md'));
|
|
|
|
$this->assertTrue(DocumentationService::is_valid_extension('markdown'));
|
|
|
|
$this->assertTrue(DocumentationService::is_valid_extension('MD'));
|
|
|
|
$this->assertTrue(DocumentationService::is_valid_extension('MARKDOWN'));
|
|
|
|
|
|
|
|
$this->assertFalse(DocumentationService::is_valid_extension('.markd'));
|
|
|
|
$this->assertFalse(DocumentationService::is_valid_extension('.exe'));
|
|
|
|
|
|
|
|
// require an extension as internally we check for extension, not using
|
|
|
|
// one could cause issues.
|
|
|
|
$this->assertFalse(DocumentationService::is_valid_extension(''));
|
|
|
|
}
|
2010-12-21 10:42:44 +01:00
|
|
|
}
|