Bug 12782: t/db_dependent/XISBN.t fails in DOM setup
[srvgit] / t / db_dependent / XISBN.t
index 01bcc0f..1f6f797 100755 (executable)
@@ -5,21 +5,25 @@
 
 use Modern::Perl;
 
-# use Test::Class::Load qw ( t/db_dependent/ );
 use Test::More tests => 5;
 use MARC::Record;
 use C4::Biblio;
 use C4::XISBN;
-use Data::Dumper;
 use C4::Context;
+use C4::Search;
+use Test::MockModule;
 
 BEGIN {
     use_ok('C4::XISBN');
 }
 
-# Avoid "redefined subroutine" warnings
-local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
-*C4::Search::SimpleSearch = \&Mock_SimpleSearch;
+my $dbh = C4::Context->dbh;
+$dbh->{RaiseError} = 1;
+$dbh->{AutoCommit} = 0;
+
+my $search_module = new Test::MockModule('C4::Search');
+
+$search_module->mock('SimpleSearch', \&Mock_SimpleSearch );
 
 my $context = C4::Context->new;
 
@@ -32,8 +36,9 @@ my ( $isbn_tag, $isbn_subfield ) =
 my $isbn1 = '0590353403';
 # ThingISBN match : Silent Wing, First Edition 1998
 my $isbn2 = '0684843897';
-# XISBN match : Harry Potter and the Philosopher's Stone, Magic ed. 2000
-my $isbn3 = '1551923963';
+# XISBN match : Harry Potter and the Sorcerer's Stone,
+# 1. Scholastic mass market paperback printing1.
+my $isbn3 = '043936213X';
 
 my $biblionumber1 = _add_biblio_with_isbn($isbn1);
 my $biblionumber2 = _add_biblio_with_isbn($isbn2);
@@ -62,10 +67,7 @@ is( $results_xisbn->[0]->{biblionumber},
     $biblionumber3,
     "Gets correct biblionumber from a book with a similar isbn using XISBN." );
 
-# clean up after ourselves
-DelBiblio($biblionumber1);
-DelBiblio($biblionumber2);
-DelBiblio($biblionumber3);
+$dbh->rollback;
 
 # Util subs
 
@@ -112,6 +114,10 @@ sub Mock_SimpleSearch {
     }
     $record->append_fields($biblionumber_field);
 
-    push @results, $record->as_usmarc;
+    my $indexing_mode = C4::Context->config('zebra_bib_index_mode') // 'dom';
+    push @results, ( $indexing_mode eq 'dom' )
+                    ? $record->as_xml()
+                    : $record->as_usmarc() ;
+
     return ( undef, \@results, 1 );
 }