Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#895)
by
unknown
07:25 queued 03:39
created

CollectionRepositoryTest::canGetIndexNameForSolr()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 14
nc 1
nop 0
dl 0
loc 21
rs 9.7998
c 0
b 0
f 0
1
<?php
2
3
namespace Kitodo\Dlf\Tests\Functional\Repository;
4
5
use TYPO3\CMS\Extbase\Persistence\Generic\QueryResult;
6
use Kitodo\Dlf\Domain\Repository\CollectionRepository;
7
use Kitodo\Dlf\Tests\Functional\FunctionalTestCase;
8
9
class CollectionRepositoryTest extends FunctionalTestCase
10
{
11
    /**
12
     * @var CollectionRepository
13
     */
14
    protected $collectionRepository;
15
16
    public function setUp(): void
17
    {
18
        parent::setUp();
19
20
        $this->collectionRepository = $this->initializeRepository(
21
            CollectionRepository::class,
22
            20000
23
        );
24
25
        $this->importDataSet(__DIR__ . '/../../Fixtures/Repository/collections.xml');
0 ignored issues
show
Deprecated Code introduced by
The function TYPO3\TestingFramework\C...stCase::importDataSet() has been deprecated: Will be removed with core v12 compatible testing-framework. Importing database fixtures based on XML format is discouraged. Switch to CSV format instead. See core functional tests or styleguide for many examples how these look like. Use method importCSVDataSet() to import such fixture files and assertCSVDataSet() to compare database state with fixture files. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

25
        /** @scrutinizer ignore-deprecated */ $this->importDataSet(__DIR__ . '/../../Fixtures/Repository/collections.xml');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
26
    }
27
28
    /**
29
     *
30
     * @group find
31
     */
32
    public function canFindAllByUids(): void
33
    {
34
        $collections = $this->collectionRepository->findAllByUids([1101, 1102]);
0 ignored issues
show
Bug introduced by
array(1101, 1102) of type array<integer,integer> is incompatible with the type string expected by parameter $uids of Kitodo\Dlf\Domain\Reposi...sitory::findAllByUids(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
        $collections = $this->collectionRepository->findAllByUids(/** @scrutinizer ignore-type */ [1101, 1102]);
Loading history...
35
        $this->assertNotNull($collections);
36
        $this->assertInstanceOf(QueryResult::class, $collections);
37
38
        $collectionsByLabel = [];
39
        foreach ($collections as $collection) {
40
            $collectionsByLabel[$collection->getLabel()] = $collection;
41
        }
42
43
        $this->assertArrayHasKey('Musik', $collectionsByLabel);
44
        $this->assertArrayHasKey('Collection with single document', $collectionsByLabel);
45
    }
46
47
    /**
48
     * @test
49
     * @group find
50
     */
51
    public function canGetCollectionForMetadata(): void
52
    {
53
        $collections = $this->collectionRepository->getCollectionForMetadata("20000");
54
        $this->assertNotNull($collections);
55
        $this->assertInstanceOf(QueryResult::class, $collections);
56
57
        $collectionsByLabel = [];
58
        foreach ($collections as $collection) {
59
            $collectionsByLabel[$collection->getLabel()] = $collection;
60
        }
61
62
        $this->assertArrayHasKey('Musik', $collectionsByLabel);
63
        $this->assertArrayHasKey('Collection with single document', $collectionsByLabel);
64
        $this->assertArrayHasKey('Geschichte', $collectionsByLabel);
65
        $this->assertArrayHasKey('Bildende Kunst', $collectionsByLabel);
66
    }
67
68
    /**
69
     * @param $settings
70
     * @return array
71
     */
72
    protected function findCollectionsBySettings($settings): array
73
    {
74
        $collections = $this->collectionRepository->findCollectionsBySettings($settings);
75
        $this->assertNotNull($collections);
76
        $this->assertInstanceOf(QueryResult::class, $collections);
77
78
        $collectionsByLabel = [];
79
        foreach ($collections as $collection) {
80
            $collectionsByLabel[$collection->getLabel()] = $collection;
81
        }
82
83
        return $collectionsByLabel;
84
    }
85
86
    /**
87
     * @test
88
     * @group find
89
     */
90
    public function canFindCollectionsBySettings(): void
91
    {
92
        $collectionsByLabel = $this->findCollectionsBySettings(['collections' => '1101, 1102']);
93
        $this->assertEquals(2, sizeof($collectionsByLabel));
94
        $this->assertArrayHasKey('Collection with single document', $collectionsByLabel);
95
        $this->assertArrayHasKey('Musik', $collectionsByLabel);
96
97
        $collectionsByLabel = $this->findCollectionsBySettings([
98
            'index_name' => ['Geschichte', 'collection-with-single-document'],
99
            'show_userdefined' => true
100
        ]);
101
        $this->assertEquals(2, sizeof($collectionsByLabel));
102
        $this->assertArrayHasKey('Geschichte', $collectionsByLabel);
103
        $this->assertArrayHasKey('Collection with single document', $collectionsByLabel);
104
105
        $collectionsByLabel = $this->findCollectionsBySettings(['show_userdefined' => true]);
106
        $this->assertEquals(4, sizeof($collectionsByLabel));
107
        $this->assertArrayHasKey('Musik', $collectionsByLabel);
108
        $this->assertArrayHasKey('Collection with single document', $collectionsByLabel);
109
        $this->assertArrayHasKey('Geschichte', $collectionsByLabel);
110
        $this->assertArrayHasKey('Bildende Kunst', $collectionsByLabel);
111
        $this->assertEquals(
112
            'Bildende Kunst, Collection with single document, Geschichte, Musik',
113
            implode(', ', array_keys($collectionsByLabel))
114
        );
115
116
        $collectionsByLabel = $this->findCollectionsBySettings(['show_userdefined' => false]);
117
        $this->assertEquals(2, sizeof($collectionsByLabel));
118
        $this->assertArrayHasKey('Musik', $collectionsByLabel);
119
        $this->assertArrayHasKey('Collection with single document', $collectionsByLabel);
120
121
        $collectionsByLabel = $this->findCollectionsBySettings(['hideEmptyOaiNames' => true]);
122
        $this->assertEquals(2, sizeof($collectionsByLabel));
123
        $this->assertArrayHasKey('Musik', $collectionsByLabel);
124
        $this->assertArrayHasKey('Collection with single document', $collectionsByLabel);
125
126
        $collectionsByLabel = $this->findCollectionsBySettings(
127
            [
128
                'hideEmptyOaiNames' => true,
129
                'show_userdefined' => true
130
            ]
131
        );
132
        $this->assertEquals(3, sizeof($collectionsByLabel));
133
        $this->assertArrayHasKey('Musik', $collectionsByLabel);
134
        $this->assertArrayHasKey('Collection with single document', $collectionsByLabel);
135
        $this->assertArrayHasKey('Geschichte', $collectionsByLabel);
136
137
        $collectionsByLabel = $this->findCollectionsBySettings(
138
            [
139
                'hideEmptyOaiNames' => false,
140
                'show_userdefined' => true
141
            ]
142
        );
143
        $this->assertEquals(4, sizeof($collectionsByLabel));
144
        $this->assertArrayHasKey('Musik', $collectionsByLabel);
145
        $this->assertArrayHasKey('Collection with single document', $collectionsByLabel);
146
        $this->assertArrayHasKey('Geschichte', $collectionsByLabel);
147
        $this->assertArrayHasKey('Bildende Kunst', $collectionsByLabel);
148
149
        $collectionsByLabel = $this->findCollectionsBySettings(
150
            [
151
                'collections' => '1101, 1102, 1103, 1104',
152
                'show_userdefined' => true,
153
                'hideEmptyOaiNames' => false,
154
                'index_name' => ['Geschichte', 'collection-with-single-document']
155
            ]
156
        );
157
158
        $this->assertEquals(2, sizeof($collectionsByLabel));
159
        $this->assertArrayHasKey('Collection with single document', $collectionsByLabel);
160
        $this->assertArrayHasKey('Geschichte', $collectionsByLabel);
161
    }
162
163
    /**
164
     * @test
165
     * @group find
166
     */
167
    public function canGetIndexNameForSolr(): void
168
    {
169
        $indexName = $this->collectionRepository->getIndexNameForSolr(
170
            ['show_userdefined' => true, 'storagePid' => '20000'], 'history'
171
        );
172
        $result = $indexName->fetchAllAssociative();
173
        $this->assertEquals(1, $indexName->rowCount());
174
        $this->assertEquals('Geschichte', $result[0]['index_name']);
175
        $this->assertEquals('*:*', $result[0]['index_query']);
176
        $this->assertEquals('1103', $result[0]['uid']);
177
178
        $indexName = $this->collectionRepository->getIndexNameForSolr(
179
            ['show_userdefined' => false, 'storagePid' => '20000'], 'history'
180
        );
181
        $this->assertEquals(0, $indexName->rowCount());
182
183
        $indexName = $this->collectionRepository->getIndexNameForSolr(
184
            ['show_userdefined' => false, 'storagePid' => '20000'], 'collection-with-single-document'
185
        );
186
        $this->assertEquals(1, $indexName->rowCount());
187
        $this->assertEquals('collection-with-single-document', $indexName->fetchOne());
188
    }
189
}
190