kitodo / kitodo-presentation

Kitodo.Presentation is a feature-rich framework for building a METS- or IIIF-based digital library. It is part of the Kitodo Digital Library Suite.
https://kitodo.github.io/kitodo-presentation/
GNU General Public License v3.0
39 stars 45 forks source link

[FEATURE] General reusable validation implementation and middleware for validating DOMDocument #1313

Closed markusweigelt closed 1 month ago

markusweigelt commented 2 months ago

This PR provides abstract classes to derived from for custom validation and reusable implementations for validation of DOMDocument.

Example of middleware

URI Query: dlf/domDocumentValidation&url=https%3A%2F%2Fwww.example.com%2Fmetsmods.xml

JSON response

{
  "valid": false,
  "results": {
    "XML-Schemes Validator": [
      "Element '{http://www.loc.gov/METS/}mdWrap', attribute 'MDTYP': The attribute 'MDTYP' is not allowed.\n",
      "Element '{http://www.loc.gov/METS/}mdWrap': The attribute 'MDTYPE' is required but missing.\n"
    ],
    ...
  }
}
markusweigelt commented 1 month ago

@sebastian-meyer Thanks, I had overlooked that. I added the lines back.

thomaslow commented 1 month ago

Hi Sebastian and Markus. Your recent changes fail unit tests in my branch (php 7.4, typo3 v11). Any ideas?

There was 1 error:

1) Kitodo\Dlf\Tests\Unit\Validation\SaxonXslToSvrlValidatorTest::testValidation
InvalidArgumentException: Saxon JAR file not found.

/home/runner/work/kitodo-presentation/kitodo-presentation/Classes/Validation/SaxonXslToSvrlValidator.php:47
/home/runner/work/kitodo-presentation/kitodo-presentation/Tests/Unit/Validation/SaxonXslToSvrlValidatorTest.php:67
phpvfscomposer:///home/runner/work/kitodo-presentation/kitodo-presentation/vendor/phpunit/phpunit/phpunit:106
/home/runner/work/kitodo-presentation/kitodo-presentation/vendor/bin/phpunit:118

--

There was 1 failure:

1) Kitodo\Dlf\Tests\Unit\Validation\SaxonXslToSvrlValidatorTest::testXslFileNotFound
Failed asserting that exception message 'Saxon JAR file not found.' contains 'XSL Schematron file not found.'.

phpvfscomposer:///home/runner/work/kitodo-presentation/kitodo-presentation/vendor/phpunit/phpunit/phpunit:106
/home/runner/work/kitodo-presentation/kitodo-presentation/vendor/bin/phpunit:118
markusweigelt commented 1 month ago

@thomaslow The problem seem to be the Typo3 function GeneralUtility::getFileAbsFileName https://github.com/thomaslow/kitodo-presentation/blob/6363217ab3c7c0a1863e45dfe75de2ebe16b7949/Classes/Validation/SaxonXslToSvrlValidator.php#L43, cause with extension path EXT:dlf/Tests/Fixtures/Format/alto.xml parameter the resolved path is not returned when running with the updated typo3/testing-framework. The behavior of resolving extension paths may have changed in the new version.

markusweigelt commented 1 month ago

@thomaslow i run the tests again with typo3/testing-framework 6.16.9, which succeeds, and with 7.1.0 I can reproduce the problem. I'll take a look at it tomorrow when I get a chance.

thomaslow commented 1 month ago

@markusweigelt I followed the empty string of GeneralUtility::getFileAbsFileName to the Typo3 PackageManager->getActivePackages(). It seems the package key EXT:dlf can not be resolved, because the package is not known at all when running the unit test.

The difference between testing-framework v6 and v7 seems to be in the UnitTestsBootstrap.php. They set composerMode = true, which prevents the PackageManager from scanning for extensions. Removing this check for composer mode loads all package paths including dlf and the unit test works.

I'm not sure how to fix this. I see two options:

sebastian-meyer commented 1 month ago

We copied Build/Test/runTests.sh a while ago from TYPO3, maybe we need to update this script in order to correctly run the tests in composerMode? The script seems really old anyways, referencing a lot of outdated versions (i. e. for MySQL) and missing current versions (like PHP 8.3).

sebastian-meyer commented 1 month ago

I opened a new issue in order to discuss this further: #1348