Lines 4-10
Link Here
|
4 |
# It requires a working Koha database with the sample data |
4 |
# It requires a working Koha database with the sample data |
5 |
|
5 |
|
6 |
use Modern::Perl; |
6 |
use Modern::Perl; |
7 |
use Test::More tests => 5; |
7 |
use Test::More tests => 6; |
|
|
8 |
use Test::MockModule; |
8 |
use Test::Warn; |
9 |
use Test::Warn; |
9 |
use Test::Deep; |
10 |
use Test::Deep; |
10 |
|
11 |
|
Lines 14-23
use C4::Context;
Link Here
|
14 |
use Koha::Database; |
15 |
use Koha::Database; |
15 |
use Koha::AuthorisedValue; |
16 |
use Koha::AuthorisedValue; |
16 |
use Koha::AuthorisedValueCategories; |
17 |
use Koha::AuthorisedValueCategories; |
|
|
18 |
use Koha::Libraries; |
17 |
|
19 |
|
18 |
BEGIN { |
20 |
BEGIN { |
19 |
use_ok('C4::Koha', qw( GetAuthorisedValues GetItemTypesCategorized xml_escape )); |
21 |
use_ok( |
20 |
use_ok('C4::Members'); |
22 |
'C4::Koha', |
|
|
23 |
qw( GetAuthorisedValues GetItemTypesCategorized xml_escape GetVariationsOfISBN GetVariationsOfISBNs GetVariationsOfISSN GetVariationsOfISSNs ) |
24 |
); |
21 |
} |
25 |
} |
22 |
|
26 |
|
23 |
my $schema = Koha::Database->new->schema; |
27 |
my $schema = Koha::Database->new->schema; |
Lines 155-186
subtest 'Authorized Values Tests' => sub {
Link Here
|
155 |
|
159 |
|
156 |
}; |
160 |
}; |
157 |
|
161 |
|
158 |
subtest 'ISBN tests' => sub { |
162 |
subtest 'isbn tests' => sub { |
159 |
plan tests => 6; |
163 |
plan tests => 29; |
160 |
|
164 |
|
161 |
my $isbn13 = "9780330356473"; |
165 |
my $isbn13 = "9780330356473"; |
162 |
my $isbn13D = "978-0-330-35647-3"; |
166 |
my $isbn13D = "978-0-330-35647-3"; |
163 |
my $isbn10 = "033035647X"; |
167 |
my $isbn10 = "033035647X"; |
164 |
my $isbn10D = "0-330-35647-X"; |
168 |
my $isbn10D = "0-330-35647-X"; |
165 |
is( xml_escape(undef), '', |
169 |
|
166 |
'xml_escape() returns empty string on undef input' ); |
170 |
my $undef = undef; |
|
|
171 |
is( xml_escape($undef), '', 'xml_escape() returns empty string on undef input' ); |
167 |
my $str = q{'"&<>'}; |
172 |
my $str = q{'"&<>'}; |
|
|
173 |
is( xml_escape($str), ''"&<>'', 'xml_escape() works as expected' ); |
174 |
is( $str, q{'"&<>'}, '... and does not change input in place' ); |
175 |
|
176 |
is( C4::Koha::_isbn_cleanup('0-590-35340-3'), '0590353403', '_isbn_cleanup removes hyphens' ); |
177 |
is( C4::Koha::_isbn_cleanup('0590353403 (pbk.)'), '0590353403', '_isbn_cleanup removes parenthetical' ); |
178 |
is( C4::Koha::_isbn_cleanup('978-0-321-49694-2'), '0321496949', '_isbn_cleanup converts ISBN-13 to ISBN-10' ); |
179 |
|
180 |
is( |
181 |
C4::Koha::NormalizeISBN( { isbn => '978-0-321-49694-2 (pbk.)', format => 'ISBN-10', strip_hyphens => 1 } ), |
182 |
'0321496949', 'Test NormalizeISBN with all features enabled' |
183 |
); |
184 |
|
185 |
my @isbns = qw/ 978-0-321-49694-2 0-321-49694-9 978-0-321-49694-2 0321496949 9780321496942/; |
186 |
is( |
187 |
join( '|', @isbns ), join( '|', GetVariationsOfISBN('978-0-321-49694-2 (pbk.)') ), |
188 |
'GetVariationsOfISBN returns all variations' |
189 |
); |
190 |
|
191 |
is( |
192 |
join( '|', @isbns ), join( '|', GetVariationsOfISBNs('978-0-321-49694-2 (pbk.)') ), |
193 |
'GetVariationsOfISBNs returns all variations' |
194 |
); |
195 |
|
196 |
my $isbn; |
197 |
eval { |
198 |
$isbn = C4::Koha::NormalizeISBN( |
199 |
{ isbn => '0788893777 (2 DVD 45th ed)', format => 'ISBN-10', strip_hyphens => 1 } ); |
200 |
}; |
201 |
ok( $@ eq '', 'NormalizeISBN does not throw exception when parsing invalid ISBN (bug 12243)' ); |
202 |
$isbn = C4::Koha::NormalizeISBN( |
203 |
{ isbn => '0788893777 (2 DVD 45th ed)', format => 'ISBN-10', strip_hyphens => 1, return_invalid => 1 } ); |
204 |
is( |
205 |
$isbn, '0788893777 (2 DVD 45th ed)', |
206 |
'NormalizeISBN returns original string when converting to ISBN10 an ISBN starting with 979 (bug 13167)' |
207 |
); |
208 |
|
209 |
eval { |
210 |
$isbn = C4::Koha::NormalizeISBN( { isbn => '979-10-90085-00-8', format => 'ISBN-10', strip_hyphens => 1 } ); |
211 |
}; |
212 |
ok( |
213 |
$@ eq '', |
214 |
'NormalizeISBN does not throw exception when converting to ISBN10 an ISBN starting with 979 (bug 13167)' |
215 |
); |
216 |
ok( !defined $isbn, 'NormalizeISBN returns undef when converting to ISBN10 an ISBN starting with 979 (bug 13167)' ); |
217 |
|
218 |
@isbns = GetVariationsOfISBNs('abc'); |
219 |
is( @isbns == 1 && $isbns[0] eq 'abc', 1, 'The unaltered version should be returned if invalid' ); |
220 |
|
221 |
is( |
222 |
C4::Koha::GetNormalizedISBN('9780062059994 (hardcover bdg.) | 0062059998 (hardcover bdg.)'), '0062059998', |
223 |
'Test GetNormalizedISBN' |
224 |
); |
225 |
is( |
226 |
C4::Koha::GetNormalizedISBN( |
227 |
'9780385753067 (trade) | 0385753063 (trade) | 9780385753074 (lib. bdg.) | 0385753071 (lib. bdg.)'), |
228 |
'0385753063', |
229 |
'Test GetNormalizedISBN' |
230 |
); |
231 |
is( |
232 |
C4::Koha::GetNormalizedISBN('9781432829162 (hardcover) | 1432829165 (hardcover)'), '1432829165', |
233 |
'Test GetNormalizedISBN' |
234 |
); |
235 |
is( |
236 |
C4::Koha::GetNormalizedISBN('9780062063625 (hardcover) | 9780062063632 | 0062063634'), '0062063626', |
237 |
'Test GetNormalizedISBN' |
238 |
); |
239 |
is( C4::Koha::GetNormalizedISBN('9780062059932 (hardback)'), '0062059939', 'Test GetNormalizedISBN' ); |
240 |
is( |
241 |
C4::Koha::GetNormalizedISBN( |
242 |
'9780316370318 (hardback) | 9780316376266 (special edition hardcover) | 9780316405454 (international paperback edition)' |
243 |
), |
244 |
'0316370312', |
245 |
'Test GetNormalizedISBN' |
246 |
); |
247 |
is( |
248 |
C4::Koha::GetNormalizedISBN('9781595148032 (hbk.) | 1595148035 (hbk.)'), '1595148035', |
249 |
'Test GetNormalizedISBN' |
250 |
); |
168 |
is( |
251 |
is( |
169 |
xml_escape($str), |
252 |
C4::Koha::GetNormalizedISBN('9780062349859 | 0062349856 | 9780062391308 | 0062391305'), '0062349856', |
170 |
''"&<>'', |
253 |
'Test GetNormalizedISBN' |
171 |
'xml_escape() works as expected' |
|
|
172 |
); |
254 |
); |
173 |
is( $str, q{'"&<>'}, '... and does not change input in place' ); |
255 |
is( |
174 |
is( C4::Koha::_isbn_cleanup('0-590-35340-3'), |
256 |
C4::Koha::GetNormalizedISBN( |
175 |
'0590353403', '_isbn_cleanup removes hyphens' ); |
257 |
'9781250075345 (hardcover) | 1250075343 (hardcover) | 9781250049872 (trade pbk.) | 1250049873 (trade pbk.)' |
176 |
is( C4::Koha::_isbn_cleanup('0590353403 (pbk.)'), |
258 |
), |
177 |
'0590353403', '_isbn_cleanup removes parenthetical' ); |
259 |
'1250075343', |
178 |
is( C4::Koha::_isbn_cleanup('978-0-321-49694-2'), |
260 |
'Test GetNormalizedISBN' |
179 |
'0321496949', '_isbn_cleanup converts ISBN-13 to ISBN-10' ); |
261 |
); |
|
|
262 |
is( C4::Koha::GetNormalizedISBN('9781250067128 | 125006712X'), '125006712X', 'Test GetNormalizedISBN' ); |
263 |
is( C4::Koha::GetNormalizedISBN('9780373211463 | 0373211465'), '0373211465', 'Test GetNormalizedISBN' ); |
180 |
|
264 |
|
|
|
265 |
is( C4::Koha::GetNormalizedUPC(), undef, 'GetNormalizedUPC should return undef if no record is passed' ); |
266 |
is( |
267 |
C4::Koha::GetNormalizedISBN(), undef, |
268 |
'GetNormalizedISBN should return undef if no record and no isbn are passed' |
269 |
); |
270 |
is( |
271 |
C4::Koha::GetNormalizedEAN(), undef, |
272 |
'GetNormalizedEAN should return undef if no record and no isbn are passed' |
273 |
); |
274 |
is( |
275 |
C4::Koha::GetNormalizedOCLCNumber(), undef, |
276 |
'GetNormalizedOCLCNumber should return undef if no record and no isbn are passed' |
277 |
); |
278 |
}; |
279 |
|
280 |
subtest 'issn stuff' => sub { |
281 |
plan tests => 7; |
282 |
|
283 |
is( |
284 |
C4::Koha::NormalizeISSN( { issn => '0024-9319', strip_hyphen => 1 } ), '00249319', |
285 |
'Test NormalizeISSN with all features enabled' |
286 |
); |
287 |
is( |
288 |
C4::Koha::NormalizeISSN( { issn => '0024-9319', strip_hyphen => 0 } ), '0024-9319', |
289 |
'Test NormalizeISSN with all features enabled' |
290 |
); |
291 |
|
292 |
my @issns = qw/ 0024-9319 00249319 /; |
293 |
is( |
294 |
join( '|', @issns ), join( '|', GetVariationsOfISSN('0024-9319') ), |
295 |
'GetVariationsOfISSN returns all variations' |
296 |
); |
297 |
is( |
298 |
join( '|', @issns ), join( '|', GetVariationsOfISSNs('0024-9319') ), |
299 |
'GetVariationsOfISSNs returns all variations' |
300 |
); |
301 |
|
302 |
my $issn; |
303 |
eval { $issn = C4::Koha::NormalizeISSN( { issn => '1234-5678', strip_hyphen => 1 } ); }; |
304 |
ok( $@ eq '', 'NormalizeISSN does not throw exception when parsing invalid ISSN' ); |
305 |
|
306 |
@issns = GetVariationsOfISSNs('abc'); |
307 |
is( $issns[0], 'abc', 'Original ISSN passed through even if invalid' ); |
308 |
is( scalar(@issns), 1, 'zero additional variations returned of invalid ISSN' ); |
309 |
}; |
310 |
|
311 |
subtest 'getFacets() tests' => sub { |
312 |
plan tests => 4; |
313 |
|
314 |
my $count = 1; |
315 |
my $library_module = Test::MockModule->new('Koha::Libraries'); |
316 |
$library_module->mock( 'count', sub { return $count } ); |
317 |
|
318 |
is( Koha::Libraries->search->count, 1, 'There should be only 1 library (singleBranchMode on)' ); |
319 |
my $facets = C4::Koha::getFacets(); |
320 |
is( |
321 |
scalar( grep { defined $_->{idx} && $_->{idx} eq 'location' } @$facets ), |
322 |
1, |
323 |
'location facet present with singleBranchMode on (bug 10078)' |
324 |
); |
325 |
|
326 |
$count = 3; # more libraries.. |
327 |
is( Koha::Libraries->search->count, 3, 'There should be more than 1 library (singleBranchMode off)' ); |
328 |
|
329 |
$facets = C4::Koha::getFacets(); |
330 |
is( |
331 |
scalar( grep { defined $_->{idx} && $_->{idx} eq 'location' } @$facets ), |
332 |
1, |
333 |
'location facet present with singleBranchMode off (bug 10078)' |
334 |
); |
181 |
}; |
335 |
}; |
182 |
|
336 |
|
183 |
subtest 'GetItemTypesCategorized test' => sub{ |
337 |
subtest 'GetItemTypesCategorized test' => sub { |
184 |
plan tests => 9; |
338 |
plan tests => 9; |
185 |
|
339 |
|
186 |
my $avc = Koha::AuthorisedValueCategories->find('ITEMTYPECAT'); |
340 |
my $avc = Koha::AuthorisedValueCategories->find('ITEMTYPECAT'); |
187 |
- |
|
|