silverstripe-docsviewer/tests/DocumentationSearchTest.php

76 lines
2.3 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();
2017-08-08 05:50:24 +02:00
// explicitly use dev/docs. Custom paths should be tested separately
2015-11-21 07:25:41 +01:00
Config::inst()->update(
2017-08-08 05:50:24 +02:00
'DocumentationViewer',
'link_base',
'dev/docs'
2015-11-21 07:25:41 +01:00
);
2015-11-21 07:25:41 +01:00
// disable automatic module registration so modules don't interfere.
Config::inst()->update(
2017-08-08 05:50:24 +02:00
'DocumentationManifest',
'automatic_registration',
false
2015-11-21 07:25:41 +01:00
);
2015-11-21 07:25:41 +01:00
Config::inst()->remove('DocumentationManifest', 'register_entities');
Config::inst()->update('DocumentationSearch', 'enabled', true);
Config::inst()->update(
2017-08-08 05:50:24 +02:00
'DocumentationManifest',
'register_entities',
array(
2015-11-21 07:25:41 +01:00
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());
2016-12-02 03:31:18 +01:00
// $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());
2016-12-02 03:31:18 +01:00
// $this->assertEquals(404, $response->getStatusCode());
2015-11-21 07:25:41 +01:00
2017-08-08 05:50:24 +02: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
2015-11-21 07:25:41 +01:00
// 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());
2016-12-02 03:31:18 +01:00
// $this->assertEquals(200, $response->getStatusCode());
2015-11-21 07:25:41 +01:00
$desc = new SimpleXMLElement($response->getBody());
2016-12-02 03:31:18 +01:00
// $this->assertEquals(2, count($desc->Url));
2015-11-21 07:25:41 +01:00
}
}