View | Details | Raw Unified | Return to bug 13264
Collapse All | Expand All

(-)a/t/db_dependent/www/auth_values_input_www.t (-7 / +19 lines)
Lines 18-31 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use utf8;
20
use utf8;
21
use Test::More;
21
use Test::More tests => 15;
22
use Test::WWW::Mechanize;
22
use Test::WWW::Mechanize;
23
use Data::Dumper;
24
use XML::Simple;
23
use XML::Simple;
25
use JSON;
24
use JSON;
26
use File::Basename;
25
use File::Basename;
27
use File::Spec;
26
use File::Spec;
28
use POSIX;
27
use POSIX;
28
use URI::Escape;
29
use Encode;
29
use Encode;
30
30
31
my $testdir = File::Spec->rel2abs( dirname(__FILE__) );
31
my $testdir = File::Spec->rel2abs( dirname(__FILE__) );
Lines 40-46 if ($@) { Link Here
40
    plan skip_all => "Tests skip. You must have a working Context\n";
40
    plan skip_all => "Tests skip. You must have a working Context\n";
41
}
41
}
42
42
43
44
my $user     = $ENV{KOHA_USER} || $xml->{config}->{user};
43
my $user     = $ENV{KOHA_USER} || $xml->{config}->{user};
45
my $password = $ENV{KOHA_PASS} || $xml->{config}->{pass};
44
my $password = $ENV{KOHA_PASS} || $xml->{config}->{pass};
46
my $intranet = $ENV{KOHA_INTRANET_URL};
45
my $intranet = $ENV{KOHA_INTRANET_URL};
Lines 57-62 my $jsonresponse; Link Here
57
56
58
# -------------------------------------------------- LOAD RECORD
57
# -------------------------------------------------- LOAD RECORD
59
58
59
my $category = '学協会μμ';
60
$agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'connect to intranet' );
60
$agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'connect to intranet' );
61
$agent->form_name('loginform');
61
$agent->form_name('loginform');
62
$agent->field( 'password', $password );
62
$agent->field( 'password', $password );
Lines 71-85 $agent->form_name('Aform'); Link Here
71
$agent->field('authorised_value', 'επιμεq');
71
$agent->field('authorised_value', 'επιμεq');
72
$agent->field('lib_opac', 'autdesc2');
72
$agent->field('lib_opac', 'autdesc2');
73
$agent->field('lib', 'desc1');
73
$agent->field('lib', 'desc1');
74
$agent->field('category', '学協会μμ');
74
$agent->field('category', $category);
75
$agent->field('branches', '');
75
$agent->field('branches', '');
76
$agent->click_ok( '', "Create new auth category and value" );
76
$agent->click_ok( '', "Create new auth category and value" );
77
77
78
my $expected_base = q|authorised_values.pl\?searchfield=| . uri_escape_utf8( $category );
79
$agent->base_like(qr|$expected_base|, "check base");
80
my $add_form_link_exists = 0;
81
my $delete_form_link_exists = 0;
82
for my $link ( $agent->links() ) {
83
    if ( $link->url =~ m|authorised_values.pl\?op=add_form&category=$category| ) {
84
        $add_form_link_exists = 1;
85
    }elsif( $link->url =~ m|authorised_values.pl\?op=delete_confirm&searchfield=$category| ) {
86
        $delete_form_link_exists = 1;
87
    }
88
}
89
is( $add_form_link_exists, 1, );
90
is( $delete_form_link_exists, 1, );
91
78
$agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl", 'Return to Authorized values page' );
92
$agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl", 'Return to Authorized values page' );
79
$agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?searchfield=学協会μμ&offset=0", 'Search the values inserted' );
93
$agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?searchfield=学協会μμ&offset=0", 'Search the values inserted' );
80
my $text = $agent->text() ;
94
my $text = $agent->text() ;
81
#Tests on UTF-8
95
#Tests on UTF-8
82
ok ( ( length(Encode::encode_utf8($text)) != length($text) ) , 'UTF-8 are multi-byte. Good') ;
96
ok ( ( length(Encode::encode('UTF-8', $text)) != length($text) ) , 'UTF-8 are multi-byte. Good') ;
83
ok ($text =~  m/学協会μμ/, 'UTF-8 (Asia) chars are correctly present. Good');
97
ok ($text =~  m/学協会μμ/, 'UTF-8 (Asia) chars are correctly present. Good');
84
ok ($text =~  m/επιμεq/, 'UTF-8 (Greek) chars are correctly present. Good');
98
ok ($text =~  m/επιμεq/, 'UTF-8 (Greek) chars are correctly present. Good');
85
my @links = $agent->links;
99
my @links = $agent->links;
Lines 98-103 if ($id_to_del) { Link Here
98
    ok($id_to_del ne undef, "error, link to delete nor working");
112
    ok($id_to_del ne undef, "error, link to delete nor working");
99
}
113
}
100
114
101
done_testing();
102
103
1;
115
1;
(-)a/t/db_dependent/www/intranet_search_utf8.t (-272 lines)
Lines 1-272 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
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.
9
#
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.
14
#
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>.
17
18
use Modern::Perl;
19
20
use utf8;
21
use Test::More;
22
use Test::WWW::Mechanize;
23
use Data::Dumper;
24
use XML::Simple;
25
use JSON;
26
use File::Basename;
27
use File::Path;
28
use File::Spec;
29
use File::Temp qw/ tempdir /;
30
use POSIX;
31
use Encode;
32
33
use C4::Context;
34
35
my $testdir = File::Spec->rel2abs( dirname(__FILE__) );
36
# global variables that will be used when forking
37
our $zebra_pid;
38
our $indexer_pid;
39
our $datadir = tempdir();;
40
41
my $koha_conf = $ENV{KOHA_CONF};
42
my $xml       = XMLin($koha_conf);
43
44
my $marcflavour = C4::Context->preference('marcflavour') || 'MARC21';
45
46
# For the purpose of this test, we can reasonably take MARC21 and NORMARC to be the same
47
my $file =
48
  $marcflavour eq 'UNIMARC'
