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

(-)a/t/db_dependent/www/search_utf8.t (-181 / +214 lines)
Lines 18-24 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use utf8;
20
use utf8;
21
use Test::More tests => 32;
21
use Test::More tests => 64;
22
use Test::WWW::Mechanize;
22
use Test::WWW::Mechanize;
23
use Data::Dumper;
23
use Data::Dumper;
24
use XML::Simple;
24
use XML::Simple;
Lines 45-70 my $xml = XMLin($koha_conf); Link Here
45
my $marcflavour = C4::Context->preference('marcflavour') || 'MARC21';
45
my $marcflavour = C4::Context->preference('marcflavour') || 'MARC21';
46
46
47
# For the purpose of this test, we can reasonably take MARC21 and NORMARC to be the same
47
# For the purpose of this test, we can reasonably take MARC21 and NORMARC to be the same
48
my $file =
48
my $file1 =
49
  $marcflavour eq 'UNIMARC'
49
  $marcflavour eq 'UNIMARC'
50
  ? "$testdir/data/unimarcutf8record.mrc"
50
  ? "$testdir/data/unimarcutf8record.mrc"
51
  : "$testdir/data/marc21utf8record.mrc";
51
  : "$testdir/data/marc21utf8record.mrc";
52
52
53
my $file2 =
54
  $marcflavour eq 'UNIMARC'
55
  ? "$testdir/data/unimarclatin1utf8rec.mrc"
56
  : "$testdir/data/marc21latin1utf8rec.mrc";
