|
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 => 1; |
| 20 |
|
| 21 |
use C4::Context; |
| 22 |
use Koha::Database; |
| 23 |
use Koha::Template::Plugin::AuthorisedValues; |
| 24 |
|
| 25 |
use t::lib::TestBuilder; |
| 26 |
use t::lib::Mocks; |
| 27 |
|
| 28 |
my $schema = Koha::Database->schema; |
| 29 |
$schema->storage->txn_begin; |
| 30 |
my $builder = t::lib::TestBuilder->new; |
| 31 |
|
| 32 |
subtest 'GetByCode' => sub { |
| 33 |
plan tests => 4; |
| 34 |
my $avc = |
| 35 |
$builder->build( { source => 'AuthorisedValueCategory' } ); |
| 36 |
my $av_1 = $builder->build( |
| 37 |
{ |
| 38 |
source => 'AuthorisedValue', |
| 39 |
value => { category => $avc->{category_name} } |
| 40 |
} |
| 41 |
); |
| 42 |
my $av_2 = $builder->build( |
| 43 |
{ |
| 44 |
class => 'AuthorisedValue', |
| 45 |
value => { category => $avc->{category_name} } |
| 46 |
} |
| 47 |
); |
| 48 |
my $av_3 = $builder->build( |
| 49 |
{ |
| 50 |
class => 'AuthorisedValue', |
| 51 |
value => { category => $avc->{category_name}, lib_opc => undef } |
| 52 |
} |
| 53 |
); |
| 54 |
my $description = |
| 55 |
Koha::Template::Plugin::AuthorisedValues->GetByCode( $avc->{category_name}, |
| 56 |
$av_1->{authorised_value} ); |
| 57 |
is( $description, $av_1->{lib}, 'GetByCode should return the correct dsecription' ); |
| 58 |
my $opac_description = |
| 59 |
Koha::Template::Plugin::AuthorisedValues->GetByCode( $avc->{category_name}, |
| 60 |
$av_1->{authorised_value}, 'opac' ); |
| 61 |
is( $opac_description, $av_1->{lib_opac}, 'GetByCode should return the correct opac_description' ); |
| 62 |
$opac_description = |
| 63 |
Koha::Template::Plugin::AuthorisedValues->GetByCode( $avc->{category_name}, |
| 64 |
$av_3->{authorised_value}, 'opac' ); |
| 65 |
is( $opac_description, $av_3->{lib}, 'GetByCode should return the staff description if the lib_opac is not filled' ); |
| 66 |
|
| 67 |
$description = |
| 68 |
Koha::Template::Plugin::AuthorisedValues->GetByCode( $avc->{category_name}, |
| 69 |
'does_not_exist' ); |
| 70 |
is( $description, 'does_not_exist', 'GetByCode should return the code passed if the AV does not exist' ); |
| 71 |
}; |