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