Bug 15939: Action logs - Do not default dates to today
[koha.git] / t / db_dependent / Circulation_OfflineOperation.t
1 #!/usr/bin/perl
2
3 use Modern::Perl;
4 use C4::Circulation;
5 use Koha::Library;
6
7 use Test::More tests => 7;
8
9 BEGIN {
10     use_ok('C4::Circulation');
11 }
12 can_ok(
13     'C4::Circulation',
14     qw(
15       AddOfflineOperation
16       GetOfflineOperation
17       GetOfflineOperations
18       DeleteOfflineOperation
19       )
20 );
21
22 #Start transaction
23 my $dbh = C4::Context->dbh;
24 $dbh->{RaiseError} = 1;
25 $dbh->{AutoCommit} = 0;
26
27 $dbh->do(q|DELETE FROM issues|);
28 $dbh->do(q|DELETE FROM borrowers|);
29 $dbh->do(q|DELETE FROM items|);
30 $dbh->do(q|DELETE FROM branches|);
31 $dbh->do(q|DELETE FROM pending_offline_operations|);
32
33 #Add branch
34 my $samplebranch1 = {
35     branchcode     => 'SAB1',
36     branchname     => 'Sample Branch',
37     branchaddress1 => 'sample adr1',
38     branchaddress2 => 'sample adr2',
39     branchaddress3 => 'sample adr3',
40     branchzip      => 'sample zip',
41     branchcity     => 'sample city',
42     branchstate    => 'sample state',
43     branchcountry  => 'sample country',
44     branchphone    => 'sample phone',
45     branchfax      => 'sample fax',
46     branchemail    => 'sample email',
47     branchurl      => 'sample url',
48     branchip       => 'sample ip',
49     branchprinter  => undef,
50     opac_info      => 'sample opac',
51 };
52 Koha::Library->new($samplebranch1)->store;
53
54 #Begin Tests
55 #Test AddOfflineOperation
56 is(
57     AddOfflineOperation(
58         'User1', $samplebranch1->{branchcode},
59         'null', 'Action1', 'CODE', 'Cardnumber1', 10
60     ),
61     'Added.',
62     "OfflineOperation has been added"
63 );
64 my $offline_id =
65   $dbh->last_insert_id( undef, undef, 'pending_offline_operations', undef );
66
67 #Test GetOfflineOperations
68 is_deeply(
69     GetOfflineOperation($offline_id),
70     {
71         operationid => $offline_id,
72         userid      => 'User1',
73         branchcode  => $samplebranch1->{branchcode},
74         timestamp   => "0000-00-00 00:00:00",
75         action      => 'Action1',
76         barcode     => 'CODE',
77         cardnumber  => 'Cardnumber1',
78         amount      => '10.000000'
79     },
80     "GetOffline returns offlineoperation's informations"
81 );
82 is( GetOfflineOperation(), undef,
83     'GetOfflineOperation without parameters returns undef' );
84 is( GetOfflineOperation(-1), undef,
85     'GetOfflineOperation with wrong parameters returns undef' );
86
87 #Test GetOfflineOperations
88 #TODO later: test GetOfflineOperations
89 # Actually we cannot mock C4::Context->userenv in unit tests
90
91 #Test DeleteOfflineOperation
92 is( DeleteOfflineOperation($offline_id),
93     'Deleted.', 'Offlineoperation has been deleted' );
94
95 #is (DeleteOfflineOperation(), undef, 'DeleteOfflineOperation without id returns undef');
96 #is (DeleteOfflineOperation(-1),undef, 'DeleteOfflineOperation with a wrong id returns undef');#FIXME
97
98 #End transaction
99 $dbh->rollback;