49
  ? "$testdir/data/unimarcutf8record.mrc"
50
  : "$testdir/data/marc21utf8record.mrc";
51
52
my $user     = $ENV{KOHA_USER} || $xml->{config}->{user};
53
my $password = $ENV{KOHA_PASS} || $xml->{config}->{pass};
54
my $intranet = $ENV{KOHA_INTRANET_URL};
55
my $opac     = $ENV{KOHA_OPAC_URL};
56
57
# launch the zebra process
58
launch_zebra( $datadir, $koha_conf );
59
if ( not defined $zebra_pid ) {
60
    plan skip_all => "Tests skip. Error starting Zebra Server to do those tests\n";
61
}
62
# launch the zebra process
63
launch_indexer( );
64
if ( not defined $indexer_pid ) {
65
    plan skip_all => "Tests skip. Error starting the indexer daemon to do those tests\n";
66
}
67
# test KOHA_INTRANET_URL is set
68
if ( not defined $intranet ) {
69
   plan skip_all => "Tests skip. You must set env. variable KOHA_INTRANET_URL to do tests\n";
70
}
71
# test KOHA_OPAC_URL is set
72
if ( not defined $opac ) {
73
   plan skip_all => "Tests skip. You must set env. variable KOHA_OPAC_URL to do tests\n";
74
}
75
76
$intranet =~ s#/$##;
77
$opac     =~ s#/$##;
78
79
my $agent = Test::WWW::Mechanize->new( autocheck => 1 );
80
my $jsonresponse;
81
82
# -------------------------------------------------- LOAD RECORD
83
84
$agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'connect to intranet' );
85
$agent->form_name('loginform');
86
$agent->field( 'password', $password );
87
$agent->field( 'userid',   $user );
88
$agent->field( 'branch',   '' );
89
$agent->click_ok( '', 'login to staff client' );
90
91
$agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'load main page' );
92
93
$agent->follow_link_ok( { url_regex => qr/tools-home/i }, 'open tools module' );
94
$agent->follow_link_ok( { text => 'Stage MARC records for import' },
95
    'go to stage MARC' );
96
97
$agent->post(
98
    "$intranet/cgi-bin/koha/tools/upload-file.pl",
99
    [ 'fileToUpload' => [$file], ],
100
    'Content_Type' => 'form-data',
101
);
102
ok( $agent->success, 'uploaded file' );
103
104
$jsonresponse = decode_json $agent->content();
105
is( $jsonresponse->{'status'}, 'done', 'upload succeeded' );
106
my $fileid = $jsonresponse->{'fileid'};
107
108
$agent->get_ok( "$intranet/cgi-bin/koha/tools/stage-marc-import.pl",
109
    'reopen stage MARC page' );
