Bug 24545: Fix license statements
[srvgit] / t / db_dependent / www / batch.t
index bf04ea1..b2b48ed 100644 (file)
@@ -1,25 +1,25 @@
 #!/usr/bin/perl
 
 # Copyright 2012 C & P Bibliography Services
+# Copyright 2017 Koha Development Team
 #
-# This is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# This is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA  02111-1307 USA
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
 
 use utf8;
-use Test::More tests => 20;
+use Test::More; #See plan tests => \d+ below
 use Test::WWW::Mechanize;
 use XML::Simple;
 use JSON;
@@ -44,15 +44,19 @@ my $file =
 my $user     = $ENV{KOHA_USER} || $xml->{config}->{user};
 my $password = $ENV{KOHA_PASS} || $xml->{config}->{pass};
 my $intranet = $ENV{KOHA_INTRANET_URL};
-my $opac     = $ENV{KOHA_OPAC_URL};
 
-BAIL_OUT("You must set the environment variable KOHA_INTRANET_URL to ".
+if (not defined $intranet) {
+    plan skip_all =>
+         "You must set the environment variable KOHA_INTRANET_URL to ".
          "point this test to your staff client. If you do not have ".
          "KOHA_CONF set, you must also set KOHA_USER and KOHA_PASS for ".
-         "your username and password") unless $intranet;
+         "your username and password";
+}
+else {
+    plan tests => 26;
+}
 
 $intranet =~ s#/$##;
-$opac     =~ s#/$##;
 
 my $agent = Test::WWW::Mechanize->new( autocheck => 1 );
 my $jsonresponse;
@@ -93,7 +97,7 @@ $agent->submit_form_ok(
             'item_action'     => 'always_add',
             'matcher'         => '',
             'comments'        => '',
-            'encoding'        => 'utf8',
+            'encoding'        => 'UTF-8',
             'parse_items'     => '1',
             'runinbackground' => '1',
             'record_type'     => 'biblio'
@@ -111,9 +115,8 @@ my $completed = 0;
 # if we haven't completed the batch in two minutes, it's not happening
 for my $counter ( 1 .. 24 ) {
     $agent->get(
-        "$intranet/cgi-bin/koha/tools/background-job-progress.pl?jobID=$jobID",
-        "get job progress"
-    );
+        "$intranet/cgi-bin/koha/tools/background-job-progress.pl?jobID=$jobID"
+    ); # get job progress
     $jsonresponse = decode_json $agent->content();
     if ( $jsonresponse->{'job_status'} eq 'completed' ) {
         $completed = 1;
@@ -147,7 +150,7 @@ $agent->submit_form_ok(
             'item_action'     => 'always_add',
             'matcher'         => '1',
             'comments'        => '',
-            'encoding'        => 'utf8',
+            'encoding'        => 'UTF-8',
             'parse_items'     => '1',
             'runinbackground' => '1',
             'completedJobID'  => $jobID,
@@ -178,13 +181,28 @@ $agent->get_ok(
 );
 $jsonresponse = decode_json $agent->content;
 like( $jsonresponse->{ aaData }[0]->{ citation }, qr/$bookdescription/, 'found book' );
-my $biblionumber = $jsonresponse->{ aaData }[0]->{ import_record_id };
+is( $jsonresponse->{ aaData }[0]->{ status }, 'staged', 'record marked as staged' );
+is( $jsonresponse->{ aaData }[0]->{ overlay_status }, 'no_match', 'record has no matches' );
+
 # Back to the manage staged records page
 $agent->get($staged_records_uri);
 $agent->form_number(6);
 $agent->field( 'framework', '' );
 $agent->click_ok( 'mainformsubmit', "imported records into catalog" );
 
+$agent->get("$intranet/cgi-bin/koha/tools/batch_records_ajax.pl?import_batch_id=$import_batch_id");
+$jsonresponse = decode_json $agent->content;
+is( $jsonresponse->{ aaData }[0]->{ status }, 'imported', 'record marked as imported' );
+
+my $biblionumber = $jsonresponse->{aaData}[0]->{matched};
+
+$agent->get_ok(
+    "$intranet/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber",
+    'getting imported bib' );
+$agent->content_contains( 'Details for ' . $bookdescription,
+    'bib is imported' );
+
+$agent->get($staged_records_uri);
 $agent->form_number(5);
 $agent->click_ok( 'mainformsubmit', "revert import" );
 $agent->get_ok(
@@ -193,4 +211,7 @@ $agent->get_ok(
 $agent->content_contains( 'The record you requested does not exist',
     'bib is gone' );
 
-1;
+$agent->get("$intranet/cgi-bin/koha/tools/batch_records_ajax.pl?import_batch_id=$import_batch_id");
+$jsonresponse = decode_json $agent->content;
+is( $jsonresponse->{ aaData }[0]->{ status }, 'reverted', 'record marked as reverted' );
+