3 # This Koha test module is a stub!
4 # Add more tests here!!!
8 use Test::More tests => 3;
21 my $dbh = C4::Context->dbh;
22 $dbh->{RaiseError} = 1;
23 $dbh->{AutoCommit} = 0;
25 my $search_module = new Test::MockModule('C4::Search');
27 $search_module->mock('SimpleSearch', \&Mock_SimpleSearch );
29 my $context = C4::Context->new;
31 my ( $biblionumber_tag, $biblionumber_subfield ) =
32 GetMarcFromKohaField( 'biblio.biblionumber', '' );
33 my ( $isbn_tag, $isbn_subfield ) =
34 GetMarcFromKohaField( 'biblioitems.isbn', '' );
36 # Harry Potter and the Sorcerer's Stone, 1st American ed. 1997
37 my $isbn1 = '0590353403';
38 # ThingISBN match : Silent Wing, First Edition 1998
39 my $isbn2 = '0684843897';
40 # XISBN match : Harry Potter and the Sorcerer's Stone,
41 # 1. Scholastic mass market paperback printing1.
42 my $isbn3 = '043936213X';
44 my $biblionumber1 = _add_biblio_with_isbn($isbn1);
45 my $biblionumber2 = _add_biblio_with_isbn($isbn2);
46 my $biblionumber3 = _add_biblio_with_isbn($isbn3);
48 my $trial = C4::XISBN::_get_biblio_from_xisbn($isbn1);
49 is( $trial->{biblionumber},
50 $biblionumber1, "Gets biblionumber like the previous test." );
53 t::lib::Mocks::mock_preference( 'ThingISBN', 1 );
55 my $results_thingisbn;
56 eval { $results_thingisbn = C4::XISBN::get_xisbns($isbn1); };
58 skip "Problem retrieving ThingISBN", 1
60 is( $results_thingisbn->[0]->{biblionumber},
62 "Gets correct biblionumber from a book with a similar isbn using ThingISBN." );
69 # Add new biblio with isbn and return biblionumber
70 sub _add_biblio_with_isbn {
73 my $marc_record = MARC::Record->new;
74 my $field = MARC::Field->new( $isbn_tag, '', '', $isbn_subfield => $isbn );
75 $marc_record->append_fields($field);
76 my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $marc_record, '' );
82 # C4::Search::SimpleSearch
83 sub Mock_SimpleSearch {
89 if ( $query =~ /$isbn1/ ) {
90 $ret_biblionumber = $biblionumber1;
92 elsif ( $query =~ /$isbn2/ ) {
93 $ret_biblionumber = $biblionumber2;
95 elsif ( $query =~ /$isbn3/ ) {
96 $ret_biblionumber = $biblionumber3;
99 my $record = MARC::Record->new;
100 $record->leader(' ngm a22 7a 4500');
101 my $biblionumber_field;
102 if ( $biblionumber_tag < 10 ) {
103 $biblionumber_field =
104 MARC::Field->new( $biblionumber_tag, $ret_biblionumber );
107 $biblionumber_field = MARC::Field->new( $biblionumber_tag, '', '',
108 $biblionumber_subfield => $ret_biblionumber );
110 $record->append_fields($biblionumber_field);
112 my $indexing_mode = C4::Context->config('zebra_bib_index_mode') // 'dom';
113 push @results, ( $indexing_mode eq 'dom' )
115 : $record->as_usmarc() ;
117 return ( undef, \@results, 1 );