Lines 26-31
use JSON;
Link Here
|
26 |
use File::Basename; |
26 |
use File::Basename; |
27 |
use File::Spec; |
27 |
use File::Spec; |
28 |
use POSIX; |
28 |
use POSIX; |
|
|
29 |
use t::lib::Mocks::Zebra; |
30 |
use Koha::BackgroundJobs; |
29 |
|
31 |
|
30 |
my $testdir = File::Spec->rel2abs( dirname(__FILE__) ); |
32 |
my $testdir = File::Spec->rel2abs( dirname(__FILE__) ); |
31 |
|
33 |
|
Lines 52-165
if (not defined $intranet) {
Link Here
|
52 |
"your username and password"; |
54 |
"your username and password"; |
53 |
} |
55 |
} |
54 |
else { |
56 |
else { |
55 |
plan tests => 26; |
57 |
plan tests => 24; |
56 |
} |
58 |
} |
57 |
|
59 |
|
58 |
$intranet =~ s#/$##; |
60 |
$intranet =~ s#/$##; |
59 |
|
61 |
|
60 |
my $agent = Test::WWW::Mechanize->new( autocheck => 1 ); |
62 |
my $mock_zebra = t::lib::Mocks::Zebra->new( |
61 |
my $jsonresponse; |
|
|
62 |
|
63 |
$agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'connect to intranet' ); |
64 |
$agent->form_name('loginform'); |
65 |
$agent->field( 'password', $password ); |
66 |
$agent->field( 'userid', $user ); |
67 |
$agent->field( 'branch', '' ); |
68 |
$agent->click_ok( '', 'login to staff interface' ); |
69 |
|
70 |
$agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'load main page' ); |
71 |
|
72 |
$agent->follow_link_ok( { url_regex => qr/cataloging-home/i }, 'open cataloging module' ); |
73 |
$agent->follow_link_ok( { text => 'Stage records for import' }, |
74 |
'go to stage MARC' ); |
75 |
|
76 |
$agent->post( |
77 |
"$intranet/cgi-bin/koha/tools/upload-file.pl?temp=1", |
78 |
[ 'fileToUpload' => [$file], ], |
79 |
'Content_Type' => 'form-data', |
80 |
); |
81 |
ok( $agent->success, 'uploaded file' ); |
82 |
|
83 |
$jsonresponse = decode_json $agent->content(); |
84 |
is( $jsonresponse->{'status'}, 'done', 'upload succeeded' ); |
85 |
my $fileid = $jsonresponse->{'fileid'}; |
86 |
|
87 |
$agent->get_ok( "$intranet/cgi-bin/koha/tools/stage-marc-import.pl", |
88 |
'reopen stage MARC page' ); |
89 |
$agent->submit_form_ok( |
90 |
{ |
63 |
{ |
91 |
form_number => 5, |
64 |
intranet => $intranet, |
92 |
fields => { |
65 |
koha_conf => $ENV{KOHA_CONF}, |
93 |
'uploadedfileid' => $fileid, |
|
|
94 |
'nomatch_action' => 'create_new', |
95 |
'overlay_action' => 'replace', |
96 |
'item_action' => 'always_add', |
97 |
'matcher' => '', |
98 |
'comments' => '', |
99 |
'encoding' => 'UTF-8', |
100 |
'parse_items' => '1', |
101 |
'runinbackground' => '1', |
102 |
'record_type' => 'biblio' |
103 |
} |
104 |
}, |
105 |
'stage MARC' |
106 |
); |
107 |
|
108 |
$jsonresponse = decode_json $agent->content(); |
109 |
my $jobID = $jsonresponse->{'jobID'}; |
110 |
ok( $jobID, 'have job ID' ); |
111 |
|
112 |
my $completed = 0; |
113 |
|
114 |
# if we haven't completed the batch in two minutes, it's not happening |
115 |
for my $counter ( 1 .. 24 ) { |
116 |
$agent->get( |
117 |
"$intranet/cgi-bin/koha/tools/background-job-progress.pl?jobID=$jobID" |
118 |
); # get job progress |
119 |
$jsonresponse = decode_json $agent->content(); |
120 |
if ( $jsonresponse->{'job_status'} eq 'completed' ) { |
121 |
$completed = 1; |
122 |
last; |
123 |
} |
66 |
} |
124 |
warn( |
|
|
125 |
( |
126 |
$jsonresponse->{'job_size'} |
127 |
? floor( |
128 |
100 * $jsonresponse->{'progress'} / $jsonresponse->{'job_size'} |
129 |
) |
130 |
: '100' |
131 |
) |
132 |
. "% completed" |
133 |
); |
134 |
sleep 5; |
135 |
} |
136 |
is( $jsonresponse->{'job_status'}, 'completed', 'job was completed' ); |
137 |
|
138 |
$agent->get_ok( |
139 |
"$intranet/cgi-bin/koha/tools/stage-marc-import.pl", |
140 |
'reopen stage MARC page at end of upload' |
141 |
); |
142 |
$agent->submit_form_ok( |
143 |
{ |
144 |
form_number => 5, |
145 |
fields => { |
146 |
'uploadedfileid' => $fileid, |
147 |
'nomatch_action' => 'create_new', |
148 |
'overlay_action' => 'replace', |
149 |
'item_action' => 'always_add', |
150 |
'matcher' => '1', |
151 |
'comments' => '', |
152 |
'encoding' => 'UTF-8', |
153 |
'parse_items' => '1', |
154 |
'runinbackground' => '1', |
155 |
'completedJobID' => $jobID, |
156 |
'record_type' => 'biblio' |
157 |
} |
158 |
}, |
159 |
'stage MARC' |
160 |
); |
67 |
); |
161 |
|
68 |
|
162 |
$agent->follow_link_ok( { text => 'Manage staged records' }, 'view batch' ); |
69 |
my $import_batch_id = $mock_zebra->load_records_ui($file); |
163 |
|
70 |
|
164 |
my $bookdescription; |
71 |
my $bookdescription; |
165 |
if ( $marcflavour eq 'UNIMARC' ) { |
72 |
if ( $marcflavour eq 'UNIMARC' ) { |
Lines 169-198
else {
Link Here
|
169 |
$bookdescription = 'Data structures'; |
76 |
$bookdescription = 'Data structures'; |
170 |
} |
77 |
} |
171 |
|
78 |
|
172 |
# Save the staged records URI for later use |
79 |
my $agent = Test::WWW::Mechanize->new( autocheck => 1 ); |
173 |
my $staged_records_uri = $agent->uri; |
80 |
$agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'connect to intranet' ); |
|
|
81 |
$agent->form_name('loginform'); |
82 |
$agent->field( 'password', $password ); |
83 |
$agent->field( 'userid', $user ); |
84 |
$agent->field( 'branch', '' ); |
85 |
$agent->click_ok( '', 'login to staff interface' ); |
174 |
|
86 |
|
175 |
my $import_batch_id = ( split( '=', $staged_records_uri->as_string ) )[-1]; |
|
|
176 |
# Get datatable for the batch id |
87 |
# Get datatable for the batch id |
177 |
$agent->get_ok( |
88 |
$agent->get("$intranet/cgi-bin/koha/tools/batch_records_ajax.pl?import_batch_id=$import_batch_id"); |
178 |
"$intranet/cgi-bin/koha/tools/batch_records_ajax.pl?import_batch_id=$import_batch_id", |
89 |
my $jsonresponse = decode_json $agent->content; |
179 |
'get the datatable for the new batch id' |
|
|
180 |
); |
181 |
$jsonresponse = decode_json $agent->content; |
182 |
like( $jsonresponse->{ aaData }[0]->{ citation }, qr/$bookdescription/, 'found book' ); |
90 |
like( $jsonresponse->{ aaData }[0]->{ citation }, qr/$bookdescription/, 'found book' ); |
183 |
is( $jsonresponse->{ aaData }[0]->{ status }, 'staged', 'record marked as staged' ); |
91 |
is( $jsonresponse->{ aaData }[0]->{ status }, 'imported', 'record marked as staged' ); |
184 |
is( $jsonresponse->{ aaData }[0]->{ overlay_status }, 'no_match', 'record has no matches' ); |
92 |
is( $jsonresponse->{ aaData }[0]->{ overlay_status }, 'no_match', 'record has no matches' ); |
185 |
|
93 |
|
186 |
# Back to the manage staged records page |
|
|
187 |
$agent->get($staged_records_uri); |
188 |
$agent->form_number(6); |
189 |
$agent->field( 'framework', '' ); |
190 |
$agent->click_ok( 'mainformsubmit', "imported records into catalog" ); |
191 |
|
192 |
$agent->get("$intranet/cgi-bin/koha/tools/batch_records_ajax.pl?import_batch_id=$import_batch_id"); |
193 |
$jsonresponse = decode_json $agent->content; |
194 |
is( $jsonresponse->{ aaData }[0]->{ status }, 'imported', 'record marked as imported' ); |
195 |
|
196 |
my $biblionumber = $jsonresponse->{aaData}[0]->{matched}; |
94 |
my $biblionumber = $jsonresponse->{aaData}[0]->{matched}; |
197 |
|
95 |
|
198 |
$agent->get_ok( |
96 |
$agent->get_ok( |
Lines 201-209
$agent->get_ok(
Link Here
|
201 |
$agent->content_contains( 'Details for ' . $bookdescription, |
99 |
$agent->content_contains( 'Details for ' . $bookdescription, |
202 |
'bib is imported' ); |
100 |
'bib is imported' ); |
203 |
|
101 |
|
204 |
$agent->get($staged_records_uri); |
102 |
$agent->get("$intranet/cgi-bin/koha/tools/manage-marc-import.pl?import_batch_id=$import_batch_id"); |
205 |
$agent->form_number(5); |
103 |
$agent->form_number(5); |
206 |
$agent->click_ok( 'mainformsubmit', "revert import" ); |
104 |
$agent->click_ok( 'mainformsubmit', "revert import" ); |
|
|
105 |
|
106 |
sleep(1); |
107 |
# FIXME - This if fragile and can fail if there is a race condition |
108 |
my $job = Koha::BackgroundJobs->search({ type => 'marc_import_revert_batch' })->last; |
109 |
my $i; |
110 |
while ( $job->discard_changes->status ne 'finished' ) { |
111 |
sleep(1); |
112 |
last if ++$i > 10; |
113 |
} |
114 |
is ( $job->status, 'finished', 'job is finished' ); |
115 |
|
207 |
$agent->get_ok( |
116 |
$agent->get_ok( |
208 |
"$intranet/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber", |
117 |
"$intranet/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber", |
209 |
'getting reverted bib' ); |
118 |
'getting reverted bib' ); |