3 # This Koha test module is a stub!
4 # Add more tests here!!!
8 use Test::More tests => 6;
9 use List::MoreUtils qw(any none);
23 my $schema = Koha::Database->new->schema;
24 $schema->storage->txn_begin;
26 my $engine = C4::Context->preference("SearchEngine") // 'Zebra';
27 my $search_module = new Test::MockModule("Koha::SearchEngine::${engine}::Search");
29 $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';
45 # Finn Family Moomintroll, won't match to other isbns
46 my $isbn4 = '014030150X';
48 my $biblionumber1 = _add_biblio_with_isbn($isbn1);
49 my $biblionumber2 = _add_biblio_with_isbn($isbn2);
50 my $biblionumber3 = _add_biblio_with_isbn($isbn3);
51 my $biblionumber4 = _add_biblio_with_isbn($isbn4);
53 my $trial = C4::XISBN::_get_biblio_from_xisbn($isbn1);
54 is( $trial->{biblionumber},
55 $biblionumber1, "Gets biblionumber like the previous test." );
58 t::lib::Mocks::mock_preference( 'ThingISBN', 1 );
60 my $results_thingisbn;
61 eval { $results_thingisbn = C4::XISBN::get_xisbns($isbn1, $biblionumber4); };
63 skip "Problem retrieving ThingISBN", 1
65 ok( (any { $_->{'biblionumber'} eq $biblionumber1 } @$results_thingisbn),
66 "Gets correct biblionumber from a book with a similar isbn using ThingISBN." );
67 ok( (any { $_->{'biblionumber'} eq $biblionumber3 } @$results_thingisbn),
68 "Gets correct biblionumber from a book with a similar isbn using ThingISBN." );
71 eval { $results_thingisbn = C4::XISBN::get_xisbns($isbn1,$biblionumber1); };
73 skip "Problem retrieving ThingISBN", 1
75 is( $results_thingisbn->[0]->{biblionumber},
77 "Gets correct biblionumber from a different book with a similar isbn using ThingISBN." );
80 eval { $results_thingisbn = C4::XISBN::get_xisbns($isbn1,$biblionumber3); };
82 skip "Problem retrieving ThingISBN", 1
84 ok( (none { $_->{'biblionumber'} eq $biblionumber3 } @$results_thingisbn),
85 "Doesn't get biblionumber if the biblionumber matches the one passed to the sub." );
90 # Add new biblio with isbn and return biblionumber
91 sub _add_biblio_with_isbn {
94 my $marc_record = MARC::Record->new;
95 my $field = MARC::Field->new( $isbn_tag, '', '', $isbn_subfield => $isbn );
96 $marc_record->append_fields($field);
97 my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $marc_record, '' );
103 # Koha::SearchEngine::${SearchEngine}::Search::simple_search_compat
104 sub Mock_simple_search_compat {
110 my $ret_biblionumber;
111 if ( $query eq "nb=$isbn1" ) {
112 $ret_biblionumber = $biblionumber1;
114 elsif ( $query eq "nb=$isbn2" ) {
115 $ret_biblionumber = $biblionumber2;
117 elsif ( $query eq "nb=$isbn3" ) {
118 $ret_biblionumber = $biblionumber3;
121 my $record = MARC::Record->new;
122 $record->leader(' ngm a22 7a 4500');
123 my $biblionumber_field;
124 if ( $biblionumber_tag < 10 ) {
125 $biblionumber_field =
126 MARC::Field->new( $biblionumber_tag, $ret_biblionumber );
129 $biblionumber_field = MARC::Field->new( $biblionumber_tag, '', '',
130 $biblionumber_subfield => $ret_biblionumber );
132 $record->append_fields($biblionumber_field);
134 push @results, $record->as_xml();
136 return ( undef, \@results, 1 );