Bug 15764: Fix timestamp sent by KOCT
[koha.git] / t / db_dependent / Linker_FirstMatch.t
blob66c03ba258129cab680cd8b5126aeb7bef801c55
1 #!/usr/bin/perl
3 # This Koha test module is a stub!
4 # Add more tests here!!!
6 use strict;
7 use warnings;
8 use Test::More tests => 3;
9 use C4::Context;
10 use C4::Heading;
11 use MARC::Record;
12 use MARC::Field;
13 use C4::Linker::FirstMatch;
16 BEGIN {
17 use_ok('C4::Linker');
19 my $dbh = C4::Context->dbh;
21 my $query = "SELECT authid, marc FROM auth_header LIMIT 1;";
22 my $sth = $dbh->prepare($query);
23 $sth->execute();
24 my ($authid, $marc) = $sth->fetchrow_array();
25 SKIP: {
26 skip "No authorities", 2 unless defined $authid;
27 my $linker = C4::Linker::FirstMatch->new();
28 my $auth = MARC::Record->new_from_usmarc($marc);
29 my $fieldmatch;
30 if (C4::Context->preference('MARCFlavour') eq 'UNIMARC') {
31 $fieldmatch = '2..';
32 } else {
33 $fieldmatch = '1..';
35 my $bibfield = $auth->field($fieldmatch);
36 my $tag = $bibfield->tag();
37 $tag =~ s/^./6/;
38 $bibfield->update(tag => $tag);
39 my $heading;
40 ok(defined ($heading = C4::Heading->new_from_bib_field($bibfield, '')), "Creating heading from bib field");
42 # If Zebra is not running, or authorities have not been indexed, test 3
43 # will fail. Skip it if we are unable to retrieve a list of headings from
44 # Zebra.
45 my @authids = $heading->authorities(1);
46 skip "Unable to search Zebra", 1 unless $#authids > 0;
48 my $authmatch;
49 my $fuzzy;
50 ($authmatch, $fuzzy) = $linker->get_link($heading);
51 is($authmatch, $authid, "Matched existing heading");