Bugzilla – Attachment 53454 Details for
Bug 16868
Silence error t/db_dependent/Linker_FirstMatch.t
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 16868: Silence error t/db_dependent/Linker_FirstMatch.t
Bug-16868-Silence-error-tdbdependentLinkerFirstMat.patch (text/plain), 6.44 KB, created by
Mark Tompsett
on 2016-07-16 15:04:04 UTC
(
hide
)
Description:
Bug 16868: Silence error t/db_dependent/Linker_FirstMatch.t
Filename:
MIME Type:
Creator:
Mark Tompsett
Created:
2016-07-16 15:04:04 UTC
Size:
6.44 KB
patch
obsolete
>From 2235030437e194899d4f2ae62538559a611705d0 Mon Sep 17 00:00:00 2001 >From: Mark Tompsett <mtompset@hotmail.com> >Date: Wed, 6 Jul 2016 21:37:21 -0400 >Subject: [PATCH] Bug 16868: Silence error t/db_dependent/Linker_FirstMatch.t > >When the auth_header table has records which exclude 1xx and >2xx tags, the $bibfield doesn't match anything. This in turn >sets it to undef, which triggers an error on the next line >killing the test. > >This was completely refactored to provide the data necessary >for the tests to pass, and to be more comprehensive (both MARC >and UNIMARC are tested). The tests are then run. > >TEST PLAN >--------- >1) back up DB >2) DELETE FROM auth_header; >3) SOURCE auth_header.sql; > -- the provided file >4) prove t/db_dependent/Linker_FirstMatch.t > -- should barf before running all the tests >5) apply all patches >6) prove t/db_dependent/Linker_FirstMatch.t > -- should work happy >7) run koha qa test tools >8) restore your backup >--- > t/db_dependent/Linker_FirstMatch.t | 135 ++++++++++++++++++++++++++++++------- > 1 file changed, 110 insertions(+), 25 deletions(-) > >diff --git a/t/db_dependent/Linker_FirstMatch.t b/t/db_dependent/Linker_FirstMatch.t >index 66c03ba..651a629 100755 >--- a/t/db_dependent/Linker_FirstMatch.t >+++ b/t/db_dependent/Linker_FirstMatch.t >@@ -1,31 +1,81 @@ > #!/usr/bin/perl > # >-# This Koha test module is a stub! >-# Add more tests here!!! >+# This file is part of Koha. >+# >+# Copyright (C) 2011 Jared Camins-Esakov <jcamins@cpbibliography.com> >+# Copyright (C) 2016 Mark Tompsett <mtompset@hotmail.com> >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. > >-use strict; >-use warnings; >+use Modern::Perl; > use Test::More tests => 3; >-use C4::Context; >-use C4::Heading; >+ > use MARC::Record; > use MARC::Field; >+use MARC::File::XML; >+use C4::Heading; > use C4::Linker::FirstMatch; >+use Test::MockModule; >+use t::lib::Database; >+use t::lib::Mocks qw( mock_preference ); >+use t::lib::TestBuilder; > > > BEGIN { > use_ok('C4::Linker'); > } >-my $dbh = C4::Context->dbh; >- >-my $query = "SELECT authid, marc FROM auth_header LIMIT 1;"; >-my $sth = $dbh->prepare($query); >-$sth->execute(); >-my ($authid, $marc) = $sth->fetchrow_array(); >-SKIP: { >- skip "No authorities", 2 unless defined $authid; >- my $linker = C4::Linker::FirstMatch->new(); >- my $auth = MARC::Record->new_from_usmarc($marc); >+ >+# This will make DBI and DBIx play friendly, >+# plus roll back automatically. >+my $dbh = t::lib::Database->dbh; >+ >+# Set up just a single authority record to find and use. >+my $builder = t::lib::TestBuilder->new(); >+$builder->delete({ source => 'AuthHeader' }); >+ >+my $auth_header = $builder->build({ >+ source => 'AuthHeader' >+}); >+my $authid = $auth_header->{authid}; >+ >+# Mock C4::Heading->authorities() so tests will all pass. >+my $mock_heading = Test::MockModule->new('C4::Heading'); >+$mock_heading->mock( authorities => sub { return [{ authid => $authid }]; } ); >+ >+# Run tests for both logic cases (UNIMARC / non-UNIMARC) >+subtest 'MARC21' => sub { >+ plan tests => 2; >+ t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); >+ run_tests(); >+}; >+ >+subtest 'UNIMARC' => sub { >+ plan tests => 2; >+ t::lib::Mocks::mock_preference('marcflavour', 'UNIMARC'); >+ run_tests(); >+}; >+ >+sub run_tests { >+ >+ # Set the data up to match nicely. >+ my $fake_xml = generateFakeMarcXML($authid); >+ my $auth = MARC::File::XML->decode( $fake_xml ); >+ my $fake_marc = $auth->as_usmarc(); >+ my $sth = $dbh->prepare( q{UPDATE auth_header SET marc=?,marcxml=? WHERE authid=?} ); >+ $sth->execute( $fake_marc, $fake_xml, $authid ); >+ >+ # Find a particular series field. > my $fieldmatch; > if (C4::Context->preference('MARCFlavour') eq 'UNIMARC') { > $fieldmatch = '2..'; >@@ -33,20 +83,55 @@ SKIP: { > $fieldmatch = '1..'; > } > my $bibfield = $auth->field($fieldmatch); >+ >+ # Convert it to a 6xx series field. > my $tag = $bibfield->tag(); >- $tag =~ s/^./6/; >- $bibfield->update(tag => $tag); >- my $heading; >- ok(defined ($heading = C4::Heading->new_from_bib_field($bibfield, '')), "Creating heading from bib field"); >+ my $new_tag = $tag; >+ $new_tag =~ s/^./6/; >+ my @subfields = $bibfield->subfields(); >+ my $new_bibfield = MARC::Field->new($new_tag,$bibfield->indicator(1),$bibfield->indicator(2),@subfields); > >- # If Zebra is not running, or authorities have not been indexed, test 3 >- # will fail. Skip it if we are unable to retrieve a list of headings from >- # Zebra. >- my @authids = $heading->authorities(1); >- skip "Unable to search Zebra", 1 unless $#authids > 0; >+ # Can we build a heading from it? >+ my $heading; >+ ok(defined ($heading = C4::Heading->new_from_bib_field($new_bibfield, '')), "Creating heading from bib field"); > >+ # Now test to see if C4::Linker can find it. > my $authmatch; > my $fuzzy; >+ my $linker = C4::Linker::FirstMatch->new(); > ($authmatch, $fuzzy) = $linker->get_link($heading); > is($authmatch, $authid, "Matched existing heading"); >+ return; >+} >+ >+sub generateFakeMarcXML { >+ my ($auth_id) = @_; >+ my $marc_xml; >+ >+ $marc_xml = << 'BLOCK'; >+<?xml version="1.0" encoding="UTF-8"?> >+<record >+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >+ xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd" >+ xmlns="http://www.loc.gov/MARC21/slim"> >+ >+ <leader>01954cz a2200289n 4500</leader> >+ <controlfield tag="001"> >+BLOCK >+ $marc_xml .= $auth_id . "</controlfield>\n"; >+ if (C4::Context->preference('MARCFlavour') eq 'UNIMARC') { >+ $marc_xml .= ' <datafield tag="200" ind1="1" ind2=" ">'; >+ } else { >+ $marc_xml .= ' <datafield tag="100" ind1="1" ind2=" ">'; >+ } >+ >+ $marc_xml .= "\n"; >+ $marc_xml .= << 'DATA'; >+ <subfield code="a">Geisel, Theodor Seuss,</subfield> >+ <subfield code="d">1904-1991</subfield> >+ </datafield> >+DATA >+ >+ $marc_xml .= "</record>\n"; >+ return $marc_xml; > } >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 16868
:
53154
|
53155
|
53411
|
53451
|
53452
|
53453
|
53454
|
53455
|
53549
|
53729
|
53880