|
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 => 2; |
| 20 |
use Test::MockModule; |
| 21 |
|
| 22 |
use Koha::CirculationRules; |
| 23 |
|
| 24 |
use t::lib::TestBuilder; |
| 25 |
use t::lib::Mocks; |
| 26 |
|
| 27 |
BEGIN { |
| 28 |
use_ok('Koha::Template::Plugin::CirculationRules'); |
| 29 |
} |
| 30 |
|
| 31 |
my $schema = Koha::Database->schema; |
| 32 |
my $builder = t::lib::TestBuilder->new; |
| 33 |
|
| 34 |
subtest 'Basic function tests' => sub { |
| 35 |
|
| 36 |
plan tests => 10; |
| 37 |
|
| 38 |
$schema->storage->txn_begin; |
| 39 |
|
| 40 |
my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); |
| 41 |
my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); |
| 42 |
|
| 43 |
my $plugin = Koha::Template::Plugin::CirculationRules->new(); |
| 44 |
ok($plugin, "initialized CirculationRules plugin"); |
| 45 |
|
| 46 |
my $rule_value = $plugin->Get($library_1->branchcode,'*','*','maxholds'); |
| 47 |
is($rule_value, undef, 'Max holds not set, Get returns undef'); |
| 48 |
|
| 49 |
$rule_value = $plugin->Search($library_1->branchcode,'*','*','maxholds'); |
| 50 |
is($rule_value, undef, 'Max holds not set, Search returns undef'); |
| 51 |
|
| 52 |
my $rule = $plugin->Search($library_1->branchcode,'*','*','maxholds', { want_rule => 1 } ); |
| 53 |
is($rule, undef, 'Max holds not set, Search with want_rule returns undef'); |
| 54 |
|
| 55 |
Koha::CirculationRules->set_rule( |
| 56 |
{ |
| 57 |
branchcode => '*', |
| 58 |
categorycode => '*', |
| 59 |
rule_name => 'max_holds', |
| 60 |
rule_value => 5, |
| 61 |
} |
| 62 |
); |
| 63 |
|
| 64 |
Koha::CirculationRules->set_rule( |
| 65 |
{ |
| 66 |
branchcode => $library_1->branchcode, |
| 67 |
categorycode => '*', |
| 68 |
rule_name => 'max_holds', |
| 69 |
rule_value => "", |
| 70 |
} |
| 71 |
); |
| 72 |
|
| 73 |
$rule_value = $plugin->Get($library_1->branchcode,'*','*','max_holds'); |
| 74 |
is($rule_value, "", 'Max holds set to blank string (unlimited), Get returns blank string for branch'); |
| 75 |
|
| 76 |
$rule = $plugin->Search($library_1->branchcode,'*','*','max_holds', { want_rule => 1 } ); |
| 77 |
is(ref $rule, "Koha::CirculationRule" , 'Max holds set to blank string, Search with want_rule returns a circulation rules object'); |
| 78 |
is( $rule->rule_value, "",'Max holds set to blank string (unlimited), returned rule has correct value'); |
| 79 |
|
| 80 |
$rule_value = $plugin->Get($library_2->branchcode,'*','*','max_holds'); |
| 81 |
is($rule_value, 5, 'Max holds default set to 5, Get returns 5 for branch with no rule set'); |
| 82 |
|
| 83 |
$rule_value = $plugin->Search('*','*','*','max_holds'); |
| 84 |
is($rule_value, 5, 'Search for all libraries max holds rule, Search returns 5'); |
| 85 |
|
| 86 |
$rule_value = $plugin->Search($library_1->branchcode,'*','*','max_holds'); |
| 87 |
is($rule_value, "", 'Max holds set to blank string (unlimited), Get returns blank string for branch'); |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
$schema->storage->txn_rollback; |
| 92 |
}; |