function testGetLink() { $entity = new DocumentationEntity('testmodule', null, BASE_PATH . '/sapphiredocs/tests/docs/'); $page = new DocumentationPage(); $page->setRelativePath('test.md'); $page->setEntity($entity); // single layer $this->assertStringEndsWith('testmodule/en/test', $page->Link(), 'The page link should have no extension and have a language'); $folder = new DocumentationPage(); $folder->setRelativePath('sort'); $folder->setEntity($entity); // folder, should have a trailing slash $this->assertStringEndsWith('testmodule/en/sort/', $folder->Link()); // second $nested = new DocumentationPage(); $nested->setRelativePath('subfolder/subpage.md'); $nested->setEntity($entity); $this->assertStringEndsWith('testmodule/en/subfolder/subpage', $nested->Link()); // test with version. $entity = DocumentationService::register("versionlinks", BASE_PATH . "/sapphiredocs/tests/docs-v2.4/", '1'); $entity->addVersion('2', BASE_PATH . "/sapphiredocs/tests/docs-v3.0/"); $entity->setStableVersion('2'); $page = new DocumentationPage(); $page->setRelativePath('test.md'); $page->setEntity($entity); $page->setVersion('1'); $this->assertStringEndsWith('versionlinks/en/1/test', $page->Link()); }
function testGetAllPages() { if (!DocumentationSearch::enabled()) { return; } DocumentationService::set_automatic_registration(false); DocumentationService::register('docs-search', BASE_PATH . '/sapphiredocs/tests/docs-search/'); $search = DocumentationSearch::get_all_documentation_pages(); $this->assertEquals(7, $search->Count(), '5 pages. 5 pages in entire folder'); }
function setUpOnce() { parent::setUpOnce(); $this->origEnabled = DocumentationService::automatic_registration_enabled(); DocumentationService::set_automatic_registration(false); $this->origModules = DocumentationService::get_registered_modules(); $this->origLinkBase = DocumentationViewer::get_link_base(); DocumentationViewer::set_link_base('dev/docs/'); foreach ($this->origModules as $module) { DocumentationService::unregister($module->getModuleFolder()); } // We set 3.0 as current, and test most assertions against 2.4 - to avoid 'current' rewriting issues DocumentationService::register("DocumentationViewerTests", BASE_PATH . "/sapphiredocs/tests/docs/", '2.4'); DocumentationService::register("DocumentationViewerTests", BASE_PATH . "/sapphiredocs/tests/docs-2/", '2.3'); DocumentationService::register("DocumentationViewerTests", BASE_PATH . "/sapphiredocs/tests/docs-3/", '3.0'); }
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); }
<?php global $project; $project = 'mysite'; global $database; $database = 'SS_ssnewdocstest'; require_once 'conf/ConfigureFromEnv.php'; MySQLDatabase::set_connection_charset('utf8'); // This line set's the current theme. More themes can be // downloaded from http://www.silverstripe.org/themes/ SSViewer::set_theme('docs'); // enable nested URLs for this site (e.g. page/sub-page/) SiteTree::enable_nested_urls(); // render the user documentation first Director::addRules(20, array('Security//$Action/$ID/$OtherID' => 'Security')); DocumentationViewer::set_link_base(''); DocumentationViewer::$check_permission = false; Director::addRules(10, array('$Action' => 'DocumentationViewer', '' => '->current/en/cms')); DocumentationService::set_automatic_registration(false); DocumentationService::register("cms", realpath("../../master/cms/docs/"), '2.4'); // We want this to be reviewed by the whole community BasicAuth::protect_entire_site(false);
error_reporting(E_ALL); // This line set's the current theme. More themes can be // downloaded from http://www.silverstripe.org/themes/ SSViewer::set_theme('userhelp'); if (@$_GET['db'] == "sqlite3") { global $databaseConfig; $databaseConfig['type'] = 'SQLite3Database'; } DocumentationService::set_automatic_registration(false); DocumentationService::enable_meta_comments(); DocumentationViewer::set_link_base(''); DocumentationViewer::$check_permission = false; try { DocumentationService::register("framework", BASE_PATH . "/src/framework_master/docs/", 'trunk'); DocumentationService::register("framework", BASE_PATH . "/src/framework_3.1/docs/", '3.1', false, true); DocumentationService::register("framework", BASE_PATH . "/src/framework_3.0/docs/", '3.0'); } catch (InvalidArgumentException $e) { } // Silence if path is not found (for CI environment) DocumentationViewer::set_edit_link('framework', 'https://github.com/silverstripe/silverstripe-userhelp-content/edit/%version%/docs/%lang%/%path%', array('rewritetrunktomaster' => true)); Object::add_extension('Controller', 'ControllerExtension'); if (Director::isLive()) { ControllerExtension::$google_analytics_code = 'UA-84547-10'; } // Validator::set_javascript_validation_handler('none'); DocumentationSearch::enable(); DocumentationSearch::set_meta_data(array('ShortName' => 'SilverStripe Userhelp', 'Description' => 'Userhelp for SilverStripe CMS / Framework', 'Tags' => 'silverstripe sapphire php framework cms content management system')); // Set shared index (avoid issues with different temp paths between CLI and web users) if (file_exists(BASE_PATH . '/.lucene-index')) { DocumentationSearch::set_index(BASE_PATH . '/.lucene-index'); }