Lines 1-22
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
|
2 |
|
3 |
# Copyright 2012 C & P Bibliography Services |
3 |
# This file is part of Koha. |
4 |
# |
4 |
# |
5 |
# This is free software; you can redistribute it and/or modify it under the |
5 |
# Koha is free software; you can redistribute it and/or modify it |
6 |
# terms of the GNU General Public License as published by the Free Software |
6 |
# under the terms of the GNU General Public License as published by |
7 |
# Foundation; either version 2 of the License, or (at your option) any later |
7 |
# the Free Software Foundation; either version 3 of the License, or |
8 |
# version. |
8 |
# (at your option) any later version. |
9 |
# |
9 |
# |
10 |
# This is distributed in the hope that it will be useful, but WITHOUT ANY |
10 |
# Koha is distributed in the hope that it will be useful, but |
11 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
# |
13 |
# GNU General Public License for more details. |
14 |
# You should have received a copy of the GNU General Public License along with |
|
|
15 |
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, |
16 |
# Suite 330, Boston, MA 02111-1307 USA |
17 |
# |
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>. |
18 |
|
17 |
|
19 |
use Modern::Perl; |
18 |
use Modern::Perl; |
|
|
19 |
|
20 |
use utf8; |
20 |
use utf8; |
21 |
use Test::More; |
21 |
use Test::More; |
22 |
use Test::WWW::Mechanize; |
22 |
use Test::WWW::Mechanize; |
Lines 24-39
use Data::Dumper;
Link Here
|
24 |
use XML::Simple; |
24 |
use XML::Simple; |
25 |
use JSON; |
25 |
use JSON; |
26 |
use File::Basename; |
26 |
use File::Basename; |
|
|
27 |
use File::Path; |
27 |
use File::Spec; |
28 |
use File::Spec; |
|
|
29 |
use File::Temp qw/ tempdir /; |
28 |
use POSIX; |
30 |
use POSIX; |
29 |
use Encode; |
31 |
use Encode; |
30 |
|
32 |
|
|
|
33 |
use C4::Context; |
34 |
|
31 |
my $testdir = File::Spec->rel2abs( dirname(__FILE__) ); |
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();; |
32 |
|
40 |
|
33 |
my $koha_conf = $ENV{KOHA_CONF}; |
41 |
my $koha_conf = $ENV{KOHA_CONF}; |
34 |
my $xml = XMLin($koha_conf); |
42 |
my $xml = XMLin($koha_conf); |
35 |
|
43 |
|
36 |
use C4::Context; |
|
|
37 |
my $marcflavour = C4::Context->preference('marcflavour') || 'MARC21'; |
44 |
my $marcflavour = C4::Context->preference('marcflavour') || 'MARC21'; |
38 |
|
45 |
|
39 |
# For the purpose of this test, we can reasonably take MARC21 and NORMARC to be the same |
46 |
# For the purpose of this test, we can reasonably take MARC21 and NORMARC to be the same |
Lines 47-68
my $password = $ENV{KOHA_PASS} || $xml->{config}->{pass};
Link Here
|
47 |
my $intranet = $ENV{KOHA_INTRANET_URL}; |
54 |
my $intranet = $ENV{KOHA_INTRANET_URL}; |
48 |
my $opac = $ENV{KOHA_OPAC_URL}; |
55 |
my $opac = $ENV{KOHA_OPAC_URL}; |
49 |
|
56 |
|
50 |
my $zebra_on = ProgProcesses('zebrasrv'); |
57 |
# launch the zebra process |
51 |
my $indexer_on = ProgProcesses('koha-index'); |
58 |
launch_zebra( $datadir, $koha_conf ); |
52 |
|
59 |
if ( not defined $zebra_pid ) { |
53 |
if ($zebra_on < 2) { |
60 |
plan skip_all => "Tests skip. Error starting Zebra Server to do those tests\n"; |
54 |
plan skip_all => "Tests skip. You must start Zebra Server to do those tests\n"; |
|
|
55 |
} |
61 |
} |
56 |
|
62 |
# launch the zebra process |
57 |
if ($indexer_on < 2) { |
63 |
launch_indexer( ); |
58 |
plan skip_all => "Tests skip. You must start Zebra Background indexer to do those tests\n"; |
64 |
if ( not defined $indexer_pid ) { |
|
|
65 |
plan skip_all => "Tests skip. Error starting the indexer daemon to do those tests\n"; |
59 |
} |
66 |
} |
60 |
|
67 |
# test KOHA_INTRANET_URL is set |
61 |
if (not defined $intranet) { |
68 |
if ( not defined $intranet ) { |
62 |
plan skip_all => "Tests skip. You must set env. variable KOHA_INTRANET_URL to do tests\n"; |
69 |
plan skip_all => "Tests skip. You must set env. variable KOHA_INTRANET_URL to do tests\n"; |
63 |
} |
70 |
} |
64 |
if (not defined $opac) { |
71 |
# test KOHA_OPAC_URL is set |
65 |
plan skip_all => "Tests skip. You must set env. variable KOHA_INTRANET_URL to do tests\n"; |
72 |
if ( not defined $opac ) { |
|
|
73 |
plan skip_all => "Tests skip. You must set env. variable KOHA_OPAC_URL to do tests\n"; |
66 |
} |
74 |
} |
67 |
|
75 |
|
68 |
$intranet =~ s#/$##; |
76 |
$intranet =~ s#/$##; |
Lines 182-189
my $webpage = $agent->{content};
Link Here
|
182 |
$webpage =~ /(.*<title>.*?)(\d{1,})(.*<\/title>)/sx; |
190 |
$webpage =~ /(.*<title>.*?)(\d{1,})(.*<\/title>)/sx; |
183 |
my $id_batch = $2; |
191 |
my $id_batch = $2; |
184 |
|
192 |
|
185 |
#Wait the indexer |
193 |
# wait enough time for the indexer |
186 |
sleep 35; |
194 |
sleep 10; |
187 |
|
195 |
|
188 |
# -------------------------------------------------- TEST ON OPAC |
196 |
# -------------------------------------------------- TEST ON OPAC |
189 |
|
197 |
|
Lines 211-218
$agent->get_ok( "$intranet/cgi-bin/koha/tools/manage-marc-import.pl", 'view and
Link Here
|
211 |
$agent->form_name('clean_batch_'.$id_batch); |
219 |
$agent->form_name('clean_batch_'.$id_batch); |
212 |
$agent->click(); |
220 |
$agent->click(); |
213 |
|
221 |
|
|
|
222 |
# clean |
223 |
cleanup(); |
224 |
|
214 |
done_testing(); |
225 |
done_testing(); |
215 |
|
226 |
|
216 |
sub ProgProcesses { |
227 |
# function that launches the zebra daemon |
217 |
return scalar grep /$_[0]/, (split /\n/, `ps -aef`); |
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 ); |
218 |
} |
252 |
} |
219 |
- |
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 |
|
264 |
|
265 |
1; |