7 use_ok 'Support::TestSetup';
8 use SL::DATEV qw(:CONSTANTS);
11 Support::TestSetup::login();
13 # first, test all the accessors
14 my $d = new_ok('SL::DATEV' => [], 'new without params');
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');
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');
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');
32 my $export_path = $d->export_path;
33 my $download_token = $d->download_token;
35 # see if that's roundtrip safe
36 $d = new_ok('SL::DATEV' => [ download_token => $download_token ], 'new with dl token');
38 is($d->download_token, $download_token, 'previously set download token');
39 is($d->export_path, $export_path, 'export path from download token');
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');
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');
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');
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');
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');
67 is($d->accnofrom, undef, 'init accnofrom');
68 is($d->accnofrom('3400'), '3400', 'set accnofrom');
69 is($d->accnofrom, '3400', 'get accnofrom');
71 is($d->accnoto, undef, 'init accnoto');
72 is($d->accnoto('3400'), '3400', 'set accnoto');
73 is($d->accnoto, '3400', 'get accnoto');
76 is($d->dbh, $::form->get_standard_dbh, 'init dbh');
77 ok(!$d->provided_dbh, 'no dbh provided');
79 my $other_dbh = $::form->get_standard_dbh->clone;
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');
86 $d = new_ok('SL::DATEV' => [], 'another clean one');
87 is($d->fromto, undef, 'if no from or to -> fromto undef');
89 # TODO:error handling. test that stuff dies if it has to