Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
|
3 |
# Copyright 2012 C & P Bibliography Services |
4 |
# |
5 |
# This is free software; you can redistribute it and/or modify it under the |
6 |
# terms of the GNU General Public License as published by the Free Software |
7 |
# Foundation; either version 2 of the License, or (at your option) any later |
8 |
# version. |
9 |
# |
10 |
# This is distributed in the hope that it will be useful, but WITHOUT ANY |
11 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
12 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
13 |
# |
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 |
# |
18 |
|
19 |
use Test::More tests => 19; |
20 |
use Test::WWW::Mechanize; |
21 |
use Data::Dumper; |
22 |
use XML::Simple; |
23 |
use JSON; |
24 |
use File::Basename; |
25 |
use File::Spec; |
26 |
|
27 |
my $testdir = File::Spec->rel2abs(dirname(__FILE__)); |
28 |
|
29 |
my $koha_conf = $ENV{KOHA_CONF}; |
30 |
my $xml = XMLin( $koha_conf ); |
31 |
|
32 |
|
33 |
my $user = $ENV{KOHA_USER} || $xml->{config}->{user}; |
34 |
my $password = $ENV{KOHA_PASS} || $xml->{config}->{pass}; |
35 |
my $intranet = $ENV{KOHA_INTRANET_URL}; |
36 |
my $opac = $ENV{KOHA_OPAC_URL}; |
37 |
|
38 |
my $agent = Test::WWW::Mechanize->new( autocheck => 1 ); |
39 |
my $jsonresponse; |
40 |
|
41 |
$agent->get_ok("$intranet/cgi-bin/koha/mainpage.pl", 'connect to intranet'); |
42 |
$agent->form_name('loginform'); |
43 |
$agent->field('password', $password); |
44 |
$agent->field('userid', $user); |
45 |
$agent->field('branch', ''); |
46 |
$agent->click_ok('', 'login to staff client'); |
47 |
|
48 |
$agent->get_ok("$intranet/cgi-bin/koha/mainpage.pl", 'load main page'); |
49 |
|
50 |
$agent->follow_link_ok({ text => 'Tools' }, 'open tools module'); |
51 |
$agent->follow_link_ok({ text => 'Stage MARC records for import' }, 'go to stage MARC'); |
52 |
|
53 |
$agent->post( "$intranet/cgi-bin/koha/tools/upload-file.pl", |
54 |
[ |
55 |
'fileToUpload' => ["$testdir/data/record.mrc"], |
56 |
], |
57 |
'Content_Type' => 'form-data', |
58 |
); |
59 |
ok($agent->success, 'uploaded file'); |
60 |
|
61 |
$jsonresponse = decode_json $agent->content(); |
62 |
is($jsonresponse->{'status'}, 'done', 'upload succeeded'); |
63 |
my $fileid = $jsonresponse->{'fileid'}; |
64 |
|
65 |
$agent->get_ok("$intranet/cgi-bin/koha/tools/stage-marc-import.pl", 'reopen stage MARC page'); |
66 |
$agent->submit_form_ok({ form_number => 5, fields => { 'uploadedfileid' => $fileid, |
67 |
'nomatch_action' => 'create_new', |
68 |
'overlay_action' => 'replace', |
69 |
'item_action' => 'always_add', |
70 |
'matcher' => '', |
71 |
'comments' => '', |
72 |
'encoding' => 'utf8', |
73 |
'parse_items' => '1', |
74 |
'runinbackground' => '1', |
75 |
} |
76 |
}, 'stage MARC'); |
77 |
|
78 |
$jsonresponse = decode_json $agent->content(); |
79 |
my $jobID = $jsonresponse->{'jobID'}; |
80 |
ok($jobID, 'have job ID'); |
81 |
|
82 |
my $completed = 0; |
83 |
# if we haven't completed the batch in two minutes, it's not happening |
84 |
for my $counter (1..24) { |
85 |
$agent->get("$intranet/cgi-bin/koha/tools/background-job-progress.pl?jobID=$jobID", "get job progress"); |
86 |
$jsonresponse = decode_json $agent->content(); |
87 |
if ($jsonresponse->{'job_status'} eq 'completed') { |
88 |
$completed = 1; |
89 |
last; |
90 |
} |
91 |
print ($jsonresponse->{'job_size'} ? floor(100 * $jsonresponse->{'progress'} / $jsonresponse->{'job_size'}) : '100') . "% completed"; |
92 |
sleep 5; |
93 |
} |
94 |
is($jsonresponse->{'job_status'}, 'completed', 'job was completed'); |
95 |
|
96 |
$agent->get_ok("$intranet/cgi-bin/koha/tools/stage-marc-import.pl", 'reopen stage MARC page at end of upload'); |
97 |
$agent->submit_form_ok({ form_number => 5, fields => { 'uploadedfileid' => $fileid, |
98 |
'nomatch_action' => 'create_new', |
99 |
'overlay_action' => 'replace', |
100 |
'item_action' => 'always_add', |
101 |
'matcher' => '1', |
102 |
'comments' => '', |
103 |
'encoding' => 'utf8', |
104 |
'parse_items' => '1', |
105 |
'runinbackground' => '1', |
106 |
'completedJobID' => $jobID, |
107 |
} |
108 |
}, 'stage MARC'); |
109 |
|
110 |
$agent->follow_link_ok({text => 'Manage staged records'}, 'view batch'); |
111 |
$agent->content_contains('Data structures : Esakov, Jeffrey', 'found book'); |
112 |
$agent->form_number(5); |
113 |
$agent->field('framework', ''); |
114 |
$agent->click_ok('mainformsubmit', "imported records into catalog"); |
115 |
my $newbib; |
116 |
foreach my $link ($agent->links()) { |
117 |
if ($link->url() =~ m#/cgi-bin/koha/catalogue/detail.pl?biblionumber='#) { |
118 |
$newbib = $link->text(); |
119 |
$agent->link_content_like($link, qr/Data structures/, 'successfully imported record'); |
120 |
last; |
121 |
} |
122 |
} |
123 |
|
124 |
$agent->form_number(4); |
125 |
$agent->click_ok('mainformsubmit', "revert import"); |
126 |
$agent->get_ok("$intranet/cgi-bin/koha/catalogue/detail.pl?biblionumber=$newbib", 'getting reverted bib'); |
127 |
$agent->content_contains('The record you requested does not exist', 'bib is gone'); |