Revert "Bug 8992: Use the existing greybox plugin in interface/theme"
[koha.git] / t / Charset.t
blob09ba5336b926b22b960f82b632952f416d53418a
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 Test::More tests => 16;
21 use Encode qw( is_utf8 );
23 use MARC::Record;
25 use utf8;
26 use open ':std', ':encoding(utf8)';
28 BEGIN {
29 use_ok('C4::Charset');
32 my $string;
33 ok(!defined(NormalizeString($string,undef,1)),'Uninitialized string case 1 normalizes to uninitialized string.');
35 $string = 'Sample';
36 ok(defined(NormalizeString($string,undef,0)), 'Initialized string case 1 normalizes to some string.');
37 ok(defined(NormalizeString($string,undef,1)), 'Initialized string case 2 normalizes to some string.');
38 ok(defined(NormalizeString($string,1,0)), 'Initialized string case 3 normalizes to some string.');
39 ok(defined(NormalizeString($string,1,1)), 'Initialized string case 4 normalizes to some string.');
41 my $octets = "abc";
42 ok(IsStringUTF8ish($octets), "verify octets are valid UTF-8 (ASCII)");
44 $octets = "flamb\c3\a9";
45 ok(!Encode::is_utf8($octets), "verify that string does not have Perl UTF-8 flag on");
46 ok(IsStringUTF8ish($octets), "verify octets are valid UTF-8 (LATIN SMALL LETTER E WITH ACUTE)");
47 ok(!Encode::is_utf8($octets), "verify that IsStringUTF8ish does not magically turn Perl UTF-8 flag on");
49 $octets = "a\xc2" . "c";
50 ok(!IsStringUTF8ish($octets), "verify octets are not valid UTF-8");
52 ok( !SetUTF8Flag(), 'SetUTF8Flag returns undef if no record passed' );
54 my $record = MARC::Record->new();
55 ok( !SetUTF8Flag($record), 'SetUTF8Flag returns undef if the record has no subfields' );
56 # Add some fields/subfields
57 $record->append_fields(
58 MARC::Field->new('100', ' ', ' ', a => 'Julio Cortazar'),
59 MARC::Field->new('245', ' ', ' ', a => 'Rayuela'),
61 # Verify our data serves its purpose
62 ok( !Encode::is_utf8($record->subfield('100','a')) &&
63 !Encode::is_utf8($record->subfield('245','a')),
64 'Verify that the subfields are NOT set the UTF-8 flag yet' );
66 SetUTF8Flag($record);
68 ok( Encode::is_utf8($record->subfield('100','a')) &&
69 Encode::is_utf8($record->subfield('245','a')),
70 'SetUTF8Flag sets the UTF-8 flag to all subfields' );
72 is( nsb_clean("˜Leœ Moyen Âge"), "Le Moyen Âge", "nsb_clean removes ˜ and œ" );