57
53
my $user     = $ENV{KOHA_USER} || $xml->{config}->{user};
58
my $user     = $ENV{KOHA_USER} || $xml->{config}->{user};
54
my $password = $ENV{KOHA_PASS} || $xml->{config}->{pass};
59
my $password = $ENV{KOHA_PASS} || $xml->{config}->{pass};
55
my $intranet = $ENV{KOHA_INTRANET_URL};
60
my $intranet = $ENV{KOHA_INTRANET_URL};
56
my $opac     = $ENV{KOHA_OPAC_URL};
61
my $opac     = $ENV{KOHA_OPAC_URL};
57
62
58
# launch the zebra process
63
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
64
# test KOHA_INTRANET_URL is set
69
if ( not defined $intranet ) {
65
if ( not defined $intranet ) {
70
   plan skip_all => "Tests skip. You must set env. variable KOHA_INTRANET_URL to do tests\n";
66
   plan skip_all => "Tests skip. You must set env. variable KOHA_INTRANET_URL to do tests\n";
Lines 77-258 if ( not defined $opac ) { Link Here
77
$intranet =~ s#/$##;
73
$intranet =~ s#/$##;
78
$opac     =~ s#/$##;
74
$opac     =~ s#/$##;
79
75
80
my $agent = Test::WWW::Mechanize->new( autocheck => 1 );
76
#-------------------------------- Test with greek and corean chars;
81
my $jsonresponse;
77
# launch the zebra saerch process
82
78
launch_zebra( $datadir, $koha_conf );
83
# -------------------------------------------------- LOAD RECORD
79
if ( not defined $zebra_pid ) {
84
80
    plan skip_all => "Tests skip. Error starting Zebra Server to do those tests\n";
85
$agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'connect to intranet' );
81
}
86
$agent->form_name('loginform');
82
# launch the zebra index process
87
$agent->field( 'password', $password );
83
launch_indexer( );
88
$agent->field( 'userid',   $user );
84
if ( not defined $indexer_pid ) {
89
$agent->field( 'branch',   '' );
85
    plan skip_all => "Tests skip. Error starting the indexer daemon to do those tests\n";
90
$agent->click_ok( '', 'login to staff client' );
86
}
91
87
92
$agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'load main page' );
88
my $utf8_reg1 = qr/学協会. μμ/;
93
89
test_search($file1,'Αθήνα', 'deuteros', $utf8_reg1);
94
$agent->follow_link_ok( { url_regex => qr/tools-home/i }, 'open tools module' );
90
95
$agent->follow_link_ok( { text => 'Stage MARC records for import' },
91
96
    'go to stage MARC' );
92
#--------------------------------- Test with only utf-8 chars in the latin-1 range;
97
93
launch_zebra( $datadir, $koha_conf );
98
$agent->post(
94
if ( not defined $zebra_pid ) {
99
    "$intranet/cgi-bin/koha/tools/upload-file.pl",
95
    plan skip_all => "Tests skip. Error starting Zebra Server to do those tests\n";
100
    [ 'fileToUpload' => [$file], ],
96
}
101
    'Content_Type' => 'form-data',
97
launch_indexer( );
102
);
98
if ( not defined $indexer_pid ) {
103
ok( $agent->success, 'uploaded file' );
99
    plan skip_all => "Tests skip. Error starting the indexer daemon to do those tests\n";
104
100
}
105
$jsonresponse = decode_json $agent->content();
101
my $utf8_reg2 = qr/Tòmas/;
106
is( $jsonresponse->{'status'}, 'done', 'upload succeeded' );
102
test_search($file2,'Ramòn', 'Tòmas',$utf8_reg2);
107
my $fileid = $jsonresponse->{'fileid'};
103
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
104
129
$jsonresponse = decode_json $agent->content();
105
sub test_search{
130
my $jobID = $jsonresponse->{'jobID'};
106
    #Params
131
ok( $jobID, 'have job ID' );
107
    my $file = $_[0];
108
    my $publisher = $_[1];
109
    my $search_key = $_[2];
110
    my $utf8_reg = $_[3];
132
111
133
my $completed = 0;
112
    my $agent = Test::WWW::Mechanize->new( autocheck => 1 );
113
    my $jsonresponse;
134
114
135
# if we haven't completed the batch in two minutes, it's not happening
115
    # -------------------------------------------------- LOAD RECORD
136
for my $counter ( 1 .. 24 ) {
116
137
    $agent->get(
117
    $agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'connect to intranet' );
138
        "$intranet/cgi-bin/koha/tools/background-job-progress.pl?jobID=$jobID",
118
    $agent->form_name('loginform');
139
        "get job progress"
119
    $agent->field( 'password', $password );
120
    $agent->field( 'userid',   $user );
121
    $agent->field( 'branch',   '' );
122
    $agent->click_ok( '', 'login to staff client' );
123
124
    $agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'load main page' );
125
126
    $agent->follow_link_ok( { url_regex => qr/tools-home/i }, 'open tools module' );
127
    $agent->follow_link_ok( { text => 'Stage MARC records for import' },
128
        'go to stage MARC' );
129
130
    $agent->post(
131
        "$intranet/cgi-bin/koha/tools/upload-file.pl",
132
        [ 'fileToUpload' => [$file], ],
133
        'Content_Type' => 'form-data',
140
    );
134
    );
135
    ok( $agent->success, 'uploaded file' );
136
137
    $jsonresponse = decode_json $agent->content();
138
    is( $jsonresponse->{'status'}, 'done', 'upload succeeded' );
139
    my $fileid = $jsonresponse->{'fileid'};
140
141
    $agent->get_ok( "$intranet/cgi-bin/koha/tools/stage-marc-import.pl",
142
        'reopen stage MARC page' );
143
    $agent->submit_form_ok(
144
        {
145
            form_number => 5,
146
            fields      => {
147
                'uploadedfileid'  => $fileid,
148
                'nomatch_action'  => 'create_new',
149
                'overlay_action'  => 'replace',
150
                'item_action'     => 'always_add',
151
                'matcher'         => '',
152
                'comments'        => '',
153
                'encoding'        => 'utf8',
154
                'parse_items'     => '1',
155
                'runinbackground' => '1',
156
            }
157
        },
158
        'stage MARC'
159
    );
160
141
    $jsonresponse = decode_json $agent->content();
161
    $jsonresponse = decode_json $agent->content();
142
    if ( $jsonresponse->{'job_status'} eq 'completed' ) {
162
    my $jobID = $jsonresponse->{'jobID'};
143
        $completed = 1;
163
    ok( $jobID, 'have job ID' );
144
        last;
164
165
    my $completed = 0;
166
167
    # if we haven't completed the batch in two minutes, it's not happening
168
    for my $counter ( 1 .. 24 ) {
169
        $agent->get(
170
            "$intranet/cgi-bin/koha/tools/background-job-progress.pl?jobID=$jobID",
171
            "get job progress"
172
        );
173
        $jsonresponse = decode_json $agent->content();
174
        if ( $jsonresponse->{'job_status'} eq 'completed' ) {
175
            $completed = 1;
176
            last;
177
        }
178
        warn(
179
            (
180
                $jsonresponse->{'job_size'}
181
                ? floor(
182
                    100 * $jsonresponse->{'progress'} / $jsonresponse->{'job_size'}
183
                  )
184
                : '100'
185
            )
186
            . "% completed"
187
        );
188
        sleep 5;
145
    }
189
    }
146
    warn(
190
    is( $jsonresponse->{'job_status'}, 'completed', 'job was completed' );
147
        (
191
148
            $jsonresponse->{'job_size'}
192
    $agent->get_ok(
149
            ? floor(
193
        "$intranet/cgi-bin/koha/tools/stage-marc-import.pl",
150
                100 * $jsonresponse->{'progress'} / $jsonresponse->{'job_size'}
194
        'reopen stage MARC page at end of upload'
151
              )
152
            : '100'
153
        )
154
        . "% completed"
155
    );
195
    );
156
    sleep 5;
196
    $agent->submit_form_ok(
197
        {
198
            form_number => 5,
199
            fields      => {
200
                'uploadedfileid'  => $fileid,
201
                'nomatch_action'  => 'create_new',
202
                'overlay_action'  => 'replace',
203
                'item_action'     => 'always_add',
204
                'matcher'         => '1',
205
                'comments'        => '',
206
                'encoding'        => 'utf8',
207
                'parse_items'     => '1',
208
                'runinbackground' => '1',
209
                'completedJobID'  => $jobID,
210
            }
211
        },
212
        'stage MARC'
213
    );
214
215
    $agent->follow_link_ok( { text => 'Manage staged records' }, 'view batch' );
216
217
218
    $agent->form_number(5);
219
    $agent->field( 'framework', '' );
220
    $agent->click_ok( 'mainformsubmit', "imported records into catalog" );
221
    my $webpage = $agent->{content};
222
223
    $webpage =~ /(.*<title>.*?)(\d{1,})(.*<\/title>)/sx;
224
    my $id_batch = $2;
225
    my $id_bib_number = GetBiblionumberFromImport($id_batch);
226
227
    # wait enough time for the indexer
228
    sleep 10;
229
230
    # --------------------------------- TEST INTRANET SEARCH
231
232
233
    $agent->get_ok( "$intranet/cgi-bin/koha/catalogue/search.pl" , "got search on intranet");
234
    $agent->form_number(1);
235
    $agent->field('idx', 'kw');
236
    $agent->field('q', $search_key);
237
    $agent->click();
238
    my $intra_text = $agent->text() ;
239
    like( $intra_text, qr|Publisher: $publisher|, );
240
241
    $agent->get_ok( "$intranet/cgi-bin/koha/catalogue/search.pl" , "got search on intranet");
242
    $agent->form_number(1);
243
    $agent->field('idx', 'kw');
244
    $agent->field('q', $publisher);
245
    $agent->click();
246
    $intra_text = $agent->text();
247
248
    like( $intra_text, qr|Publisher: $publisher|, );
249
    my $expected_base = q|search.pl\?idx=kw&q=| . uri_escape_utf8( $publisher );
250
    $agent->base_like(qr|$expected_base|, );
251
252
    ok ( ( length(Encode::encode('UTF-8', $intra_text)) != length($intra_text) ) , 'UTF-8 are multi-byte. Goog') ;
253
    ok ($intra_text =~  $utf8_reg, 'UTF-8 chars are correctly present. Good');
254
    # -------------------------------------------------- TEST ON OPAC
255
256
    $agent->get_ok( "$opac" , "got opac");
257
    $agent->form_name('searchform');
258
    $agent->field( 'q',   $search_key );
259
    $agent->field( 'idx',   '' );
260
    $agent->click( );
261
    my $opac_text = $agent->text() ;
262
    like( $opac_text, qr|Publisher: $publisher|, );
263
264
    $agent->get_ok( "$opac" , "got opac");
265
    $agent->form_name('searchform');
266
    $agent->field('q', $publisher);
267
    $agent->field( 'idx',   '' );
268
    $agent->click();
269
    $opac_text = $agent->text();
270
271
    like( $opac_text, qr|Publisher: $publisher|, );
272
    $expected_base = q|opac-search.pl\?idx=&q=| . uri_escape_utf8( $publisher );
273
    $agent->base_like(qr|$expected_base|, );
274
275
    ok ( ( length(Encode::encode('UTF-8', $opac_text)) != length($opac_text) ) , 'UTF-8 are multi-byte. Goog') ;
276
    ok ($opac_text =~  $utf8_reg, 'UTF-8 chars are correctly present. Good');
277
278
    #-------------------------------------------------- REVERT
279
280
    $agent->get_ok( "$intranet/cgi-bin/koha/tools/manage-marc-import.pl", 'view and clean batch' );
281
    $agent->form_name('clean_batch_'.$id_batch);
282
    $agent->click();
283
    $agent->get_ok( "$intranet/cgi-bin/koha/catalogue/detail.pl?biblionumber=$id_bib_number", 'biblio on intranet' );
284
    $agent->get_ok( "$intranet/cgi-bin/koha/cataloguing/addbiblio.pl?op=delete&biblionumber=$id_bib_number", 'biblio deleted' );
285
286
    # clean
287
    cleanup();
157
}
288
}
158
is( $jsonresponse->{'job_status'}, 'completed', 'job was completed' );
289
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', $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( $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\?idx=&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
290
257
# function that launches the zebra daemon
291
# function that launches the zebra daemon
258
sub launch_zebra {
292
sub launch_zebra {
259
- 

Return to bug 13264