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_object( { class => 'Koha::AuthorisedValueCategories' } ); |
36 |
my $av_1 = $builder->build_object( |
37 |
{ |
38 |
class => 'Koha::AuthorisedValues', |
39 |
value => { category => $avc->category_name } |
40 |
} |
41 |
); |
42 |
my $av_2 = $builder->build_object( |
43 |
{ |
44 |
class => 'Koha::AuthorisedValues', |
45 |
value => { category => $avc->category_name } |
46 |
} |
47 |
); |
48 |
my $description = |
49 |
Koha::Template::Plugin::AuthorisedValues->GetByCode( $avc->category_name, |
50 |
$av_1->authorised_value ); |
51 |
is( $description, $av_1->lib, 'GetByCode should return the correct dsecription' ); |
52 |
my $opac_description = |
53 |
Koha::Template::Plugin::AuthorisedValues->GetByCode( $avc->category_name, |
54 |
$av_1->authorised_value, 'opac' ); |
55 |
is( $opac_description, $av_1->opac_description, 'GetByCode should return the correct opac_description' ); |
56 |
$av_1->lib_opac(undef)->store; |
57 |
$opac_description = |
58 |
Koha::Template::Plugin::AuthorisedValues->GetByCode( $avc->category_name, |
59 |
$av_1->authorised_value, 'opac' ); |
60 |
is( $opac_description, $av_1->lib, 'GetByCode should return the staff description if the lib_opac is not filled' ); |
61 |
|
62 |
$description = |
63 |
Koha::Template::Plugin::AuthorisedValues->GetByCode( $avc->category_name, |
64 |
'does_not_exist' ); |
65 |
is( $description, 'does_not_exist', 'GetByCode should return the code passed if the AV does not exist' ); |
66 |
}; |