13 use Support::TestSetup;
15 Support::TestSetup::login();
17 File::Find::find(sub {
18 return unless /(xml|pdf)$/;
20 # diag "found file $_";
21 test_file($_, SL::ZUGFeRD::RES_OK());
22 }, "t/xml_invoice/corpus");
26 my ($filename, $expect_error) = @_;
28 open my $fh, '<', $filename or die "can't open $filename: $!";
29 my $data = do { local $/ = undef; <$fh> };
35 if ($data =~ /^%PDF/) {
36 $res = SL::ZUGFeRD->extract_from_pdf($data);
38 $res = SL::ZUGFeRD->extract_from_xml($data);
43 ok 0, "failure to parse $filename: $@";
47 is $res->{result}, $expect_error, "$filename: expected result $expect_error, got $res->{result} with message $res->{message}";
50 return if $res->{result} != SL::ZUGFeRD::RES_OK();
53 local $TODO = "invoice parses, but contains warnings. likely missing XMP metadata";
54 ok 0 == @{$res->{warnings}}, "$filename has no warnings.";
57 ok $res->{invoice_xml}, "$filename has parsed xml data";
59 my $invoice = $res->{invoice_xml};
61 # minimal set of contents that should be present
63 ok $invoice->metadata->{vendor_name}, "$filename contains vendor name";
64 ok $invoice->metadata->{gross_total}, "$filename contains net_total";
65 ok $invoice->metadata->{net_total}, "$filename contains net_total";
66 ok $invoice->metadata->{transdate}, "$filename contains transdate";
67 ok $invoice->metadata->{currency}, "$filename contains currency";
69 ok $invoice->items, "$filename contains items";
71 for my $item (@{ $invoice->items }) {
72 ok $item->{price}, "item of $filename contains price";
73 ok $item->{subtotal}, "item of $filename contains subtotal";
74 ok $item->{tax_rate}, "item of $filename contains tax_rate";
75 ok $item->{tax_scheme}, "item of $filename contains tax_scheme";