3 # This Koha test module is a stub!
4 # Add more tests here!!!
8 use Test
::More tests
=> 5;
22 my $schema = Koha
::Database
->new->schema;
23 $schema->storage->txn_begin;
25 my $engine = C4
::Context
->preference("SearchEngine") // 'Zebra';
26 my $search_module = new Test
::MockModule
("Koha::SearchEngine::${engine}::Search");
28 $search_module->mock('simple_search_compat', \
&Mock_simple_search_compat
);
30 my $context = C4
::Context
->new;
32 my ( $biblionumber_tag, $biblionumber_subfield ) =
33 GetMarcFromKohaField
( 'biblio.biblionumber' );
34 my ( $isbn_tag, $isbn_subfield ) =
35 GetMarcFromKohaField
( 'biblioitems.isbn' );
37 # Harry Potter and the Sorcerer's Stone, 1st American ed. 1997
38 my $isbn1 = '0590353403';
39 # ThingISBN match : Silent Wing, First Edition 1998
40 my $isbn2 = '0684843897';
41 # XISBN match : Harry Potter and the Sorcerer's Stone,
42 # 1. Scholastic mass market paperback printing1.
43 my $isbn3 = '043936213X';
45 my $biblionumber1 = _add_biblio_with_isbn
($isbn1);
46 my $biblionumber2 = _add_biblio_with_isbn
($isbn2);
47 my $biblionumber3 = _add_biblio_with_isbn
($isbn3);
49 my $trial = C4
::XISBN
::_get_biblio_from_xisbn
($isbn1);
50 is
( $trial->{biblionumber
},
51 $biblionumber1, "Gets biblionumber like the previous test." );
54 t
::lib
::Mocks
::mock_preference
( 'ThingISBN', 1 );
56 my $results_thingisbn;
57 eval { $results_thingisbn = C4
::XISBN
::get_xisbns
($isbn1); };
59 skip
"Problem retrieving ThingISBN", 1
61 is
( $results_thingisbn->[0]->{biblionumber
},
63 "Gets correct biblionumber from a book with a similar isbn using ThingISBN." );
66 eval { $results_thingisbn = C4
::XISBN
::get_xisbns
($isbn1,$biblionumber1); };
68 skip
"Problem retrieving ThingISBN", 1
70 is
( $results_thingisbn->[0]->{biblionumber
},
72 "Gets correct biblionumber from a different book with a similar isbn using ThingISBN." );
75 eval { $results_thingisbn = C4
::XISBN
::get_xisbns
($isbn1,$biblionumber3); };
77 skip
"Problem retrieving ThingISBN", 1
79 is
( $results_thingisbn->[0]->{biblionumber
},
81 "Doesn't get biblionumber if the biblionumber matches the one passed to the sub." );
86 # Add new biblio with isbn and return biblionumber
87 sub _add_biblio_with_isbn
{
90 my $marc_record = MARC
::Record
->new;
91 my $field = MARC
::Field
->new( $isbn_tag, '', '', $isbn_subfield => $isbn );
92 $marc_record->append_fields($field);
93 my ( $biblionumber, $biblioitemnumber ) = AddBiblio
( $marc_record, '' );
99 # Koha::SearchEngine::${SearchEngine}::Search::simple_search_compat
100 sub Mock_simple_search_compat
{
106 my $ret_biblionumber;
107 if ( $query =~ /$isbn1/ ) {
108 $ret_biblionumber = $biblionumber1;
110 elsif ( $query =~ /$isbn2/ ) {
111 $ret_biblionumber = $biblionumber2;
113 elsif ( $query =~ /$isbn3/ ) {
114 $ret_biblionumber = $biblionumber3;
117 my $record = MARC
::Record
->new;
118 $record->leader(' ngm a22 7a 4500');
119 my $biblionumber_field;
120 if ( $biblionumber_tag < 10 ) {
121 $biblionumber_field =
122 MARC
::Field
->new( $biblionumber_tag, $ret_biblionumber );
125 $biblionumber_field = MARC
::Field
->new( $biblionumber_tag, '', '',
126 $biblionumber_subfield => $ret_biblionumber );
128 $record->append_fields($biblionumber_field);
130 push @results, $record->as_xml();
132 return ( undef, \
@results, 1 );