Bug 26157: Hide expected DBI warnings from tests
[koha.git] / t / db_dependent / Circulation / OfflineOperation.t
blob6a92da4b1ceb5598ad3f89809e1eb8adb6cbddac
1 #!/usr/bin/perl
3 use Modern::Perl;
4 use C4::Circulation;
6 use Koha::Database;
7 use Koha::DateUtils qw( dt_from_string output_pref );
8 use Koha::Library;
10 use Test::More tests => 7;
12 BEGIN {
13 use_ok('C4::Circulation');
15 can_ok(
16 'C4::Circulation',
17 qw(
18 AddOfflineOperation
19 GetOfflineOperation
20 GetOfflineOperations
21 DeleteOfflineOperation
25 my $schema = Koha::Database->new->schema;
26 $schema->storage->txn_begin;
27 my $dbh = C4::Context->dbh;
29 $dbh->do(q|DELETE FROM issues|);
30 $dbh->do(q|DELETE FROM borrowers|);
31 $dbh->do(q|DELETE FROM items|);
32 $dbh->do(q|DELETE FROM branches|);
33 $dbh->do(q|DELETE FROM pending_offline_operations|);
35 #Add branch
36 my $samplebranch1 = {
37 branchcode => 'SAB1',
38 branchname => 'Sample Branch',
39 branchaddress1 => 'sample adr1',
40 branchaddress2 => 'sample adr2',
41 branchaddress3 => 'sample adr3',
42 branchzip => 'sample zip',
43 branchcity => 'sample city',
44 branchstate => 'sample state',
45 branchcountry => 'sample country',
46 branchphone => 'sample phone',
47 branchfax => 'sample fax',
48 branchemail => 'sample email',
49 branchurl => 'sample url',
50 branchip => 'sample ip',
51 opac_info => 'sample opac',
53 Koha::Library->new($samplebranch1)->store;
55 my $now = dt_from_string->truncate( to => 'minute' );
57 #Begin Tests
58 #Test AddOfflineOperation
59 is(
60 AddOfflineOperation(
61 'User1', $samplebranch1->{branchcode},
62 $now, 'Action1', 'CODE', 'Cardnumber1', 10
64 'Added.',
65 "OfflineOperation has been added"
67 my $offline_id =
68 $dbh->last_insert_id( undef, undef, 'pending_offline_operations', undef );
70 #Test GetOfflineOperations
71 is_deeply(
72 GetOfflineOperation($offline_id),
74 operationid => $offline_id,
75 userid => 'User1',
76 branchcode => $samplebranch1->{branchcode},
77 # FIXME sounds like we need a 'timestamp' dateformat
78 timestamp => output_pref({ dt => $now, dateformat => 'iso', dateonly => 0 }) . ':00',
79 action => 'Action1',
80 barcode => 'CODE',
81 cardnumber => 'Cardnumber1',
82 amount => '10.000000'
84 "GetOffline returns offlineoperation's informations"
86 is( GetOfflineOperation(), undef,
87 'GetOfflineOperation without parameters returns undef' );
88 is( GetOfflineOperation(-1), undef,
89 'GetOfflineOperation with wrong parameters returns undef' );
91 #Test GetOfflineOperations
92 #TODO later: test GetOfflineOperations
93 # Actually we cannot mock C4::Context->userenv in unit tests
95 #Test DeleteOfflineOperation
96 is( DeleteOfflineOperation($offline_id),
97 'Deleted.', 'Offlineoperation has been deleted' );
99 #is (DeleteOfflineOperation(), undef, 'DeleteOfflineOperation without id returns undef');
100 #is (DeleteOfflineOperation(-1),undef, 'DeleteOfflineOperation with a wrong id returns undef');#FIXME