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

(-)a/t/db_dependent/www/batch.t (-120 / +29 lines)
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' );
(-)a/t/db_dependent/www/search_utf8.t (-1 / +1 lines)
Lines 63-69 elsif ( not $opac ) { Link Here
63
   plan skip_all => "Tests skip. You must set env. variable KOHA_OPAC_URL to do tests\n";
63
   plan skip_all => "Tests skip. You must set env. variable KOHA_OPAC_URL to do tests\n";
64
}
64
}
65
else {
65
else {
66
    plan tests => 89;
66
    plan tests => 80;
67
}
67
}
68
68
69
$intranet =~ s#/$##;
69
$intranet =~ s#/$##;
(-)a/t/lib/Mocks/Zebra.pm (-58 / +14 lines)
Lines 22-27 use File::Temp qw( tempdir ); Link Here
22
use File::Path qw( rmtree );
22
use File::Path qw( rmtree );
23
use JSON qw( decode_json );
23
use JSON qw( decode_json );
24
use C4::ImportBatch;
24
use C4::ImportBatch;
25
use Koha::BackgroundJobs;
25
26
26
=head1 NAME
27
=head1 NAME
27
28
Lines 172-246 sub load_records_ui { Link Here
172
        'stage MARC'
173
        'stage MARC'
173
    );
174
    );
174
175
175
    $jsonresponse = decode_json $agent->content();
176
    sleep(1);
176
    my $jobID = $jsonresponse->{'jobID'};
177
    # FIXME - This if fragile and can fail if there is a race condition
177
    ok( $jobID, 'have job ID' );
178
    my $job = Koha::BackgroundJobs->search({ type => 'stage_marc_for_import' })->last;
178
179
    my $i;
179
    my $completed = 0;
180
    while ( $job->discard_changes->status ne 'finished' ) {
180
181
        sleep(1);
181
    # if we haven't completed the batch in two minutes, it's not happening
182
        last if ++$i > 10;
182
    for my $counter ( 1 .. 24 ) {
183
        $agent->get(
184
            "$cgi_root/tools/background-job-progress.pl?jobID=$jobID"
185
        ); # get job progress
186
        $jsonresponse = decode_json $agent->content();
187
        if ( $jsonresponse->{'job_status'} eq 'completed' ) {
188
            $completed = 1;
189
            last;
190
        }
191
        warn(
192
            (
193
                $jsonresponse->{'job_size'}
194
                ? floor(
195
                    100 * $jsonresponse->{'progress'} / $jsonresponse->{'job_size'}
196
                  )
197
                : '100'
198
            )
199
            . "% completed"
200
        );
201
        sleep 5;
202
    }
183
    }
203
    is( $jsonresponse->{'job_status'}, 'completed', 'job was completed' );
184
    is ( $job->status, 'finished', 'job is finished' );
185
186
    $job->discard_changes;
187
    my $import_batch_id = $job->report->{import_batch_id};
204
188
205
    $agent->get_ok(
189
    $agent->get_ok(
206
        "$cgi_root/tools/stage-marc-import.pl",
190
        "$cgi_root/tools/manage-marc-import.pl?import_batch_id=$import_batch_id",
207
        'reopen stage MARC page at end of upload'
208
    );
209
    $agent->submit_form_ok(
210
        {
211
            form_number => 5,
212
            fields      => {
213
                'uploadedfileid'  => $fileid,
214
                'nomatch_action'  => 'create_new',
215
                'overlay_action'  => 'replace',
216
                'item_action'     => 'always_add',
217
                'matcher'         => '1',
218
                'comments'        => '',
219
                'encoding'        => 'utf8',
220
                'parse_items'     => '1',
221
                'runinbackground' => '1',
222
                'completedJobID'  => $jobID,
223
                'record_type'     => 'biblio'
224
            }
225
        },
226
        'stage MARC'
227
    );
191
    );
228
192
229
    $agent->follow_link_ok( { text => 'Manage staged records' }, 'view batch' );
230
231
232
    $agent->form_number(6);
193
    $agent->form_number(6);
233
    $agent->field( 'framework', '' );
194
    $agent->field( 'framework', '' );
234
    $agent->click_ok( 'mainformsubmit', "imported records into catalog" );
195
    $agent->click_ok( 'mainformsubmit', "imported records into catalog" );
235
    my $webpage = $agent->{content};
236
237
    $webpage =~ /(.*<title>.*?)(\d{1,})(.*<\/title>)/sx;
238
    my $batch_id = $2;
239
196
240
    # wait enough time for the indexer
197
    # wait enough time for the indexer
241
    sleep 10;
198
    sleep 10;
242
199
243
    return $batch_id;
200
    return $import_batch_id;
244
201
245
}
202
}
246
203
247
- 

Return to bug 31992