Skip to content

Commit edd4a4b

Browse files
thomaslowhaogatypoliver-stoehrchrizzorsebastian-meyer
authored
[MAINTENANCE] Updated tests for Controller (merged with Typo3 v13 update) (kitodo#1708)
Co-authored-by: haogatyp <gatermann@effective-webwork.de> Co-authored-by: Oliver Stöhr <stoehr@effective-webwork.de> Co-authored-by: Christopher Timm <timm@effective-webwork.de> Co-authored-by: Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
1 parent 6cc3fde commit edd4a4b

40 files changed

+2128
-35
lines changed

Classes/Common/DocumentAnnotation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ protected static function loadData($document)
377377
{
378378
$annotationData = [];
379379
$conf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('dlf');
380-
$apiBaseUrl = $conf['annotationServerUrl'];
380+
$apiBaseUrl = $conf['annotationServerUrl'] ?? null;
381381
if ($apiBaseUrl && $document->getCurrentDocument() instanceof MetsDocument) {
382382
$purl = $document->getCurrentDocument()->mets->xpath('//mods:mods/mods:identifier[@type="purl"]');
383383
if (count($purl) > 0) {

Classes/Controller/AbstractController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,4 +743,12 @@ protected function getDocumentByUrl(string $documentUrl)
743743

744744
return $doc;
745745
}
746+
747+
/**
748+
* For testing purposes only.
749+
*/
750+
public function setSettingsForTest($settings)
751+
{
752+
$this->settings = $settings;
753+
}
746754
}

Classes/Controller/CalendarController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function yearsAction(): ResponseInterface
177177

178178
$years[] = [
179179
'title' => $yearLabel,
180-
'uid' => $year['points'],
180+
'uid' => $year['points'] ?? null,
181181
];
182182
}
183183
} else {
@@ -490,7 +490,7 @@ private function getIssuesFromTableOfContents(): Generator
490490
}
491491

492492
yield [
493-
'uid' => $issue['points'],
493+
'uid' => $issue['points'] ?? null,
494494
'title' => $title,
495495
'year' => $day['orderlabel'],
496496
];

