]> wagnertech.de Git - mfinanz.git/blob - t/xml_invoice/xml_invoice.t
date error in mapping
[mfinanz.git] / t / xml_invoice / xml_invoice.t
1 use Test::More;
2 use Test::Exception;
3
4 use strict;
5
6 use lib 't';
7 use utf8;
8
9 use File::Find;
10 use File::Slurp;
11 use SL::ZUGFeRD;
12 use Data::Dumper;
13 use Support::TestSetup;
14
15 Support::TestSetup::login();
16
17 File::Find::find(sub {
18   return unless /(xml|pdf)$/;
19
20 #   diag "found file $_";
21   test_file($_, SL::ZUGFeRD::RES_OK());
22 }, "t/xml_invoice/corpus");
23
24
25 sub test_file {
26   my ($filename, $expect_error) = @_;
27
28   open my $fh, '<', $filename or die "can't open $filename: $!";
29   my $data = do { local $/ = undef; <$fh> };
30   close $fh;
31
32   my $res;
33
34   eval {
35     if ($data =~ /^%PDF/) {
36       $res = SL::ZUGFeRD->extract_from_pdf($data);
37     } else {
38       $res = SL::ZUGFeRD->extract_from_xml($data);
39     }
40
41     1;
42   } or do {
43     ok 0, "failure to parse $filename: $@";
44     return;
45   };
46
47   is $res->{result}, $expect_error, "$filename: expected result $expect_error, got $res->{result} with message $res->{message}";
48 #   print Dumper($res);
49
50   return if $res->{result} != SL::ZUGFeRD::RES_OK();
51
52   {
53     local $TODO = "invoice parses, but contains warnings. likely missing XMP metadata";
54     ok 0 == @{$res->{warnings}}, "$filename has no warnings.";
55   }
56
57   ok $res->{invoice_xml}, "$filename has parsed xml data";
58
59   my $invoice = $res->{invoice_xml};
60
61   # minimal set of contents that should be present
62
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";
68
69   ok $invoice->items, "$filename contains items";
70
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";
76   }
77
78
79 }
80
81 done_testing;