110
$agent->submit_form_ok(
111
    {
112
        form_number => 5,
113
        fields      => {
114
            'uploadedfileid'  => $fileid,
115
            'nomatch_action'  => 'create_new',
116
            'overlay_action'  => 'replace',
117
            'item_action'     => 'always_add',
118
            'matcher'         => '',
119
            'comments'        => '',
120
            'encoding'        => 'utf8',
121
            'parse_items'     => '1',
122
            'runinbackground' => '1',
123
        }
124
    },
125
    'stage MARC'
126
);
127
128
$jsonresponse = decode_json $agent->content();
129
my $jobID = $jsonresponse->{'jobID'};
130
ok( $jobID, 'have job ID' );
131
132
my $completed = 0;
133
134
# if we haven't completed the batch in two minutes, it's not happening
135
for my $counter ( 1 .. 24 ) {
136
    $agent->get(
137
        "$intranet/cgi-bin/koha/tools/background-job-progress.pl?jobID=$jobID",
138
        "get job progress"
139
    );
140
    $jsonresponse = decode_json $agent->content();
141
    if ( $jsonresponse->{'job_status'} eq 'completed' ) {
142
        $completed = 1;
143
        last;
144
    }
145
    warn(
146
        (
147
            $jsonresponse->{'job_size'}
148
            ? floor(
149
                100 * $jsonresponse->{'progress'} / $jsonresponse->{'job_size'}
150
              )
151
            : '100'
152
        )
153
        . "% completed"
154
    );
155
    sleep 5;
156
}
157
is( $jsonresponse->{'job_status'}, 'completed', 'job was completed' );
158
159
$agent->get_ok(
160
    "$intranet/cgi-bin/koha/tools/stage-marc-import.pl",
161
    'reopen stage MARC page at end of upload'
162
);
163
$agent->submit_form_ok(
164
    {
165
        form_number => 5,
166
        fields      => {
167
            'uploadedfileid'  => $fileid,
168
            'nomatch_action'  => 'create_new',
169
            'overlay_action'  => 'replace',
170
            'item_action'     => 'always_add',
171
            'matcher'         => '1',
172
            'comments'        => '',
173
            'encoding'        => 'utf8',
174
            'parse_items'     => '1',
175
            'runinbackground' => '1',
176
            'completedJobID'  => $jobID,
177
        }
178
    },
179
    'stage MARC'
180
);
181
182
$agent->follow_link_ok( { text => 'Manage staged records' }, 'view batch' );
183
184
185
$agent->form_number(5);
186
$agent->field( 'framework', '' );
187
$agent->click_ok( 'mainformsubmit', "imported records into catalog" );
188
my $webpage = $agent->{content};
189
190
$webpage =~ /(.*<title>.*?)(\d{1,})(.*<\/title>)/sx;
191
my $id_batch = $2;
192
my $id_bib_number = GetBiblionumberFromImport($id_batch);
193
194
# wait enough time for the indexer
195
sleep 10;
196
197
# --------------------------------- TEST INTRANET SEARCH
198
199
$agent->get_ok( "$intranet/cgi-bin/koha/catalogue/search.pl" , "got search on intranet");
200
$agent->form_number(1);
201
$agent->field('idx', 'kw');
202
$agent->field('q', 'deuteros');
203
$agent->click();
204
205
my $text = $agent->text() ;
206
207
#Tests on UTF-8
208
209
ok ( ( length(Encode::encode_utf8($text)) != length($text) ) , 'UTF-8 are multi-byte. Goog') ;
210
ok ($text =~  m/学協会. μμ/, 'UTF-8 chars are correctly present. Good');
211
212
213
214
#-------------------------------------------------- REVERT
215
216
$agent->get_ok( "$intranet/cgi-bin/koha/tools/manage-marc-import.pl", 'view and clean batch' );
217
$agent->form_name('clean_batch_'.$id_batch);
218
$agent->click();
219
$agent->get_ok( "$intranet/cgi-bin/koha/catalogue/detail.pl?biblionumber=$id_bib_number", 'biblio on intranet' );
220
$agent->get_ok( "$intranet/cgi-bin/koha/cataloguing/addbiblio.pl?op=delete&biblionumber=$id_bib_number", 'biblio deleted' );
221
222
# clean
223
cleanup();
224
225
done_testing();
226
227
# function that launches the zebra daemon
228
sub launch_zebra {
229
230
    my ( $datadir, $koha_conf ) = @_;
231
232
    $zebra_pid = fork();
233
    if ( $zebra_pid == 0 ) {
234
        exec("zebrasrv -f $koha_conf -v none,request -l $datadir/zebra.log");
235
        exit;
236
    }
237
    sleep( 1 );
238
}
239
240
sub launch_indexer {
241
242
    my $rootdir       = dirname(__FILE__) . '/../../../';
243
    my $rebuild_zebra = "$rootdir/misc/migration_tools/rebuild_zebra.pl";
244
245
    $indexer_pid = fork();
246
247
    if ( $indexer_pid == 0 ) {
248
        exec("$rebuild_zebra -daemon -sleep 5");
249
        exit;
250
    }
251
    sleep( 1 );
252
}
253
254
sub cleanup {
255
256
    kill 9, $zebra_pid   if defined $zebra_pid;
257
    kill 9, $indexer_pid if defined $indexer_pid;
258
    # Clean up the Zebra files since the child process was just shot
259
    rmtree $datadir;
260
261
}
262
263
sub GetBiblionumberFromImport{
264
    my ( $batch_id) = @_;
265
    use C4::ImportBatch;
266
    my $data = C4::ImportBatch::GetImportRecordsRange($batch_id, '', '', undef,
267
                    { order_by => 'import_record_id', order_by_direction => 'DESC' });
268
    my $biblionumber = $data->[0]->{'matched_biblionumber'};
269
    
270
    return $biblionumber;
271
}
272
1;
(-)a/t/db_dependent/www/opac_utf8.t (-277 lines)
Lines 1-277 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
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.
9
#
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.
14
#
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>.
17
18
use Modern::Perl;
19
20
use utf8;
21
use Test::More;
22
use Test::WWW::Mechanize;
23
use Data::Dumper;
24
use XML::Simple;
25
use JSON;
26
use File::Basename;
27
use File::Path;
28
use File::Spec;
29
use File::Temp qw/ tempdir /;
30
use POSIX;
31
use Encode;
32
33
use C4::Context;
34
35
my $testdir = File::Spec->rel2abs( dirname(__FILE__) );
36
# global variables that will be used when forking
37
our $zebra_pid;
38
our $indexer_pid;
39
our $datadir = tempdir();;
40
41
my $koha_conf = $ENV{KOHA_CONF};
42
my $xml       = XMLin($koha_conf);
43
44
my $marcflavour = C4::Context->preference('marcflavour') || 'MARC21';
45
46
# For the purpose of this test, we can reasonably take MARC21 and NORMARC to be the same
47
my $file =
48
  $marcflavour eq 'UNIMARC'