Classes/Controller/CollectionController.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,7 @@ public function showAction(Collection $collection): ResponseInterface
164164
if (is_array($search) && !empty($search)) {
165165
$solrResults = $this->documentRepository->findSolrByCollection($collection, $this->settings, $search, $listedMetadata, $indexedMetadata);
166166

167-
$itemsPerPage = $this->settings['list']['paginate']['itemsPerPage'];
168-
if (empty($itemsPerPage)) {
169-
$itemsPerPage = 25;
170-
}
167+
$itemsPerPage = $this->settings['list']['paginate']['itemsPerPage'] ?? 25;
171168
$solrPaginator = new SolrPaginator($solrResults, $currentPage, $itemsPerPage);
172169
$simplePagination = new SimplePagination($solrPaginator);
173170

@@ -199,7 +196,7 @@ public function showSortedAction(): ResponseInterface
199196
$search = $this->getParametersSafely('search');
200197

201198
$collection = null;
202-
if ($search['collection']['__identity'] && MathUtility::canBeInterpretedAsInteger($search['collection']['__identity'])) {
199+
if (!empty($search['collection']) && $search['collection']['__identity'] && MathUtility::canBeInterpretedAsInteger($search['collection']['__identity'])) {
203200
$collection = $this->collectionRepository->findByUid($search['collection']['__identity']);
204201
}
205202

Classes/Controller/ListViewController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,7 @@ public function mainAction(): ResponseInterface
107107
$solrResults = $this->documentRepository->findSolrByCollections($collections, $this->settings, $this->search, $listedMetadata, $indexedMetadata);
108108
$numResults = $solrResults->getNumFound();
109109

110-
$itemsPerPage = $this->settings['list']['paginate']['itemsPerPage'];
111-
if (empty($itemsPerPage)) {
112-
$itemsPerPage = 25;
113-
}
110+
$itemsPerPage = $this->settings['list']['paginate']['itemsPerPage'] ?? 25;
114111
$solrPaginator = new SolrPaginator($solrResults, $currentPage, $itemsPerPage);
115112
$simplePagination = new SimplePagination($solrPaginator);
116113

Classes/Controller/MetadataController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ protected function printMetadata(array $metadata): void
159159
// findBySettings also sorts entries by the `sorting` field
160160
$metadataResult = $this->metadataRepository->findBySettings(
161161
[
162-
'is_listed' => !$this->settings['showFull'],
162+
'is_listed' => !($this->settings['showFull'] ?? true),
163163
]
164164
);
165165

@@ -314,7 +314,7 @@ private function buildUrlFromMetadata(array $metadata): array
314314
$buildUrl = [];
315315

316316
foreach ($metadata as $i => $section) {
317-
if ($this->settings['linkTitle'] && $section['_id'] && isset($section['title']) && !empty($section['title'])) {
317+
if (!empty($this->settings['linkTitle']) && $section['_id'] && isset($section['title']) && !empty($section['title'])) {
318318
$details = $this->currentDocument->getLogicalStructure($section['_id'][0]);
319319
$buildUrl[$i]['title'] = [
320320
'id' => $this->document->getUid(),

Classes/Controller/NavigationController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function mainAction(): ResponseInterface
123123

124124
// prepare feature array for fluid
125125
$features = [];
126-
foreach (explode(',', $this->settings['features']) as $feature) {
126+
foreach (explode(',', $this->settings['features'] ?? '') as $feature) {
127127
$features[$feature] = true;
128128
}
129129
$this->view->assign('features', $features);

Classes/Controller/PageGridController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ public function mainAction(): ResponseInterface
6868
// Get current page from request data because the parameter is shared between plugins
6969
$currentPage = $this->requestData['page'] ?? 1;
7070

71-
$itemsPerPage = $this->settings['paginate']['itemsPerPage'];
72-
if (empty($itemsPerPage)) {
73-
$itemsPerPage = 25;
74-
}
71+
$itemsPerPage = $this->settings['paginate']['itemsPerPage'] ?? 25;
7572

7673
$pageGridPaginator = new PageGridPaginator($entryArray, $currentPage, $itemsPerPage);
7774
$pageGridPagination = new PageGridPagination($pageGridPaginator);

Classes/Controller/PageViewController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ public function mainAction(): ResponseInterface
130130
$this->measures = $this->getMeasures($page);
131131

132132
// Get the controls for the map.
133-
$this->controls = explode(',', $this->settings['features']);
133+
$this->controls = explode(',', $this->settings['features'] ?? '');
134134

135135
$this->view->assign('viewData', $this->viewData);
136-
$this->view->assign('forceAbsoluteUrl', $this->extConf['general']['forceAbsoluteUrl']);
136+
$this->view->assign('forceAbsoluteUrl', $this->extConf['general']['forceAbsoluteUrl'] ?? 0);
137137

138138
$this->addViewerJS();
139139

@@ -537,7 +537,7 @@ protected function addViewerJS(): void
537537

538538
$viewer = [
539539
'controls' => $this->controls,
540-
'div' => $this->settings['elementId'],
540+
'div' => $this->settings['elementId'] ?? 'tx-dlf-map',
541541
'progressElementId' => $this->settings['progressElementId'] ?? 'tx-dlf-page-progress',
542542
'images' => $this->images,
543543
'fulltexts' => $this->fulltexts,

Classes/Controller/SearchController.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,7 @@ public function mainAction(): ResponseInterface
191191
$solrResults = $this->documentRepository->findSolrWithoutCollection($this->settings, $this->search, $listedMetadata, $indexedMetadata);
192192
$numResults = $solrResults->getNumFound();
193193

194-
$itemsPerPage = $this->settings['list']['paginate']['itemsPerPage'];
195-
if (empty($itemsPerPage)) {
196-
$itemsPerPage = 25;
197-
}
194+
$itemsPerPage = $this->settings['list']['paginate']['itemsPerPage'] ?? 25;
198195
$solrPaginator = new SolrPaginator($solrResults, $currentPage, $itemsPerPage);
199196
$simplePagination = new SimplePagination($solrPaginator);
200197

@@ -275,7 +272,7 @@ private function makeFacetsMenuArray(array $facets): array
275272
$searchParams = $this->search;
276273
if (
277274
(array_key_exists('fulltext', $searchParams))
278-
|| preg_match('/' . $fields['fulltext'] . ':\((.*)\)/', trim($searchParams['query']), $matches)
275+
|| preg_match('/' . $fields['fulltext'] . ':\((.*)\)/', trim($searchParams['query'] ?? ''), $matches)
279276
) {
280277
// If the query already is a fulltext query e.g using the facets
281278
$searchParams['query'] = empty($matches[1]) ? $searchParams['query'] : $matches[1];
@@ -344,7 +341,7 @@ private function makeFacetsMenuArray(array $facets): array
344341
'mincount' => '1',
345342
'key' => $field,
346343
'field' => $field,
347-
'limit' => $this->settings['limitFacets'],
344+
'limit' => $this->settings['limitFacets'] ?? 15,
348345
'sort' => isset($this->settings['sortingFacets']) ? $this->settings['sortingFacets'] : 'count'
349346
];
350347
}
@@ -517,7 +514,7 @@ private function processResults($facet, array $facetCollectionArray, array $sear
517514
$entryArray['ITEM_STATE'] = 'IFSUB';
518515
}
519516
$entryArray['_SUB_MENU'][] = $this->getFacetsMenuEntry($field, $value, $count, $search, $entryArray['ITEM_STATE']);
520-
if (++$i == $this->settings['limit']) {
517+
if (++$i == ($this->settings['limitFacets'] ?? 15)) {
521518
break;
522519
}
523520
} else {
@@ -587,7 +584,7 @@ private function addFieldsForExtendedSearch(): void
587584
private function enableSuggester(): void
588585
{
589586
// Add uHash parameter to suggest parameter to make a basic protection of this form.
590-
if ($this->settings['suggest']) {
587+
if ($this->settings['suggest'] ?? true) {
591588
$this->view->assign('uHash', GeneralUtility::hmac((string) (new Typo3Version()) . Environment::getExtensionsPath(), 'SearchSuggest'));
592589
}
593590
}

0 commit comments

Comments
 (0)