-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6676f03
commit aeb34f8
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?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 SolrSearchTest extends FunctionalTestCase | ||
{ | ||
static array $databaseFixtures = [ | ||
__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 | ||
*/ | ||
public function canPrepareAndSubmit() | ||
{ | ||
$documentRepository = $this->initializeRepository(DocumentRepository::class, 0); | ||
$settings = ['solrcore' => 4]; | ||
|
||
$params1 = []; | ||
$search = new SolrSearch($documentRepository, null, $settings, $params1); | ||
$search->prepare(); | ||
$this->assertEquals(33, $search->getNumFound()); | ||
$this->assertEquals(3, $search->getSolrResults()['numberOfToplevels']); | ||
$this->assertCount(15, $search->getSolrResults()['documents']); | ||
|
||
$params2 = ['query' => '10 Keyboard pieces']; | ||
$search2 = new SolrSearch($documentRepository, null, $settings, $params2); | ||
$search2->prepare(); | ||
$this->assertEquals(1, $search2->getNumFound()); | ||
$this->assertEquals(1, $search2->getSolrResults()['numberOfToplevels']); | ||
$this->assertCount(1, $search2->getSolrResults()['documents']); | ||
|
||
$params3 = ['query' => 'foobar']; | ||
$search3 = new SolrSearch($documentRepository, null, $settings, $params3); | ||
$search3->prepare(); | ||
$this->assertEquals(0, $search3->getNumFound()); | ||
$this->assertEquals(0, $search3->getSolrResults()['numberOfToplevels']); | ||
$this->assertCount(0, $search3->getSolrResults()['documents']); | ||
} | ||
|
||
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; | ||
} | ||
} |