Skip to content

Commit

Permalink
Add test for SolrSearchQuery (producing error)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-stoehr committed May 19, 2023
1 parent 93960aa commit 5ca0c7e
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions Tests/Functional/Common/SolrSearchQueryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

/**
* (c) Kitodo. Key to digital objects e.V. <[email protected]>
*
* This file is part of the Kitodo and TYPO3 projects.
*
* @license GNU General Public License version 3 or later.
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

namespace Kitodo\Dlf\Tests\Functional\Common;

use Kitodo\Dlf\Common\Solr;
use Kitodo\Dlf\Common\SolrSearch;
use Kitodo\Dlf\Domain\Repository\DocumentRepository;
use Kitodo\Dlf\Domain\Repository\SolrCoreRepository;
use Kitodo\Dlf\Tests\Functional\FunctionalTestCase;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;

class SolrSearchQueryTest extends FunctionalTestCase
{

static array $databaseFixtures = [
__DIR__ . '/../../Fixtures/Common/documents_1.xml',
__DIR__ . '/../../Fixtures/Common/pages.xml',
__DIR__ . '/../../Fixtures/Common/solrcores.xml'
];

static array $solrFixtures = [
__DIR__ . '/../../Fixtures/Common/documents_1.solr.json'
];

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

/**
* @test
* @ignore
*/
public function canExecute()
{
$documentRepository = $this->initializeRepository(DocumentRepository::class, 0);
$settings = ['solrcore' => 4];

$params = ['query' => '10 Keyboard pieces'];
$search = new SolrSearch($documentRepository, null, $settings, $params);
$search->prepare();
$solrSearchQuery = $search->getQuery();
$result = $solrSearchQuery->execute();
// FIXME: test will fail because it is not possible to set $this->settings['storagePid'] for the
// documentRepository used in DocumentRepository.php:502

$this->assertCount(123, $result);
$this->assertEquals(123, $solrSearchQuery->getLimit());
}

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

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);
}
}

$coreModel = $this->solrCoreRepository->findByUid($uid);
$coreModel->setIndexName($solr->core);
$this->solrCoreRepository->update($coreModel);
$this->persistenceManager->persistAll();
return $solr;
}
}

0 comments on commit 5ca0c7e

Please sign in to comment.