-
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.
Add test for SolrSearchQuery (producing error)
- Loading branch information
1 parent
50eaf44
commit 5e2c8de
Showing
1 changed file
with
93 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,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; | ||
} | ||
} |