Skip to content

Commit

Permalink
Create solr core and db solrCore for each test
Browse files Browse the repository at this point in the history
  • Loading branch information
chrizzor committed Jul 18, 2024
1 parent eb756a2 commit 8ef040a
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 61 deletions.
6 changes: 3 additions & 3 deletions Tests/Fixtures/Controller/documents.solr.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"sid": "LOG_0000",
"toplevel": true,
"type": "manuscript",
"type_faceting": "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 @@ -43,7 +43,7 @@
"sid": "LOG_0001",
"toplevel": false,
"type": "other",
"type_faceting": "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 @@ -72,7 +72,7 @@
"sid": "LOG_0002",
"toplevel": false,
"type": "other",
"type_faceting": "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
2 changes: 1 addition & 1 deletion Tests/Functional/Api/OaiPmhTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected function setUpOaiSolr()
static $solr = null;

if ($solr === null) {
$coreName = Solr::createCore();
$coreName = Solr::createCore('OaiCore');
$solr = Solr::getInstance($coreName);

$this->importSolrDocuments($solr, __DIR__ . '/../../Fixtures/Common/documents_1.solr.json');
Expand Down
13 changes: 4 additions & 9 deletions Tests/Functional/Common/SolrSearchQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,10 @@ protected function setUpSolr($uid, $storagePid, $solrFixtures)
{
$this->solrCoreRepository = $this->initializeRepository(SolrCoreRepository::class, $storagePid);

// Setup Solr only once for all tests in this suite
static $solr = null;

if ($solr === null) {
$coreName = Solr::createCore();
$solr = Solr::getInstance($coreName);
foreach ($solrFixtures as $filePath) {
$this->importSolrDocuments($solr, $filePath);
}
$coreName = Solr::createCore('solrSearchQueryTest');
$solr = Solr::getInstance($coreName);
foreach ($solrFixtures as $filePath) {
$this->importSolrDocuments($solr, $filePath);
}

$coreModel = $this->solrCoreRepository->findByUid($uid);
Expand Down
13 changes: 4 additions & 9 deletions Tests/Functional/Common/SolrSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,10 @@ protected function setUpSolr($uid, $storagePid, $solrFixtures)
{
$this->solrCoreRepository = $this->initializeRepository(SolrCoreRepository::class, $storagePid);

// Setup Solr only once for all tests in this suite
static $solr = null;

if ($solr === null) {
$coreName = Solr::createCore();
$solr = Solr::getInstance($coreName);
foreach ($solrFixtures as $filePath) {
$this->importSolrDocuments($solr, $filePath);
}
$coreName = Solr::createCore('solrSearchTest');
$solr = Solr::getInstance($coreName);
foreach ($solrFixtures as $filePath) {
$this->importSolrDocuments($solr, $filePath);
}

$coreModel = $this->solrCoreRepository->findByUid($uid);
Expand Down
19 changes: 7 additions & 12 deletions Tests/Functional/Common/SolrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public function canEscapeQueryKeepField()
*/
public function canGetNextCoreNumber()
{
$this->assertEquals(5, Solr::getNextCoreNumber());
$this->assertEquals(5, Solr::getNextCoreNumber());
$this->assertEquals(2, Solr::getNextCoreNumber());
$this->assertEquals(2, Solr::getNextCoreNumber());
Solr::createCore();
$this->assertEquals(6, Solr::getNextCoreNumber());
$this->assertEquals(3, Solr::getNextCoreNumber());
}

/**
Expand Down Expand Up @@ -98,15 +98,10 @@ protected function setUpSolr($uid, $storagePid, $solrFixtures)
{
$this->solrCoreRepository = $this->initializeRepository(SolrCoreRepository::class, $storagePid);

// Setup Solr only once for all tests in this suite
static $solr = null;

if ($solr === null) {
$coreName = Solr::createCore();
$solr = Solr::getInstance($coreName);
foreach ($solrFixtures as $filePath) {
$this->importSolrDocuments($solr, $filePath);
}
$coreName = Solr::createCore('SolrTestCore');
$solr = Solr::getInstance($coreName);
foreach ($solrFixtures as $filePath) {
$this->importSolrDocuments($solr, $filePath);
}

$coreModel = $this->solrCoreRepository->findByUid($uid);
Expand Down
27 changes: 20 additions & 7 deletions Tests/Functional/Controller/AbstractControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use Kitodo\Dlf\Common\Solr\Solr;
use Kitodo\Dlf\Controller\AbstractController;
use Kitodo\Dlf\Domain\Model\SolrCore;
use Kitodo\Dlf\Domain\Repository\DocumentRepository;
use Kitodo\Dlf\Domain\Repository\SolrCoreRepository;
use Kitodo\Dlf\Tests\Functional\FunctionalTestCase;
Expand All @@ -26,22 +27,31 @@

abstract class AbstractControllerTest extends FunctionalTestCase
{
public $currentSolrUid = 1;

public $currentCoreName = '';

protected function setUpData($databaseFixtures): void
{
foreach ($databaseFixtures as $filePath) {
$this->importCSVDataSet($filePath);
}
$this->persistenceManager = $this->objectManager->get(PersistenceManager::class);
$this->initializeRepository(DocumentRepository::class, 0);
$documentRepository = $this->initializeRepository(DocumentRepository::class, 0);

$allFixtureDocuments = $documentRepository->findAll();
foreach ($allFixtureDocuments as $document) {
$document->setSolrCore($this->currentSolrUid);
$documentRepository->update($document);
}
$this->persistenceManager->persistAll();
}

protected function setUpSolr($uid, $storagePid, $solrFixtures)
protected function setUpSolr($uid, $storagePid, $solrFixtures, $name = '')

Check warning on line 50 in Tests/Functional/Controller/AbstractControllerTest.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Tests/Functional/Controller/AbstractControllerTest.php#L50

Avoid unused parameters such as '$uid'.
{
$this->solrCoreRepository = $this->initializeRepository(SolrCoreRepository::class, $storagePid);

// Setup Solr only once for all tests in this suite
static $solr = null;
$solr = null;

if ($solr === null) {
$coreName = Solr::createCore();
Expand All @@ -51,10 +61,13 @@ protected function setUpSolr($uid, $storagePid, $solrFixtures)
}
}

$coreModel = $this->solrCoreRepository->findByUid($uid);
$coreModel->setIndexName($solr->core);
$this->solrCoreRepository->update($coreModel);
$coreModel = new SolrCore();
$coreModel->setIndexName($coreName);
$this->solrCoreRepository->add($coreModel);
$this->persistenceManager->persistAll();
$this->currentSolrUid = $coreModel->getUid();
$this->currentCoreName = $coreName;

}

protected function setUpRequest($actionName, $arguments = []): Request
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/Controller/CalendarControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function setUp(): void
*/
public function canCalendarAction()
{
$settings = ['solrcore' => 4];
$settings = ['solrcore' => $this->currentSolrUid];
$templateHtml = '<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers">
calendarData:<f:for each="{calendarData}" as="month">
<f:for each="{month.week}" as="week"><f:for each="{week}" as="day"><f:if condition="{day.issues}">
Expand Down Expand Up @@ -89,7 +89,7 @@ public function canMainAction()
*/
public function canYearsAction()
{
$settings = ['solrcore' => 4];
$settings = ['solrcore' => $this->currentSolrUid];
$templateHtml = '<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers">
documentId: {documentId}
allYearDocTitle: {allYearDocTitle}
Expand Down
8 changes: 4 additions & 4 deletions Tests/Functional/Controller/CollectionControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function setUp(): void
public function canListAction()
{
$settings = [
'solrcore' => 4,
'solrcore' => $this->currentSolrUid,
'collections' => '1',
'dont_show_single' => 'some_value',
'randomize' => ''
Expand All @@ -62,7 +62,7 @@ public function canListAction()
public function canListActionForwardToShow()
{
$settings = [
'solrcore' => 4,
'solrcore' => $this->currentSolrUid,
'collections' => '1',
'randomize' => ''
];
Expand All @@ -80,7 +80,7 @@ public function canListActionForwardToShow()
public function canShowAction()
{
$settings = [
'solrcore' => 4,
'solrcore' => $this->currentSolrUid,
'collections' => '1',
'dont_show_single' => 'some_value',
'randomize' => ''
Expand All @@ -104,7 +104,7 @@ public function canShowAction()
public function canShowSortedAction()
{
$settings = [
'solrcore' => 4,
'solrcore' => $this->currentSolrUid,
'collections' => '1',
'dont_show_single' => 'some_value',
'randomize' => ''
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/Controller/FeedsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function canMainAction()
{
$GLOBALS['LANG'] = LanguageService::create('default');
$settings = [
'solrcore' => 4,
'solrcore' => $this->currentSolrUid,
'collections' => '1',
'limit' => 1
];
Expand Down
5 changes: 2 additions & 3 deletions Tests/Functional/Controller/ListViewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,16 @@ public function canMainAction(): void
]
];
$settings = [
'solrcore' => 4,
'solrcore' => $this->currentSolrUid,
'storagePid' => 2,
'dont_show_single' => 'some_value',
'randomize' => ''
];
$templateHtml = '<html xmlns:v="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers">
<f:spaceless>
uniqueId-length: <v:count.bytes>{viewData.uniqueId}</v:count.bytes>
page: {viewData.requestData.page}
page: {page}
double: {viewData.requestData.double}
widgetPage: {widgetPage.currentPage}
lastSearch.query: {lastSearch.query}
numResults: {numResults}
</f:spaceless>
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/Controller/MetadataControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function setUp(): void
public function canMainAction()
{
$settings = [
'solrcore' => 4,
'solrcore' => $this->currentSolrUid,
'storagePid' => 0
];
$templateHtml = '<html>
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/Controller/NavigationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function canMainAction()
numPages: {numPages}
pageOptions:<f:for each="{pageOptions}" as="entry">{entry},</f:for>
</html>';
$controller = $this->setUpController(NavigationController::class, ['solrcore' => 4], $templateHtml);
$controller = $this->setUpController(NavigationController::class, ['solrcore' => $this->currentSolrUid], $templateHtml);
$request = $this->setUpRequest('main');
$response = $this->getResponse();
$GLOBALS['TSFE']->fe_user = new FrontendUserAuthentication();

Check failure on line 49 in Tests/Functional/Controller/NavigationControllerTest.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Tests/Functional/Controller/NavigationControllerTest.php#L49

Direct use of $GLOBALS Superglobal detected.

Check failure on line 49 in Tests/Functional/Controller/NavigationControllerTest.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Tests/Functional/Controller/NavigationControllerTest.php#L49

Direct use of $GLOBALS Superglobal detected.
Expand All @@ -69,7 +69,7 @@ public function canPageSelectAction()
$pageSelectForm->setPage(2);
$pageSelectForm->setDouble(false);

$controller = $this->setUpController(NavigationController::class, ['solrcore' => 4], '');
$controller = $this->setUpController(NavigationController::class, ['solrcore' => $this->currentSolrUid], '');
$request = $this->setUpRequest('pageSelect', ['pageSelectForm' => $pageSelectForm]);
$response = $this->getResponse();

Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/Controller/PageViewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function canMainAction()
{image.mimetype}</f:for>
viewerConfiguration:{viewerConfiguration}
</html>';
$controller = $this->setUpController(PageViewController::class, ['solrcore' => 4], $templateHtml);
$controller = $this->setUpController(PageViewController::class, ['solrcore' => $this->currentSolrUid], $templateHtml);
$request = $this->setUpRequest('main');
$response = $this->getResponse();

Expand Down
6 changes: 3 additions & 3 deletions Tests/Functional/Controller/SearchControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class SearchControllerTest extends AbstractControllerTest
public function setUp(): void
{
parent::setUp();
$this->setUpData(self::$databaseFixtures);
$this->setUpSolr(4, 0, self::$solrFixtures);
$this->setUpData(self::$databaseFixtures);
}

/**
Expand All @@ -52,7 +52,7 @@ public function canMainAction()
]
];
$settings = [
'solrcore' => 4,
'solrcore' => $this->currentSolrUid,
'extendedFields' => 'field1,field2,field3',
'extendedSlotCount' => 1
];
Expand Down Expand Up @@ -94,7 +94,7 @@ public function canMakeFacetsMenuArray()
'query' => '*'
];
$settings = [
'solrcore' => 4,
'solrcore' => $this->currentSolrUid,
'storagePid' => 0,
'facets' => 'type',
'facetCollections' => '1'
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/Controller/StatisticsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function canMainAction()
$GLOBALS['LANG'] = LanguageService::create('default');

Check failure on line 36 in Tests/Functional/Controller/StatisticsControllerTest.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Tests/Functional/Controller/StatisticsControllerTest.php#L36

Direct use of $GLOBALS Superglobal detected.

Check failure on line 36 in Tests/Functional/Controller/StatisticsControllerTest.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Tests/Functional/Controller/StatisticsControllerTest.php#L36

Direct use of $GLOBALS Superglobal detected.

$settings = [
'solrcore' => 4,
'solrcore' => $this->currentSolrUid,
'collections' => '1',
'storagePid' => '0',
'description' => 'There are ###TITLES### and ###VOLUMES###.'
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/Controller/ToolboxControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function canMainAction()
'double' => 1
];
$settings = [
'solrcore' => 4,
'solrcore' => $this->currentSolrUid,
'library' => 1,
'tools' => 'tx_dlf_annotationtool',
'limit' => 1
Expand Down Expand Up @@ -197,7 +197,7 @@ public function canSearchindocumenttool()
'page' => 1
];
$settings = [
'solrcore' => 4,
'solrcore' => $this->currentSolrUid,
'tools' => 'tx_dlf_searchindocumenttool',
'queryInputName' => 'queryInputName',
'startInputName' => 'startInputName',
Expand Down

0 comments on commit 8ef040a

Please sign in to comment.