3 # This Koha test module is a stub!
4 # Add more tests here!!!
8 use Test::More tests => 5;
19 my $dbh = C4::Context->dbh;
20 $dbh->{RaiseError} = 1;
21 $dbh->{AutoCommit} = 0;
23 my $search_module = new Test::MockModule('C4::Search');
25 $search_module->mock('SimpleSearch', \&Mock_SimpleSearch );
27 my $context = C4::Context->new;
29 my ( $biblionumber_tag, $biblionumber_subfield ) =
30 GetMarcFromKohaField( 'biblio.biblionumber', '' );
31 my ( $isbn_tag, $isbn_subfield ) =
32 GetMarcFromKohaField( 'biblioitems.isbn', '' );
34 # Harry Potter and the Sorcerer's Stone, 1st American ed. 1997
35 my $isbn1 = '0590353403';
36 # ThingISBN match : Silent Wing, First Edition 1998
37 my $isbn2 = '0684843897';
38 # XISBN match : Harry Potter and the Philosopher's Stone, Magic ed. 2000
39 my $isbn3 = '1551923963';
41 my $biblionumber1 = _add_biblio_with_isbn($isbn1);
42 my $biblionumber2 = _add_biblio_with_isbn($isbn2);
43 my $biblionumber3 = _add_biblio_with_isbn($isbn3);
45 my $trial = C4::XISBN::get_biblionumber_from_isbn($isbn1);
46 is( $trial->[0]->{biblionumber},
48 "It gets the correct biblionumber from the only isbn we have added." );
50 $trial = C4::XISBN::_get_biblio_from_xisbn($isbn1);
51 is( $trial->{biblionumber},
52 $biblionumber1, "Gets biblionumber like the previous test." );
54 $context->set_preference( 'ThingISBN', 1 );
55 $context->set_preference( 'XISBN', 0 );
56 my $results_thingisbn = C4::XISBN::get_xisbns($isbn1);
57 is( $results_thingisbn->[0]->{biblionumber},
59 "Gets correct biblionumber from a book with a similar isbn using ThingISBN." );
61 $context->set_preference( 'ThingISBN', 0 );
62 $context->set_preference( 'XISBN', 1 );
63 my $results_xisbn = C4::XISBN::get_xisbns($isbn1);
64 is( $results_xisbn->[0]->{biblionumber},
66 "Gets correct biblionumber from a book with a similar isbn using XISBN." );
72 # Add new biblio with isbn and return biblionumber
73 sub _add_biblio_with_isbn {
76 my $marc_record = MARC::Record->new;
77 my $field = MARC::Field->new( $isbn_tag, '', '', $isbn_subfield => $isbn );
78 $marc_record->append_fields($field);
79 my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $marc_record, '' );
85 # C4::Search::SimpleSearch
86 sub Mock_SimpleSearch {
92 if ( $query =~ /$isbn1/ ) {
93 $ret_biblionumber = $biblionumber1;
95 elsif ( $query =~ /$isbn2/ ) {
96 $ret_biblionumber = $biblionumber2;
98 elsif ( $query =~ /$isbn3/ ) {
99 $ret_biblionumber = $biblionumber3;
102 my $record = MARC::Record->new;
103 $record->leader(' ngm a22 7a 4500');
104 my $biblionumber_field;
105 if ( $biblionumber_tag < 10 ) {
106 $biblionumber_field =
107 MARC::Field->new( $biblionumber_tag, $ret_biblionumber );
110 $biblionumber_field = MARC::Field->new( $biblionumber_tag, '', '',
111 $biblionumber_subfield => $ret_biblionumber );
113 $record->append_fields($biblionumber_field);
115 push @results, $record->as_usmarc;
116 return ( undef, \@results, 1 );