Bug 26214: Remove the use of jquery.checkboxes plugin on late orders page
[koha.git] / t / db_dependent / XISBN.t
blob4cc939d28acd4ae6efd75238e5e1840618a95100
1 #!/usr/bin/perl
3 # This Koha test module is a stub!
4 # Add more tests here!!!
6 use Modern::Perl;
8 use Test::More tests => 5;
9 use MARC::Record;
10 use C4::Biblio;
11 use C4::XISBN;
12 use C4::Context;
13 use C4::Search;
14 use Koha::Database;
15 use t::lib::Mocks;
16 use Test::MockModule;
18 BEGIN {
19 use_ok('C4::XISBN');
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." );
53 ## Test ThingISBN
54 t::lib::Mocks::mock_preference( 'ThingISBN', 1 );
56 my $results_thingisbn;
57 eval { $results_thingisbn = C4::XISBN::get_xisbns($isbn1); };
58 SKIP: {
59 skip "Problem retrieving ThingISBN", 1
60 unless $@ eq '';
61 is( $results_thingisbn->[0]->{biblionumber},
62 $biblionumber3,
63 "Gets correct biblionumber from a book with a similar isbn using ThingISBN." );
66 eval { $results_thingisbn = C4::XISBN::get_xisbns($isbn1,$biblionumber1); };
67 SKIP: {
68 skip "Problem retrieving ThingISBN", 1
69 unless $@ eq '';
70 is( $results_thingisbn->[0]->{biblionumber},
71 $biblionumber3,
72 "Gets correct biblionumber from a different book with a similar isbn using ThingISBN." );
75 eval { $results_thingisbn = C4::XISBN::get_xisbns($isbn1,$biblionumber3); };
76 SKIP: {
77 skip "Problem retrieving ThingISBN", 1
78 unless $@ eq '';
79 is( $results_thingisbn->[0]->{biblionumber},
80 undef,
81 "Doesn't get biblionumber if the biblionumber matches the one passed to the sub." );
84 # Util subs
86 # Add new biblio with isbn and return biblionumber
87 sub _add_biblio_with_isbn {
88 my $isbn = shift;
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, '' );
94 return $biblionumber;
97 # Mocked subs
99 # Koha::SearchEngine::${SearchEngine}::Search::simple_search_compat
100 sub Mock_simple_search_compat {
101 my $self = shift;
102 my $query = shift;
103 my @results;
105 $query =~ s/-//g;
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 );
124 else {
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 );