From cc321a9302a4d2d8b21d7bbab3011cae0b139d8b Mon Sep 17 00:00:00 2001 From: Beatrycze Volk Date: Tue, 30 Jun 2026 16:17:49 +0200 Subject: [PATCH 1/2] [MAINTENANCE] Correct behavior of 'showSingle' setting in CollectionController The `showSingle` setting previously caused a redirect to a single collection view when it was disabled (empty or false). This change corrects the condition so that the redirect only occurs when `showSingle` is explicitly enabled (`true`), aligning with its intended purpose to directly display a single collection. --- Classes/Controller/CollectionController.php | 2 +- Tests/Functional/Controller/CollectionControllerTest.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Classes/Controller/CollectionController.php b/Classes/Controller/CollectionController.php index b1a06559d..bbce009c3 100644 --- a/Classes/Controller/CollectionController.php +++ b/Classes/Controller/CollectionController.php @@ -97,7 +97,7 @@ public function listAction(): ResponseInterface $collections = $this->collectionRepository->findAll(); } - if (iterator_count($collections) == 1 && empty($this->settings['showSingle']) && is_array($collections)) { + if (iterator_count($collections) == 1 && $this->settings['showSingle'] && is_array($collections)) { return $this->redirect('show', null, null, ['collection' => array_pop($collections)]); } diff --git a/Tests/Functional/Controller/CollectionControllerTest.php b/Tests/Functional/Controller/CollectionControllerTest.php index 020812d9c..6a48d70e4 100644 --- a/Tests/Functional/Controller/CollectionControllerTest.php +++ b/Tests/Functional/Controller/CollectionControllerTest.php @@ -41,7 +41,7 @@ public function canListAction() 'storagePid' => self::$storagePid, 'solrcore' => self::$solrCoreId, 'collections' => '1', - 'showSingle' => '1', + 'showSingle' => '0', 'randomize' => '' ]; $templateHtml = '{item.collection.indexName}'; @@ -62,6 +62,7 @@ public function canListActionForwardToShow() 'storagePid' => self::$storagePid, 'solrcore' => self::$solrCoreId, 'collections' => '1', + 'showSingle' => '1', 'randomize' => '' ]; $controller = $this->setUpController(CollectionController::class, $settings); From f15f2532593012f858057a43fe2d37b09b7e1582 Mon Sep 17 00:00:00 2001 From: Beatrycze Volk Date: Mon, 29 Jun 2026 13:07:03 +0200 Subject: [PATCH 2/2] [TEST] Refactor collection tests for granular display options Breaks down the comprehensive `canListAction` and `canShowAction` tests into several distinct test cases. This enables specific verification of the `showSingle`, `showOverview`, and `showDocuments` settings, ensuring their correct behavior in the collection view. New private helper functions `getContentsList` and `getContentsShow` are extracted to reduce duplication and improve readability across the new test cases. Test attributes are updated to PHPUnit 8+. --- Tests/Fixtures/Controller/pages.csv | 1 + .../Controller/CollectionControllerTest.php | 168 ++++++++++++++++-- 2 files changed, 154 insertions(+), 15 deletions(-) diff --git a/Tests/Fixtures/Controller/pages.csv b/Tests/Fixtures/Controller/pages.csv index 1444c7d5b..45bd7d035 100644 --- a/Tests/Fixtures/Controller/pages.csv +++ b/Tests/Fixtures/Controller/pages.csv @@ -80,3 +80,4 @@ tt_content,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, tx_dlf_collections,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,uid,pid,tstamp,crdate,cruser_id,deleted,sys_language_uid,l18n_parent,l18n_diffsource,hidden,fe_group,fe_cruser_id,fe_admin_lock,label,index_name,index_search,oai_name,description,thumbnail,priority,documents,owner,status,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,1,2,1678700538,1678700538,2,0,0,0,"a:16:{s:16:"sys_language_uid";N;s:11:"l18n_parent";N;s:6:"hidden";N;s:8:"fe_group";N;s:5:"label";N;s:10:"index_name";N;s:12:"index_search";N;s:8:"oai_name";N;s:11:"description";N;s:8:"priority";N;s:9:"documents";N;s:5:"owner";N;s:12:"fe_cruser_id";N;s:13:"fe_admin_lock";N;s:6:"status";N;s:9:"thumbnail";N;}"",0,,0,0,""Test Collection",0,,0,0,Test Collection,test-collection,,test-collection,,,3,0,0,0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +,2,2,1678700538,1678700538,2,0,0,0,"a:16:{s:16:"sys_language_uid";N;s:11:"l18n_parent";N;s:6:"hidden";N;s:8:"fe_group";N;s:5:"label";N;s:10:"index_name";N;s:12:"index_search";N;s:8:"oai_name";N;s:11:"description";N;s:8:"priority";N;s:9:"documents";N;s:5:"owner";N;s:12:"fe_cruser_id";N;s:13:"fe_admin_lock";N;s:6:"status";N;s:9:"thumbnail";N;}"",0,,0,0,""Second Collection",0,,0,0,Second Collection,second-collection,,second-collection,,,3,0,0,0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, diff --git a/Tests/Functional/Controller/CollectionControllerTest.php b/Tests/Functional/Controller/CollectionControllerTest.php index 6a48d70e4..90081a8f6 100644 --- a/Tests/Functional/Controller/CollectionControllerTest.php +++ b/Tests/Functional/Controller/CollectionControllerTest.php @@ -13,6 +13,7 @@ namespace Kitodo\Dlf\Tests\Functional\Controller; use Kitodo\Dlf\Controller\CollectionController; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\Test; use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder; @@ -35,27 +36,25 @@ public function setUp(): void } #[Test] + #[Group("listAction")] public function canListAction() { $settings = [ 'storagePid' => self::$storagePid, 'solrcore' => self::$solrCoreId, - 'collections' => '1', + 'collections' => '1,2', 'showSingle' => '0', 'randomize' => '' ]; - $templateHtml = '{item.collection.indexName}'; - $controller = $this->setUpController(CollectionController::class, $settings, $templateHtml); - $request = $this->setUpRequest('list', [ 'tx_dlf' => ['id' => 1] ]); + $templateHtml = '{item.collection.indexName},'; - $response = $controller->processRequest($request); - $response->getBody()->rewind(); - $actual = $response->getBody()->getContents(); - $expected = 'test-collection'; + $actual = $this->getContentsList($settings, $templateHtml); + $expected = 'test-collection,second-collection,'; $this->assertEquals($expected, $actual); } #[Test] + #[Group("listAction")] public function canListActionForwardToShow() { $settings = [ @@ -74,28 +73,121 @@ public function canListActionForwardToShow() } #[Test] - public function canShowAction() + #[Group("listAction")] + public function canNotListActionForwardToShow() { $settings = [ 'storagePid' => self::$storagePid, 'solrcore' => self::$solrCoreId, 'collections' => '1', - 'showSingle' => '1', + 'showSingle' => '0', + 'randomize' => '' + ]; + $templateHtml = '{item.collection.indexName}'; + + $actual = $this->getContentsList($settings, $templateHtml); + $expected = 'test-collection'; + $this->assertEquals($expected, $actual); + } + + #[Test] + #[Group("showAction")] + public function canShowSingleCollection() + { + $settings = [ + 'storagePid' => self::$storagePid, + 'solrcore' => self::$solrCoreId, + 'collections' => '1', + 'showSingle' => '0', 'showOverview' => '1', 'showDocuments' => '1', 'randomize' => '' ]; $templateHtml = '{page.title},'; - $controller = $this->setUpController(CollectionController::class, $settings, $templateHtml); - $request = $this->setUpRequest('show', [], ['collection' => '1' ]); + $actual = $this->getContentsShow($settings, $templateHtml); + $expected = '10 Keyboard pieces - Go. S. 658,'; + $this->assertEquals($expected, $actual); + } - $response = $controller->processRequest($request); - $response->getBody()->rewind(); - $actual = $response->getBody()->getContents(); + #[Test] + #[Group("showAction")] + public function canShowCollectionOverview() + { + $settings = [ + 'storagePid' => self::$storagePid, + 'solrcore' => self::$solrCoreId, + 'collections' => '1', + 'showSingle' => '1', + 'showOverview' => '1', + 'showDocuments' => '1', + 'randomize' => '' + ]; + $templateHtml = '{collection.label}'; + + $actual = $this->getContentsShow($settings, $templateHtml);; + $expected = 'Test Collection'; + $this->assertEquals($expected, $actual); + } + + #[Test] + #[Group("showAction")] + public function canNotShowCollectionOverview() + { + $settings = [ + 'storagePid' => self::$storagePid, + 'solrcore' => self::$solrCoreId, + 'collections' => '1', + 'showSingle' => '1', + 'showOverview' => '0', + 'showDocuments' => '1', + 'randomize' => '' + ]; + $templateHtml = '{collection.label}'; + + $actual = $this->getContentsShow($settings, $templateHtml);; + $expected = ''; + $this->assertEquals($expected, $actual); + } + + #[Test] + #[Group("showAction")] + public function canShowCollectionDocuments() + { + $settings = [ + 'storagePid' => self::$storagePid, + 'solrcore' => self::$solrCoreId, + 'collections' => '1', + 'showSingle' => '1', + 'showOverview' => '1', + 'showDocuments' => '1', + 'randomize' => '' + ]; + $templateHtml = '{page.title},'; + + $actual = $this->getContentsShow($settings, $templateHtml);; $expected = '10 Keyboard pieces - Go. S. 658,'; $this->assertEquals($expected, $actual); + } + #[Test] + #[Group("showAction")] + public function canNotShowCollectionDocuments() + { + $settings = [ + 'storagePid' => self::$storagePid, + 'solrcore' => self::$solrCoreId, + 'collections' => '1', + 'showSingle' => '1', + 'showOverview' => '1', + 'showDocuments' => '0', + 'randomize' => '' + ]; + $templateHtml = '{page.title},'; + + $actual = $this->getContentsShow($settings, $templateHtml);; + $expected = ''; + $this->assertEquals($expected, $actual); } #[Test] @@ -115,4 +207,50 @@ public function canShowSortedAction() $response = $controller->processRequest($request); $this->assertEquals(303, $response->getStatusCode()); } + + /** + * @access private + * + * @param array $settings + * @param string $templateHtml + * + * @return string + */ + private function getContentsList(array $settings, string $templateHtml): string + { + return $this->getContents('list', [ 'tx_dlf' => ['id' => 1] ], $settings, $templateHtml); + } + + /** + * @access private + * + * @param array $settings + * @param string $templateHtml + * + * @return string + */ + private function getContentsShow(array $settings, string $templateHtml): string + { + return $this->getContents('show', ['collection' => '1' ], $settings, $templateHtml); + } + + /** + * @access private + * + * @param string $action + * @param array $parameters + * @param array $settings + * @param string $templateHtml + * + * @return string + */ + private function getContents(string $action, array $parameters, array $settings, string $templateHtml): string + { + $controller = $this->setUpController(CollectionController::class, $settings, $templateHtml); + $request = $this->setUpRequest($action, [], $parameters); + + $response = $controller->processRequest($request); + $response->getBody()->rewind(); + return $response->getBody()->getContents(); + } }