Bug 14585: Fixing up online help on main page
[koha.git] / t / Koha.t
blob18dacd60d2093c7fb1e2b4c338e62213fa1ee6c0
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
18 use Modern::Perl;
20 use C4::Context;
21 use Test::More tests => 18;
22 use Test::MockModule;
23 use DBD::Mock;
25 use_ok('C4::Koha');
27 my $module_context = new Test::MockModule('C4::Context');
28 $module_context->mock(
29 '_new_dbh',
30 sub {
31 my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
32 || die "Cannot create handle: $DBI::errstr\n";
33 return $dbh;
37 SKIP: {
39 skip "DBD::Mock is too old", 3
40 unless $DBD::Mock::VERSION >= 1.45;
42 my @loc_results = (['category'],['LOC']);
43 my @empty_results = ([]);
44 my @relterms_results = (['category'],['RELTERMS']);
46 my $dbh = C4::Context->dbh();
48 $dbh->{mock_add_resultset} = \@loc_results;
49 is ( IsAuthorisedValueCategory('LOC'), 1, 'LOC is a valid authorized value category');
50 $dbh->{mock_add_resultset} = \@empty_results;
51 is ( IsAuthorisedValueCategory('something'), 0, 'something is not a valid authorized value category');
52 $dbh->{mock_add_resultset} = \@relterms_results;
53 is ( IsAuthorisedValueCategory('RELTERMS'), 1, 'RELTERMS is a valid authorized value category');
55 } # End SKIP block
58 # test that &slashifyDate returns correct (non-US) date
60 my $date = "01/01/2002";
61 my $newdate = &slashifyDate("2002-01-01");
62 my $isbn13 = "9780330356473";
63 my $isbn13D = "978-0-330-35647-3";
64 my $isbn10 = "033035647X";
65 my $isbn10D = "0-330-35647-X";
67 ok($date eq $newdate, 'slashifyDate');
69 my $undef = undef;
70 is(xml_escape($undef), '', 'xml_escape() returns empty string on undef input');
71 my $str = q{'"&<>'};
72 is(xml_escape($str), '&apos;&quot;&amp;&lt;&gt;&apos;', 'xml_escape() works as expected');
73 is($str, q{'"&<>'}, '... and does not change input in place');
75 is(C4::Koha::_isbn_cleanup('0-590-35340-3'), '0590353403', '_isbn_cleanup removes hyphens');
76 is(C4::Koha::_isbn_cleanup('0590353403 (pbk.)'), '0590353403', '_isbn_cleanup removes parenthetical');
77 is(C4::Koha::_isbn_cleanup('978-0-321-49694-2'), '0321496949', '_isbn_cleanup converts ISBN-13 to ISBN-10');
79 is(C4::Koha::NormalizeISBN({ isbn => '978-0-321-49694-2 (pbk.)', format => 'ISBN-10', strip_hyphens => 1 }), '0321496949', 'Test NormalizeISBN with all features enabled' );
81 my @isbns = qw/ 978-0-321-49694-2 0-321-49694-9 978-0-321-49694-2 0321496949 9780321496942/;
82 is( join('|', @isbns), join('|', GetVariationsOfISBN('978-0-321-49694-2 (pbk.)')), 'GetVariationsOfISBN returns all variations' );
84 is( join('|', @isbns), join('|', GetVariationsOfISBNs('978-0-321-49694-2 (pbk.)')), 'GetVariationsOfISBNs returns all variations' );
86 my $isbn;
87 eval {
88 $isbn = C4::Koha::NormalizeISBN({ isbn => '0788893777 (2 DVD 45th ed)', format => 'ISBN-10', strip_hyphens => 1 });
90 ok($@ eq '', 'NormalizeISBN does not throw exception when parsing invalid ISBN (bug 12243)');
92 eval {
93 $isbn = C4::Koha::NormalizeISBN({ isbn => '979-10-90085-00-8', format => 'ISBN-10', strip_hyphens => 1 });
95 ok($@ eq '', 'NormalizeISBN does not throw exception when converting to ISBN10 an ISBN starting with 979 (bug 13167)');
96 ok(!defined $isbn, 'NormalizeISBN returns undef when converting to ISBN10 an ISBN starting with 979 (bug 13167)');
98 @isbns = GetVariationsOfISBNs('abc');
99 is(scalar(@isbns), 0, 'zero variations returned of invalid ISBN');