All tests with folders start with the following methods:
# Instantiation of PDFUnit for a folder: AssertThat->eachDocument()->inFolder($folder)
->passedFilter($allPdfunitFiles)
->... ;
These two methods start each test using all files in the given folder that have the extension '.pdf'. This extension is case-insensitive. |
|
An optional filter can be used to reduce the number of documents. Multiple filters can be concatenated. Without a filter, all PDF documents in the folder will be checked. |
A test ends for all documents when one document in the folder fails.
If the filters filter out every document, an error message is shown. Also, an error message will be shown if a folder contains no PDF documents.
The following example checks whether all PDF documents in the given folder comply with the ZUGFeRD specification version 1.0:
lives_ok { my $folder = File->new("$resources_dir/zugferd10/"); AssertThat->eachDocument() ->inFolder($folder) ->compliesWith() ->zugferdSpecification(ZugferdVersion::VERSION10) ; } "validate compliance with ZUGFeRD specification of all PDF of a given folder";
In the next example, all PDF documents with 'doc-under-test' or 'reference' in their names are selected. Then the title is validated in each of the selected documents.
lives_ok { my $folder = File->new($resources_dir); my $allPdfunitFiles = FilenameMatchingFilter->new('.*(doc-under-test|reference)\.pdf$'); AssertThat ->eachDocument() ->inFolder($folder) ->passedFilter($allPdfunitFiles) ->hasProperty("Title")->equalsTo("PDFUnit - Automated PDF Tests") ; } "demo using a folder with a file filter";
There are two kinds of filters. The filter FilenameContainingFilter
filters files whoes names (including the path) contain the given substring.
The filter FilenameMatchingFilter
evaluates whether names matches
a regular expression.
The regular expression should always begin with '.*
'.