49
  ? "$testdir/data/unimarcutf8record.mrc"
50
  : "$testdir/data/marc21utf8record.mrc";
51
52
my $user     = $ENV{KOHA_USER} || $xml->{config}->{user};
53
my $password = $ENV{KOHA_PASS} || $xml->{config}->{pass};
54
my $intranet = $ENV{KOHA_INTRANET_URL};
55
my $opac     = $ENV{KOHA_OPAC_URL};
56
57
# launch the zebra process
58
launch_zebra( $datadir, $koha_conf );
59
if ( not defined $zebra_pid ) {
60
    plan skip_all => "Tests skip. Error starting Zebra Server to do those tests\n";
61
}
62
# launch the zebra process
63
launch_indexer( );
64
if ( not defined $indexer_pid ) {
65
    plan skip_all => "Tests skip. Error starting the indexer daemon to do those tests\n";
66
}
67
# test KOHA_INTRANET_URL is set
68
if ( not defined $intranet ) {
69
   plan skip_all => "Tests skip. You must set env. variable KOHA_INTRANET_URL to do tests\n";
70
}
71
# test KOHA_OPAC_URL is set
72
if ( not defined $opac ) {
73
   plan skip_all => "Tests skip. You must set env. variable KOHA_OPAC_URL to do tests\n";
74
}
75
76
$intranet =~ s#/$##;
77
$opac     =~ s#/$##;
78
79
my $agent = Test::WWW::Mechanize->new( autocheck => 1 );
80
my $jsonresponse;
81
82
# -------------------------------------------------- LOAD RECORD
83
84
$agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'connect to intranet' );
85
$agent->form_name('loginform');
86
$agent->field( 'password', $password );
87
$agent->field( 'userid',   $user );
88
$agent->field( 'branch',   '' );
89
$agent->click_ok( '', 'login to staff client' );
90
91
$agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'load main page' );
92
93
$agent->follow_link_ok( { url_regex => qr/tools-home/i }, 'open tools module' );
94
$agent->follow_link_ok( { text => 'Stage MARC records for import' },
95
    'go to stage MARC' );
