mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 09:05:56 +00:00
ENHANCEMENT Rewriting current version URL path to 'current/'
This commit is contained in:
parent
f623dcc887
commit
845e2e61b2
@ -99,7 +99,7 @@ class DocumentationViewer extends Controller {
|
||||
// /2.4/en/sapphire/page and
|
||||
// /en/sapphire/page which is a link to the latest one
|
||||
|
||||
if(!is_numeric($this->Version)) {
|
||||
if(!is_numeric($this->Version) && $this->Version != 'current') {
|
||||
array_unshift($this->Remaining, $this->ModuleName);
|
||||
|
||||
// not numeric so /en/sapphire/folder/page
|
||||
@ -125,6 +125,25 @@ class DocumentationViewer extends Controller {
|
||||
$this->Lang = 'en';
|
||||
}
|
||||
|
||||
// 'current' version mapping
|
||||
$module = DocumentationService::is_registered_module($this->ModuleName, null, $this->Lang);
|
||||
if($this->Version && $module) {
|
||||
$current = $module->getCurrentVersion();
|
||||
if($this->Version == 'current') {
|
||||
$this->Version = $current;
|
||||
} else {
|
||||
if($current == $this->Version) {
|
||||
$this->Version = 'current';
|
||||
$link = $this->Link($this->Remaining);
|
||||
$this->response = new SS_HTTPResponse();
|
||||
$this->redirect($link, 301); // permanent redirect
|
||||
return $this->response;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return parent::handleRequest($request);
|
||||
}
|
||||
|
||||
|
@ -11,16 +11,24 @@ class DocumentationViewerTests extends FunctionalTest {
|
||||
|
||||
static $fixture_file = 'sapphiredocs/tests/DocumentTests.yml';
|
||||
|
||||
protected $autoFollowRedirection = false;
|
||||
|
||||
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 tearDownOnce() {
|
||||
@ -28,17 +36,39 @@ class DocumentationViewerTests extends FunctionalTest {
|
||||
|
||||
DocumentationService::unregister("DocumentationViewerTests");
|
||||
DocumentationService::set_automatic_registration($this->origEnabled);
|
||||
DocumentationViewer::set_link_base($this->origLinkBase);
|
||||
// $this->origModules = Documentation::get_registered_modules();
|
||||
// foreach($this->origModules as $name => $module) {
|
||||
// DocumentationService::register($name);
|
||||
// }
|
||||
}
|
||||
|
||||
function testCurrentRedirection() {
|
||||
$response = $this->get('dev/docs/3.0/en/DocumentationViewerTests/test');
|
||||
$this->assertEquals(301, $response->getStatusCode());
|
||||
$this->assertEquals(
|
||||
Director::absoluteBaseURL() . 'dev/docs/current/en/DocumentationViewerTests/test/',
|
||||
$response->getHeader('Location'),
|
||||
'Redirection to current on page'
|
||||
);
|
||||
|
||||
$response = $this->get('dev/docs/3.0/en/DocumentationViewerTests/');
|
||||
$this->assertEquals(301, $response->getStatusCode());
|
||||
$this->assertEquals(
|
||||
Director::absoluteBaseURL() . 'dev/docs/current/en/DocumentationViewerTests/',
|
||||
$response->getHeader('Location'),
|
||||
'Redirection to current on index'
|
||||
);
|
||||
|
||||
$response = $this->get('dev/docs/2.3/en/DocumentationViewerTests/');
|
||||
$this->assertEquals(200, $response->getStatusCode(), 'No redirection on older versions');
|
||||
}
|
||||
|
||||
function testUrlParsing() {
|
||||
// Module index
|
||||
$v = new DocumentationViewer();
|
||||
$response = $v->handleRequest(new SS_HTTPRequest('GET', '2.4/en/DocumentationViewerTests/test'));
|
||||
$this->assertEquals('2.4', $v->Version);
|
||||
$response = $v->handleRequest(new SS_HTTPRequest('GET', '2.3/en/DocumentationViewerTests/test'));
|
||||
$this->assertEquals('2.3', $v->Version);
|
||||
$this->assertEquals('en', $v->Lang);
|
||||
$this->assertEquals('DocumentationViewerTests', $v->ModuleName);
|
||||
$this->assertEquals(array('test'), $v->Remaining);
|
||||
|
0
tests/docs-2/en/test.md
Normal file
0
tests/docs-2/en/test.md
Normal file
Loading…
x
Reference in New Issue
Block a user