Passed
Pull Request — master (#123)
by
unknown
04:41
created

SolrSearchQueryTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 35
c 2
b 0
f 0
dl 0
loc 70
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpData() 0 6 2
A setUpSolr() 0 20 3
A setUp() 0 5 1
A canExecute() 0 15 1
1
<?php
2
3
/**
4
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
5
 *
6
 * This file is part of the Kitodo and TYPO3 projects.
7
 *
8
 * @license GNU General Public License version 3 or later.
9
 * For the full copyright and license information, please read the
10
 * LICENSE.txt file that was distributed with this source code.
11
 */
12
13
namespace Kitodo\Dlf\Tests\Functional\Common;
14
15
use Kitodo\Dlf\Common\Solr\Solr;
16
use Kitodo\Dlf\Common\Solr\SolrSearch;
17
use Kitodo\Dlf\Domain\Repository\DocumentRepository;
18
use Kitodo\Dlf\Domain\Repository\SolrCoreRepository;
19
use Kitodo\Dlf\Tests\Functional\FunctionalTestCase;
20
21
class SolrSearchQueryTest extends FunctionalTestCase
22
{
23
    private $solrCoreRepository;
24
25
    private static array $databaseFixtures = [
26
        __DIR__ . '/../../Fixtures/Common/documents_1.csv',
27
        __DIR__ . '/../../Fixtures/Common/pages.csv',
28
        __DIR__ . '/../../Fixtures/Common/solrcores.csv'
29
    ];
30
31
    private static array $solrFixtures = [
32
        __DIR__ . '/../../Fixtures/Common/documents_1.solr.json'
33
    ];
34
35
    public function setUp(): void
36
    {
37
        parent::setUp();
38
        $this->setUpData(self::$databaseFixtures);
39
        $this->setUpSolr(4, 0, self::$solrFixtures);
40
    }
41
42
    /**
43
     * @test
44
     * @ignore
45
     */
46
    public function canExecute()
47
    {
48
        $documentRepository = $this->initializeRepository(DocumentRepository::class, 0);
49
        $settings = ['solrcore' => 4, 'storagePid' => 0];
50
51
        $params = ['query' => '10 Keyboard pieces'];
52
        $search = new SolrSearch($documentRepository, [], $settings, $params);
53
        $search->prepare();
54
        $solrSearchQuery = $search->getQuery();
55
        $result = $solrSearchQuery->execute();
56
        // FIXME: test would fail because it is not possible to set $this->settings['storagePid'] for the
57
        //  documentRepository used in DocumentRepository.php:502
58
59
        $this->assertCount(0, $result);
60
        $this->assertEquals(0, $solrSearchQuery->getLimit());
61
    }
62
63
    protected function setUpData($databaseFixtures): void
64
    {
65
        foreach ($databaseFixtures as $filePath) {
66
            $this->importCSVDataSet($filePath);
67
        }
68
        $this->initializeRepository(DocumentRepository::class, 0);
69
    }
70
71
    protected function setUpSolr($uid, $storagePid, $solrFixtures)
72
    {
73
        $this->solrCoreRepository = $this->initializeRepository(SolrCoreRepository::class, $storagePid);
74
75
        // Setup Solr only once for all tests in this suite
76
        static $solr = null;
77
78
        if ($solr === null) {
79
            $coreName = Solr::createCore();
80
            $solr = Solr::getInstance($coreName);
81
            foreach ($solrFixtures as $filePath) {
82
                $this->importSolrDocuments($solr, $filePath);
83
            }
84
        }
85
86
        $coreModel = $this->solrCoreRepository->findByUid($uid);
87
        $coreModel->setIndexName($solr->core);
88
        $this->solrCoreRepository->update($coreModel);
89
        $this->persistenceManager->persistAll();
90
        return $solr;
91
    }
92
}
93