3 # This Koha test module is a stub!
4 # Add more tests here!!!
8 use Test
::More tests
=> 5;
20 my $dbh = C4
::Context
->dbh;
21 $dbh->{RaiseError
} = 1;
22 $dbh->{AutoCommit
} = 0;
24 my $search_module = new Test
::MockModule
('C4::Search');
26 $search_module->mock('SimpleSearch', \
&Mock_SimpleSearch
);
28 my $context = C4
::Context
->new;
30 my ( $biblionumber_tag, $biblionumber_subfield ) =
31 GetMarcFromKohaField
( 'biblio.biblionumber', '' );
32 my ( $isbn_tag, $isbn_subfield ) =
33 GetMarcFromKohaField
( 'biblioitems.isbn', '' );
35 # Harry Potter and the Sorcerer's Stone, 1st American ed. 1997
36 my $isbn1 = '0590353403';
37 # ThingISBN match : Silent Wing, First Edition 1998
38 my $isbn2 = '0684843897';
39 # XISBN match : Harry Potter and the Sorcerer's Stone,
40 # 1. Scholastic mass market paperback printing1.
41 my $isbn3 = '043936213X';
43 my $biblionumber1 = _add_biblio_with_isbn
($isbn1);
44 my $biblionumber2 = _add_biblio_with_isbn
($isbn2);
45 my $biblionumber3 = _add_biblio_with_isbn
($isbn3);
47 my $trial = C4
::XISBN
::get_biblionumber_from_isbn
($isbn1);
48 is
( $trial->[0]->{biblionumber
},
50 "It gets the correct biblionumber from the only isbn we have added." );
52 $trial = C4
::XISBN
::_get_biblio_from_xisbn
($isbn1);
53 is
( $trial->{biblionumber
},
54 $biblionumber1, "Gets biblionumber like the previous test." );
57 $context->set_preference( 'ThingISBN', 1 );
58 $context->set_preference( 'XISBN', 0 );
60 my $results_thingisbn;
61 eval { $results_thingisbn = C4
::XISBN
::get_xisbns
($isbn1); };
63 skip
"Problem retrieving ThingISBN", 1
65 is
( $results_thingisbn->[0]->{biblionumber
},
67 "Gets correct biblionumber from a book with a similar isbn using ThingISBN." );
71 $context->set_preference( 'ThingISBN', 0 );
72 $context->set_preference( 'XISBN', 1 );
75 eval { $results_xisbn = C4
::XISBN
::get_xisbns
($isbn1); };
77 skip
"Problem retrieving XISBN", 1
79 is
( $results_xisbn->[0]->{biblionumber
},
81 "Gets correct biblionumber from a book with a similar isbn using XISBN." );
88 # Add new biblio with isbn and return biblionumber
89 sub _add_biblio_with_isbn
{
92 my $marc_record = MARC
::Record
->new;
93 my $field = MARC
::Field
->new( $isbn_tag, '', '', $isbn_subfield => $isbn );
94 $marc_record->append_fields($field);
95 my ( $biblionumber, $biblioitemnumber ) = AddBiblio
( $marc_record, '' );
101 # C4::Search::SimpleSearch
102 sub Mock_SimpleSearch
{
107 my $ret_biblionumber;
108 if ( $query =~ /$isbn1/ ) {
109 $ret_biblionumber = $biblionumber1;
111 elsif ( $query =~ /$isbn2/ ) {
112 $ret_biblionumber = $biblionumber2;
114 elsif ( $query =~ /$isbn3/ ) {
115 $ret_biblionumber = $biblionumber3;
118 my $record = MARC
::Record
->new;
119 $record->leader(' ngm a22 7a 4500');
120 my $biblionumber_field;
121 if ( $biblionumber_tag < 10 ) {
122 $biblionumber_field =
123 MARC
::Field
->new( $biblionumber_tag, $ret_biblionumber );
126 $biblionumber_field = MARC
::Field
->new( $biblionumber_tag, '', '',
127 $biblionumber_subfield => $ret_biblionumber );
129 $record->append_fields($biblionumber_field);
131 my $indexing_mode = C4
::Context
->config('zebra_bib_index_mode') // 'dom';
132 push @results, ( $indexing_mode eq 'dom' )
134 : $record->as_usmarc() ;
136 return ( undef, \
@results, 1 );