View | Details | Raw Unified | Return to bug 9728
Collapse All | Expand All

(-)a/C4/XISBN.pm (-1 / +1 lines)
Lines 64-70 sub _get_biblio_from_xisbn { Link Here
64
    my $xisbn = shift;
64
    my $xisbn = shift;
65
    my $dbh = C4::Context->dbh;
65
    my $dbh = C4::Context->dbh;
66
66
67
    my ( $errors, $results, $total_hits ) = SimpleSearch( "nb=$xisbn", 0, 1 );
67
    my ( $errors, $results, $total_hits ) = C4::Search::SimpleSearch( "nb=$xisbn", 0, 1 );
68
    return unless ( !$errors && scalar @$results );
68
    return unless ( !$errors && scalar @$results );
69
69
70
    my $record = MARC::Record::new_from_usmarc( $results->[0] );
70
    my $record = MARC::Record::new_from_usmarc( $results->[0] );
(-)a/t/db_dependent/XISBN.t (-27 / +95 lines)
Lines 1-12 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
#
2
#
3
# This Koha test module is a stub!  
3
# This Koha test module is a stub!
4
# Add more tests here!!!
4
# Add more tests here!!!
5
5
6
use strict;
6
use Modern::Perl;
7
use warnings;
7
8
# use Test::Class::Load qw ( t/db_dependent/ );
8
# use Test::Class::Load qw ( t/db_dependent/ );
9
use Test::More tests => 4;
9
use Test::More tests => 5;
10
use MARC::Record;
10
use MARC::Record;
11
use C4::Biblio;
11
use C4::Biblio;
12
use C4::XISBN;
12
use C4::XISBN;
Lines 14-51 use Data::Dumper; Link Here
14
use C4::Context;
14
use C4::Context;
15
15
16
BEGIN {
16
BEGIN {
17
	use_ok('C4::XISBN');
17
    use_ok('C4::XISBN');
18
}
18
}
19
19
20
# Avoid "redefined subroutine" warnings
21
local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
22
*C4::Search::SimpleSearch = \&Mock_SimpleSearch;
23
20
# KohaTest::clear_test_database();
24
# KohaTest::clear_test_database();
21
# KohaTest::create_test_database();
25
# KohaTest::create_test_database();
22
26
23
my $isbn = '0590353403';
27
my $context = C4::Context->new;
24
my $isbn2 = '0684843897';
28
29
my ( $biblionumber_tag, $biblionumber_subfield ) =
30
  GetMarcFromKohaField( 'biblio.biblionumber', '' );
31
my ( $isbn_tag, $isbn_subfield ) =
32
  GetMarcFromKohaField( 'biblioitems.isbn', '' );
25
33
26
my $marc_record=MARC::Record->new;
34
# Harry Potter and the Sorcerer's Stone, 1st American ed. 1997
27
my $field = MARC::Field->new('020','','','a' => $isbn);
35
my $isbn1 = '0590353403';
28
$marc_record->append_fields($field);
36
# ThingISBN match : Silent Wing, First Edition 1998
29
my($biblionumber,$biblioitemnumber) = AddBiblio($marc_record,'');
37
my $isbn2 = '0684843897';
38
# XISBN match : Harry Potter and the Philosopher's Stone, Magic ed. 2000
39
my $isbn3 = '1551923963';
30
40
31
my $marc_record=MARC::Record->new;
41
my $biblionumber1 = _add_biblio_with_isbn($isbn1);
32
my $field = MARC::Field->new('020','','','a' => $isbn2);
42
my $biblionumber2 = _add_biblio_with_isbn($isbn2);
33
$marc_record->append_fields($field);
43
my $biblionumber3 = _add_biblio_with_isbn($isbn3);
34
my($biblionumber2,$biblioitemnumber2) = AddBiblio($marc_record,'');
35
44
45
my $trial = C4::XISBN::get_biblionumber_from_isbn($isbn1);
46
is( $trial->[0]->{biblionumber},
47
    $biblionumber1,
48
    "It gets the correct biblionumber from the only isbn we have added." );
36
49
37
my $trial = C4::XISBN::get_biblionumber_from_isbn($isbn);
50
$trial = C4::XISBN::_get_biblio_from_xisbn($isbn1);
38
is($trial->[0]->{biblionumber},$biblionumber,"It gets the correct biblionumber from the only isbn we have added.");
51
is( $trial->{biblionumber},
52
    $biblionumber1, "Gets biblionumber like the previous test." );
39
53
40
$trial = C4::XISBN::_get_biblio_from_xisbn($isbn);
54
$context->set_preference( 'ThingISBN', 1 );
41
is($trial->{biblionumber},$biblionumber,"Gets biblionumber like the previous test.");
55
$context->set_preference( 'XISBN', 0 );
56
my $results_thingisbn = C4::XISBN::get_xisbns($isbn1);
57
is( $results_thingisbn->[0]->{biblionumber},
58
    $biblionumber2,
59
    "Gets correct biblionumber from a book with a similar isbn using ThingISBN." );
42
60
43
my $context = C4::Context->new();
61
$context->set_preference( 'ThingISBN', 0 );
44
$context->set_preference('ThingISBN','on');
62
$context->set_preference( 'XISBN', 1 );
45
diag C4::Context::preference('ThingISBN');
63
my $results_xisbn = C4::XISBN::get_xisbns($isbn1);
46
my $var = C4::XISBN::get_xisbns($isbn);
64
is( $results_xisbn->[0]->{biblionumber},
47
is($var->[0]->{biblionumber},$biblionumber2,"Gets correct biblionumber from a book with a similar isbn.");
65
    $biblionumber3,
66
    "Gets correct biblionumber from a book with a similar isbn using XISBN." );
48
67
49
# clean up after ourselves
68
# clean up after ourselves
50
DelBiblio($biblionumber);
69
DelBiblio($biblionumber1);
51
DelBiblio($biblionumber2);
70
DelBiblio($biblionumber2);
71
DelBiblio($biblionumber3);
72
73
# Util subs
74
75
# Add new biblio with isbn and return biblionumber
76
sub _add_biblio_with_isbn {
77
    my $isbn = shift;
78
79
    my $marc_record = MARC::Record->new;
80
    my $field = MARC::Field->new( $isbn_tag, '', '', $isbn_subfield => $isbn );
81
    $marc_record->append_fields($field);
82
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $marc_record, '' );
83
    return $biblionumber;
84
}
85
86
# Mocked subs
87
88
# C4::Search::SimpleSearch
89
sub Mock_SimpleSearch {
90
    my $query = shift;
91
    my @results;
92
93
    $query =~ s/-//g;
94
    my $ret_biblionumber;
95
    if ( $query =~ /$isbn1/ ) {
96
        $ret_biblionumber = $biblionumber1;
97
    }
98
    elsif ( $query =~ /$isbn2/ ) {
99
        $ret_biblionumber = $biblionumber2;
100
    }
101
    elsif ( $query =~ /$isbn3/ ) {
102
        $ret_biblionumber = $biblionumber3;
103
    }
104
105
    my $record = MARC::Record->new;
106
    $record->leader('     ngm a22     7a 4500');
107
    my $biblionumber_field;
108
    if ( $biblionumber_tag < 10 ) {
109
        $biblionumber_field =
110
          MARC::Field->new( $biblionumber_tag, $ret_biblionumber );
111
    }
112
    else {
113
        $biblionumber_field = MARC::Field->new( $biblionumber_tag, '', '',
114
            $biblionumber_subfield => $ret_biblionumber );
115
    }
116
    $record->append_fields($biblionumber_field);
117
118
    push @results, $record->as_usmarc;
119
    return ( undef, \@results, 1 );
120
}
52
- 

Return to bug 9728