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
);
31 my $context = C4
::Context
->new;
33 my ( $biblionumber_tag, $biblionumber_subfield ) =
34 GetMarcFromKohaField
( 'biblio.biblionumber' );
35 my ( $isbn_tag, $isbn_subfield ) =
36 GetMarcFromKohaField
( 'biblioitems.isbn' );
38 # Harry Potter and the Sorcerer's Stone, 1st American ed. 1997
39 my $isbn1 = '0590353403';
40 # ThingISBN match : Silent Wing, First Edition 1998
41 my $isbn2 = '0684843897';
42 # XISBN match : Harry Potter and the Sorcerer's Stone,
43 # 1. Scholastic mass market paperback printing1.
44 my $isbn3 = '043936213X';
46 my $biblionumber1 = _add_biblio_with_isbn
($isbn1);
47 my $biblionumber2 = _add_biblio_with_isbn
($isbn2);
48 my $biblionumber3 = _add_biblio_with_isbn
($isbn3);
50 my $trial = C4
::XISBN
::_get_biblio_from_xisbn
($isbn1);
51 is
( $trial->{biblionumber
},
52 $biblionumber1, "Gets biblionumber like the previous test." );
55 t
::lib
::Mocks
::mock_preference
( 'ThingISBN', 1 );
57 my $results_thingisbn;
58 eval { $results_thingisbn = C4
::XISBN
::get_xisbns
($isbn1); };
60 skip
"Problem retrieving ThingISBN", 1
62 is
( $results_thingisbn->[0]->{biblionumber
},
64 "Gets correct biblionumber from a book with a similar isbn using ThingISBN." );
67 eval { $results_thingisbn = C4
::XISBN
::get_xisbns
($isbn1,$biblionumber1); };
69 skip
"Problem retrieving ThingISBN", 1
71 is
( $results_thingisbn->[0]->{biblionumber
},
73 "Gets correct biblionumber from a different book with a similar isbn using ThingISBN." );
76 eval { $results_thingisbn = C4
::XISBN
::get_xisbns
($isbn1,$biblionumber3); };
78 skip
"Problem retrieving ThingISBN", 1
80 is
( $results_thingisbn->[0]->{biblionumber
},
82 "Doesn't get biblionumber if the biblionumber matches the one passed to the sub." );
87 # Add new biblio with isbn and return biblionumber
88 sub _add_biblio_with_isbn
{
91 my $marc_record = MARC
::Record
->new;
92 my $field = MARC
::Field
->new( $isbn_tag, '', '', $isbn_subfield => $isbn );
93 $marc_record->append_fields($field);
94 my ( $biblionumber, $biblioitemnumber ) = AddBiblio
( $marc_record, '' );
100 # Koha::SearchEngine::${SearchEngine}::Search::simple_search_compat
101 sub Mock_simple_search_compat
{
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 push @results, $record->as_xml();
133 return ( undef, \
@results, 1 );