Merge remote branch 'kc/new/bug_5586' into kcmaster
[koha.git] / t / db_dependent / XISBN.t
1 #!/usr/bin/perl
2 #
3 # This Koha test module is a stub!  
4 # Add more tests here!!!
5
6 use strict;
7 use warnings;
8 # use Test::Class::Load qw ( t/db_dependent/ );
9 use Test::More tests => 4;
10 use MARC::Record;
11 use C4::Biblio;
12 use C4::XISBN;
13 use Data::Dumper;
14 use C4::Context;
15
16 BEGIN {
17         use_ok('C4::XISBN');
18 }
19
20 # KohaTest::clear_test_database();
21 # KohaTest::create_test_database();
22
23 my $isbn = '0590353403';
24 my $isbn2 = '0747554560';
25
26 my $marc_record=MARC::Record->new;
27 my $field = MARC::Field->new('020','','','a' => $isbn);
28 $marc_record->append_fields($field);
29 my($biblionumber,$biblioitemnumber) = AddBiblio($marc_record,'');
30
31 my $marc_record=MARC::Record->new;
32 my $field = MARC::Field->new('020','','','a' => $isbn2);
33 $marc_record->append_fields($field);
34 my($biblionumber2,$biblioitemnumber2) = AddBiblio($marc_record,'');
35
36
37 my $trial = C4::XISBN::get_biblionumber_from_isbn($isbn);
38 is($trial->[0]->{biblionumber},$biblionumber,"It gets the correct biblionumber from the only isbn we have added.");
39
40 $trial = C4::XISBN::_get_biblio_from_xisbn($isbn);
41 is($trial->{biblionumber},$biblionumber,"Gets biblionumber like the previous test.");
42
43 my $context = C4::Context->new();
44 $context->set_preference('ThingISBN','on');
45 diag C4::Context::preference('ThingISBN');
46 my $var = C4::XISBN::get_xisbns($isbn);
47 is($var->[0]->{biblionumber},$biblionumber2,"Gets correct biblionumber from a book with a similar isbn.");
48
49 # clean up after ourselves
50 DelBiblio($biblionumber);
51 DelBiblio($biblionumber2);