View | Details | Raw Unified | Return to bug 10710
Collapse All | Expand All

(-)a/t/db_dependent/Circulation_OfflineOperation.t (-1 / +97 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use C4::Branch;
5
use C4::Circulation;
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
    add            => 1,
36
    branchcode     => 'SAB1',
37
    branchname     => 'Sample Branch',
38
    branchaddress1 => 'sample adr1',
39
    branchaddress2 => 'sample adr2',
40
    branchaddress3 => 'sample adr3',
41
    branchzip      => 'sample zip',
42
    branchcity     => 'sample city',
43
    branchstate    => 'sample state',
44
    branchcountry  => 'sample country',
45
    branchphone    => 'sample phone',
46
    branchfax      => 'sample fax',
47
    branchemail    => 'sample email',
48
    branchurl      => 'sample url',
49
    branchip       => 'sample ip',
50
    branchprinter  => undef,
51
    opac_info      => 'sample opac',
52
};
53
ModBranch($samplebranch1);
54
55
#Begin Tests
56
#Test AddOfflineOperation
57
is(
58
    AddOfflineOperation(
59
        'User1', $samplebranch1->{branchcode},
60
        'null', 'Action1', 'CODE', 'Cardnumber1', 10
61
    ),
62
    'Added.',
63
    "OfflineOperation has been added"
64
);
65
my $offline_id =
66
  $dbh->last_insert_id( undef, undef, 'pending_offline_operations', undef );
67
68
#Test GetOfflineOperations
69
is_deeply(
70
    GetOfflineOperation($offline_id),
71
    {
72
        operationid => $offline_id,
73
        userid      => 'User1',
74
        branchcode  =>  $samplebranch1->{branchcode},
75
        timestamp   => "0000-00-00 00:00:00",
76
        action      => 'Action1',
77
        barcode     => 'CODE',
78
        cardnumber  => 'Cardnumber1',
79
        amount      => '10.000000'
80
    },
81
    "GetOffline returns offlineoperation's informations"
82
);
83
is(GetOfflineOperation,undef,'GetOfflineOperation without parameters returns undef');
84
is(GetOfflineOperation(-1),undef,'GetOfflineOperation with wrong parameters returns undef');
85
86
#Test GetOfflineOperations
87
#TODO later: test GetOfflineOperations
88
# Actually we cannot mock C4::Context->userenv in unit tests
89
90
#Test DeleteOfflineOperation
91
is (DeleteOfflineOperation($offline_id),'Deleted.','Offlineoperation has been deleted');
92
#is (DeleteOfflineOperation, undef, 'DeleteOfflineOperation without id returns undef');
93
#is (DeleteOfflineOperation(-1),undef, 'DeleteOfflineOperation with a wrong id returns undef');#FIXME
94
95
#End transaction
96
$dbh->rollback;
97

Return to bug 10710