ShopOrder: billing_email zusätzlich als invoice_mail ...
[kivitendo-erp.git] / t / datev / interface.t
1 use strict;
2 use Test::More;
3 use Test::Deep ();
4
5 use lib 't';
6
7 use_ok 'Support::TestSetup';
8 use SL::DATEV qw(:CONSTANTS);
9 use DateTime;
10
11 Support::TestSetup::login();
12
13 # first, test all the accessors
14 my $d = new_ok('SL::DATEV' => [], 'new without params');
15
16 # export_type
17 ok(!$d->has_exporttype, 'no exporttype');
18 is($d->exporttype(DATEV_ET_BUCHUNGEN), DATEV_ET_BUCHUNGEN, 'set exporttype');
19 is($d->exporttype, DATEV_ET_BUCHUNGEN, 'get exporttype');
20 ok($d->has_exporttype, 'now exporttype');
21
22 # export_path/download_token
23 ok(!$d->has_format, 'no format');
24 is($d->format(DATEV_FORMAT_KNE), DATEV_FORMAT_KNE, 'set format');
25 is($d->format, DATEV_FORMAT_KNE, 'get format');
26 ok($d->has_format, 'now format');
27
28 # check if autogenerated download token work work
29 ok($d->export_path, 'auto generated export path');
30 ok($d->download_token, 'auto generated download token');
31
32 my $export_path = $d->export_path;
33 my $download_token = $d->download_token;
34
35 # see if that's roundtrip safe
36 $d = new_ok('SL::DATEV' => [ download_token => $download_token ], 'new with dl token');
37
38 is($d->download_token, $download_token, 'previously set download token');
39 is($d->export_path, $export_path, 'export path from download token');
40
41
42 # array attributes
43 Test::Deep::cmp_deeply([$d->filenames], [], 'init filenames');
44 is($d->add_filenames(qw(a b c)), 3, 'add filenames');
45 Test::Deep::cmp_deeply([$d->filenames], [qw(a b c)], 'get filenames');
46
47 Test::Deep::cmp_deeply([$d->errors], [], 'init errors');
48 is($d->add_error(qw(a b c)), 3, 'add error');
49 Test::Deep::cmp_deeply([$d->errors], [qw(a b c)], 'get errors');
50
51 Test::Deep::cmp_deeply([$d->net_gross_differences], [], 'init net_gross_differences');
52 is($d->add_net_gross_differences(qw(1 2 3)), 3, 'add net_gross_differences');
53 Test::Deep::cmp_deeply([$d->net_gross_differences], [qw(1 2 3)], 'get net_gross_differences');
54 is($d->sum_net_gross_differences, 6, 'sum net_gross_differences');
55
56
57 #get/set attributes
58
59 is($d->from, undef, 'init from');
60 is($d->from(DateTime->today), DateTime->today, 'set from');
61 is($d->from, DateTime->today, 'get from');
62
63 is($d->to, undef, 'init to');
64 is($d->to(DateTime->today), DateTime->today, 'set to');
65 is($d->to, DateTime->today, 'get to');
66
67 is($d->accnofrom, undef, 'init accnofrom');
68 is($d->accnofrom('3400'), '3400', 'set accnofrom');
69 is($d->accnofrom, '3400', 'get accnofrom');
70
71 is($d->accnoto, undef, 'init accnoto');
72 is($d->accnoto('3400'), '3400', 'set accnoto');
73 is($d->accnoto, '3400', 'get accnoto');
74
75 # dbh handling
76 is($d->dbh, $::form->get_standard_dbh, 'init dbh');
77 ok(!$d->provided_dbh, 'no dbh provided');
78
79 my $other_dbh = $::form->get_standard_dbh->clone;
80
81 $d = new_ok('SL::DATEV' => [ dbh => $other_dbh ], 'new with dbh');
82 isnt($d->dbh, $::form->get_standard_dbh, 'now a different dbh');
83 ok($d->provided_dbh, 'now got some provided dbh');
84
85
86 $d = new_ok('SL::DATEV' => [], 'another clean one');
87 is($d->fromto, undef, 'if no from or to -> fromto undef');
88
89 # TODO:error handling. test that stuff dies if it has to
90
91 done_testing();
92
93
94 1;