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

(-)a/t/db_dependent/www/batch.t (+180 lines)
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 Modern::Perl;
20
use utf8;
21
use Test::More tests => 20;
22
use Test::WWW::Mechanize;
23
use Data::Dumper;
24
use XML::Simple;
25
use JSON;
26
use File::Basename;
27
use File::Spec;
28
29
my $testdir = File::Spec->rel2abs( dirname(__FILE__) );
30
31
my $koha_conf = $ENV{KOHA_CONF};
32
my $xml       = XMLin($koha_conf);
33
34
use C4::Context;
35
my $marcflavour = C4::Context->preference('marcflavour') || 'MARC21';
36
37
# For the purpose of this test, we can reasonably take MARC21 and NORMARC to be the same
38
my $file =
39
  $marcflavour eq 'UNIMARC'
40
  ? "$testdir/data/unimarcrecord.mrc"
41
  : "$testdir/data/marc21record.mrc";
42
43
my $user     = $ENV{KOHA_USER} || $xml->{config}->{user};
44
my $password = $ENV{KOHA_PASS} || $xml->{config}->{pass};
45
my $intranet = $ENV{KOHA_INTRANET_URL};
46
my $opac     = $ENV{KOHA_OPAC_URL};
47
48
$intranet =~ s#/$##;
49
$opac     =~ s#/$##;
50
51
my $agent = Test::WWW::Mechanize->new( autocheck => 1 );
52
my $jsonresponse;
53
54
$agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'connect to intranet' );
55
$agent->form_name('loginform');
56
$agent->field( 'password', $password );
57
$agent->field( 'userid',   $user );
58
$agent->field( 'branch',   '' );
59
$agent->click_ok( '', 'login to staff client' );
60
61
$agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'load main page' );
62
63
$agent->follow_link_ok( { text => 'Tools' }, 'open tools module' );
64
$agent->follow_link_ok( { text => 'Stage MARC records for import' },
65
    'go to stage MARC' );
66
67
$agent->post(
68
    "$intranet/cgi-bin/koha/tools/upload-file.pl",
69
    [ 'fileToUpload' => [$file], ],
70
    'Content_Type' => 'form-data',
71
);
72
ok( $agent->success, 'uploaded file' );
73
74
$jsonresponse = decode_json $agent->content();
75
is( $jsonresponse->{'status'}, 'done', 'upload succeeded' );
76
my $fileid = $jsonresponse->{'fileid'};
77
78
$agent->get_ok( "$intranet/cgi-bin/koha/tools/stage-marc-import.pl",
79
    'reopen stage MARC page' );
