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.
|
|
|
|
*
|
2012-04-08 11:36:16 +02:00
|
|
|
* @package docsviewer
|
2012-04-08 11:23:49 +02:00
|
|
|
* @subpackage tests
|
2010-06-24 16:22:41 +02:00
|
|
|
*/
|
|
|
|
|
2010-12-22 09:21:49 +01:00
|
|
|
class DocumentationViewerTest extends FunctionalTest {
|
2010-06-24 16:22:41 +02:00
|
|
|
|
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();
|
2011-02-01 21:41:45 +01:00
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
$this->origEnabled = DocumentationService::automatic_registration_enabled();
|
|
|
|
DocumentationService::set_automatic_registration(false);
|
2011-07-01 08:49:31 +02:00
|
|
|
$this->origModules = DocumentationService::get_registered_entities();
|
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) {
|
2011-07-01 08:49:31 +02:00
|
|
|
DocumentationService::unregister($module->getFolder());
|
2010-08-01 06:46:32 +02:00
|
|
|
}
|
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
|
2012-04-08 11:36:16 +02:00
|
|
|
DocumentationService::register("DocumentationViewerTests", DOCSVIEWER_PATH . "/tests/docs/", '2.3');
|
|
|
|
DocumentationService::register("DocumentationViewerTests", DOCSVIEWER_PATH . "/tests/docs-v2.4/", '2.4', 'Doc Test', true);
|
|
|
|
DocumentationService::register("DocumentationViewerTests", DOCSVIEWER_PATH . "/tests/docs-v3.0/", '3.0', 'Doc Test');
|
2011-07-04 06:58:15 +02:00
|
|
|
|
2012-04-08 11:36:16 +02:00
|
|
|
DocumentationService::register("DocumentationViewerAltModule1", DOCSVIEWER_PATH . "/tests/docs-parser/", '1.0');
|
|
|
|
DocumentationService::register("DocumentationViewerAltModule2", DOCSVIEWER_PATH . "/tests/docs-search/", '1.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-07-01 03:19:35 +02:00
|
|
|
/**
|
|
|
|
* This tests that all the locations will exist if we access it via the urls.
|
|
|
|
*/
|
|
|
|
function testLocationsExists() {
|
|
|
|
$response = $this->get('dev/docs/DocumentationViewerTests/en/2.3/subfolder');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 200, 'Existing base folder');
|
|
|
|
|
|
|
|
$response = $this->get('dev/docs/DocumentationViewerTests/en/2.4');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 200, 'Existing base folder');
|
|
|
|
|
|
|
|
$response = $this->get('dev/docs/DocumentationViewerTests/en/2.4/');
|
2011-07-01 04:37:55 +02:00
|
|
|
$this->assertEquals($response->getStatusCode(), 200, 'Existing base folder');
|
2011-07-01 03:19:35 +02:00
|
|
|
|
|
|
|
$response = $this->get('dev/docs/DocumentationViewerTests/en/2.3/nonexistant-subfolder');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 404, 'Nonexistant subfolder');
|
|
|
|
|
|
|
|
$response = $this->get('dev/docs/DocumentationViewerTests/en/2.3/nonexistant-file.txt');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 404, 'Nonexistant file');
|
|
|
|
|
|
|
|
$response = $this->get('dev/docs/DocumentationViewerTests/en/2.3/test');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 200, 'Existing file');
|
|
|
|
|
|
|
|
$response = $this->get('dev/docs/DocumentationViewerTests/en/3.0/empty?foo');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 200, 'Existing page');
|
|
|
|
|
|
|
|
$response = $this->get('dev/docs/DocumentationViewerTests/en/3.0/empty.md');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 200, 'Existing page');
|
|
|
|
|
|
|
|
$response = $this->get('dev/docs/DocumentationViewerTests/en/3.0/empty/');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 200, 'Existing page');
|
|
|
|
|
|
|
|
$response = $this->get('dev/docs/DocumentationViewerTests/en/3.0/test');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 404, 'Missing page');
|
|
|
|
|
|
|
|
$response = $this->get('dev/docs/DocumentationViewerTests/en/3.0/test.md');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 404, 'Missing page');
|
|
|
|
|
|
|
|
$response = $this->get('dev/docs/DocumentationViewerTests/en/3.0/test/');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 404, 'Missing page');
|
2011-07-01 04:37:55 +02:00
|
|
|
|
|
|
|
$response = $this->get('dev/docs/en');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 404, 'Must include a module');
|
|
|
|
|
|
|
|
$response = $this->get('dev/docs/DocumentationViewerTests/dk/');;
|
|
|
|
$this->assertEquals($response->getStatusCode(), 404, 'Access a language that doesn\'t exist');
|
2011-07-01 03:19:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function testRouting() {
|
|
|
|
$response = $this->get('dev/docs/DocumentationViewerTests/en/2.4');
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
|
|
$this->assertContains('english test', $response->getBody(), 'Toplevel content page');
|
|
|
|
|
|
|
|
$response = $this->get('dev/docs/DocumentationViewerTests/en/2.4/');
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
|
|
$this->assertContains('english test', $response->getBody(), 'Toplevel content page');
|
|
|
|
|
|
|
|
$response = $this->get('dev/docs/DocumentationViewerTests/en/2.4/index.md');
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
|
|
$this->assertContains('english test', $response->getBody(), 'Toplevel content page');
|
|
|
|
}
|
2011-01-17 07:00:16 +01:00
|
|
|
|
2010-12-22 09:21:49 +01:00
|
|
|
function testGetModulePagesShort() {
|
|
|
|
$v = new DocumentationViewer();
|
2012-04-14 08:02:53 +02:00
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/2.3/subfolder/'), DataModel::inst());
|
2011-07-01 08:49:31 +02:00
|
|
|
$pages = $v->getEntityPages();
|
2011-07-01 03:19:35 +02:00
|
|
|
|
2010-12-22 09:21:49 +01:00
|
|
|
$arr = $pages->toArray();
|
2011-07-01 03:19:35 +02:00
|
|
|
|
2010-12-22 09:21:49 +01:00
|
|
|
$page = $arr[2];
|
|
|
|
|
|
|
|
$this->assertEquals('Subfolder', $page->Title);
|
|
|
|
}
|
|
|
|
|
2011-07-04 06:58:15 +02:00
|
|
|
function testGetEntityPages() {
|
2010-12-22 09:21:49 +01:00
|
|
|
$v = new DocumentationViewer();
|
2012-04-14 08:02:53 +02:00
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/2.3/subfolder/'), DataModel::inst());
|
2011-07-01 08:49:31 +02:00
|
|
|
$pages = $v->getEntityPages();
|
2010-12-22 09:21:49 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
array('sort/', 'subfolder/', 'test.md'),
|
|
|
|
$pages->column('Filename')
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
array('link','current', 'link'),
|
|
|
|
$pages->column('LinkingMode')
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach($pages as $page) {
|
2011-07-01 03:19:35 +02:00
|
|
|
$page->setVersion('2.3');
|
2010-12-22 09:21:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$links = $pages->column('Link');
|
2011-07-01 03:19:35 +02:00
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/en/2.3/sort/', $links[0]);
|
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/en/2.3/subfolder/', $links[1]);
|
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/en/2.3/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->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) {
|
2011-07-01 03:19:35 +02:00
|
|
|
$child->setVersion('2.3');
|
2010-12-22 09:21:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$child2Links = $children->column('Link');
|
|
|
|
$subpage = $children->First();
|
2011-01-17 07:00:16 +01:00
|
|
|
|
2011-07-01 03:19:35 +02:00
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/en/2.3/subfolder/subpage', $child2Links[0]);
|
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/en/2.3/subfolder/subsubfolder/', $child2Links[1]);
|
2010-08-01 09:03:52 +02:00
|
|
|
}
|
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
function testUrlParsing() {
|
|
|
|
// Module index
|
|
|
|
$v = new DocumentationViewer();
|
2012-04-14 08:02:53 +02:00
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/2.3/test'), DataModel::inst());
|
2010-10-22 03:10:04 +02:00
|
|
|
$this->assertEquals('2.3', $v->getVersion());
|
|
|
|
$this->assertEquals('en', $v->getLang());
|
2011-07-01 08:49:31 +02:00
|
|
|
$this->assertEquals('DocumentationViewerTests', $v->getEntity()->getTitle());
|
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();
|
2012-04-14 08:02:53 +02:00
|
|
|
$response = $v2->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/test'), DataModel::inst());
|
2011-01-17 07:00:16 +01:00
|
|
|
|
2011-07-01 08:49:31 +02:00
|
|
|
$this->assertEquals('2.4', $v2->getVersion());
|
2010-10-22 03:10:04 +02:00
|
|
|
$this->assertEquals('en', $v2->getLang());
|
2011-07-01 08:49:31 +02:00
|
|
|
$this->assertEquals('DocumentationViewerTests', $v2->getEntity()->getTitle());
|
2010-10-22 03:10:04 +02:00
|
|
|
$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();
|
2012-04-14 08:02:53 +02:00
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', ''), DataModel::inst());
|
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();
|
2012-04-14 08:02:53 +02:00
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/2.4'), DataModel::inst());
|
2010-08-01 06:46:32 +02:00
|
|
|
$crumbs = $v->getBreadcrumbs();
|
|
|
|
$this->assertEquals(1, $crumbs->Count());
|
2010-06-24 16:22:41 +02:00
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
// Subfolder index
|
|
|
|
$v = new DocumentationViewer();
|
2012-04-14 08:02:53 +02:00
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/2.4/subfolder/'), DataModel::inst());
|
2010-08-01 06:46:32 +02:00
|
|
|
$crumbs = $v->getBreadcrumbs();
|
|
|
|
$this->assertEquals(2, $crumbs->Count());
|
2010-06-24 16:22:41 +02:00
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
// Subfolder page
|
|
|
|
$v = new DocumentationViewer();
|
2012-04-14 08:02:53 +02:00
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/2.4/subfolder/subpage'), DataModel::inst());
|
2010-08-01 06:46:32 +02:00
|
|
|
$crumbs = $v->getBreadcrumbs();
|
|
|
|
$this->assertEquals(3, $crumbs->Count());
|
|
|
|
}
|
|
|
|
|
2011-07-01 03:19:35 +02:00
|
|
|
function testGetVersion() {
|
|
|
|
$v = new DocumentationViewer();
|
2012-04-14 08:02:53 +02:00
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/2.4'), DataModel::inst());
|
2011-07-01 03:19:35 +02:00
|
|
|
$this->assertEquals('2.4', $v->getVersion());
|
|
|
|
|
2012-04-14 08:02:53 +02:00
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/1'), DataModel::inst());
|
2011-07-01 03:19:35 +02:00
|
|
|
$this->assertEquals('1', $v->getVersion());
|
|
|
|
|
2012-04-14 08:02:53 +02:00
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/3.0'), DataModel::inst());
|
2011-07-01 03:19:35 +02:00
|
|
|
$this->assertEquals('3.0', $v->getVersion());
|
2010-06-24 16:22:41 +02:00
|
|
|
}
|
2011-07-04 06:58:15 +02:00
|
|
|
|
|
|
|
function testGetEntities() {
|
|
|
|
$v = new DocumentationViewer();
|
2012-04-14 08:02:53 +02:00
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/2.4'), DataModel::inst());
|
2011-07-04 06:58:15 +02:00
|
|
|
|
|
|
|
$pages = $v->getEntities();
|
|
|
|
|
|
|
|
$this->assertEquals(3, $pages->Count(), 'Registered 3 entities');
|
|
|
|
|
|
|
|
// check to see the links don't have version or pages in them
|
|
|
|
foreach($pages as $page) {
|
|
|
|
$expected = Controller::join_links('docs', $page->Title, 'en');
|
|
|
|
|
|
|
|
$this->assertStringEndsWith($expected, $page->Link);
|
|
|
|
}
|
|
|
|
}
|
2011-07-08 04:42:52 +02:00
|
|
|
|
|
|
|
function testVersionWarning() {
|
|
|
|
$v = new DocumentationViewer();
|
|
|
|
|
|
|
|
// the current version is set to 2.4, no notice should be shown on that page
|
2012-04-14 08:02:53 +02:00
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/2.4'), DataModel::inst());
|
2011-07-08 04:42:52 +02:00
|
|
|
$this->assertFalse($v->VersionWarning());
|
|
|
|
|
|
|
|
// 2.3 is an older release, hitting that should return us an outdated flag
|
2012-04-14 08:02:53 +02:00
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/2.3'), DataModel::inst());
|
2011-07-08 04:42:52 +02:00
|
|
|
$warn = $v->VersionWarning();
|
|
|
|
|
|
|
|
$this->assertTrue($warn->OutdatedRelease);
|
|
|
|
$this->assertNull($warn->FutureRelease);
|
|
|
|
|
|
|
|
// 3.0 is a future release
|
2012-04-14 08:02:53 +02:00
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/3.0'), DataModel::inst());
|
2011-07-08 04:42:52 +02:00
|
|
|
$warn = $v->VersionWarning();
|
|
|
|
|
|
|
|
$this->assertNull($warn->OutdatedRelease);
|
|
|
|
$this->assertTrue($warn->FutureRelease);
|
|
|
|
}
|
2012-05-17 23:48:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that the pages comes back sorted by filename
|
|
|
|
*/
|
|
|
|
function testGetEntityPagesSortedByFilename() {
|
|
|
|
$v = new DocumentationViewer();
|
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/3.0/'), DataModel::inst());
|
|
|
|
$pages = $v->getEntityPages();
|
|
|
|
$links = $pages->column('Link');
|
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/en/3.0/ChangeLog', $links[0]);
|
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/en/3.0/Tutorials', $links[1]);
|
|
|
|
$this->assertStringEndsWith('DocumentationViewerTests/en/3.0/empty', $links[2]);
|
|
|
|
}
|
2010-06-24 16:22:41 +02:00
|
|
|
}
|