silverstripe-docsviewer/tests/DocumentationViewerVersionWarningTest.php

89 lines
2.7 KiB
PHP
Raw Normal View History

<?php
/**
* @package docsviewer
* @subpackage tests
*/
2015-11-21 07:25:41 +01:00
class DocumentationViewerVersionWarningTest extends SapphireTest
{
protected $autoFollowRedirection = false;
private $manifest;
2015-11-21 07:25:41 +01:00
public function setUp()
{
parent::setUp();
2015-11-21 07:25:41 +01:00
Config::nest();
2015-11-21 07:25:41 +01:00
// explicitly use dev/docs. Custom paths should be tested separately
Config::inst()->update(
'DocumentationViewer', 'link_base', 'dev/docs'
);
2015-11-21 07:25:41 +01:00
// disable automatic module registration so modules don't interfere.
Config::inst()->update(
'DocumentationManifest', 'automatic_registration', false
);
2015-11-21 07:25:41 +01:00
Config::inst()->remove('DocumentationManifest', 'register_entities');
2015-11-21 07:25:41 +01:00
Config::inst()->update(
'DocumentationManifest', 'register_entities', array(
array(
'Path' => DOCSVIEWER_PATH . "/tests/docs/",
'Title' => 'Doc Test',
'Key' => 'testdocs',
'Version' => '2.3'
),
array(
'Path' => DOCSVIEWER_PATH . "/tests/docs-v2.4/",
'Title' => 'Doc Test',
'Version' => '2.4',
'Key' => 'testdocs',
'Stable' => true
),
array(
'Path' => DOCSVIEWER_PATH . "/tests/docs-v3.0/",
'Title' => 'Doc Test',
'Key' => 'testdocs',
'Version' => '3.0'
)
)
);
2015-11-21 07:25:41 +01:00
$this->manifest = new DocumentationManifest(true);
}
public function tearDown()
{
parent::tearDown();
Config::unnest();
}
2015-11-21 07:25:41 +01:00
public function testVersionWarning()
{
$v = new DocumentationViewer();
// the current version is set to 2.4, no notice should be shown on that page
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'en/testdocs/'), DataModel::inst());
// $this->assertFalse($v->VersionWarning());
2015-11-21 07:25:41 +01:00
// 2.3 is an older release, hitting that should return us an outdated flag
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'en/testdocs/2.3/'), DataModel::inst());
$warn = $v->VersionWarning();
// $this->assertTrue($warn->OutdatedRelease);
// $this->assertNull($warn->FutureRelease);
2015-11-21 07:25:41 +01:00
// 3.0 is a future release
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'en/testdocs/3.0/'), DataModel::inst());
$warn = $v->VersionWarning();
// $this->assertNull($warn->OutdatedRelease);
// $this->assertTrue($warn->FutureRelease);
2015-11-21 07:25:41 +01:00
}
}