3 # This Koha test module is a stub!
4 # Add more tests here!!!
8 use Test
::More tests
=> 5;
21 my $dbh = C4
::Context
->dbh;
22 $dbh->{RaiseError
} = 1;
23 $dbh->{AutoCommit
} = 0;
25 my $search_module = new Test
::MockModule
('C4::Search');
27 $search_module->mock('SimpleSearch', \
&Mock_SimpleSearch
);
29 my $context = C4
::Context
->new;
31 my ( $biblionumber_tag, $biblionumber_subfield ) =
32 GetMarcFromKohaField
( 'biblio.biblionumber', '' );
33 my ( $isbn_tag, $isbn_subfield ) =
34 GetMarcFromKohaField
( 'biblioitems.isbn', '' );
36 # Harry Potter and the Sorcerer's Stone, 1st American ed. 1997
37 my $isbn1 = '0590353403';
38 # ThingISBN match : Silent Wing, First Edition 1998
39 my $isbn2 = '0684843897';
40 # XISBN match : Harry Potter and the Sorcerer's Stone,
41 # 1. Scholastic mass market paperback printing1.
42 my $isbn3 = '043936213X';
44 my $biblionumber1 = _add_biblio_with_isbn
($isbn1);
45 my $biblionumber2 = _add_biblio_with_isbn
($isbn2);
46 my $biblionumber3 = _add_biblio_with_isbn
($isbn3);
48 my $trial = C4
::XISBN
::get_biblionumber_from_isbn
($isbn1);
49 is
( $trial->[0]->{biblionumber
},
51 "It gets the correct biblionumber from the only isbn we have added." );
53 $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 );
59 t
::lib
::Mocks
::mock_preference
( 'XISBN', 0 );
61 my $results_thingisbn;
62 eval { $results_thingisbn = C4
::XISBN
::get_xisbns
($isbn1); };
64 skip
"Problem retrieving ThingISBN", 1
66 is
( $results_thingisbn->[0]->{biblionumber
},
68 "Gets correct biblionumber from a book with a similar isbn using ThingISBN." );
72 t
::lib
::Mocks
::mock_preference
( 'ThingISBN', 0 );
73 t
::lib
::Mocks
::mock_preference
( 'XISBN', 1 );
76 eval { $results_xisbn = C4
::XISBN
::get_xisbns
($isbn1); };
78 skip
"Problem retrieving XISBN", 1
80 is
( $results_xisbn->[0]->{biblionumber
},
82 "Gets correct biblionumber from a book with a similar isbn using XISBN." );
89 # Add new biblio with isbn and return biblionumber
90 sub _add_biblio_with_isbn
{
93 my $marc_record = MARC
::Record
->new;
94 my $field = MARC
::Field
->new( $isbn_tag, '', '', $isbn_subfield => $isbn );
95 $marc_record->append_fields($field);
96 my ( $biblionumber, $biblioitemnumber ) = AddBiblio
( $marc_record, '' );
102 # C4::Search::SimpleSearch
103 sub Mock_SimpleSearch
{
108 my $ret_biblionumber;
109 if ( $query =~ /$isbn1/ ) {
110 $ret_biblionumber = $biblionumber1;
112 elsif ( $query =~ /$isbn2/ ) {
113 $ret_biblionumber = $biblionumber2;
115 elsif ( $query =~ /$isbn3/ ) {
116 $ret_biblionumber = $biblionumber3;
119 my $record = MARC
::Record
->new;
120 $record->leader(' ngm a22 7a 4500');
121 my $biblionumber_field;
122 if ( $biblionumber_tag < 10 ) {
123 $biblionumber_field =
124 MARC
::Field
->new( $biblionumber_tag, $ret_biblionumber );
127 $biblionumber_field = MARC
::Field
->new( $biblionumber_tag, '', '',
128 $biblionumber_subfield => $ret_biblionumber );
130 $record->append_fields($biblionumber_field);
132 my $indexing_mode = C4
::Context
->config('zebra_bib_index_mode') // 'dom';
133 push @results, ( $indexing_mode eq 'dom' )
135 : $record->as_usmarc() ;
137 return ( undef, \
@results, 1 );