|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Koha is free software; you can redistribute it and/or modify it under the |
| 6 |
# terms of the GNU General Public License as published by the Free Software |
| 7 |
# Foundation; either version 3 of the License, or (at your option) any later |
| 8 |
# version. |
| 9 |
# |
| 10 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
| 11 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
| 12 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License along |
| 15 |
# with Koha; if not, see <http://www.gnu.org/licenses>. |
| 16 |
|
| 17 |
use Modern::Perl; |
| 18 |
|
| 19 |
use Test::More tests => 8; |
| 20 |
|
| 21 |
use C4::Context; |
| 22 |
use C4::Circulation qw(AddIssue); |
| 23 |
use Koha::Database; |
| 24 |
use Koha::CirculationRules; |
| 25 |
|
| 26 |
use t::lib::TestBuilder; |
| 27 |
use t::lib::Mocks; |
| 28 |
|
| 29 |
BEGIN { |
| 30 |
use_ok('Koha::Template::Plugin::CirculationRules'); |
| 31 |
} |
| 32 |
|
| 33 |
my $schema = Koha::Database->schema; |
| 34 |
my $builder = t::lib::TestBuilder->new; |
| 35 |
|
| 36 |
$schema->storage->txn_begin; |
| 37 |
my $dbh = C4::Context->dbh; |
| 38 |
|
| 39 |
$dbh->do('DELETE FROM circulation_rules'); |
| 40 |
Koha::CirculationRules->set_rules( |
| 41 |
{ |
| 42 |
categorycode => undef, |
| 43 |
branchcode => undef, |
| 44 |
itemtype => undef, |
| 45 |
rules => { |
| 46 |
reservesallowed => 25, |
| 47 |
issuelength => 14, |
| 48 |
lengthunit => 'days', |
| 49 |
renewalsallowed => 1, |
| 50 |
renewalperiod => 7, |
| 51 |
norenewalbefore => undef, |
| 52 |
auto_renew => 0, |
| 53 |
fine => .10, |
| 54 |
chargeperiod => 1, |
| 55 |
renewalsallowed => 111, |
| 56 |
unseen_renewals_allowed => 222, |
| 57 |
} |
| 58 |
} |
| 59 |
); |
| 60 |
|
| 61 |
my $plugin = Koha::Template::Plugin::CirculationRules->new(); |
| 62 |
ok( $plugin, "initialized CirculationRules plugin" ); |
| 63 |
|
| 64 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 65 |
my $biblio = $builder->build_sample_biblio(); |
| 66 |
|
| 67 |
t::lib::Mocks::mock_userenv( { branchcode => $patron->branchcode } ); |
| 68 |
|
| 69 |
# Item at each patron branch |
| 70 |
my $item = $builder->build_sample_item( |
| 71 |
{ |
| 72 |
biblionumber => $biblio->biblionumber, |
| 73 |
homebranch => $patron->branchcode |
| 74 |
} |
| 75 |
); |
| 76 |
|
| 77 |
my $issue = AddIssue( $patron->unblessed, $item->barcode ); |
| 78 |
|
| 79 |
my $rules = $plugin->Renewals( $patron->id, $item->id ); |
| 80 |
|
| 81 |
is( $rules->{unseen_allowed}, 222, "Unseen allowed is correct" ); |
| 82 |
is( $rules->{remaining}, 111, "Remaining is correct" ); |
| 83 |
is( $rules->{unseen_count}, 0, "Unseen count is correct" ); |
| 84 |
is( $rules->{unseen_remaining}, 222, "Unseen remaining is correct" ); |
| 85 |
is( $rules->{count}, 0, "Count renewals is correct" ); |
| 86 |
is( $rules->{allowed}, 111, "Allowed is correct" ); |
| 87 |
|
| 88 |
$schema->storage->txn_rollback; |
| 89 |
|
| 90 |
1; |