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

(-)a/t/db_dependent/www/batch.t (+186 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
use POSIX;
29
30
my $testdir = File::Spec->rel2abs( dirname(__FILE__) );
31
32
my $koha_conf = $ENV{KOHA_CONF};
33
my $xml       = XMLin($koha_conf);
34
35
use C4::Context;
36
my $marcflavour = C4::Context->preference('marcflavour') || 'MARC21';
37
38
# For the purpose of this test, we can reasonably take MARC21 and NORMARC to be the same
39
my $file =
40
  $marcflavour eq 'UNIMARC'
41
  ? "$testdir/data/unimarcrecord.mrc"
42
  : "$testdir/data/marc21record.mrc";
43
44
my $user     = $ENV{KOHA_USER} || $xml->{config}->{user};
45
my $password = $ENV{KOHA_PASS} || $xml->{config}->{pass};
46
my $intranet = $ENV{KOHA_INTRANET_URL};
47
my $opac     = $ENV{KOHA_OPAC_URL};
48
49
BAIL_OUT("You must set the environment variable KOHA_INTRANET_URL to ".
50
         "point this test to your staff client. If you do not have ".
51
         "KOHA_CONF set, you must also set KOHA_USER and KOHA_PASS for ".
52
         "your username and password") unless $intranet;
53
54
$intranet =~ s#/$##;
55
$opac     =~ s#/$##;
56
57
my $agent = Test::WWW::Mechanize->new( autocheck => 1 );
58
my $jsonresponse;
59
60
$agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'connect to intranet' );
61
$agent->form_name('loginform');
62
$agent->field( 'password', $password );
63
$agent->field( 'userid',   $user );
64
$agent->field( 'branch',   '' );
65
$agent->click_ok( '', 'login to staff client' );
66
67
$agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'load main page' );
68
69
$agent->follow_link_ok( { url_regex => qr/tools-home/i }, 'open tools module' );
70
$agent->follow_link_ok( { text => 'Stage MARC records for import' },
71
    'go to stage MARC' );
72
73
$agent->post(
74
    "$intranet/cgi-bin/koha/tools/upload-file.pl",
75
    [ 'fileToUpload' => [$file], ],
76
    'Content_Type' => 'form-data',
77
);
78
ok( $agent->success, 'uploaded file' );
79
80
$jsonresponse = decode_json $agent->content();
81
is( $jsonresponse->{'status'}, 'done', 'upload succeeded' );
82
my $fileid = $jsonresponse->{'fileid'};
83
84
$agent->get_ok( "$intranet/cgi-bin/koha/tools/stage-marc-import.pl",
85
    'reopen stage MARC page' );
86
$agent->submit_form_ok(
87
    {
88
        form_number => 5,
89
        fields      => {
90
            'uploadedfileid'  => $fileid,
91
            'nomatch_action'  => 'create_new',
92
            'overlay_action'  => 'replace',
93
            'item_action'     => 'always_add',
94
            'matcher'         => '',
95
            'comments'        => '',
96
            'encoding'        => 'utf8',
97
            'parse_items'     => '1',
98
            'runinbackground' => '1',
99
        }
100
    },
101
    'stage MARC'
102
);
103
104
$jsonresponse = decode_json $agent->content();
105
my $jobID = $jsonresponse->{'jobID'};
106
ok( $jobID, 'have job ID' );
107
108
my $completed = 0;
109
110
# if we haven't completed the batch in two minutes, it's not happening
111
for my $counter ( 1 .. 24 ) {
112
    $agent->get(
113
        "$intranet/cgi-bin/koha/tools/background-job-progress.pl?jobID=$jobID",
114
        "get job progress"
115
    );
116
    $jsonresponse = decode_json $agent->content();
117
    if ( $jsonresponse->{'job_status'} eq 'completed' ) {
118
        $completed = 1;
119
        last;
120
    }
121
    warn(
122
        (
123
            $jsonresponse->{'job_size'}
124
            ? floor(
125
                100 * $jsonresponse->{'progress'} / $jsonresponse->{'job_size'}
126
              )
127
            : '100'
128
        )
129
        . "% completed"
130
    );
131
    sleep 5;
132
}
133
is( $jsonresponse->{'job_status'}, 'completed', 'job was completed' );
134
135
$agent->get_ok(
136
    "$intranet/cgi-bin/koha/tools/stage-marc-import.pl",
137
    'reopen stage MARC page at end of upload'
138
);
139
$agent->submit_form_ok(
140
    {
141
        form_number => 5,
142
        fields      => {
143
            'uploadedfileid'  => $fileid,
144
            'nomatch_action'  => 'create_new',
145
            'overlay_action'  => 'replace',
146
            'item_action'     => 'always_add',
147
            'matcher'         => '1',
148
            'comments'        => '',
149
            'encoding'        => 'utf8',
150
            'parse_items'     => '1',
151
            'runinbackground' => '1',
152
            'completedJobID'  => $jobID,
153
        }
154
    },
155
    'stage MARC'
156
);
157
158
$agent->follow_link_ok( { text => 'Manage staged records' }, 'view batch' );
159
my $bookdescription;
160
if ( $marcflavour eq 'UNIMARC' ) {
161
    $bookdescription = 'Jeffrey Esakov et Tom Weiss';
162
}
163
else {
164
    $bookdescription = 'Data structures';
165
}
166
$agent->content_contains( $bookdescription, 'found book' );
167
$agent->form_number(5);
168
$agent->field( 'framework', '' );
169
$agent->click_ok( 'mainformsubmit', "imported records into catalog" );
170
my $newbib;
171
foreach my $link ( $agent->links() ) {
172
    if ( $link->url() =~ m#/cgi-bin/koha/catalogue/detail.pl\?biblionumber=# ) {
173
        $newbib = $link->text();
174
        $agent->link_content_like( [$link], qr/$bookdescription/,
175
            'successfully imported record' );
176
        last;
177
    }
178
}
179
180
$agent->form_number(4);
181
$agent->click_ok( 'mainformsubmit', "revert import" );
182
$agent->get_ok(
183
    "$intranet/cgi-bin/koha/catalogue/detail.pl?biblionumber=$newbib",
184
    'getting reverted bib' );
185
$agent->content_contains( 'The record you requested does not exist',
186
    '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