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>.
21 use Test::More; #See plan tests => \d+ below
22 use Test::WWW::Mechanize;
25 use File::Basename qw(dirname );
32 use t::lib::Mocks::Zebra;
34 my $testdir = File::Spec->rel2abs( dirname(__FILE__) );
35 # global variables that will be used when forking
37 my $marcflavour = C4::Context->preference('marcflavour') || 'MARC21';
40 $marcflavour eq 'UNIMARC'
41 ? "$testdir/data/unimarcutf8record.mrc"
42 : "$testdir/data/marc21utf8record.mrc";
45 $marcflavour eq 'UNIMARC'
46 ? "$testdir/data/unimarclatin1utf8rec.mrc"
47 : "$testdir/data/marc21latin1utf8rec.mrc";
50 $marcflavour eq 'UNIMARC'
51 ? "$testdir/data/unimarcutf8supprec.mrc"
52 : "$testdir/data/marc21utf8supprec.mrc";
54 our $intranet = $ENV{KOHA_INTRANET_URL};
55 our $opac = $ENV{KOHA_OPAC_URL};
57 # test KOHA_INTRANET_URL is set
58 if ( not $intranet ) {
59 plan skip_all => "Tests skip. You must set env. variable KOHA_INTRANET_URL to do tests\n";
61 # test KOHA_OPAC_URL is set
63 plan skip_all => "Tests skip. You must set env. variable KOHA_OPAC_URL to do tests\n";
72 my $mock_zebra = t::lib::Mocks::Zebra->new(
74 intranet => $intranet,
76 koha_conf => $ENV{KOHA_CONF},
80 #-------------------------------- Test with greek and corean chars;
81 # launch the zebra saerch process
82 $mock_zebra->launch_zebra;
83 if ( not defined $mock_zebra->{zebra_pid} ) {
84 plan skip_all => "Tests skip. Error starting Zebra Server to do those tests\n";
86 # launch the zebra index process
87 $mock_zebra->launch_indexer;
88 if ( not defined $mock_zebra->{indexer_pid} ) {
89 plan skip_all => "Tests skip. Error starting the indexer daemon to do those tests\n";
92 our $agent = Test::WWW::Mechanize->new( autocheck => 1 );
93 $agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'connect to intranet' );
94 $agent->form_name('loginform');
95 $agent->field( 'userid', $ENV{KOHA_PASS} );
96 $agent->field( 'password', $ENV{KOHA_USER} );
97 $agent->field( 'branch', '' );
98 $agent->click_ok( '', 'login to staff interface' );
100 my $batch_id = $mock_zebra->load_records_ui($file1);
101 my $utf8_reg1 = qr/学協会. μμ/;
102 test_search('Αθήνα', 'deuteros', $utf8_reg1);
103 $mock_zebra->clean_records($batch_id);
104 $mock_zebra->cleanup;
106 #--------------------------------- Test with only utf-8 chars in the latin-1 range;
107 $mock_zebra->launch_zebra;
108 if ( not defined $mock_zebra->{zebra_pid} ) {
109 plan skip_all => "Tests skip. Error starting Zebra Server to do those tests\n";
111 $mock_zebra->launch_indexer;
112 if ( not defined $mock_zebra->{indexer_pid} ) {
113 plan skip_all => "Tests skip. Error starting the indexer daemon to do those tests\n";
115 $batch_id = $mock_zebra->load_records_ui($file2);
116 my $utf8_reg2 = qr/Tòmas/;
117 test_search('Ramòn', 'Tòmas',$utf8_reg2);
118 $mock_zebra->clean_records($batch_id);
119 $mock_zebra->cleanup;
121 #--------------------------------- Test with supplementary utf-8 chars;
122 $mock_zebra->launch_zebra;
123 if ( not defined $mock_zebra->{zebra_pid} ) {
124 plan skip_all => "Tests skip. Error starting Zebra Server to do those tests\n";
126 $mock_zebra->launch_indexer;
127 if ( not defined $mock_zebra->{indexer_pid} ) {
128 plan skip_all => "Tests skip. Error starting the indexer daemon to do those tests\n";
130 $batch_id = $mock_zebra->load_records_ui($file3);
131 my $utf8_reg3 = qr/😀/;
132 test_search("𠻺tomasito𠻺", 'A tiny record', $utf8_reg3);
133 $mock_zebra->clean_records($batch_id);
134 $mock_zebra->cleanup;
137 my ( $publisher, $search_key, $utf8_reg ) = @_;
139 # --------------------------------- TEST INTRANET SEARCH
141 $agent->get_ok( "$intranet/cgi-bin/koha/catalogue/search.pl" , "got search on intranet");
142 $agent->form_number(5);
143 $agent->field('idx', 'kw');
144 $agent->field('q', $search_key);
146 my $intra_text = $agent->text() ;
148 $agent->get_ok( "$intranet/cgi-bin/koha/catalogue/search.pl" , "got search on intranet");
149 $agent->form_number(5);
150 $agent->field('idx', 'kw');
151 $agent->field('q', $publisher);
153 $intra_text = $agent->text();
155 my $expected_base = q|search.pl\?advsearch=1&idx=kw&q=| . uri_escape_utf8( $publisher );
156 $agent->base_like(qr|$expected_base|, );
158 ok ( ( length(Encode::encode('UTF-8', $intra_text)) != length($intra_text) ) , 'UTF-8 are multi-byte. Good') ;
159 ok ($intra_text =~ $utf8_reg, 'UTF-8 chars are correctly present. Good');
160 # -------------------------------------------------- TEST ON OPAC
162 $agent->get_ok( "$opac" , "got opac");
163 $agent->form_name('searchform');
164 $agent->field( 'q', $search_key );
165 $agent->field( 'idx', '' );
167 my $opac_text = $agent->text() ;
169 $agent->get_ok( "$opac" , "got opac");
170 $agent->form_name('searchform');
171 $agent->field('q', $publisher);
172 $agent->field( 'idx', '' );
174 $opac_text = $agent->text();
176 $expected_base = q|opac-search.pl\?(idx=&)?q=| . uri_escape_utf8( $publisher );
177 $agent->base_like(qr|$expected_base|, );
178 # Test added on BZ 14909 in addition to making the empty idx= optional
179 # in the previous regex
180 $agent->base_unlike( qr|idx=\w+|, 'Base does not contain an idx' );
182 ok ( ( length(Encode::encode('UTF-8', $opac_text)) != length($opac_text) ) , 'UTF-8 are multi-byte. Good') ;
183 ok ($opac_text =~ $utf8_reg, 'UTF-8 chars are correctly present. Good');
188 $mock_zebra->cleanup;