Lines 16-36
Link Here
|
16 |
|
16 |
|
17 |
use Modern::Perl; |
17 |
use Modern::Perl; |
18 |
|
18 |
|
19 |
use Test::More tests => 1; |
19 |
use Test::More tests => 2; |
20 |
|
20 |
|
21 |
use C4::Context; |
21 |
use C4::Context; |
|
|
22 |
use Koha::Caches; |
22 |
use Koha::Database; |
23 |
use Koha::Database; |
|
|
24 |
use Koha::MarcSubfieldStructures; |
23 |
use Koha::Template::Plugin::AuthorisedValues; |
25 |
use Koha::Template::Plugin::AuthorisedValues; |
24 |
|
26 |
|
25 |
use t::lib::TestBuilder; |
27 |
use t::lib::TestBuilder; |
26 |
use t::lib::Mocks; |
28 |
use t::lib::Mocks; |
27 |
|
29 |
|
28 |
my $schema = Koha::Database->schema; |
30 |
my $schema = Koha::Database->schema; |
29 |
$schema->storage->txn_begin; |
|
|
30 |
my $builder = t::lib::TestBuilder->new; |
31 |
my $builder = t::lib::TestBuilder->new; |
31 |
|
32 |
|
32 |
subtest 'GetByCode' => sub { |
33 |
subtest 'GetByCode' => sub { |
33 |
plan tests => 4; |
34 |
plan tests => 4; |
|
|
35 |
|
36 |
$schema->storage->txn_begin; |
37 |
|
34 |
my $avc = |
38 |
my $avc = |
35 |
$builder->build_object( { class => 'Koha::AuthorisedValueCategories' } ); |
39 |
$builder->build_object( { class => 'Koha::AuthorisedValueCategories' } ); |
36 |
my $av_1 = $builder->build_object( |
40 |
my $av_1 = $builder->build_object( |
Lines 63-66
subtest 'GetByCode' => sub {
Link Here
|
63 |
Koha::Template::Plugin::AuthorisedValues->GetByCode( $avc->category_name, |
67 |
Koha::Template::Plugin::AuthorisedValues->GetByCode( $avc->category_name, |
64 |
'does_not_exist' ); |
68 |
'does_not_exist' ); |
65 |
is( $description, 'does_not_exist', 'GetByCode should return the code passed if the AV does not exist' ); |
69 |
is( $description, 'does_not_exist', 'GetByCode should return the code passed if the AV does not exist' ); |
|
|
70 |
|
71 |
$schema->storage->txn_rollback; |
72 |
}; |
73 |
|
74 |
subtest 'GetDescriptionByKohaField' => sub { |
75 |
|
76 |
plan tests => 7; |
77 |
|
78 |
$schema->storage->txn_begin; |
79 |
|
80 |
my $avc = $builder->build_object( { class => 'Koha::AuthorisedValueCategories' } ); |
81 |
|
82 |
# Create a framework mapping |
83 |
Koha::MarcSubfieldStructure->new( |
84 |
{ tagfield => '988', |
85 |
tagsubfield => 'a', |
86 |
liblibrarian => 'Dummy field', |
87 |
libopac => 'Dummy field', |
88 |
repeatable => 0, |
89 |
mandatory => 0, |
90 |
kohafield => 'dummy.field', |
91 |
tab => '9', |
92 |
authorised_value => $avc->category_name, |
93 |
authtypecode => q{}, |
94 |
value_builder => q{}, |
95 |
isurl => 0, |
96 |
hidden => 0, |
97 |
frameworkcode => q{}, |
98 |
seealso => q{}, |
99 |
link => q{}, |
100 |
defaultvalue => undef |
101 |
} |
102 |
)->store; |
103 |
|
104 |
# Make sure we are not catch by cache |
105 |
Koha::Caches->get_instance->flush_all; |
106 |
my $av_1 = $builder->build_object( |
107 |
{ class => 'Koha::AuthorisedValues', |
108 |
value => { category => $avc->category_name, lib_opac => 'lib_opac', lib => 'lib' } |
109 |
} |
110 |
); |
111 |
my $av_2 = $builder->build_object( |
112 |
{ class => 'Koha::AuthorisedValues', |
113 |
value => { category => $avc->category_name, lib_opac => undef, lib => 'lib' } |
114 |
} |
115 |
); |
116 |
my $av_3 = $builder->build_object( |
117 |
{ class => 'Koha::AuthorisedValues', |
118 |
value => { category => $avc->category_name, lib_opac => undef, lib => undef } |
119 |
} |
120 |
); |
121 |
my $non_existent_av = $av_3->authorised_value; |
122 |
$av_3->delete; |
123 |
|
124 |
my $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( |
125 |
{ opac => 1, kohafield => 'dummy.field', authorised_value => $av_1->authorised_value } ); |
126 |
is( $av, 'lib_opac', 'We requested an existing AV description for the OPAC' ); |
127 |
$av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( |
128 |
{ opac => 1, kohafield => 'dummy.field', authorised_value => $av_2->authorised_value } ); |
129 |
is( $av, 'lib', 'We requested an OPAC AV description for the OPAC, return a regular description' ); |
130 |
$av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( |
131 |
{ opac => 1, kohafield => 'dummy.field', authorised_value => $av_3->authorised_value } ); |
132 |
is( $av, $av_3->authorised_value, 'We requested an non-existing OPAC AV description for the OPAC, return the authorised_value.' ); |
133 |
$av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( |
134 |
{ opac => 1, kohafield => 'dummy.field', authorised_value => $non_existent_av } ); |
135 |
is( $av, '', 'We requested a non existing AV description for the OPAC, return empty string' ); |
136 |
$av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( |
137 |
{ kohafield => 'dummy.field', authorised_value => $av_1->authorised_value } ); |
138 |
is( $av, 'lib', 'We requested an existing AV regular description.' ); |
139 |
$av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( |
140 |
{ kohafield => 'dummy.field', authorised_value => $av_3->authorised_value } ); |
141 |
is( $av, $av_3->authorised_value, 'We requested an non-existing AV regular description, return the authorised_value.' ); |
142 |
$av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( |
143 |
{ kohafield => 'dummy.field', authorised_value => $non_existent_av } ); |
144 |
is( $av, '', |
145 |
'We requested a non existing AV description, not for the OPAC, return empty string' ); |
146 |
|
147 |
$schema->storage->txn_rollback; |
66 |
}; |
148 |
}; |
67 |
- |
|
|