Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 49 commits into from
Sep 23, 2024

Conversation

markusweigelt
Copy link
Contributor

@markusweigelt markusweigelt commented Aug 26, 2024

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

  • Abstract validator and validation stack from which it can be derived (Can be handled as standalone validators as well, since they are derived from the AbstractValidator of Extbase)
  • Implementation and tests of DOMDocumentValidationStack, XMLSchemesValidator and SaxonXslToSvrlValidator
  • Comprehensive documentation
  • Customisable DOMDocumentValidation middleware via TypoScript setting domDocumentValidationValidators

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 markusweigelt marked this pull request as draft August 26, 2024 17:10
@markusweigelt markusweigelt changed the title Xml validator [FEATURE] Validation Aug 26, 2024
@sebastian-meyer sebastian-meyer added the ⚙ feature A new feature or enhancement. label Aug 27, 2024
@markusweigelt markusweigelt marked this pull request as ready for review August 29, 2024 16:29
@markusweigelt markusweigelt changed the title [FEATURE] Validation [FEATURE] General reusable validation implementation and middleware for validating DOMDocument Aug 29, 2024
DEVELOPMENT.md Outdated Show resolved Hide resolved
@markusweigelt
Copy link
Contributor Author

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

@sebastian-meyer sebastian-meyer merged commit c5d13ea into kitodo:master Sep 23, 2024
7 checks passed
@thomaslow
Copy link
Contributor

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
Copy link
Contributor Author

@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
Copy link
Contributor Author

markusweigelt commented Sep 24, 2024

@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
Copy link
Contributor

thomaslow commented Sep 24, 2024

@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:

  • not use GeneralUtility::getFileAbsFileName with an extension key in unit tests, e.g., specify only absolute file paths
  • move tests to functional tests, which have a different bootstrap process

@sebastian-meyer
Copy link
Member

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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚙ feature A new feature or enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants