We are building custom forms, however I would like to run automated validation tests for these forms using HTML Form Entry.
What I am looking to validate:
- Concepts exist
- Encounters, Identifiers and Provider tags are valid
- Required values are entered (driven by test data)
Are there examples of such tests and how would I approach this?
For the first 2, I think you can register a custom validator for your forms which will get invoked every time any of the forms is getting saved, you can take a look at any validator in core for an example.
@wyclif I am looking to test this within my development environment as a sanity check, rather than being used by a user
Do you mean for all the 3 bullets? If yes, for the first 2, there is a validation module that you can run against metadata, this typically will invoke registered validators against the forms, I believe unit unit tests can work too.
@wyclif Is there any example of code or API used by the validation module for runtime checking during the build process?
The validation module has a UI that you can use to run the validation, you can see how to do this from the module’s documentation page I include in my previous response, no need to write any code except for the validator itself that you can add via a custom module.
Yes, what @wyclif suggests, to create a custom validator for an HtmForm object makes sense.
Although it wasn’t intended for this use case, the HtmlFormExporter class might be helpful. It is used with Metadatasharing to gather up all metadata associated with a form. Right now it looks like it fails silently if a piece of metadata isn’t found, but it’s possible that the calculateDependencies class could be factored out into a common utility method and given a “fail hard” option if a dependency isn’t found, so therefore acting like a validator. If that approach does seem appealing, let me know your design plans, and I can review.