|
Lines 193-226
subtest 'can_be_transferred' => sub {
Link Here
|
| 193 |
}; |
193 |
}; |
| 194 |
|
194 |
|
| 195 |
subtest 'custom_cover_image_url' => sub { |
195 |
subtest 'custom_cover_image_url' => sub { |
| 196 |
plan tests => 6; |
196 |
plan tests => 10; |
| 197 |
|
197 |
|
| 198 |
t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{isbn}_{issn}.png' ); |
198 |
t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{isbn}_{issn}.png' ); |
| 199 |
|
199 |
|
| 200 |
my $isbn = '0553573403 | 9780553573404 (pbk.).png'; |
200 |
my $isbn = '0553573403 | 9780553573404 (pbk.).png'; |
|
|
201 |
my $normalized_isbn = C4::Koha::GetNormalizedISBN($isbn); |
| 201 |
my $issn = 'my_issn'; |
202 |
my $issn = 'my_issn'; |
| 202 |
my $cf_value = 'from_control_field'; |
203 |
my $cf_value = 'from_control_field'; |
| 203 |
my $marc_record = MARC::Record->new; |
204 |
my $marc_record = MARC::Record->new; |
| 204 |
my ( $biblionumber, undef ) = C4::Biblio::AddBiblio($marc_record, ''); |
205 |
my ( $biblionumber, undef ) = C4::Biblio::AddBiblio($marc_record, ''); |
| 205 |
|
206 |
|
|
|
207 |
my $custom_cover_image_url; |
| 208 |
|
| 206 |
my $biblio = Koha::Biblios->find( $biblionumber ); |
209 |
my $biblio = Koha::Biblios->find( $biblionumber ); |
| 207 |
my $biblioitem = $biblio->biblioitem->set( |
210 |
my $biblioitem = $biblio->biblioitem->set( |
| 208 |
{ isbn => $isbn, issn => $issn }); |
211 |
{ isbn => $isbn, issn => $issn }); |
| 209 |
is( $biblio->custom_cover_image_url, "https://my_url/${isbn}_${issn}.png" ); |
212 |
is( $biblio->custom_cover_image_url, "https://my_url/${isbn}_${issn}.png", "URL is correctly generated for isbn and issbn when called as object" ); |
|
|
213 |
$custom_cover_image_url = Koha::Biblio->custom_cover_image_url({ |
| 214 |
isbn => $isbn, |
| 215 |
issn => $issn, |
| 216 |
record => $marc_record, |
| 217 |
normalized_isbn => $normalized_isbn |
| 218 |
}); |
| 219 |
is( $custom_cover_image_url, "https://my_url/${isbn}_${issn}.png", "URL is correctly generated for isbn and issn when values passed as parameters" ); |
| 220 |
|
| 210 |
|
221 |
|
| 211 |
my $marc_024a = '710347104926'; |
222 |
my $marc_024a = '710347104926'; |
| 212 |
$marc_record->append_fields( MARC::Field->new( '024', '', '', a => $marc_024a ) ); |
223 |
$marc_record->append_fields( MARC::Field->new( '024', '', '', a => $marc_024a ) ); |
| 213 |
C4::Biblio::ModBiblio( $marc_record, $biblio->biblionumber ); |
224 |
C4::Biblio::ModBiblio( $marc_record, $biblio->biblionumber ); |
| 214 |
|
225 |
|
| 215 |
t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{024$a}.png' ); |
226 |
t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{024$a}.png' ); |
| 216 |
is( $biblio->custom_cover_image_url, "https://my_url/$marc_024a.png" ); |
227 |
is( $biblio->custom_cover_image_url, "https://my_url/$marc_024a.png", "URL is correctly generated using a custom field when called as object method" ); |
|
|
228 |
$custom_cover_image_url = Koha::Biblio->custom_cover_image_url({ |
| 229 |
isbn => $isbn, |
| 230 |
issn => $issn, |
| 231 |
record => $marc_record, |
| 232 |
normalized_isbn => $normalized_isbn |
| 233 |
}); |
| 234 |
is( $custom_cover_image_url, "https://my_url/$marc_024a.png", "URL is correctly generated using a custom fieldwhen parameters passed" ); |
| 217 |
|
235 |
|
| 218 |
t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{normalized_isbn}.png' ); |
236 |
t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{normalized_isbn}.png' ); |
| 219 |
my $normalized_isbn = C4::Koha::GetNormalizedISBN($isbn); |
237 |
is( $biblio->custom_cover_image_url, "https://my_url/$normalized_isbn.png", "URL correctly generated using normalized ISBN when called as object method" ); |
| 220 |
is( $biblio->custom_cover_image_url, "https://my_url/$normalized_isbn.png" ); |
238 |
$custom_cover_image_url = Koha::Biblio->custom_cover_image_url({ |
|
|
239 |
isbn => $isbn, |
| 240 |
issn => $issn, |
| 241 |
record => $marc_record, |
| 242 |
normalized_isbn => $normalized_isbn |
| 243 |
}); |
| 244 |
is( $custom_cover_image_url, "https://my_url/$normalized_isbn.png", "URL correctly generated using normalized ISBN when passed parameters" ); |
| 221 |
|
245 |
|
| 222 |
$biblio->biblioitem->isbn('')->store; |
246 |
$biblio->biblioitem->isbn('')->store; |
| 223 |
is( $biblio->custom_cover_image_url, undef, "Don't generate the url if the biblio does not have the value needed to generate it" ); |
247 |
is( $biblio->custom_cover_image_url, undef, "Don't generate the url if the biblio does not have the value needed to generate it" ); |
|
|
248 |
$custom_cover_image_url = Koha::Biblio->custom_cover_image_url({ |
| 249 |
isbn => $isbn, |
| 250 |
issn => $issn, |
| 251 |
record => $marc_record, |
| 252 |
normalized_isbn => '' |
| 253 |
}); |
| 254 |
is( $custom_cover_image_url, undef, "Don't generate the url if the value needed to generate it is not passed" ); |
| 224 |
|
255 |
|
| 225 |
t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{001}.png' ); |
256 |
t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{001}.png' ); |
| 226 |
is( $biblio->custom_cover_image_url, undef, 'Record does not have 001' ); |
257 |
is( $biblio->custom_cover_image_url, undef, 'Record does not have 001' ); |
| 227 |
- |
|
|