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
|
|
|
|
*/
|
|
|
|
|
2010-12-22 09:21:49 +01:00
|
|
|
class DocumentationViewerTest extends FunctionalTest {
|
2010-06-24 16:22:41 +02:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-01-17 07:00:16 +01:00
|
|
|
function testLocationExists() {
|
|
|
|
$response = $this->get('DocumentationViewerTests/en/2.4/');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 200, 'Existing base folder');
|
|
|
|
|
|
|
|
$response = $this->get('DocumentationViewerTests/en/2.4/subfolder');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 200, 'Existing subfolder');
|
|
|
|
|
|
|
|
$response = $this->get('DocumentationViewerTests/en/2.4/nonexistant-subfolder');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 404, 'Nonexistant subfolder');
|
|
|
|
|
|
|
|
$response = $this->get('DocumentationViewerTests/en/2.4/nonexistant-file.txt');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 404, 'Nonexistant file');
|
|
|
|
|
|
|
|
$response = $this->get('DocumentationViewerTests/en/2.4/test');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 200, 'Existing file');
|
|
|
|
}
|
|
|
|
|
2010-12-22 09:21:49 +01:00
|
|
|
function testGetModulePagesShort() {
|
|
|
|
$v = new DocumentationViewer();
|
2011-01-14 02:03:46 +01:00
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/2.4/subfolder/'));
|
2010-12-22 09:21:49 +01:00
|
|
|
$pages = $v->getModulePages();
|
|
|
|
|
|
|
|
$arr = $pages->toArray();
|
|
|
|
$page = $arr[2];
|
|
|
|
|
|
|
|
$this->assertEquals('Subfolder', $page->Title);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetModulePages() {
|
|
|
|
$v = new DocumentationViewer();
|
2011-01-14 02:03:46 +01:00
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/2.4/subfolder/'));
|
2010-12-22 09:21:49 +01:00
|
|
|
$pages = $v->getModulePages();
|
|
|
|
$this->assertEquals(
|
|
|
|
array('sort/', 'subfolder/', 'test.md'),
|
|
|
|
$pages->column('Filename')
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
array('link','current', 'link'),
|
|
|
|
$pages->column('LinkingMode')
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach($pages as $page) {
|
|
|
|
$page->setVersion('2.4');
|
|
|
|
}
|
|
|
|
|
|
|
|
$links = $pages->column('Link');
|
|
|
|
|
2011-01-14 02:03:46 +01:00
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/en/2.4/sort/', $links[0]);
|
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/en/2.4/subfolder/', $links[1]);
|
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/en/2.4/test', $links[2]);
|
2010-12-22 09:21:49 +01:00
|
|
|
|
|
|
|
// Children
|
|
|
|
$pagesArr = $pages->toArray();
|
|
|
|
$child1 = $pagesArr[1];
|
2011-01-17 07:00:16 +01:00
|
|
|
|
2010-12-22 09:21:49 +01:00
|
|
|
$this->assertFalse($child1->Children);
|
|
|
|
$child2 = $pagesArr[2];
|
|
|
|
|
|
|
|
$this->assertType('DataObjectSet', $child2->Children);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
array('subfolder/subpage.md', 'subfolder/subsubfolder/'),
|
|
|
|
$child2->Children->column('Filename')
|
|
|
|
);
|
2011-01-17 07:00:16 +01:00
|
|
|
|
2010-12-22 09:21:49 +01:00
|
|
|
$children = $child2->Children;
|
|
|
|
|
|
|
|
foreach($children as $child) {
|
|
|
|
$child->setVersion('2.4');
|
|
|
|
}
|
|
|
|
|
|
|
|
$child2Links = $children->column('Link');
|
|
|
|
$subpage = $children->First();
|
2011-01-17 07:00:16 +01:00
|
|
|
|
2011-01-14 02:03:46 +01:00
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/en/2.4/subfolder/subpage', $child2Links[0]);
|
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/en/2.4/subfolder/subsubfolder/', $child2Links[1]);
|
2010-12-22 09:21:49 +01:00
|
|
|
}
|
|
|
|
|
2010-08-01 09:03:52 +02:00
|
|
|
function testCurrentRedirection() {
|
2011-01-14 02:03:46 +01:00
|
|
|
$response = $this->get('dev/docs/DocumentationViewerTests/en/3.0/test');
|
2011-01-17 07:00:16 +01:00
|
|
|
|
2010-08-01 09:03:52 +02:00
|
|
|
$this->assertEquals(301, $response->getStatusCode());
|
|
|
|
$this->assertEquals(
|
2011-01-14 02:03:46 +01:00
|
|
|
Director::absoluteBaseURL() . 'dev/docs/DocumentationViewerTests/en/test/',
|
2010-08-01 09:03:52 +02:00
|
|
|
$response->getHeader('Location'),
|
|
|
|
'Redirection to current on page'
|
|
|
|
);
|
|
|
|
|
2011-01-14 02:03:46 +01:00
|
|
|
$response = $this->get('dev/docs/DocumentationViewerTests/en/3.0');
|
2010-08-01 09:03:52 +02:00
|
|
|
$this->assertEquals(301, $response->getStatusCode());
|
|
|
|
$this->assertEquals(
|
2011-01-14 02:03:46 +01:00
|
|
|
Director::absoluteBaseURL() . 'dev/docs/DocumentationViewerTests/en/',
|
2010-08-01 09:03:52 +02:00
|
|
|
$response->getHeader('Location'),
|
|
|
|
'Redirection to current on index'
|
|
|
|
);
|
|
|
|
|
2011-01-14 02:03:46 +01:00
|
|
|
$response = $this->get('dev/docs/DocumentationViewerTests/en/2.3');
|
2010-08-01 09:03:52 +02:00
|
|
|
$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();
|
2011-01-14 02:03:46 +01:00
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/2.3/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);
|
2011-01-17 07:00:16 +01:00
|
|
|
|
2010-10-22 03:10:04 +02:00
|
|
|
// Module index without version and language. Should pick up the defaults
|
|
|
|
$v2 = new DocumentationViewer();
|
2011-01-14 02:03:46 +01:00
|
|
|
$response = $v2->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/test'));
|
2011-01-17 07:00:16 +01:00
|
|
|
|
2010-10-22 03:10:04 +02:00
|
|
|
$this->assertEquals('3.0', $v2->getVersion());
|
|
|
|
$this->assertEquals('en', $v2->getLang());
|
|
|
|
$this->assertEquals('DocumentationViewerTests', $v2->module);
|
|
|
|
$this->assertEquals(array('test'), $v2->Remaining);
|
2011-01-17 07:00:16 +01:00
|
|
|
|
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', ''));
|
2011-01-14 02:03:46 +01:00
|
|
|
$this->assertEquals('', $v->getVersion());
|
2010-10-22 03:10:04 +02:00
|
|
|
$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();
|
2011-01-14 02:03:46 +01:00
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/2.4'));
|
2010-08-01 06:46:32 +02:00
|
|
|
$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');
|
2011-01-14 02:03:46 +01:00
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/en/2.4/', $crumbLinks[0]);
|
2010-06-24 16:22:41 +02:00
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
// Subfolder index
|
|
|
|
$v = new DocumentationViewer();
|
2011-01-14 02:03:46 +01:00
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/2.4/subfolder/'));
|
2010-08-01 06:46:32 +02:00
|
|
|
$crumbs = $v->getBreadcrumbs();
|
|
|
|
$this->assertEquals(2, $crumbs->Count());
|
|
|
|
$crumbLinks = $crumbs->column('Link');
|
2011-01-14 02:03:46 +01:00
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/en/2.4/', $crumbLinks[0]);
|
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/en/2.4/subfolder/', $crumbLinks[1]);
|
2010-06-24 16:22:41 +02:00
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
// Subfolder page
|
|
|
|
$v = new DocumentationViewer();
|
2011-01-14 02:03:46 +01:00
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/2.4/subfolder/subpage'));
|
2010-08-01 06:46:32 +02:00
|
|
|
$crumbs = $v->getBreadcrumbs();
|
|
|
|
$this->assertEquals(3, $crumbs->Count());
|
|
|
|
$crumbLinks = $crumbs->column('Link');
|
2011-01-14 02:03:46 +01:00
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/en/2.4/', $crumbLinks[0]);
|
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/en/2.4/subfolder/', $crumbLinks[1]);
|
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/en/2.4/subfolder/subpage/', $crumbLinks[2]);
|
2010-08-01 06:46:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function testRouting() {
|
2011-01-14 02:03:46 +01:00
|
|
|
$response = $this->get('dev/docs/DocumentationViewerTests/en/2.4/test');
|
2010-08-01 06:46:32 +02:00
|
|
|
$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
|
|
|
}
|