Bug 13400: Untranslatable "Are you sure you want to delete this authority?"
[koha.git] / t / Koha.t
blob31365e6e1c5b23a8e64b405b1eec694d385d9739
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
5 use C4::Context;
6 use Test::More tests => 16;
7 use Test::MockModule;
8 use DBD::Mock;
10 use_ok('C4::Koha');
12 my $module_context = new Test::MockModule('C4::Context');
13 $module_context->mock(
14 '_new_dbh',
15 sub {
16 my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
17 || die "Cannot create handle: $DBI::errstr\n";
18 return $dbh;
22 SKIP: {
24 skip "DBD::Mock is too old", 3
25 unless $DBD::Mock::VERSION >= 1.45;
27 my @loc_results = (['category'],['LOC']);
28 my @empty_results = ([]);
29 my @relterms_results = (['category'],['RELTERMS']);
31 my $dbh = C4::Context->dbh();
33 $dbh->{mock_add_resultset} = \@loc_results;
34 is ( IsAuthorisedValueCategory('LOC'), 1, 'LOC is a valid authorized value category');
35 $dbh->{mock_add_resultset} = \@empty_results;
36 is ( IsAuthorisedValueCategory('something'), 0, 'something is not a valid authorized value category');
37 $dbh->{mock_add_resultset} = \@relterms_results;
38 is ( IsAuthorisedValueCategory('RELTERMS'), 1, 'RELTERMS is a valid authorized value category');
40 } # End SKIP block
43 # test that &slashifyDate returns correct (non-US) date
45 my $date = "01/01/2002";
46 my $newdate = &slashifyDate("2002-01-01");
47 my $isbn13 = "9780330356473";
48 my $isbn13D = "978-0-330-35647-3";
49 my $isbn10 = "033035647X";
50 my $isbn10D = "0-330-35647-X";
52 ok($date eq $newdate, 'slashifyDate');
54 my $undef = undef;
55 is(xml_escape($undef), '', 'xml_escape() returns empty string on undef input');
56 my $str = q{'"&<>'};
57 is(xml_escape($str), '&apos;&quot;&amp;&lt;&gt;&apos;', 'xml_escape() works as expected');
58 is($str, q{'"&<>'}, '... and does not change input in place');
60 is(C4::Koha::_isbn_cleanup('0-590-35340-3'), '0590353403', '_isbn_cleanup removes hyphens');
61 is(C4::Koha::_isbn_cleanup('0590353403 (pbk.)'), '0590353403', '_isbn_cleanup removes parenthetical');
62 is(C4::Koha::_isbn_cleanup('978-0-321-49694-2'), '0321496949', '_isbn_cleanup converts ISBN-13 to ISBN-10');
64 is(C4::Koha::NormalizeISBN({ isbn => '978-0-321-49694-2 (pbk.)', format => 'ISBN-10', strip_hyphens => 1 }), '0321496949', 'Test NormalizeISBN with all features enabled' );
66 my @isbns = qw/ 978-0-321-49694-2 0-321-49694-9 978-0-321-49694-2 0321496949 9780321496942/;
67 is( join('|', @isbns), join('|', GetVariationsOfISBN('978-0-321-49694-2 (pbk.)')), 'GetVariationsOfISBN returns all variations' );
69 is( join('|', @isbns), join('|', GetVariationsOfISBNs('978-0-321-49694-2 (pbk.)')), 'GetVariationsOfISBNs returns all variations' );
71 my $isbn;
72 eval {
73 $isbn = C4::Koha::NormalizeISBN({ isbn => '0788893777 (2 DVD 45th ed)', format => 'ISBN-10', strip_hyphens => 1 });
75 ok($@ eq '', 'NormalizeISBN does not throw exception when parsing invalid ISBN (bug 12243)');
77 @isbns = GetVariationsOfISBNs('abc');
78 is(scalar(@isbns), 0, 'zero variations returned of invalid ISBN');