Lines 80-103
subtest 'GetDescriptionByKohaField' => sub {
Link Here
|
80 |
my $avc = $builder->build_object( { class => 'Koha::AuthorisedValueCategories' } ); |
80 |
my $avc = $builder->build_object( { class => 'Koha::AuthorisedValueCategories' } ); |
81 |
|
81 |
|
82 |
# Create a framework mapping |
82 |
# Create a framework mapping |
83 |
Koha::MarcSubfieldStructure->new( |
83 |
$builder->build_object( |
84 |
{ tagfield => '988', |
84 |
{ |
85 |
tagsubfield => 'a', |
85 |
class => 'Koha::MarcSubfieldStructures', |
86 |
liblibrarian => 'Dummy field', |
86 |
value => { |
87 |
libopac => 'Dummy field', |
87 |
|
88 |
repeatable => 0, |
88 |
tagfield => '988', |
89 |
mandatory => 0, |
89 |
tagsubfield => 'a', |
90 |
kohafield => 'dummy.field', |
90 |
liblibrarian => 'Dummy field', |
91 |
tab => '9', |
91 |
libopac => 'Dummy field', |
92 |
authorised_value => $avc->category_name, |
92 |
kohafield => 'dummy.field', |
93 |
authtypecode => q{}, |
93 |
authorised_value => $avc->category_name, |
94 |
value_builder => q{}, |
94 |
frameworkcode => q{}, |
95 |
isurl => 0, |
95 |
} |
96 |
hidden => 0, |
|
|
97 |
frameworkcode => q{}, |
98 |
seealso => q{}, |
99 |
link => q{}, |
100 |
defaultvalue => undef |
101 |
} |
96 |
} |
102 |
)->store; |
97 |
)->store; |
103 |
|
98 |
|
Lines 107-147
subtest 'GetDescriptionByKohaField' => sub {
Link Here
|
107 |
{ class => 'Koha::AuthorisedValues', |
102 |
{ class => 'Koha::AuthorisedValues', |
108 |
value => { category => $avc->category_name, lib_opac => 'lib_opac', lib => 'lib' } |
103 |
value => { category => $avc->category_name, lib_opac => 'lib_opac', lib => 'lib' } |
109 |
} |
104 |
} |
110 |
); |
105 |
)->store; |
111 |
my $av_2 = $builder->build_object( |
106 |
my $av_2 = $builder->build_object( |
112 |
{ class => 'Koha::AuthorisedValues', |
107 |
{ class => 'Koha::AuthorisedValues', |
113 |
value => { category => $avc->category_name, lib_opac => undef, lib => 'lib' } |
108 |
value => { category => $avc->category_name, lib_opac => undef, lib => 'lib' } |
114 |
} |
109 |
} |
115 |
); |
110 |
)->store; |
116 |
my $av_3 = $builder->build_object( |
111 |
my $av_3 = $builder->build_object( |
117 |
{ class => 'Koha::AuthorisedValues', |
112 |
{ class => 'Koha::AuthorisedValues', |
118 |
value => { category => $avc->category_name, lib_opac => undef, lib => undef } |
113 |
value => { category => $avc->category_name, lib_opac => undef, lib => undef } |
119 |
} |
114 |
} |
120 |
); |
115 |
)->store; |
121 |
my $non_existent_av = $av_3->authorised_value; |
116 |
|
122 |
$av_3->delete; |
117 |
my $non_existent_av = $builder->build_object( |
|
|
118 |
{ |
119 |
class => 'Koha::AuthorisedValues', |
120 |
value => { category => $avc->category_name, } |
121 |
} |
122 |
)->store->delete; |
123 |
|
123 |
|
|
|
124 |
# Opac display |
124 |
my $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( |
125 |
my $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( |
125 |
{ opac => 1, kohafield => 'dummy.field', authorised_value => $av_1->authorised_value } ); |
126 |
{ opac => 1, kohafield => 'dummy.field', authorised_value => $av_1->authorised_value } ); |
126 |
is( $av, 'lib_opac', 'We requested OPAC description.' ); |
127 |
is( $av, 'lib_opac', 'The OPAC description should be displayed if exists' ); |
127 |
$av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( |
128 |
$av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( |
128 |
{ opac => 1, kohafield => 'dummy.field', authorised_value => $av_2->authorised_value } ); |
129 |
{ opac => 1, kohafield => 'dummy.field', authorised_value => $av_2->authorised_value } ); |
129 |
is( $av, 'lib', 'We requested OPAC description, return a regular description.' ); |
130 |
is( $av, 'lib', 'The staff description should be displayed if none exists for OPAC' ); |
130 |
$av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( |
131 |
$av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( |
131 |
{ opac => 1, kohafield => 'dummy.field', authorised_value => $av_3->authorised_value } ); |
132 |
{ opac => 1, kohafield => 'dummy.field', authorised_value => $av_3->authorised_value } ); |
132 |
is( $av, $av_3->authorised_value, 'We requested OPAC or regular description, return the authorised_value.' ); |
133 |
is( $av, $av_3->authorised_value, 'If both OPAC and staff descriptions are missing, the code should be displayed'); |
133 |
$av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( |
134 |
$av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( |
134 |
{ opac => 1, kohafield => 'dummy.field', authorised_value => $non_existent_av } ); |
135 |
{ opac => 1, kohafield => 'dummy.field', authorised_value => $non_existent_av } ); |
135 |
is( $av, $av_3->authorised_value, 'We requested a non existing authorised_value for the OPAC, return the authorised_value.' ); |
136 |
is( $av, $non_existent_av, 'If both OPAC and staff descriptions are missing, the parameter should be displayed'); |
|
|
137 |
|
138 |
# Staff display |
136 |
$av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( |
139 |
$av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( |
137 |
{ kohafield => 'dummy.field', authorised_value => $av_1->authorised_value } ); |
140 |
{ kohafield => 'dummy.field', authorised_value => $av_1->authorised_value } ); |
138 |
is( $av, 'lib', 'We requested a regular description.' ); |
141 |
is( $av, 'lib', 'The staff description should be displayed' ); |
139 |
$av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( |
142 |
$av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( |
140 |
{ kohafield => 'dummy.field', authorised_value => $av_3->authorised_value } ); |
143 |
{ kohafield => 'dummy.field', authorised_value => $av_3->authorised_value } ); |
141 |
is( $av, $av_3->authorised_value, 'We requested a regular description, return the authorised_value.' ); |
144 |
is( $av, $av_3->authorised_value, 'If both OPAC and staff descriptions are missing, the code should be displayed'); |
142 |
$av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( |
145 |
$av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( |
143 |
{ kohafield => 'dummy.field', authorised_value => $non_existent_av } ); |
146 |
{ kohafield => 'dummy.field', authorised_value => $non_existent_av } ); |
144 |
is( $av, $av_3->authorised_value, 'We requested a non existing authorised_value, return the authorised_value.' ); |
147 |
is( $av, $non_existent_av, 'If both OPAC and staff descriptions are missing, the parameter should be displayed'); |
145 |
|
148 |
|
146 |
$schema->storage->txn_rollback; |
149 |
$schema->storage->txn_rollback; |
147 |
}; |
150 |
}; |
148 |
- |
|
|