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'); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* |
30
|
|
|
* @group find |
31
|
|
|
*/ |
32
|
|
|
public function canFindAllByUids(): void |
33
|
|
|
{ |
34
|
|
|
$collections = $this->collectionRepository->findAllByUids([1101, 1102]); |
|
|
|
|
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
|
|
|
|
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.