96
97
$agent->post(
98
    "$intranet/cgi-bin/koha/tools/upload-file.pl",
99
    [ 'fileToUpload' => [$file], ],
100
    'Content_Type' => 'form-data',
101
);
102
ok( $agent->success, 'uploaded file' );
103
104
$jsonresponse = decode_json $agent->content();
105
is( $jsonresponse->{'status'}, 'done', 'upload succeeded' );
106
my $fileid = $jsonresponse->{'fileid'};
107
108
$agent->get_ok( "$intranet/cgi-bin/koha/tools/stage-marc-import.pl",
109
    'reopen stage MARC page' );
110
$agent->submit_form_ok(
111
    {
112
        form_number => 5,
113
        fields      => {
114
            'uploadedfileid'  => $fileid,
115
            'nomatch_action'  => 'create_new',
116
            'overlay_action'  => 'replace',
117
            'item_action'     => 'always_add',
118
            'matcher'         => '',
119
            'comments'        => '',
120
            'encoding'        => 'utf8',
121
            'parse_items'     => '1',
122
            'runinbackground' => '1',
123
        }
124
    },
125
    'stage MARC'
126
);
127
128
$jsonresponse = decode_json $agent->content();
129
my $jobID = $jsonresponse->{'jobID'};
130
ok( $jobID, 'have job ID' );
131
132
my $completed = 0;
133
134
# if we haven't completed the batch in two minutes, it's not happening
135
for my $counter ( 1 .. 24 ) {
136
    $agent->get(
137
        "$intranet/cgi-bin/koha/tools/background-job-progress.pl?jobID=$jobID",
138
        "get job progress"
139
    );
140
    $jsonresponse = decode_json $agent->content();
141
    if ( $jsonresponse->{'job_status'} eq 'completed' ) {
142
        $completed = 1;
143
        last;
144
    }
145
    warn(
146
        (
147
            $jsonresponse->{'job_size'}
148
            ? floor(
149
                100 * $jsonresponse->{'progress'} / $jsonresponse->{'job_size'}
150
              )
151
            : '100'
152
        )
153
        . "% completed"
154
    );
155
    sleep 5;
156
}
157
is( $jsonresponse->{'job_status'}, 'completed', 'job was completed' );
158
159
$agent->get_ok(
160
    "$intranet/cgi-bin/koha/tools/stage-marc-import.pl",
161
    'reopen stage MARC page at end of upload'
162
);
163
$agent->submit_form_ok(
164
    {
165
        form_number => 5,
166
        fields      => {
167
            'uploadedfileid'  => $fileid,
168
            'nomatch_action'  => 'create_new',
169
            'overlay_action'  => 'replace',
170
            'item_action'     => 'always_add',
171
            'matcher'         => '1',
172
            'comments'        => '',
173
            'encoding'        => 'utf8',
174
            'parse_items'     => '1',
175
            'runinbackground' => '1',
176
            'completedJobID'  => $jobID,
177
        }
178
    },
179
    'stage MARC'
180
);
181
182
$agent->follow_link_ok( { text => 'Manage staged records' }, 'view batch' );
183
184
185
$agent->form_number(5);
186
$agent->field( 'framework', '' );
187
$agent->click_ok( 'mainformsubmit', "imported records into catalog" );
188
my $webpage = $agent->{content};
189
190
$webpage =~ /(.*<title>.*?)(\d{1,})(.*<\/title>)/sx;
191
my $id_batch = $2;
192
my $id_bib_number = GetBiblionumberFromImport($id_batch);
193
194
# wait enough time for the indexer
195
sleep 10;
196
197
198
199
# -------------------------------------------------- TEST ON OPAC
200
201
202
$agent->get_ok( "$opac" , "got opac");
203
$agent->form_name('searchform');
204
$agent->field( 'q',   'deuteros' );
205
$agent->field( 'idx',   '' );
206
$agent->click( );
207
208
# ok( $agent->success, 'uploaded file' );
209
210
my $text = $agent->text() ;
211
212
#Tests on UTF-8
213
214
ok ( ( length(Encode::encode_utf8($text)) != length($text) ) , 'UTF-8 are multi-byte. Goog') ;
215
ok ($text =~  m/学協会. μμ/, 'UTF-8 chars are correctly present. Good');
216
217
218
219
#-------------------------------------------------- REVERT
220
221
$agent->get_ok( "$intranet/cgi-bin/koha/tools/manage-marc-import.pl", 'view and clean batch' );
222
$agent->form_name('clean_batch_'.$id_batch);
223
$agent->click();
224
$agent->get_ok( "$intranet/cgi-bin/koha/catalogue/detail.pl?biblionumber=$id_bib_number", 'biblio on intranet' );
225
$agent->get_ok( "$intranet/cgi-bin/koha/cataloguing/addbiblio.pl?op=delete&biblionumber=$id_bib_number", 'biblio deleted' );
226
227
# clean
228
cleanup();
229
230
done_testing();
231
232
# function that launches the zebra daemon
233
sub launch_zebra {
234
235
    my ( $datadir, $koha_conf ) = @_;
236
237
    $zebra_pid = fork();
238
    if ( $zebra_pid == 0 ) {
239
        exec("zebrasrv -f $koha_conf -v none,request -l $datadir/zebra.log");
240
        exit;
241
    }
242
    sleep( 1 );
243
}
244
245
sub launch_indexer {
246
247
    my $rootdir       = dirname(__FILE__) . '/../../../';
248
    my $rebuild_zebra = "$rootdir/misc/migration_tools/rebuild_zebra.pl";
249
250
    $indexer_pid = fork();
251
252
    if ( $indexer_pid == 0 ) {
253
        exec("$rebuild_zebra -daemon -sleep 5");
254
        exit;
255
    }
256
    sleep( 1 );
257
}
258
259
sub cleanup {
260
261
    kill 9, $zebra_pid   if defined $zebra_pid;
262
    kill 9, $indexer_pid if defined $indexer_pid;
263
    # Clean up the Zebra files since the child process was just shot
264
    rmtree $datadir;
265
266
}
267
268
sub GetBiblionumberFromImport{
269
    my ( $batch_id) = @_;
270
    use C4::ImportBatch;
271
    my $data = C4::ImportBatch::GetImportRecordsRange($batch_id, '', '', undef,
272
                    { order_by => 'import_record_id', order_by_direction => 'DESC' });
273
    my $biblionumber = $data->[0]->{'matched_biblionumber'};
274
    
275
    return $biblionumber;
276
}
277
1;
(-)a/t/db_dependent/www/search_utf8.t (-1 / +302 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
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.
9
#
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.
14
#
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>.
17
18
use Modern::Perl;
19
20
use utf8;
21
use Test::More tests => 32;
22
use Test::WWW::Mechanize;
23
use Data::Dumper;
24
use XML::Simple;
25
use JSON;
26
use File::Basename;
27
use File::Path;
28
use File::Spec;
29
use File::Temp qw/ tempdir /;
30
use POSIX;
31
use Encode;
32
use URI::Escape;
33
34
use C4::Context;
35
36
my $testdir = File::Spec->rel2abs( dirname(__FILE__) );
37
# global variables that will be used when forking
38
our $zebra_pid;
39
our $indexer_pid;
40
our $datadir = tempdir();;
41
42
my $koha_conf = $ENV{KOHA_CONF};
43
my $xml       = XMLin($koha_conf);
44
45
my $marcflavour = C4::Context->preference('marcflavour') || 'MARC21';
46
47
# For the purpose of this test, we can reasonably take MARC21 and NORMARC to be the same
48
my $file =
49
  $marcflavour eq 'UNIMARC'
50
  ? "$testdir/data/unimarcutf8record.mrc"
51
  : "$testdir/data/marc21utf8record.mrc";
52
53
my $user     = $ENV{KOHA_USER} || $xml->{config}->{user};
54
my $password = $ENV{KOHA_PASS} || $xml->{config}->{pass};
55
my $intranet = $ENV{KOHA_INTRANET_URL};
56
my $opac     = $ENV{KOHA_OPAC_URL};
57
58
# launch the zebra process
59
launch_zebra( $datadir, $koha_conf );
60
if ( not defined $zebra_pid ) {
61
    plan skip_all => "Tests skip. Error starting Zebra Server to do those tests\n";
62
}
63
# launch the zebra process
64
launch_indexer( );
65
if ( not defined $indexer_pid ) {
66
    plan skip_all => "Tests skip. Error starting the indexer daemon to do those tests\n";
67
}
68
# test KOHA_INTRANET_URL is set
69
if ( not defined $intranet ) {
70
   plan skip_all => "Tests skip. You must set env. variable KOHA_INTRANET_URL to do tests\n";
71
}
72
# test KOHA_OPAC_URL is set
73
if ( not defined $opac ) {
74
   plan skip_all => "Tests skip. You must set env. variable KOHA_OPAC_URL to do tests\n";
75
}
76
77
$intranet =~ s#/$##;
78
$opac     =~ s#/$##;
79
80
my $agent = Test::WWW::Mechanize->new( autocheck => 1 );
81
my $jsonresponse;
82
83
# -------------------------------------------------- LOAD RECORD
84
85
$agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'connect to intranet' );
86
$agent->form_name('loginform');
87
$agent->field( 'password', $password );
88
$agent->field( 'userid',   $user );
89
$agent->field( 'branch',   '' );
90
$agent->click_ok( '', 'login to staff client' );
91
92
$agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'load main page' );
93
94
$agent->follow_link_ok( { url_regex => qr/tools-home/i }, 'open tools module' );
95
$agent->follow_link_ok( { text => 'Stage MARC records for import' },
96
    'go to stage MARC' );