80
$agent->submit_form_ok(
81
    {
82
        form_number => 5,
83
        fields      => {
84
            'uploadedfileid'  => $fileid,
85
            'nomatch_action'  => 'create_new',
86
            'overlay_action'  => 'replace',
87
            'item_action'     => 'always_add',
88
            'matcher'         => '',
89
            'comments'        => '',
90
            'encoding'        => 'utf8',
91
            'parse_items'     => '1',
92
            'runinbackground' => '1',
93
        }
94
    },
95
    'stage MARC'
96
);
97
98
$jsonresponse = decode_json $agent->content();
99
my $jobID = $jsonresponse->{'jobID'};
100
ok( $jobID, 'have job ID' );
101
102
my $completed = 0;
103
104
# if we haven't completed the batch in two minutes, it's not happening
105
for my $counter ( 1 .. 24 ) {
106
    $agent->get(
107
        "$intranet/cgi-bin/koha/tools/background-job-progress.pl?jobID=$jobID",
108
        "get job progress"
109
    );
110
    $jsonresponse = decode_json $agent->content();
111
    if ( $jsonresponse->{'job_status'} eq 'completed' ) {
112
        $completed = 1;
113
        last;
114
    }
115
    warn(
116
        (
117
            $jsonresponse->{'job_size'}
118
            ? floor(
119
                100 * $jsonresponse->{'progress'} / $jsonresponse->{'job_size'}
120
              )
121
            : '100'
122
        )
123
        . "% completed"
124
    );
125
    sleep 5;
126
}
127
is( $jsonresponse->{'job_status'}, 'completed', 'job was completed' );
128
129
$agent->get_ok(
130
    "$intranet/cgi-bin/koha/tools/stage-marc-import.pl",
131
    'reopen stage MARC page at end of upload'
132
);
133
$agent->submit_form_ok(
134
    {
135
        form_number => 5,
136
        fields      => {
137
            'uploadedfileid'  => $fileid,
138
            'nomatch_action'  => 'create_new',
139
            'overlay_action'  => 'replace',
140
            'item_action'     => 'always_add',
141
            'matcher'         => '1',
142
            'comments'        => '',
143
            'encoding'        => 'utf8',
144
            'parse_items'     => '1',
145
            'runinbackground' => '1',
146
            'completedJobID'  => $jobID,
147
        }
148
    },
149
    'stage MARC'
150
);
151
152
$agent->follow_link_ok( { text => 'Manage staged records' }, 'view batch' );
153
my $bookdescription;
154
if ( $marcflavour eq 'UNIMARC' ) {
155
    $bookdescription = 'Jeffrey Esakov et Tom Weiss';
156
}
157
else {
158
    $bookdescription = 'Data structures';
159
}
160
$agent->content_contains( $bookdescription, 'found book' );
161
$agent->form_number(5);
162
$agent->field( 'framework', '' );
163
$agent->click_ok( 'mainformsubmit', "imported records into catalog" );
164
my $newbib;
165
foreach my $link ( $agent->links() ) {
166
    if ( $link->url() =~ m#/cgi-bin/koha/catalogue/detail.pl\?biblionumber=# ) {
167
        $newbib = $link->text();
168
        $agent->link_content_like( [$link], qr/$bookdescription/,
169
            'successfully imported record' );
170
        last;
171
    }
172
}
173
174
$agent->form_number(4);
175
$agent->click_ok( 'mainformsubmit', "revert import" );
176
$agent->get_ok(
177
    "$intranet/cgi-bin/koha/catalogue/detail.pl?biblionumber=$newbib",
178
    'getting reverted bib' );
179
$agent->content_contains( 'The record you requested does not exist',
180
    'bib is gone' );
(-)a/t/db_dependent/www/data/marc21record.mrc (+1 lines)
Line 0 Link Here
1
01002pam a2200289 a 4500001000800000005001700008008004100025035002100066906004500087010001700132020002500149040001800174050002600192082001700218100002100235245008200256260005300338300003300391440003400424504003000458500002000488650003400508650003900542700001600581991005200597991006300649338389719890317122103.8880830s1989    njua     b    001 0 eng    9(DLC)   88028856  a7bcbccorignewd1eocipf19gy-gencatlg  a   88028856   a0131988476 :c$27.00  aDLCcDLCdDLC00aQA76.73.C15bE83 198900a005.13/32191 aEsakov, Jeffrey.10aData structures :ban advanced approach using C /cJeffrey Esakov, Tom Weiss.  aEnglewood Cliffs, N.J. :bPrentice Hall,cc1989.  axi, 372 p. :bill. ;c25 cm. 0aPrentice Hall software series  aBibliography: p. 361-366.  aIncludes index. 0aC (Computer program language) 0aData structures (Computer science)1 aWeiss, Tom.  bc-GenCollhQA76.73.C15iE83 1989tCopy 1wBOOKS  bc-GenCollhQA76.73.C15iE83 1989p00009695734tCopy 2wCCF
(-)a/t/db_dependent/www/data/unimarcrecord.mrc (-1 / +1 lines)
Line 0 Link Here
0
- 
1
00413     2200121   45000010005000000100023000050900009000281000041000372000166000782100016002442150023002601010008002835001  a2-12-486514-5bbr.  a5001  a19951005d1994    m  y0frey50      ba  aStructures de donnéesbLIVReune approche avancée utilisant CfJeffrey Esakov et Tom Weissgtrad. française, Clotilde Fermautgrévision, Emmanuel Fermaut  cAFNORd1994  aXIII-382 p.d24 cm  afre

Return to bug 8300