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

(-)a/t/db_dependent/www/batch.t (-110 / +19 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;
29
30
30
my $testdir = File::Spec->rel2abs( dirname(__FILE__) );
31
my $testdir = File::Spec->rel2abs( dirname(__FILE__) );
31
32
Lines 52-165 if (not defined $intranet) { Link Here
52
         "your username and password";
53
         "your username and password";
53
}
54
}
54
else {
55
else {
55
    plan tests => 26;
56
    plan tests => 13;
56
}
57
}
57
58
58
$intranet =~ s#/$##;
59
$intranet =~ s#/$##;
59
60
60
my $agent = Test::WWW::Mechanize->new( autocheck => 1 );
61
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
    {
62
    {
91
        form_number => 5,
63
        intranet  => $intranet,
92
        fields      => {
64
        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
    }
65
    }
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
);
66
);
161
67
162
$agent->follow_link_ok( { text => 'Manage staged records' }, 'view batch' );
68
my $import_batch_id = $mock_zebra->load_records_ui($file);
163
69
164
my $bookdescription;
70
my $bookdescription;
165
if ( $marcflavour eq 'UNIMARC' ) {
71
if ( $marcflavour eq 'UNIMARC' ) {
Lines 169-190 else { Link Here
169
    $bookdescription = 'Data structures';
75
    $bookdescription = 'Data structures';
170
}
76
}
171
77
172
# Save the staged records URI for later use
78
my $agent = Test::WWW::Mechanize->new( autocheck => 1 );
173
my $staged_records_uri = $agent->uri;
79
$agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'connect to intranet' );
80
$agent->form_name('loginform');
81
$agent->field( 'password', $password );
82
$agent->field( 'userid',   $user );
83
$agent->field( 'branch',   '' );
84
$agent->click_ok( '', 'login to staff interface' );
174
85
175
my $import_batch_id = ( split( '=', $staged_records_uri->as_string ) )[-1];
176
# Get datatable for the batch id
86
# Get datatable for the batch id
177
$agent->get_ok(
87
warn $import_batch_id;
178
    "$intranet/cgi-bin/koha/tools/batch_records_ajax.pl?import_batch_id=$import_batch_id",
88
$agent->get("$intranet/cgi-bin/koha/tools/batch_records_ajax.pl?import_batch_id=$import_batch_id");
179
    'get the datatable for the new batch id'
89
warn $agent->content;
180
);
90
my $jsonresponse = decode_json $agent->content;
181
$jsonresponse = decode_json $agent->content;
182
like( $jsonresponse->{ aaData }[0]->{ citation }, qr/$bookdescription/, 'found book' );
91
like( $jsonresponse->{ aaData }[0]->{ citation }, qr/$bookdescription/, 'found book' );
183
is( $jsonresponse->{ aaData }[0]->{ status }, 'staged', 'record marked as staged' );
92
is( $jsonresponse->{ aaData }[0]->{ status }, 'staged', 'record marked as staged' );
184
is( $jsonresponse->{ aaData }[0]->{ overlay_status }, 'no_match', 'record has no matches' );
93
is( $jsonresponse->{ aaData }[0]->{ overlay_status }, 'no_match', 'record has no matches' );
185
94
186
# Back to the manage staged records page
95
# Back to the manage staged records page
187
$agent->get($staged_records_uri);
96
$agent->get("$intranet/cgi-bin/koha/tools/manage-marc-import.pl?import_batch_id=$import_batch_id");
188
$agent->form_number(6);
97
$agent->form_number(6);
189
$agent->field( 'framework', '' );
98
$agent->field( 'framework', '' );
190
$agent->click_ok( 'mainformsubmit', "imported records into catalog" );
99
$agent->click_ok( 'mainformsubmit', "imported records into catalog" );
Lines 201-207 $agent->get_ok( Link Here
201
$agent->content_contains( 'Details for ' . $bookdescription,
110
$agent->content_contains( 'Details for ' . $bookdescription,
202
    'bib is imported' );
111
    'bib is imported' );
203
112
204
$agent->get($staged_records_uri);
113
$agent->get("$intranet/cgi-bin/koha/tools/manage-marc-import.pl?import_batch_id=$import_batch_id");
205
$agent->form_number(5);
114
$agent->form_number(5);
206
$agent->click_ok( 'mainformsubmit', "revert import" );
115
$agent->click_ok( 'mainformsubmit', "revert import" );
207
$agent->get_ok(
116
$agent->get_ok(
(-)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 / +16 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
    warn $job->status;
180
181
    while ( $job->status ne 'finished' ) {
181
    # if we haven't completed the batch in two minutes, it's not happening
182
        sleep(1);
182
    for my $counter ( 1 .. 24 ) {
183
    warn $job->status;
183
        $agent->get(
184
        last if ++$i > 10;
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
    }
185
    }
203
    is( $jsonresponse->{'job_status'}, 'completed', 'job was completed' );
186
    is ( $job->status, 'finished', 'job is finished' );
187
188
    $job->discard_changes;
189
    my $import_batch_id = $job->report->{import_batch_id};
204
190
205
    $agent->get_ok(
191
    $agent->get_ok(
206
        "$cgi_root/tools/stage-marc-import.pl",
192
        "$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
    );
193
    );
228
194
229
    $agent->follow_link_ok( { text => 'Manage staged records' }, 'view batch' );
230
231
232
    $agent->form_number(6);
195
    $agent->form_number(6);
233
    $agent->field( 'framework', '' );
196
    $agent->field( 'framework', '' );
234
    $agent->click_ok( 'mainformsubmit', "imported records into catalog" );
197
    $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
198
240
    # wait enough time for the indexer
199
    # wait enough time for the indexer
241
    sleep 10;
200
    sleep 10;
242
201
243
    return $batch_id;
202
    return $import_batch_id;
244
203
245
}
204
}
246
205
247
- 

Return to bug 31992