Skip to content

Commit

Permalink
Merge branch 'master' into ControllerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
chrizzor authored Oct 9, 2024
2 parents b6f2a6b + 63041f8 commit 486a8b5
Show file tree
Hide file tree
Showing 13 changed files with 483 additions and 457 deletions.
3 changes: 2 additions & 1 deletion Classes/Api/Orcid/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public function __construct(string $orcid, RequestFactory $requestFactory)
*
* @return void
*/
public function setEndpoint(string $endpoint): void {
public function setEndpoint(string $endpoint): void
{
$this->endpoint = $endpoint;
}

Expand Down
5 changes: 3 additions & 2 deletions Classes/Api/Viaf/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public function __construct(string $viaf, RequestFactory $requestFactory)
*
* @return void
*/
public function setEndpoint(string $endpoint): void {
public function setEndpoint(string $endpoint): void
{
$this->endpoint = $endpoint;
}

Expand All @@ -103,7 +104,7 @@ public function getData()

/**
* Creates the qualified API endpoint for retrieving the desired data
*
*
* @access private
*
* @return string
Expand Down
42 changes: 20 additions & 22 deletions Classes/Common/MetsDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -1336,33 +1336,31 @@ protected function magicGetFileGrps(): array
// Get configured USE attributes.
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey, 'files');
$useGrps = GeneralUtility::trimExplode(',', $extConf['fileGrpImages']);
if (!empty($extConf['fileGrpThumbs'])) {
$useGrps = array_merge($useGrps, GeneralUtility::trimExplode(',', $extConf['fileGrpThumbs']));
}
if (!empty($extConf['fileGrpDownload'])) {
$useGrps = array_merge($useGrps, GeneralUtility::trimExplode(',', $extConf['fileGrpDownload']));
}
if (!empty($extConf['fileGrpFulltext'])) {
$useGrps = array_merge($useGrps, GeneralUtility::trimExplode(',', $extConf['fileGrpFulltext']));
}
if (!empty($extConf['fileGrpAudio'])) {
$useGrps = array_merge($useGrps, GeneralUtility::trimExplode(',', $extConf['fileGrpAudio']));
}
if (!empty($extConf['fileGrpScore'])) {
$useGrps = array_merge($useGrps, GeneralUtility::trimExplode(',', $extConf['fileGrpScore']));

$configKeys = [
'fileGrpThumbs',
'fileGrpDownload',
'fileGrpFulltext',
'fileGrpAudio',
'fileGrpScore'
];

foreach ($configKeys as $key) {
if (!empty($extConf[$key])) {
$useGrps = array_merge($useGrps, GeneralUtility::trimExplode(',', $extConf[$key]));
}
}

// Get all file groups.
$fileGrps = $this->mets->xpath('./mets:fileSec/mets:fileGrp');
if (!empty($fileGrps)) {
// Build concordance for configured USE attributes.
foreach ($fileGrps as $fileGrp) {
if (in_array((string) $fileGrp['USE'], $useGrps)) {
foreach ($useGrps as $useGrp) {
// Perform XPath query for each configured USE attribute
$fileGrps = $this->mets->xpath("./mets:fileSec/mets:fileGrp[@USE='$useGrp']");
if (!empty($fileGrps)) {
foreach ($fileGrps as $fileGrp) {
foreach ($fileGrp->children('http://www.loc.gov/METS/')->file as $file) {
$fileId = (string) $file->attributes()->ID;
$this->fileGrps[$fileId] = (string) $fileGrp['USE'];
$this->fileGrps[$fileId] = $useGrp;
$this->fileInfos[$fileId] = [
'fileGrp' => (string) $fileGrp['USE'],
'fileGrp' => $useGrp,
'admId' => (string) $file->attributes()->ADMID,
'dmdId' => (string) $file->attributes()->DMDID,
];
Expand Down
7 changes: 7 additions & 0 deletions Classes/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ protected function sanitizeSettings(): void
$this->setDefaultIntSetting('displayIiifLinks', 1);
}

if ($this instanceof NavigationController) {
$this->setDefaultIntSetting('pageStep', 5);
}

if ($this instanceof OaiPmhController) {
$this->setDefaultIntSetting('limit', 5);
$this->setDefaultIntSetting('solr_limit', 50000);
Expand Down Expand Up @@ -525,11 +529,14 @@ protected function buildSimplePagination(PaginationInterface $pagination, Pagina
*/
private function getDocumentByUid(int $documentId)
{
// TODO: implement multiView as it is in getDocumentByUrl
$doc = null;
$this->document = $this->documentRepository->findOneByIdAndSettings($documentId);

if ($this->document) {
$doc = AbstractDocument::getInstance($this->document->getLocation(), $this->settings, true);
// fix for count(): Argument #1 ($value) must be of type Countable|array, null given
$this->documentArray[] = $doc;
} else {
$this->logger->error('Invalid UID "' . $documentId . '" or PID "' . $this->settings['storagePid'] . '" for document loading');
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Controller/MetadataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ private function buildUrlFromMetadata(array $metadata): array

foreach ($metadata as $i => $section) {
if ($this->settings['linkTitle'] && $section['_id'] && isset($section['title']) && !empty($section['title'])) {
$details = $this->currentDocument->getLogicalStructure($section['_id']);
$details = $this->currentDocument->getLogicalStructure($section['_id'][0]);
$buildUrl[$i]['title'] = [
'id' => $this->document->getUid(),
'page' => (!empty($details['points']) ? (int) $details['points'] : 1),
Expand Down
6 changes: 3 additions & 3 deletions Classes/Controller/TableOfContentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private function getMenuEntry(array $entry, bool $recursive = false): array
$entryArray['doNotLinkIt'] = 1;
$entryArray['ITEM_STATE'] = 'NO';

$this->buildMenuLinks($entryArray, $entry['id'], $entry['points'], $entry['targetUid']);
$this->buildMenuLinks($entryArray, $entry['id'], $entry['points'] ?? null, $entry['targetUid'] ?? null);

// Set "ITEM_STATE" to "CUR" if this entry points to current page.
if (in_array($entry['id'], $this->activeEntries)) {
Expand All @@ -148,7 +148,7 @@ private function getMenuEntry(array $entry, bool $recursive = false): array
// 3. Current menu node has no corresponding images
if (
$entryArray['ITEM_STATE'] == 'CUR'
|| is_string($entry['points'])
|| (array_key_exists('points', $entry) && is_string($entry['points']))
|| empty($this->document->getCurrentDocument()->smLinks['l2p'][$entry['id']])
) {
$entryArray['_SUB_MENU'] = [];
Expand Down Expand Up @@ -241,7 +241,7 @@ private function resolveMenuEntry(array $entry): array
$doc = $this->document->getCurrentDocument();
if (
$doc instanceof MetsDocument
&& ($entry['points'] === $doc->parentHref || $this->isMultiElement($entry['type']))
&& ((array_key_exists('points', $entry) && $entry['points'] === $doc->parentHref) || $this->isMultiElement($entry['type']))
&& !empty($this->document->getPartof())
) {
unset($entry['points']);
Expand Down
1 change: 0 additions & 1 deletion Classes/Validation/AbstractDlfValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
namespace Kitodo\Dlf\Validation;

use InvalidArgumentException;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down
14 changes: 12 additions & 2 deletions Classes/Validation/SaxonXslToSvrlValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use InvalidArgumentException;
use Psr\Log\LoggerAwareInterface;
use SimpleXMLElement;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
use TYPO3\CMS\Core\Utility\GeneralUtility;

Expand Down Expand Up @@ -52,12 +51,19 @@ public function __construct(array $configuration)
}
}

protected function isValid($value)
protected function isValid($value): void
{
$svrl = $this->process($value);
$this->addErrorsOfSvrl($svrl);
}

/**
* @param mixed $value
*
* @throws InvalidArgumentException
*
* @return string
*/
protected function process(mixed $value): string
{
// using source from standard input
Expand All @@ -74,7 +80,11 @@ protected function process(mixed $value): string
/**
* Add errors of schematron output.
*
* @param string $svrl
*
* @throws InvalidArgumentException
*
* @return void
*/
private function addErrorsOfSvrl(string $svrl): void
{
Expand Down
2 changes: 1 addition & 1 deletion Classes/Validation/XmlSchemesValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class XmlSchemesValidator extends AbstractDlfValidator

public function __construct(array $configuration)
{
parent::__construct(\DOMDocument::class);
parent::__construct(DOMDocument::class);
$this->schemes = $configuration;
}

Expand Down
8 changes: 6 additions & 2 deletions Tests/Unit/Validation/SaxonXslToSvrlValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use InvalidArgumentException;
use Kitodo\Dlf\Validation\SaxonXslToSvrlValidator;
use ReflectionClass;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Extbase\Error\Result;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

Expand All @@ -41,10 +42,13 @@ class SaxonXslToSvrlValidatorTest extends UnitTestCase
</svrl:schematron-output>
SVRL;

private string $dlfExtensionPath;

public function setUp(): void
{
parent::setUp();
$this->resetSingletonInstances = true;
$this->dlfExtensionPath = Environment::getExtensionsPath() . 'dlf';
}

public function testJarFileNotFound(): void
Expand All @@ -59,12 +63,12 @@ public function testXslFileNotFound(): void
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage("XSL Schematron file not found.");
// It only checks if a file exists at the specified path, so we can use one of the test files.
new SaxonXslToSvrlValidator(["jar" => 'EXT:dlf/Tests/Fixtures/Format/alto.xml']);
new SaxonXslToSvrlValidator(["jar" => $this->dlfExtensionPath . '/Tests/Fixtures/Format/alto.xml']);
}

public function testValidation(): void
{
$saxonXslToSvrlValidator = new SaxonXslToSvrlValidator(["jar" => 'EXT:dlf/Tests/Fixtures/Format/alto.xml', "xsl" => 'EXT:dlf/Tests/Fixtures/Format/alto.xml']);
$saxonXslToSvrlValidator = new SaxonXslToSvrlValidator(["jar" => $this->dlfExtensionPath . '/Tests/Fixtures/Format/alto.xml', "xsl" => $this->dlfExtensionPath . '/Tests/Fixtures/Format/alto.xml']);
$reflection = new ReflectionClass($saxonXslToSvrlValidator);

$result = $reflection->getProperty("result");
Expand Down
26 changes: 13 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@
"ext-libxml": "*",
"ext-openssl": "*",
"ext-simplexml": "*",
"typo3/cms-core": "^10.4.37|^11.5.38",
"typo3/cms-extbase": "^10.4.37|^11.5.38",
"typo3/cms-scheduler" : "^10.4.37|^11.5.38",
"typo3/cms-tstemplate": "^10.4.37|^11.5.38",
"typo3/cms-core": "^10.4.37|^11.5.40",
"typo3/cms-extbase": "^10.4.37|^11.5.40",
"typo3/cms-scheduler" : "^10.4.37|^11.5.40",
"typo3/cms-tstemplate": "^10.4.37|^11.5.40",
"caseyamcl/phpoaipmh": "^3.3.1",
"slub/php-mods-reader": "^0.4.0",
"ubl/php-iiif-prezi-reader": "0.3.0",
"solarium/solarium": "5.2 - 6.3",
"symfony/process": "^5.4.40"
"symfony/process": "^5.4"
},
"require-dev": {
"fluidtypo3/vhs": "^6.1",
"phpstan/phpstan": "^1.11.10",
"spatie/phpunit-watcher": "^1.23.6",
"typo3/cms-backend": "^10.4.37|^11.5.38",
"typo3/cms-fluid": "^10.4.37|^11.5.38",
"typo3/cms-fluid-styled-content": "^10.4.37|^11.5.38",
"typo3/cms-frontend": "^10.4.37|^11.5.38",
"typo3/testing-framework": "^6.16.9",
"fluidtypo3/vhs": "^6.1",
"phpstan/phpstan": "^1.12",
"spatie/phpunit-watcher": "^1.23",
"typo3/cms-backend": "^10.4.37|^11.5.40",
"typo3/cms-fluid": "^10.4.37|^11.5.40",
"typo3/cms-fluid-styled-content": "^10.4.37|^11.5.40",
"typo3/cms-frontend": "^10.4.37|^11.5.40",
"typo3/testing-framework": "^6.16.10",
"vlucas/phpdotenv": "^5.6.1"
},
"replace": {
Expand Down
Loading

0 comments on commit 486a8b5

Please sign in to comment.