97
98
$agent->post(
99
    "$intranet/cgi-bin/koha/tools/upload-file.pl",
100
    [ 'fileToUpload' => [$file], ],
101
    'Content_Type' => 'form-data',
102
);
103
ok( $agent->success, 'uploaded file' );
104
105
$jsonresponse = decode_json $agent->content();
106
is( $jsonresponse->{'status'}, 'done', 'upload succeeded' );
107
my $fileid = $jsonresponse->{'fileid'};
108
109
$agent->get_ok( "$intranet/cgi-bin/koha/tools/stage-marc-import.pl",
110
    'reopen stage MARC page' );
111
$agent->submit_form_ok(
112
    {
113
        form_number => 5,
114
        fields      => {
115
            'uploadedfileid'  => $fileid,
116
            'nomatch_action'  => 'create_new',
117
            'overlay_action'  => 'replace',
118
            'item_action'     => 'always_add',
119
            'matcher'         => '',
120
            'comments'        => '',
121
            'encoding'        => 'utf8',
122
            'parse_items'     => '1',
123
            'runinbackground' => '1',
124
        }
125
    },
126
    'stage MARC'
127
);
128
129
$jsonresponse = decode_json $agent->content();
130
my $jobID = $jsonresponse->{'jobID'};
131
ok( $jobID, 'have job ID' );
132
133
my $completed = 0;
134
135
# if we haven't completed the batch in two minutes, it's not happening
136
for my $counter ( 1 .. 24 ) {
137
    $agent->get(
138
        "$intranet/cgi-bin/koha/tools/background-job-progress.pl?jobID=$jobID",
139
        "get job progress"
140
    );
141
    $jsonresponse = decode_json $agent->content();
142
    if ( $jsonresponse->{'job_status'} eq 'completed' ) {
143
        $completed = 1;
144
        last;
145
    }
146
    warn(
147
        (
148
            $jsonresponse->{'job_size'}
149
            ? floor(
150
                100 * $jsonresponse->{'progress'} / $jsonresponse->{'job_size'}
151
              )
152
            : '100'
153
        )
154
        . "% completed"
155
    );
156
    sleep 5;
157
}
158
is( $jsonresponse->{'job_status'}, 'completed', 'job was completed' );
159
160
$agent->get_ok(
161
    "$intranet/cgi-bin/koha/tools/stage-marc-import.pl",
162
    'reopen stage MARC page at end of upload'
163
);
164
$agent->submit_form_ok(
165
    {
166
        form_number => 5,
167
        fields      => {
168
            'uploadedfileid'  => $fileid,
169
            'nomatch_action'  => 'create_new',
170
            'overlay_action'  => 'replace',
171
            'item_action'     => 'always_add',
172
            'matcher'         => '1',
173
            'comments'        => '',
174
            'encoding'        => 'utf8',
175
            'parse_items'     => '1',
176
            'runinbackground' => '1',
177
            'completedJobID'  => $jobID,
178
        }
179
    },
180
    'stage MARC'
181
);
182
183
$agent->follow_link_ok( { text => 'Manage staged records' }, 'view batch' );
184
185
186
$agent->form_number(5);
187
$agent->field( 'framework', '' );
188
$agent->click_ok( 'mainformsubmit', "imported records into catalog" );
189
my $webpage = $agent->{content};
190
191
$webpage =~ /(.*<title>.*?)(\d{1,})(.*<\/title>)/sx;
192
my $id_batch = $2;
193
my $id_bib_number = GetBiblionumberFromImport($id_batch);
194
195
# wait enough time for the indexer
196
sleep 10;
197
198
# --------------------------------- TEST INTRANET SEARCH
199
200
my $publisher = 'Αθήνα';
201
$agent->get_ok( "$intranet/cgi-bin/koha/catalogue/search.pl" , "got search on intranet");
202
$agent->form_number(1);
203
$agent->field('idx', 'kw');
204
$agent->field('q', 'deuteros');
205
$agent->click();
206
my $intra_text = $agent->text() ;
207
like( $intra_text, qr|Publisher: $publisher|, );
208
209
$agent->get_ok( "$intranet/cgi-bin/koha/catalogue/search.pl" , "got search on intranet");
210
$agent->form_number(1);
211
$agent->field('idx', 'kw');
212
$agent->field('q', Encode::encode('UTF-8', $publisher));
213
$agent->click();
214
$intra_text = $agent->text();
215
216
like( $intra_text, qr|Publisher: $publisher|, );
217
my $expected_base = q|search.pl\?idx=kw&q=| . uri_escape_utf8( Encode::encode('UTF-8', $publisher ) );
218
$agent->base_like(qr|$expected_base|, );
219
220
ok ( ( length(Encode::encode('UTF-8', $intra_text)) != length($intra_text) ) , 'UTF-8 are multi-byte. Goog') ;
221
ok ($intra_text =~  m/学協会. μμ/, 'UTF-8 chars are correctly present. Good');
222
# -------------------------------------------------- TEST ON OPAC
223
224
$agent->get_ok( "$opac" , "got opac");
225
$agent->form_name('searchform');
226
$agent->field( 'q',   'deuteros' );
227
$agent->field( 'idx',   '' );
228
$agent->click( );
229
my $opac_text = $agent->text() ;
230
like( $opac_text, qr|Publisher: $publisher|, );
231
232
$agent->get_ok( "$opac" , "got opac");
233
$agent->form_name('searchform');
234
$agent->field('q', $publisher);
235
$agent->field( 'idx',   '' );
236
$agent->click();
237
$opac_text = $agent->text();
238
239
like( $opac_text, qr|Publisher: $publisher|, );
240
$expected_base = q|opac-search.pl\?q=| . uri_escape_utf8( $publisher );
241
$agent->base_like(qr|$expected_base|, );
242
243
ok ( ( length(Encode::encode('UTF-8', $opac_text)) != length($opac_text) ) , 'UTF-8 are multi-byte. Goog') ;
244
ok ($opac_text =~  m/学協会. μμ/, 'UTF-8 chars are correctly present. Good');
245
246
#-------------------------------------------------- REVERT
247
248
$agent->get_ok( "$intranet/cgi-bin/koha/tools/manage-marc-import.pl", 'view and clean batch' );
249
$agent->form_name('clean_batch_'.$id_batch);
250
$agent->click();
251
$agent->get_ok( "$intranet/cgi-bin/koha/catalogue/detail.pl?biblionumber=$id_bib_number", 'biblio on intranet' );
252
$agent->get_ok( "$intranet/cgi-bin/koha/cataloguing/addbiblio.pl?op=delete&biblionumber=$id_bib_number", 'biblio deleted' );
253
254
# clean
255
cleanup();
256
257
# function that launches the zebra daemon
258
sub launch_zebra {
259
260
    my ( $datadir, $koha_conf ) = @_;
261
262
    $zebra_pid = fork();
263
    if ( $zebra_pid == 0 ) {
264
        exec("zebrasrv -f $koha_conf -v none,request -l $datadir/zebra.log");
265
        exit;
266
    }
267
    sleep( 1 );
268
}
269
270
sub launch_indexer {
271
272
    my $rootdir       = dirname(__FILE__) . '/../../../';
273
    my $rebuild_zebra = "$rootdir/misc/migration_tools/rebuild_zebra.pl";
274
275
    $indexer_pid = fork();
276
277
    if ( $indexer_pid == 0 ) {
278
        exec("$rebuild_zebra -daemon -sleep 5");
279
        exit;
280
    }
281
    sleep( 1 );
282
}
283
284
sub cleanup {
285
286
    kill 9, $zebra_pid   if defined $zebra_pid;
287
    kill 9, $indexer_pid if defined $indexer_pid;
288
    # Clean up the Zebra files since the child process was just shot
289
    rmtree $datadir;
290
291
}
292
293
sub GetBiblionumberFromImport{
294
    my ( $batch_id) = @_;
295
    use C4::ImportBatch;
296
    my $data = C4::ImportBatch::GetImportRecordsRange($batch_id, '', '', undef,
297
                    { order_by => 'import_record_id', order_by_direction => 'DESC' });
298
    my $biblionumber = $data->[0]->{'matched_biblionumber'};
299
    
300
    return $biblionumber;
301
}
302
1;

Return to bug 13264