2010-06-24 16:22:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Some of these tests are simply checking that pages load. They should not assume
|
|
|
|
* somethings working.
|
|
|
|
*
|
|
|
|
* @package sapphiredocs
|
|
|
|
*/
|
|
|
|
|
|
|
|
class DocumentationViewerTests extends FunctionalTest {
|
|
|
|
|
|
|
|
static $fixture_file = 'sapphiredocs/tests/DocumentTests.yml';
|
2010-08-01 09:03:52 +02:00
|
|
|
|
|
|
|
protected $autoFollowRedirection = false;
|
2010-06-24 16:22:41 +02:00
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
function setUpOnce() {
|
|
|
|
parent::setUpOnce();
|
|
|
|
|
|
|
|
$this->origEnabled = DocumentationService::automatic_registration_enabled();
|
|
|
|
DocumentationService::set_automatic_registration(false);
|
|
|
|
$this->origModules = DocumentationService::get_registered_modules();
|
2010-08-01 09:03:52 +02:00
|
|
|
$this->origLinkBase = DocumentationViewer::get_link_base();
|
|
|
|
DocumentationViewer::set_link_base('dev/docs/');
|
2010-08-01 06:46:32 +02:00
|
|
|
foreach($this->origModules as $module) {
|
|
|
|
DocumentationService::unregister($module->getModuleFolder());
|
|
|
|
}
|
2010-08-01 09:03:52 +02:00
|
|
|
|
|
|
|
// We set 3.0 as current, and test most assertions against 2.4 - to avoid 'current' rewriting issues
|
2010-08-01 06:46:32 +02:00
|
|
|
DocumentationService::register("DocumentationViewerTests", BASE_PATH . "/sapphiredocs/tests/docs/", '2.4');
|
2010-08-01 09:03:52 +02:00
|
|
|
DocumentationService::register("DocumentationViewerTests", BASE_PATH . "/sapphiredocs/tests/docs-2/", '2.3');
|
|
|
|
DocumentationService::register("DocumentationViewerTests", BASE_PATH . "/sapphiredocs/tests/docs-3/", '3.0');
|
2010-08-01 06:46:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function tearDownOnce() {
|
|
|
|
parent::tearDownOnce();
|
2010-06-24 16:22:41 +02:00
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
DocumentationService::unregister("DocumentationViewerTests");
|
|
|
|
DocumentationService::set_automatic_registration($this->origEnabled);
|
2010-08-01 09:03:52 +02:00
|
|
|
DocumentationViewer::set_link_base($this->origLinkBase);
|
2010-08-01 06:46:32 +02:00
|
|
|
}
|
|
|
|
|
2010-08-01 09:03:52 +02:00
|
|
|
function testCurrentRedirection() {
|
|
|
|
$response = $this->get('dev/docs/3.0/en/DocumentationViewerTests/test');
|
2010-10-22 03:10:04 +02:00
|
|
|
|
2010-08-01 09:03:52 +02:00
|
|
|
$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');
|
|
|
|
}
|
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
function testUrlParsing() {
|
|
|
|
// Module index
|
|
|
|
$v = new DocumentationViewer();
|
2010-08-01 09:03:52 +02:00
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', '2.3/en/DocumentationViewerTests/test'));
|
2010-10-22 03:10:04 +02:00
|
|
|
$this->assertEquals('2.3', $v->getVersion());
|
|
|
|
$this->assertEquals('en', $v->getLang());
|
|
|
|
$this->assertEquals('DocumentationViewerTests', $v->module);
|
2010-08-01 06:46:32 +02:00
|
|
|
$this->assertEquals(array('test'), $v->Remaining);
|
|
|
|
|
2010-10-22 03:10:04 +02:00
|
|
|
// Module index without version and language. Should pick up the defaults
|
|
|
|
$v2 = new DocumentationViewer();
|
|
|
|
$response = $v2->handleRequest(new SS_HTTPRequest('GET', 'en/DocumentationViewerTests/test'));
|
|
|
|
|
|
|
|
$this->assertEquals('3.0', $v2->getVersion());
|
|
|
|
$this->assertEquals('en', $v2->getLang());
|
|
|
|
$this->assertEquals('DocumentationViewerTests', $v2->module);
|
|
|
|
$this->assertEquals(array('test'), $v2->Remaining);
|
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
// Overall index
|
2010-10-22 03:10:04 +02:00
|
|
|
$v = new DocumentationViewer();
|
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', ''));
|
|
|
|
$this->assertEquals('current', $v->getVersion());
|
|
|
|
$this->assertEquals('en', $v->getLang());
|
|
|
|
$this->assertEquals('', $v->module);
|
|
|
|
$this->assertEquals(array(), $v->Remaining);
|
2010-06-24 16:22:41 +02:00
|
|
|
}
|
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
function testBreadcrumbs() {
|
|
|
|
// Module index
|
|
|
|
$v = new DocumentationViewer();
|
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', '2.4/en/DocumentationViewerTests/'));
|
|
|
|
$crumbs = $v->getBreadcrumbs();
|
2010-10-22 03:10:04 +02:00
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
$this->assertEquals(1, $crumbs->Count());
|
|
|
|
$crumbLinks = $crumbs->column('Link');
|
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/', $crumbLinks[0]);
|
2010-06-24 16:22:41 +02:00
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
// Subfolder index
|
|
|
|
$v = new DocumentationViewer();
|
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', '2.4/en/DocumentationViewerTests/subfolder/'));
|
|
|
|
$crumbs = $v->getBreadcrumbs();
|
|
|
|
$this->assertEquals(2, $crumbs->Count());
|
|
|
|
$crumbLinks = $crumbs->column('Link');
|
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/', $crumbLinks[0]);
|
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/subfolder/', $crumbLinks[1]);
|
2010-06-24 16:22:41 +02:00
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
// Subfolder page
|
|
|
|
$v = new DocumentationViewer();
|
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', '2.4/en/DocumentationViewerTests/subfolder/subpage'));
|
|
|
|
$crumbs = $v->getBreadcrumbs();
|
|
|
|
$this->assertEquals(3, $crumbs->Count());
|
|
|
|
$crumbLinks = $crumbs->column('Link');
|
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/', $crumbLinks[0]);
|
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/subfolder/', $crumbLinks[1]);
|
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/subfolder/subpage/', $crumbLinks[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetModulePages() {
|
|
|
|
$v = new DocumentationViewer();
|
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', '2.4/en/DocumentationViewerTests/subfolder/'));
|
|
|
|
$pages = $v->getModulePages();
|
|
|
|
$this->assertEquals(
|
2010-10-29 04:12:20 +02:00
|
|
|
array('sort', 'subfolder', 'test'),
|
2010-08-01 06:46:32 +02:00
|
|
|
$pages->column('Filename')
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
2010-10-29 04:12:20 +02:00
|
|
|
array('link','current', 'link'),
|
2010-08-01 06:46:32 +02:00
|
|
|
$pages->column('LinkingMode')
|
|
|
|
);
|
|
|
|
$links = $pages->column('Link');
|
2010-10-29 04:12:20 +02:00
|
|
|
|
|
|
|
$this->assertStringEndsWith('2.4/en/DocumentationViewerTests/sort/', $links[0]);
|
|
|
|
$this->assertStringEndsWith('2.4/en/DocumentationViewerTests/subfolder/', $links[1]);
|
|
|
|
$this->assertStringEndsWith('2.4/en/DocumentationViewerTests/test/', $links[2]);
|
2010-08-01 06:46:32 +02:00
|
|
|
|
|
|
|
// Children
|
|
|
|
$pagesArr = $pages->toArray();
|
2010-10-29 04:12:20 +02:00
|
|
|
|
|
|
|
$child1 = $pagesArr[1];
|
2010-10-08 05:31:19 +02:00
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
$this->assertFalse($child1->Children);
|
2010-06-24 16:22:41 +02:00
|
|
|
|
2010-10-08 05:31:19 +02:00
|
|
|
$child2 = $pagesArr[2];
|
2010-12-21 10:42:44 +01:00
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
$this->assertType('DataObjectSet', $child2->Children);
|
2010-12-21 10:42:44 +01:00
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
$this->assertEquals(
|
|
|
|
array('subpage', 'subsubfolder'),
|
|
|
|
$child2->Children->column('Filename')
|
|
|
|
);
|
2010-12-21 10:42:44 +01:00
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
$child2Links = $child2->Children->column('Link');
|
|
|
|
$this->assertStringEndsWith('2.4/en/DocumentationViewerTests/subfolder/subpage/', $child2Links[0]);
|
|
|
|
$this->assertStringEndsWith('2.4/en/DocumentationViewerTests/subfolder/subsubfolder/', $child2Links[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testRouting() {
|
|
|
|
$response = $this->get('dev/docs/2.4/en/DocumentationViewerTests/test');
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
|
|
$this->assertContains('english test', $response->getBody(), 'Toplevel content page');
|
2010-06-24 16:22:41 +02:00
|
|
|
}
|
2010-08-01 06:46:32 +02:00
|
|
|
|
|
|
|
// function testGetPage() {
|
|
|
|
// $v = new DocumentationViewer();
|
|
|
|
// $v->handleRequest(new SS_HTTPRequest('GET', '2.4/en/cms'));
|
|
|
|
// $p = $v->getPage();
|
|
|
|
// $this->assertType('DocumentationPage', $p);
|
|
|
|
// $this->assertEquals('/', $p->getRelativePath());
|
|
|
|
// $this->assertEquals('en', $p->getLang());
|
|
|
|
// $this->assertEquals('2.4', $p->getVersion());
|
|
|
|
// }
|
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
}
|