silverstripe-docsviewer/tests/DocumentationSearchTest.php

70 lines
2.2 KiB
PHP
Raw Normal View History

<?php
/**
* @package docsviewer
* @subpackage tests
*/
2015-11-21 07:25:41 +01:00
class DocumentationSearchTest extends FunctionalTest
{
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');
Config::inst()->update('DocumentationSearch', 'enabled', true);
Config::inst()->update(
'DocumentationManifest', 'register_entities', array(
array(
'Path' => DOCSVIEWER_PATH . "/tests/docs-search/",
'Title' => 'Docs Search Test', )
)
);
2015-11-21 07:25:41 +01:00
$this->manifest = new DocumentationManifest(true);
}
public function tearDown()
{
parent::tearDown();
Config::unnest();
}
public function testOpenSearchControllerAccessible()
{
$c = new DocumentationOpenSearchController();
$response = $c->handleRequest(new SS_HTTPRequest('GET', ''), DataModel::inst());
// $this->assertEquals(404, $response->getStatusCode());
2015-11-21 07:25:41 +01:00
Config::inst()->update('DocumentationSearch', 'enabled', false);
2015-11-21 07:25:41 +01:00
$response = $c->handleRequest(new SS_HTTPRequest('GET', 'description/'), DataModel::inst());
// $this->assertEquals(404, $response->getStatusCode());
2015-11-21 07:25:41 +01:00
// test we get a response to the description. The meta data test will
// check that the individual fields are valid but we should check urls
// are there
2015-11-21 07:25:41 +01:00
Config::inst()->update('DocumentationSearch', 'enabled', true);
$response = $c->handleRequest(new SS_HTTPRequest('GET', 'description'), DataModel::inst());
// $this->assertEquals(200, $response->getStatusCode());
2015-11-21 07:25:41 +01:00
$desc = new SimpleXMLElement($response->getBody());
// $this->assertEquals(2, count($desc->Url));
2015-11-21 07:25:41 +01:00
}
}