FIX Language viewer test.

This commit is contained in:
Will Rossiter 2014-09-21 11:19:17 +12:00
parent 5ab53e65f2
commit 8057c9257c
2 changed files with 75 additions and 51 deletions

View File

@ -205,17 +205,22 @@ class DocumentationViewer extends Controller {
//
$languages = i18n::get_common_languages();
if(!$request->param('Lang')) {
if(!$lang = $request->param('Lang')) {
$lang = $request->param('Action');
$action = $request->param('ID');
} else {
$action = $request->param('Action');
}
if(!$lang) {
return $this->redirect($this->Link('en'));
} else if(!isset($languages[$request->param('Lang')])) {
} else if(!isset($languages[$lang])) {
return $this->httpError(404);
}
$action = $request->param('Action');
$allowed = $this->config()->allowed_actions;
$request->shift(10);
$request->shift();
$request->shift();
$allowed = $this->config()->allowed_actions;
if(in_array($action, $allowed)) {
//
@ -248,7 +253,7 @@ class DocumentationViewer extends Controller {
));
return new SS_HTTPResponse($body, 200);
} else if(!$url || $url == $request->param('Lang')) {
} else if(!$url || $url == $lang) {
$body = $this->renderWith(array(
"DocumentationViewer_DocumentationFolder",
"DocumentationViewer"
@ -291,7 +296,11 @@ class DocumentationViewer extends Controller {
* @return string
*/
public function getLanguage() {
return $this->request->param('Lang');
if(!$lang = $this->request->param('Lang')) {
$lang = $this->request->param('Action');
}
return $lang;
}
@ -308,7 +317,10 @@ class DocumentationViewer extends Controller {
$record = $this->getPage();
$current = $this->getEntity();
foreach($entities as $entity) {
// only show entities with the same language
if($entity->getLanguage() !== $this->getLanguage()) {
continue;
@ -393,11 +405,13 @@ class DocumentationViewer extends Controller {
return $this->getManifest()->getChildrenFor(
$this->record->getPath()
);
} else {
} else if($this->record) {
return $this->getManifest()->getChildrenFor(
dirname($this->record->getPath())
);
}
return new ArrayList();
}
/**
@ -589,7 +603,8 @@ class DocumentationViewer extends Controller {
*/
public function getNextPage() {
return ($this->record)
? $this->getManifest()->getNextPage($this->record->getPath())
? $this->getManifest()->getNextPage(
$this->record->getPath(), $this->getEntity()->getPath())
: null;
}
@ -601,7 +616,8 @@ class DocumentationViewer extends Controller {
*/
public function getPreviousPage() {
return ($this->record)
? $this->getManifest()->getPreviousPage($this->record->getPath())
? $this->getManifest()->getPreviousPage(
$this->record->getPath(), $this->getEntity()->getPath())
: null;
}

View File

@ -60,6 +60,8 @@ class DocumentationViewerTest extends FunctionalTest {
)
);
Config::inst()->update('SSViewer', 'theme_enabled', false);
$this->manifest = new DocumentationManifest(true);
}
@ -69,46 +71,21 @@ class DocumentationViewerTest extends FunctionalTest {
Config::unnest();
}
public function testGetMenu() {
$v = new DocumentationViewer();
// check with children
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'en/doc_test/2.3/'), DataModel::inst());
$expected = array(
'dev/docs/en/doc_test/2.3/sort/' => 'Sort',
'dev/docs/en/doc_test/2.3/subfolder/' => 'Subfolder',
'dev/docs/en/doc_test/2.3/test/' => 'Test'
);
$actual = $v->getMenu()->first()->Children->map('Link', 'Title');
$this->assertEquals($expected, $actual);
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'en/doc_test/'), DataModel::inst());
$this->assertEquals('current', $v->getMenu()->first()->LinkingMode);
// 2.4 stable release has 1 child page (not including index)
$this->assertEquals(1, $v->getMenu()->first()->Children->count());
// menu should contain all the english entities
$expected = array(
'dev/docs/en/doc_test/' => 'Doc Test',
'dev/docs/en/documentationvieweraltmodule1/' => 'DocumentationViewerAltModule1',
'dev/docs/en/documentationvieweraltmodule2/' => 'DocumentationViewerAltModule2'
);
$this->assertEquals($expected, $v->getMenu()->map('Link', 'Title'));
}
/**
* This tests that all the locations will exist if we access it via the urls.
*/
public function testLocationsExists() {
$this->autoFollowRedirection = false;
$response = $this->get('dev/docs/en/doc_test/2.3/subfolder/');
$this->assertEquals($response->getStatusCode(), 200, 'Existing base folder');
$response = $this->get('dev/docs/en/doc_test/2.3/subfolder/subsubfolder/');
$this->assertEquals($response->getStatusCode(), 200, 'Existing base folder');
$response = $this->get('dev/docs/en/doc_test/2.3/subfolder/subsubfolder/subsubpage/');
$this->assertEquals($response->getStatusCode(), 200, 'Existing base folder');
$response = $this->get('dev/docs/en/');
$this->assertEquals($response->getStatusCode(), 200, 'Lists the home index');
@ -116,10 +93,6 @@ class DocumentationViewerTest extends FunctionalTest {
$this->assertEquals($response->getStatusCode(), 302, 'Go to english view');
$response = $this->get('dev/docs/en/doc_test/2.3/subfolder/');
$this->assertEquals($response->getStatusCode(), 200, 'Existing base folder');
$response = $this->get('dev/docs/en/doc_test/3.0/empty.md');
$this->assertEquals(301, $response->getStatusCode(), 'Direct markdown links also work. They should redirect to /empty/');
@ -168,6 +141,41 @@ class DocumentationViewerTest extends FunctionalTest {
}
public function testGetMenu() {
$v = new DocumentationViewer();
// check with children
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'en/doc_test/2.3/'), DataModel::inst());
$expected = array(
'dev/docs/en/doc_test/2.3/sort/' => 'Sort',
'dev/docs/en/doc_test/2.3/subfolder/' => 'Subfolder',
'dev/docs/en/doc_test/2.3/test/' => 'Test'
);
$actual = $v->getMenu()->first()->Children->map('Link', 'Title');
$this->assertEquals($expected, $actual);
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'en/doc_test/'), DataModel::inst());
$this->assertEquals('current', $v->getMenu()->first()->LinkingMode);
// 2.4 stable release has 1 child page (not including index)
$this->assertEquals(1, $v->getMenu()->first()->Children->count());
// menu should contain all the english entities
$expected = array(
'dev/docs/en/doc_test/' => 'Doc Test',
'dev/docs/en/documentationvieweraltmodule1/' => 'DocumentationViewerAltModule1',
'dev/docs/en/documentationvieweraltmodule2/' => 'DocumentationViewerAltModule2'
);
$this->assertEquals($expected, $v->getMenu()->map('Link', 'Title'));
}
public function testGetLanguage() {
$v = new DocumentationViewer();
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'en/doc_test/2.3/'), DataModel::inst());