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;
|
2014-09-07 01:26:12 +02:00
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
protected $manifest;
|
2014-09-07 01:26:12 +02:00
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
Config::nest();
|
|
|
|
|
|
|
|
// explicitly use dev/docs. Custom paths should be tested separately
|
|
|
|
Config::inst()->update(
|
|
|
|
'DocumentationViewer', 'link_base', 'dev/docs/'
|
|
|
|
);
|
|
|
|
|
|
|
|
// disable automatic module registration so modules don't interfere.
|
|
|
|
Config::inst()->update(
|
|
|
|
'DocumentationManifest', 'automatic_registration', false
|
|
|
|
);
|
|
|
|
|
|
|
|
Config::inst()->remove('DocumentationManifest', 'register_entities');
|
|
|
|
|
|
|
|
Config::inst()->update(
|
|
|
|
'DocumentationManifest', 'register_entities', array(
|
|
|
|
array(
|
|
|
|
'Path' => DOCSVIEWER_PATH . "/tests/docs/",
|
|
|
|
'Title' => 'Doc Test',
|
|
|
|
'Version' => '2.3'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Path' => DOCSVIEWER_PATH . "/tests/docs-v2.4/",
|
|
|
|
'Title' => 'Doc Test',
|
|
|
|
'Version' => '2.4',
|
|
|
|
'Stable' => true
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Path' => DOCSVIEWER_PATH . "/tests/docs-v3.0/",
|
|
|
|
'Title' => 'Doc Test',
|
|
|
|
'Version' => '3.0'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Path' => DOCSVIEWER_PATH . "/tests/docs-parser/",
|
|
|
|
'Title' => 'DocumentationViewerAltModule1'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Path' => DOCSVIEWER_PATH . "/tests/docs-search/",
|
|
|
|
'Title' => 'DocumentationViewerAltModule2'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2014-09-21 01:19:17 +02:00
|
|
|
Config::inst()->update('SSViewer', 'theme_enabled', false);
|
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
$this->manifest = new DocumentationManifest(true);
|
2010-08-01 06:46:32 +02:00
|
|
|
}
|
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
public function tearDown() {
|
|
|
|
parent::tearDown();
|
2010-06-24 16:22:41 +02:00
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
Config::unnest();
|
|
|
|
}
|
|
|
|
|
2011-07-01 03:19:35 +02:00
|
|
|
/**
|
|
|
|
* This tests that all the locations will exist if we access it via the urls.
|
|
|
|
*/
|
2014-09-15 11:47:45 +02:00
|
|
|
public function testLocationsExists() {
|
|
|
|
$this->autoFollowRedirection = false;
|
|
|
|
|
2014-09-21 01:19:17 +02:00
|
|
|
$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');
|
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
$response = $this->get('dev/docs/en/');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 200, 'Lists the home index');
|
|
|
|
|
|
|
|
$response = $this->get('dev/docs/');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 302, 'Go to english view');
|
|
|
|
|
|
|
|
|
|
|
|
$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/');
|
|
|
|
|
|
|
|
|
|
|
|
// 2.4 is the stable release. Not in the URL
|
|
|
|
$response = $this->get('dev/docs/en/doc_test/');
|
2011-07-01 03:19:35 +02:00
|
|
|
$this->assertEquals($response->getStatusCode(), 200, 'Existing base folder');
|
2014-09-15 11:47:45 +02:00
|
|
|
$this->assertContains('english test', $response->getBody(), 'Toplevel content page');
|
2011-07-01 03:19:35 +02:00
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
// accessing 2.4 is redirects to the version without the version number.
|
|
|
|
$response = $this->get('dev/docs/en/doc_test/2.4/');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 404, 'Existing base folder redirects to without version');
|
|
|
|
|
|
|
|
$response = $this->get('dev/docs/en/doc_test/3.0/');
|
2011-07-01 04:37:55 +02:00
|
|
|
$this->assertEquals($response->getStatusCode(), 200, 'Existing base folder');
|
2011-07-01 03:19:35 +02:00
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
$response = $this->get('dev/docs/en/doc_test/2.3/nonexistant-subfolder');
|
2011-07-01 03:19:35 +02:00
|
|
|
$this->assertEquals($response->getStatusCode(), 404, 'Nonexistant subfolder');
|
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
$response = $this->get('dev/docs/en/doc_test/2.3/nonexistant-file.txt');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 301, 'Nonexistant file');
|
|
|
|
|
|
|
|
$response = $this->get('dev/docs/en/doc_test/2.3/nonexistant-file/');
|
2011-07-01 03:19:35 +02:00
|
|
|
$this->assertEquals($response->getStatusCode(), 404, 'Nonexistant file');
|
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
$response = $this->get('dev/docs/en/doc_test/2.3/test');
|
2011-07-01 03:19:35 +02:00
|
|
|
$this->assertEquals($response->getStatusCode(), 200, 'Existing file');
|
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
$response = $this->get('dev/docs/en/doc_test/3.0/empty?foo');
|
|
|
|
$this->assertEquals(200, $response->getStatusCode(), 'Existing page');
|
2011-07-01 03:19:35 +02:00
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
$response = $this->get('dev/docs/en/doc_test/3.0/empty/');
|
2011-07-01 03:19:35 +02:00
|
|
|
$this->assertEquals($response->getStatusCode(), 200, 'Existing page');
|
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
$response = $this->get('dev/docs/en/doc_test/3.0/test');
|
2011-07-01 03:19:35 +02:00
|
|
|
$this->assertEquals($response->getStatusCode(), 404, 'Missing page');
|
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
$response = $this->get('dev/docs/en/doc_test/3.0/test.md');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 301, 'Missing page');
|
2011-07-01 03:19:35 +02:00
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
$response = $this->get('dev/docs/en/doc_test/3.0/test/');
|
2011-07-01 03:19:35 +02:00
|
|
|
$this->assertEquals($response->getStatusCode(), 404, 'Missing page');
|
2011-07-01 04:37:55 +02:00
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
$response = $this->get('dev/docs/dk/');
|
2011-07-01 04:37:55 +02:00
|
|
|
$this->assertEquals($response->getStatusCode(), 404, 'Access a language that doesn\'t exist');
|
2011-07-01 03:19:35 +02:00
|
|
|
}
|
2014-09-15 11:47:45 +02:00
|
|
|
|
|
|
|
|
2014-09-21 01:19:17 +02:00
|
|
|
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'));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-20 03:45:35 +02:00
|
|
|
public function testGetLanguage() {
|
|
|
|
$v = new DocumentationViewer();
|
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'en/doc_test/2.3/'), DataModel::inst());
|
2014-09-15 11:47:45 +02:00
|
|
|
|
2014-09-20 03:45:35 +02:00
|
|
|
$this->assertEquals('en', $v->getLanguage());
|
|
|
|
|
|
|
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'en/doc_test/2.3/subfolder/subsubfolder/subsubpage/'), DataModel::inst());
|
|
|
|
$this->assertEquals('en', $v->getLanguage());
|
|
|
|
}
|
2011-07-01 03:19:35 +02:00
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
|
|
|
|
public function testAccessingAll() {
|
|
|
|
$response = $this->get('dev/docs/en/all/');
|
|
|
|
|
|
|
|
// should response with the documentation index
|
2011-07-01 03:19:35 +02:00
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
2014-09-15 11:47:45 +02:00
|
|
|
|
|
|
|
$items = $this->cssParser()->getBySelector('#documentation_index');
|
|
|
|
$this->assertNotEmpty($items);
|
|
|
|
|
|
|
|
// should also have a DE version of the page
|
|
|
|
$response = $this->get('dev/docs/de/all/');
|
|
|
|
|
|
|
|
// should response with the documentation index
|
2011-07-01 03:19:35 +02:00
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
$items = $this->cssParser()->getBySelector('#documentation_index');
|
|
|
|
$this->assertNotEmpty($items);
|
2011-07-01 03:19:35 +02:00
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
// accessing a language that doesn't exist should throw a 404
|
|
|
|
$response = $this->get('dev/docs/fu/all/');
|
|
|
|
$this->assertEquals(404, $response->getStatusCode());
|
2014-09-07 07:09:28 +02:00
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
// accessing all without a language should fail
|
|
|
|
$response = $this->get('dev/docs/all/');
|
|
|
|
$this->assertEquals(404, $response->getStatusCode());
|
2012-05-17 23:48:57 +02:00
|
|
|
|
|
|
|
}
|
2010-06-24 16:22:41 +02:00
|
|
|
}
|