|
Lines 15-21
Link Here
|
| 15 |
# with Koha; if not, see <http://www.gnu.org/licenses>. |
15 |
# with Koha; if not, see <http://www.gnu.org/licenses>. |
| 16 |
|
16 |
|
| 17 |
use Modern::Perl; |
17 |
use Modern::Perl; |
| 18 |
use Test::More tests => 18; |
18 |
use Test::More tests => 19; |
| 19 |
use Test::Warn; |
19 |
use Test::Warn; |
| 20 |
use MARC::Record; |
20 |
use MARC::Record; |
| 21 |
|
21 |
|
|
Lines 43-55
my $another_library = $builder->build({ source => 'Branch' });
Link Here
|
| 43 |
my $itemtype = $builder->build({ source => 'Itemtype' })->{itemtype}; |
43 |
my $itemtype = $builder->build({ source => 'Itemtype' })->{itemtype}; |
| 44 |
|
44 |
|
| 45 |
C4::Context->_new_userenv('xxx'); |
45 |
C4::Context->_new_userenv('xxx'); |
| 46 |
C4::Context->set_userenv(0, 0, 0, 'firstname', 'surname', $library->{branchcode}, $library->{branchcode}, '', '', '', ''); |
|
|
| 47 |
my $patron = $builder->build({ |
46 |
my $patron = $builder->build({ |
| 48 |
source => 'Borrower', |
47 |
source => 'Borrower', |
| 49 |
value => { |
48 |
value => { |
| 50 |
branchcode => $library->{branchcode}, |
49 |
branchcode => $library->{branchcode}, |
|
|
50 |
flags => 1, # superlibrarian |
| 51 |
} |
51 |
} |
| 52 |
}); |
52 |
}); |
|
|
53 |
my $p = Koha::Patrons->find( $patron->{borrowernumber} ); |
| 54 |
set_logged_in_user( $p ); |
| 55 |
|
| 53 |
my $patron2 = $builder->build({ |
56 |
my $patron2 = $builder->build({ |
| 54 |
source => 'Borrower', |
57 |
source => 'Borrower', |
| 55 |
value => { |
58 |
value => { |
|
Lines 60-67
my $patron3 = $builder->build({
Link Here
|
| 60 |
source => 'Borrower', |
63 |
source => 'Borrower', |
| 61 |
value => { |
64 |
value => { |
| 62 |
branchcode => $another_library->{branchcode}, |
65 |
branchcode => $another_library->{branchcode}, |
|
|
66 |
flags => undef, |
| 63 |
} |
67 |
} |
| 64 |
}); |
68 |
}); |
|
|
69 |
my $p3 = Koha::Patrons->find( $patron3->{borrowernumber} ); |
| 65 |
|
70 |
|
| 66 |
# Discharge not possible with issues |
71 |
# Discharge not possible with issues |
| 67 |
my ( $biblionumber ) = AddBiblio( MARC::Record->new, ''); |
72 |
my ( $biblionumber ) = AddBiblio( MARC::Record->new, ''); |
|
Lines 80-87
is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->{bor
Link Here
|
| 80 |
|
85 |
|
| 81 |
is( Koha::Patron::Discharge::request({ borrowernumber => $patron->{borrowernumber} }), undef, 'No request done if patron has issues' ); |
86 |
is( Koha::Patron::Discharge::request({ borrowernumber => $patron->{borrowernumber} }), undef, 'No request done if patron has issues' ); |
| 82 |
is( Koha::Patron::Discharge::discharge({ borrowernumber => $patron->{borrowernumber} }), undef, 'No discharge done if patron has issues' ); |
87 |
is( Koha::Patron::Discharge::discharge({ borrowernumber => $patron->{borrowernumber} }), undef, 'No discharge done if patron has issues' ); |
| 83 |
is_deeply( Koha::Patron::Discharge::get_pendings(), [], 'There is no pending discharge request' ); |
88 |
is_deeply( [ Koha::Patron::Discharge::get_pendings ], [], 'There is no pending discharge request' ); |
| 84 |
is_deeply( Koha::Patron::Discharge::get_validated(), [], 'There is no validated discharge' ); |
89 |
is_deeply( [ Koha::Patron::Discharge::get_validated ], [], 'There is no validated discharge' ); |
| 85 |
|
90 |
|
| 86 |
AddReturn( $barcode ); |
91 |
AddReturn( $barcode ); |
| 87 |
|
92 |
|
|
Lines 96-113
Koha::Patron::Discharge::discharge( { borrowernumber => $patron2->{borrowernumbe
Link Here
|
| 96 |
Koha::Patron::Discharge::discharge( { borrowernumber => $patron3->{borrowernumber} } ); |
101 |
Koha::Patron::Discharge::discharge( { borrowernumber => $patron3->{borrowernumber} } ); |
| 97 |
is( Koha::Patron::Discharge::is_discharged( { borrowernumber => $patron->{borrowernumber} } ), 1, 'The patron has been discharged' ); |
102 |
is( Koha::Patron::Discharge::is_discharged( { borrowernumber => $patron->{borrowernumber} } ), 1, 'The patron has been discharged' ); |
| 98 |
is( Koha::Patrons->find( $patron->{borrowernumber} )->is_debarred, '9999-12-31', 'The patron has been debarred after discharge' ); |
103 |
is( Koha::Patrons->find( $patron->{borrowernumber} )->is_debarred, '9999-12-31', 'The patron has been debarred after discharge' ); |
| 99 |
is( scalar( @{ Koha::Patron::Discharge::get_validated() } ), 3, 'There are 3 validated discharges' ); |
104 |
is( scalar( Koha::Patron::Discharge::get_validated ), 3, 'There are 3 validated discharges' ); |
| 100 |
is( scalar( @{ Koha::Patron::Discharge::get_validated( { borrowernumber => $patron->{borrowernumber} } ) } ), 1, 'There is 1 validated discharge for a given patron' ); |
105 |
is( scalar( Koha::Patron::Discharge::get_validated( { borrowernumber => $patron->{borrowernumber} } ) ), 1, 'There is 1 validated discharge for a given patron' ); |
| 101 |
is( scalar( @{ Koha::Patron::Discharge::get_validated( { branchcode => $library->{branchcode} } ) } ), 2, 'There is 2 validated discharges for a given branchcode' ); # This is not used in the code yet |
106 |
is( scalar( Koha::Patron::Discharge::get_validated( { branchcode => $library->{branchcode} } ) ), 2, 'There is 2 validated discharges for a given branchcode' ); # This is not used in the code yet |
| 102 |
Koha::Patron::Debarments::DelUniqueDebarment( { 'borrowernumber' => $patron->{borrowernumber}, 'type' => 'DISCHARGE' } ); |
107 |
Koha::Patron::Debarments::DelUniqueDebarment( { 'borrowernumber' => $patron->{borrowernumber}, 'type' => 'DISCHARGE' } ); |
| 103 |
ok( !Koha::Patrons->find( $patron->{borrowernumber} )->is_debarred, 'The debarment has been lifted' ); |
108 |
ok( !Koha::Patrons->find( $patron->{borrowernumber} )->is_debarred, 'The debarment has been lifted' ); |
| 104 |
ok( !Koha::Patron::Discharge::is_discharged( { borrowernumber => $patron->{borrowernumber} } ), 'The patron is not discharged after the restriction has been lifted' ); |
109 |
ok( !Koha::Patron::Discharge::is_discharged( { borrowernumber => $patron->{borrowernumber} } ), 'The patron is not discharged after the restriction has been lifted' ); |
| 105 |
|
110 |
|
| 106 |
# Verify that the discharge works multiple times |
111 |
# Verify that the discharge works multiple times |
| 107 |
Koha::Patron::Discharge::request({ borrowernumber => $patron->{borrowernumber} }); |
112 |
Koha::Patron::Discharge::request({ borrowernumber => $patron->{borrowernumber} }); |
| 108 |
is(scalar( @{ Koha::Patron::Discharge::get_pendings() }), 1, 'There is a pending discharge request (second time)'); |
113 |
is(scalar( Koha::Patron::Discharge::get_pendings ), 1, 'There is a pending discharge request (second time)'); |
| 109 |
Koha::Patron::Discharge::discharge( { borrowernumber => $patron->{borrowernumber} } ); |
114 |
Koha::Patron::Discharge::discharge( { borrowernumber => $patron->{borrowernumber} } ); |
| 110 |
is_deeply( Koha::Patron::Discharge::get_pendings(), [], 'There is no pending discharge request (second time)'); |
115 |
is_deeply( [ Koha::Patron::Discharge::get_pendings ], [], 'There is no pending discharge request (second time)'); |
| 111 |
|
116 |
|
| 112 |
# Check if PDF::FromHTML is installed. |
117 |
# Check if PDF::FromHTML is installed. |
| 113 |
my $check = eval { require PDF::FromHTML; }; |
118 |
my $check = eval { require PDF::FromHTML; }; |
|
Lines 126-131
else {
Link Here
|
| 126 |
# FIXME Should be a Koha::Object object |
131 |
# FIXME Should be a Koha::Object object |
| 127 |
is( ref(Koha::Patron::Discharge::request({ borrowernumber => $patron->{borrowernumber} })), 'Koha::Schema::Result::Discharge', 'Discharge request sent' ); |
132 |
is( ref(Koha::Patron::Discharge::request({ borrowernumber => $patron->{borrowernumber} })), 'Koha::Schema::Result::Discharge', 'Discharge request sent' ); |
| 128 |
|
133 |
|
|
|
134 |
subtest 'search_limited' => sub { |
| 135 |
plan tests => 4; |
| 136 |
$dbh->do(q|DELETE FROM discharges|); |
| 137 |
my $group_1 = Koha::Library::Group->new( { title => 'TEST Group 1' } )->store; |
| 138 |
my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2' } )->store; |
| 139 |
# $patron and $patron2 are from the same library, $patron3 from another one |
| 140 |
# Logged in user is $patron, superlibrarian |
| 141 |
set_logged_in_user( $p ); |
| 142 |
Koha::Library::Group->new({ parent_id => $group_1->id, branchcode => $patron->{branchcode} })->store(); |
| 143 |
Koha::Library::Group->new({ parent_id => $group_2->id, branchcode => $patron3->{branchcode} })->store(); |
| 144 |
Koha::Patron::Discharge::request({ borrowernumber => $patron->{borrowernumber} }); |
| 145 |
Koha::Patron::Discharge::request({ borrowernumber => $patron2->{borrowernumber} }); |
| 146 |
Koha::Patron::Discharge::request({ borrowernumber => $patron3->{borrowernumber} }); |
| 147 |
is( scalar( Koha::Patron::Discharge::get_pendings), 3, 'With permission, all discharges are visible' ); |
| 148 |
is( Koha::Patron::Discharge::count({pending => 1}), 3, 'With permission, all discharges are visible' ); |
| 149 |
|
| 150 |
# With patron 3 logged in, only discharges from his group are visible |
| 151 |
set_logged_in_user( $p3 ); |
| 152 |
is( scalar( Koha::Patron::Discharge::get_pendings), 1, 'Without permission, only discharge from our group are visible' ); |
| 153 |
is( Koha::Patron::Discharge::count({pending => 1}), 1, 'Without permission, only discharge from our group are visible' ); |
| 154 |
}; |
| 155 |
|
| 129 |
$schema->storage->txn_rollback; |
156 |
$schema->storage->txn_rollback; |
| 130 |
|
157 |
|
|
|
158 |
sub set_logged_in_user { |
| 159 |
my ($patron) = @_; |
| 160 |
C4::Context->set_userenv( |
| 161 |
$patron->borrowernumber, $patron->userid, |
| 162 |
$patron->cardnumber, 'firstname', |
| 163 |
'surname', $patron->library->branchcode, |
| 164 |
'Midway Public Library', $patron->flags, |
| 165 |
'', '' |
| 166 |
); |
| 167 |
} |
| 168 |
|
| 131 |
1; |
169 |
1; |
| 132 |
- |
|
|