Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Tests/Fixtures/Controller/pages.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
168 changes: 153 additions & 15 deletions Tests/Functional/Controller/CollectionControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -35,27 +36,25 @@
}

#[Test]
#[Group("listAction")]
public function canListAction()
{
$settings = [
'storagePid' => self::$storagePid,
'solrcore' => self::$solrCoreId,
'collections' => '1',
'collections' => '1,2',
'showSingle' => '0',
'randomize' => ''
];
$templateHtml = '<html><f:for each="{collections}" as="item">{item.collection.indexName}</f:for></html>';
$controller = $this->setUpController(CollectionController::class, $settings, $templateHtml);
$request = $this->setUpRequest('list', [ 'tx_dlf' => ['id' => 1] ]);
$templateHtml = '<html><f:for each="{collections}" as="item">{item.collection.indexName},</f:for></html>';

$response = $controller->processRequest($request);
$response->getBody()->rewind();
$actual = $response->getBody()->getContents();
$expected = '<html>test-collection</html>';
$actual = $this->getContentsList($settings, $templateHtml);
$expected = '<html>test-collection,second-collection,</html>';
$this->assertEquals($expected, $actual);
}

#[Test]
#[Group("listAction")]
public function canListActionForwardToShow()
{
$settings = [
Expand All @@ -74,28 +73,121 @@
}

#[Test]
public function canShowAction()
#[Group("listAction")]
public function canNotListActionForwardToShow()
{
$settings = [
'storagePid' => self::$storagePid,
'solrcore' => self::$solrCoreId,
'collections' => '1',
'showSingle' => '1',
'showSingle' => '0',
'randomize' => ''
];
$templateHtml = '<html><f:for each="{collections}" as="item">{item.collection.indexName}</f:for></html>';

$actual = $this->getContentsList($settings, $templateHtml);
$expected = '<html>test-collection</html>';
$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 = '<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"><f:for each="{documents.solrResults.documents}" as="page" iteration="docIterator">{page.title},</f:for></html>';

$controller = $this->setUpController(CollectionController::class, $settings, $templateHtml);
$request = $this->setUpRequest('show', [], ['collection' => '1' ]);
$actual = $this->getContentsShow($settings, $templateHtml);
$expected = '<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers">10 Keyboard pieces - Go. S. 658,</html>';
$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 = '<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers">{collection.label}</html>';

$actual = $this->getContentsShow($settings, $templateHtml);;

Check notice on line 128 in Tests/Functional/Controller/CollectionControllerTest.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Tests/Functional/Controller/CollectionControllerTest.php#L128

Each PHP statement must be on a line by itself
$expected = '<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers">Test Collection</html>';
$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 = '<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers">{collection.label}</html>';

$actual = $this->getContentsShow($settings, $templateHtml);;
$expected = '<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"></html>';
$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 = '<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"><f:for each="{documents.solrResults.documents}" as="page" iteration="docIterator">{page.title},</f:for></html>';

$actual = $this->getContentsShow($settings, $templateHtml);;
$expected = '<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers">10 Keyboard pieces - Go. S. 658,</html>';
$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 = '<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"><f:for each="{documents.solrResults.documents}" as="page" iteration="docIterator">{page.title},</f:for></html>';

$actual = $this->getContentsShow($settings, $templateHtml);;
$expected = '<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"></html>';
$this->assertEquals($expected, $actual);
}

#[Test]
Expand All @@ -115,4 +207,50 @@
$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();
}
}