Lines 1-7
Link Here
|
1 |
#!/usr/bin/perl; |
1 |
#!/usr/bin/perl; |
2 |
|
2 |
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
4 |
use Test::More; |
4 |
use Test::More tests => 15; |
5 |
use Test::Warn; |
5 |
use Test::Warn; |
6 |
use MARC::Record; |
6 |
use MARC::Record; |
7 |
|
7 |
|
Lines 11-72
use C4::Context;
Link Here
|
11 |
use C4::Items qw( AddItem ); |
11 |
use C4::Items qw( AddItem ); |
12 |
use C4::Members qw( AddMember GetMember ); |
12 |
use C4::Members qw( AddMember GetMember ); |
13 |
|
13 |
|
|
|
14 |
use t::lib::TestBuilder; |
14 |
use Koha::Borrower::Discharge; |
15 |
use Koha::Borrower::Discharge; |
15 |
|
16 |
|
|
|
17 |
my $builder = t::lib::TestBuilder->new; |
16 |
my $dbh = C4::Context->dbh; |
18 |
my $dbh = C4::Context->dbh; |
17 |
$dbh->{AutoCommit} = 0; |
|
|
18 |
$dbh->{RaiseError} = 1; |
19 |
|
20 |
$dbh->do(q|DELETE FROM discharges|); |
19 |
$dbh->do(q|DELETE FROM discharges|); |
21 |
|
20 |
|
22 |
C4::Context->_new_userenv('xxx'); |
21 |
C4::Context->_new_userenv('xxx'); |
23 |
C4::Context->set_userenv(0, 0, 0, 'firstname', 'surname', 'CPL', 'CPL', '', '', '', '', ''); |
22 |
C4::Context->set_userenv(0, 0, 0, 'firstname', 'surname', 'CPL', 'CPL', '', '', '', '', ''); |
24 |
|
23 |
my $branchcode = 'CPL'; |
25 |
my $borrowernumber = AddMember( |
24 |
my $another_branchcode = 'MPL'; |
26 |
cardnumber => 'UTCARD1', |
25 |
my $borrower = $builder->build({ |
27 |
firstname => 'my firstname', |
26 |
source => 'Borrower', |
28 |
surname => 'my surname', |
27 |
value => { |
29 |
categorycode => 'S', |
28 |
branchcode => $branchcode, |
30 |
branchcode => 'CPL', |
29 |
} |
31 |
); |
30 |
}); |
32 |
my $borrower = GetMember( borrowernumber => $borrowernumber ); |
31 |
my $borrower2 = $builder->build({ |
|
|
32 |
source => 'Borrower', |
33 |
value => { |
34 |
branchcode => $branchcode, |
35 |
} |
36 |
}); |
37 |
my $borrower3 = $builder->build({ |
38 |
source => 'Borrower', |
39 |
value => { |
40 |
branchcode => $another_branchcode, |
41 |
} |
42 |
}); |
33 |
|
43 |
|
34 |
# Discharge not possible with issues |
44 |
# Discharge not possible with issues |
35 |
my ( $biblionumber ) = AddBiblio( MARC::Record->new, ''); |
45 |
my ( $biblionumber ) = AddBiblio( MARC::Record->new, ''); |
36 |
my $barcode = 'BARCODE42'; |
46 |
my $barcode = 'BARCODE42'; |
37 |
my ( undef, undef, $itemnumber ) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL', barcode => $barcode }, $biblionumber); |
47 |
my ( undef, undef, $itemnumber ) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL', barcode => $barcode }, $biblionumber); |
38 |
AddIssue( $borrower, $barcode ); |
48 |
AddIssue( $borrower, $barcode ); |
39 |
is( Koha::Borrower::Discharge::can_be_discharged({ borrowernumber => $borrowernumber }), 0, 'A patron with issues cannot be discharged' ); |
49 |
is( Koha::Borrower::Discharge::can_be_discharged({ borrowernumber => $borrower->{borrowernumber} }), 0, 'A patron with issues cannot be discharged' ); |
40 |
|
50 |
|
41 |
is( Koha::Borrower::Discharge::request({ borrowernumber => $borrowernumber }), undef, 'No request done if patron has issues' ); |
51 |
is( Koha::Borrower::Discharge::request({ borrowernumber => $borrower->{borrowernumber} }), undef, 'No request done if patron has issues' ); |
42 |
is( Koha::Borrower::Discharge::discharge({ borrowernumber => $borrowernumber }), undef, 'No discharge done if patron has issues' ); |
52 |
is( Koha::Borrower::Discharge::discharge({ borrowernumber => $borrower->{borrowernumber} }), undef, 'No discharge done if patron has issues' ); |
43 |
is_deeply( Koha::Borrower::Discharge::get_pendings(), [], 'There is no pending discharge request' ); |
53 |
is_deeply( Koha::Borrower::Discharge::get_pendings(), [], 'There is no pending discharge request' ); |
|
|
54 |
is_deeply( Koha::Borrower::Discharge::get_validated(), [], 'There is no validated discharge' ); |
44 |
|
55 |
|
45 |
AddReturn( $barcode ); |
56 |
AddReturn( $barcode ); |
46 |
|
57 |
|
47 |
# Discharge possible without issue |
58 |
# Discharge possible without issue |
48 |
is( Koha::Borrower::Discharge::can_be_discharged({ borrowernumber => $borrowernumber }), 1, 'A patron without issues can be discharged' ); |
59 |
is( Koha::Borrower::Discharge::can_be_discharged({ borrowernumber => $borrower->{borrowernumber} }), 1, 'A patron without issues can be discharged' ); |
49 |
|
60 |
|
50 |
is(Koha::Borrower::Discharge::generate_as_pdf,undef,"Confirm failure when lacking borrower number"); |
61 |
is(Koha::Borrower::Discharge::generate_as_pdf,undef,"Confirm failure when lacking borrower number"); |
51 |
|
62 |
|
52 |
# Verify that the user is not discharged anymore if the restriction has been lifted |
63 |
# Verify that the user is not discharged anymore if the restriction has been lifted |
53 |
Koha::Borrower::Discharge::discharge({ borrowernumber => $borrowernumber }); |
64 |
Koha::Borrower::Discharge::discharge( { borrowernumber => $borrower->{borrowernumber} } ); |
54 |
is( Koha::Borrower::Discharge::is_discharged({ borrowernumber => $borrowernumber }), 1, 'The patron has been discharged' ); |
65 |
Koha::Borrower::Discharge::discharge( { borrowernumber => $borrower2->{borrowernumber} } ); |
55 |
is(Koha::Borrower::Debarments::IsDebarred($borrowernumber), '9999-12-31', 'The patron has been debarred after discharge'); |
66 |
Koha::Borrower::Discharge::discharge( { borrowernumber => $borrower3->{borrowernumber} } ); |
56 |
Koha::Borrower::Debarments::DelUniqueDebarment({'borrowernumber' => $borrowernumber, 'type' => 'DISCHARGE'}); |
67 |
is( Koha::Borrower::Discharge::is_discharged( { borrowernumber => $borrower->{borrowernumber} } ), 1, 'The patron has been discharged' ); |
57 |
ok(! Koha::Borrower::Debarments::IsDebarred($borrowernumber), 'The debarment has been lifted'); |
68 |
is( Koha::Borrower::Debarments::IsDebarred( $borrower->{borrowernumber} ), '9999-12-31', 'The patron has been debarred after discharge' ); |
58 |
ok(! Koha::Borrower::Discharge::is_discharged({ borrowernumber => $borrowernumber }), 'The patron is not discharged after the restriction has been lifted' ); |
69 |
is( scalar( @{ Koha::Borrower::Discharge::get_validated() } ), 3, 'There are 3 validated discharges' ); |
|
|
70 |
is( scalar( @{ Koha::Borrower::Discharge::get_validated( { borrowernumber => $borrower->{borrowernumber} } ) } ), 1, 'There is 1 validated discharge for a given patron' ); |
71 |
is( scalar( @{ Koha::Borrower::Discharge::get_validated( { branchcode => 'CPL' } ) } ), 2, 'There is 2 validated discharge for a given branchcode' ); # This is not used in the code yet |
72 |
Koha::Borrower::Debarments::DelUniqueDebarment( { 'borrowernumber' => $borrower->{borrowernumber}, 'type' => 'DISCHARGE' } ); |
73 |
ok( !Koha::Borrower::Debarments::IsDebarred( $borrower->{borrowernumber} ), 'The debarment has been lifted' ); |
74 |
ok( !Koha::Borrower::Discharge::is_discharged( { borrowernumber => $borrower->{borrowernumber} } ), 'The patron is not discharged after the restriction has been lifted' ); |
59 |
|
75 |
|
60 |
# Check if PDF::FromHTML is installed. |
76 |
# Check if PDF::FromHTML is installed. |
61 |
my $check = eval { require PDF::FromHTML; }; |
77 |
my $check = eval { require PDF::FromHTML; }; |
62 |
|
78 |
|
63 |
# Tests for if PDF::FromHTML is installed |
79 |
# Tests for if PDF::FromHTML is installed |
64 |
if ($check) { |
80 |
if ($check) { |
65 |
isnt( Koha::Borrower::Discharge::generate_as_pdf({ borrowernumber => $borrowernumber }), undef, "Temporary PDF generated." ); |
81 |
isnt( Koha::Borrower::Discharge::generate_as_pdf({ borrowernumber => $borrower->{borrowernumber} }), undef, "Temporary PDF generated." ); |
66 |
} |
82 |
} |
67 |
# Tests for if PDF::FromHTML is not installed |
83 |
# Tests for if PDF::FromHTML is not installed |
68 |
else { |
84 |
else { |
69 |
warning_like { Koha::Borrower::Discharge::generate_as_pdf({ borrowernumber => $borrowernumber, testing => 1 }) } |
85 |
warning_like { Koha::Borrower::Discharge::generate_as_pdf({ borrowernumber => $borrower->{borrowernumber}, testing => 1 }) } |
70 |
[ qr/Can't locate PDF\/FromHTML.pm in \@INC/ ], |
86 |
[ qr/Can't locate PDF\/FromHTML.pm in \@INC/ ], |
71 |
"Expected failure because of missing PDF::FromHTML."; |
87 |
"Expected failure because of missing PDF::FromHTML."; |
72 |
} |
88 |
} |
Lines 79-84
else {
Link Here
|
79 |
# Even if we switch off this flag, the connection will be blocked. |
95 |
# Even if we switch off this flag, the connection will be blocked. |
80 |
# The error is: |
96 |
# The error is: |
81 |
# DBIx::Class::ResultSet::create(): DBI Exception: DBD::mysql::st execute failed: Lock wait timeout exceeded; try restarting transaction [for Statement "INSERT INTO discharges ( borrower, needed, validated) VALUES ( ?, ?, ? )" with ParamValues: 0='121', 1='2014-01-08T16:38:29', 2=undef] at /home/koha/src/Koha/DataObject/Discharge.pm line 33 |
97 |
# DBIx::Class::ResultSet::create(): DBI Exception: DBD::mysql::st execute failed: Lock wait timeout exceeded; try restarting transaction [for Statement "INSERT INTO discharges ( borrower, needed, validated) VALUES ( ?, ?, ? )" with ParamValues: 0='121', 1='2014-01-08T16:38:29', 2=undef] at /home/koha/src/Koha/DataObject/Discharge.pm line 33 |
82 |
#is( Koha::Service::Borrower::Discharge::request({ borrowernumber => $borrowernumber }), 1, 'Discharge request sent' ); |
98 |
#is( Koha::Service::Borrower::Discharge::request({ borrowernumber => $borrower->{borrowernumber} }), 1, 'Discharge request sent' ); |
83 |
|
|
|
84 |
done_testing; |
85 |
- |
|
|