Skip to content

Commit

Permalink
Complete tests for SearchController
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-stoehr committed Apr 28, 2023
1 parent e113319 commit b3d02f4
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Tests/Fixtures/Controller/documents.solr.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"sid": "LOG_0000",
"toplevel": true,
"type": "manuscript",
"type_faceting": "manuscript",
"title": "10 Keyboard pieces - Go. S. 658",
"record_id": "oai:de:slub-dresden:db:id-476251419",
"purl": "http://digital.slub-dresden.de/id476251419",
Expand Down Expand Up @@ -42,6 +43,7 @@
"sid": "LOG_0001",
"toplevel": false,
"type": "other",
"type_faceting": "other",
"title": "Beigefügte Quellenbeschreibung",
"location": "https://digital.slub-dresden.de/data/kitodo/10Kepi_476251419/10Kepi_476251419_mets.xml",
"collection": [
Expand Down Expand Up @@ -70,6 +72,7 @@
"sid": "LOG_0002",
"toplevel": false,
"type": "other",
"type_faceting": "other",
"title": "Beigefügtes Inhaltsverzeichnis",
"location": "https://digital.slub-dresden.de/data/kitodo/10Kepi_476251419/10Kepi_476251419_mets.xml",
"collection": [],
Expand Down
111 changes: 106 additions & 5 deletions Tests/Functional/Controller/SearchControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,137 @@

namespace Kitodo\Dlf\Tests\Functional\Controller;

use Kitodo\Dlf\Tests\Functional\FunctionalTestCase;
use Kitodo\Dlf\Controller\SearchController;
use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException;
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;

class SearchControllerTest extends FunctionalTestCase
class SearchControllerTest extends AbstractControllerTest
{
static array $databaseFixtures = [
__DIR__ . '/../../Fixtures/Controller/pages.xml',
__DIR__ . '/../../Fixtures/Controller/documents.xml',
__DIR__ . '/../../Fixtures/Controller/solrcores.xml'
];

static array $solrFixtures = [
__DIR__ . '/../../Fixtures/Controller/documents.solr.json'
];

public function setUp(): void
{
parent::setUp();
$this->setUpData(self::$databaseFixtures);
$this->setUpSolr(4, 0, self::$solrFixtures);
}

/**
* @test
*/
public function canMainAction()
{
// TODO implement
$_POST['tx_dlf'] = [
'id' => 1001
];
$_POST['tx_dlf_listview'] = [
'searchParameter' => []
];
$arguments = [
'searchParameter' => [
'dateFrom' => '1800'
],
'@widget_0' => [
'currentPage' => 3
]
];
$settings = [
'solrcore' => 4,
'extendedFields' => 'field1,field2,field3',
'extendedSlotCount' => 1
];
$templateHtml = '<html>
widgetPage.currentPage:{widgetPage.currentPage}
lastSearch:<f:for each="{lastSearch}" as="searchEntry" key="key">{key}:{searchEntry},</f:for>
currentDocument:{currentDocument.uid}
searchFields:<f:for each="{searchFields}" as="field">{field},</f:for>
</html>';
$controller = $this->setUpController(SearchController::class, $settings, $templateHtml);
$request = $this->setUpRequest('main', $arguments);
$response = $this->getResponse();
$GLOBALS['TSFE']->fe_user = new FrontendUserAuthentication();

$controller->processRequest($request, $response);
$actual = $response->getContent();
$expected = '<html>
widgetPage.currentPage:3
lastSearch:dateFrom:1800,dateTo:NOW,
currentDocument:1001
searchFields:field1,field2,field3,
</html>';
$this->assertEquals($expected, $actual);
}

/**
* @test
*/
public function canMakeFacetsMenuArray()
{
// TODO implement
$_POST['tx_dlf'] = [
'id' => 1001
];
$_POST['tx_dlf_listview'] = [
'searchParameter' => []
];
$arguments = [
'searchParameter' => [
'title' => '10 Keyboard pieces'
],
'query' => '*',
'@widget_0' => [
'currentPage' => 3
]
];
$settings = [
'solrcore' => 4,
'facets' => 'type',
'facetCollections' => '1'
];
$templateHtml = '<html>
widgetPage.currentPage:{widgetPage.currentPage}
lastSearch:<f:for each="{lastSearch}" as="searchEntry" key="key">{key}:{searchEntry},</f:for>
currentDocument:{currentDocument.uid}
facetsMenu:<f:for each="{facetsMenu}" as="menuEntry">
{menuEntry.field}
<f:for each="{menuEntry._SUB_MENU}" as="subMenuEntry"> {subMenuEntry.title}: {subMenuEntry.queryColumn.0}</f:for></f:for>
</html>';
$controller = $this->setUpController(SearchController::class, $settings, $templateHtml);
$request = $this->setUpRequest('main', $arguments);
$response = $this->getResponse();
$GLOBALS['TSFE']->fe_user = new FrontendUserAuthentication();

$controller->processRequest($request, $response);
$actual = $response->getContent();
$expected = '<html>
widgetPage.currentPage:3
lastSearch:title:10 Keyboard pieces,
currentDocument:1001
facetsMenu:
type
other: type_faceting:(&quot;other&quot;) manuscript: type_faceting:(&quot;manuscript&quot;)
</html>';
$this->assertEquals($expected, $actual);

}

/**
* @test
*/
public function canSearchAction()
{
// TODO implement
$controller = $this->setUpController(SearchController::class, [], '');
$request = $this->setUpRequest('search', []);
$response = $this->getResponse();

$this->expectException(StopActionException::class);
$controller->processRequest($request, $response);
}
}

0 comments on commit b3d02f4

Please sign in to comment.