Bugzilla – Attachment 11465 Details for
Bug 7417
Include alternate forms from authorities in bibliographic searches
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[SIGNED-OFF] Bug 7417 follow-up: incorporate QA comments
SIGNED-OFF-Bug-7417-follow-up-incorporate-QA-comme.patch (text/plain), 30.79 KB, created by
Katrin Fischer
on 2012-08-09 04:46:33 UTC
(
hide
)
Description:
[SIGNED-OFF] Bug 7417 follow-up: incorporate QA comments
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2012-08-09 04:46:33 UTC
Size:
30.79 KB
patch
obsolete
>From 6b043581c7b75830a62e8aefc622ece5fd91ca2a Mon Sep 17 00:00:00 2001 >From: Jared Camins-Esakov <jcamins@cpbibliography.com> >Date: Mon, 6 Aug 2012 15:10:15 -0400 >Subject: [PATCH] [SIGNED-OFF] Bug 7417 follow-up: incorporate QA comments > >This patch incorporates the following QA comments: >* Renames Koha::Authority to Koha::DataObject::Authority >* Uses Modern::Perl instead of 'use strict; use warnings;' >* perltidied all new files again >* wrote an intelligent constructor for Koha::DataObject::Authority which > takes a hash with the construction criteria >* added rudimentary error handling in C4::AuthoritiesMarc::GetAuthority >* added missing t/AuthoritiesMarc.t > >This patch also improves test coverage, and eliminates the need for a >database to test the EmbedSeeFromHeadings RecordProcessor plugin. > >In order to make the Koha codebase more consistent, this patch switches >the RecordProcessor and Koha::DataObject::Authority code to use the >Moose-like syntax supported by Class::Accessor. > >Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de> >Follow up passes test plan. >--- > C4/AuthoritiesMarc.pm | 7 +- > Koha/Authority.pm | 92 -------------- > Koha/DataObject/Authority.pm | 102 ++++++++++++++++ > Koha/Filter/MARC/EmbedSeeFromHeadings.pm | 41 ++++--- > Koha/Filter/MARC/Null.pm | 8 +- > Koha/RecordProcessor.pm | 47 +++++--- > Koha/RecordProcessor/Base.pm | 26 ++-- > t/AuthoritiesMarc.t | 31 ++++- > t/RecordProcessor.t | 61 ++++++---- > t/RecordProcessor_EmbedSeeFromHeadings.t | 127 ++++++++++++++++++++ > t/db_dependent/Koha_Authority.t | 40 +++--- > .../RecordProcessor_EmbedSeeFromHeadings.t | 66 ---------- > 12 files changed, 383 insertions(+), 265 deletions(-) > delete mode 100644 Koha/Authority.pm > create mode 100644 Koha/DataObject/Authority.pm > create mode 100755 t/RecordProcessor_EmbedSeeFromHeadings.t > delete mode 100755 t/db_dependent/RecordProcessor_EmbedSeeFromHeadings.t > >diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm >index c533ad0..14cfb02 100644 >--- a/C4/AuthoritiesMarc.pm >+++ b/C4/AuthoritiesMarc.pm >@@ -26,7 +26,7 @@ use C4::AuthoritiesMarc::MARC21; > use C4::AuthoritiesMarc::UNIMARC; > use C4::Charset; > use C4::Log; >-use Koha::Authority; >+use Koha::DataObject::Authority; > > use vars qw($VERSION @ISA @EXPORT); > >@@ -849,8 +849,9 @@ Returns MARC::Record of the authority passed in parameter. > > sub GetAuthority { > my ($authid)=@_; >- my $authority = Koha::Authority->get_from_authid($authid); >- return ($authority->record); >+ my $authority = Koha::DataObject::Authority->new( { authid => $authid } ); >+ return unless $authority; >+ return ($authority->marcrecord); > } > > =head2 GetAuthType >diff --git a/Koha/Authority.pm b/Koha/Authority.pm >deleted file mode 100644 >index b64f8de..0000000 >--- a/Koha/Authority.pm >+++ /dev/null >@@ -1,92 +0,0 @@ >-package Koha::Authority; >- >-# Copyright 2012 C & P Bibliography Services >-# >-# This file is part of Koha. >-# >-# 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 2 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, write to the Free Software Foundation, Inc., >-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >- >-=head1 NAME >- >-Koha::Authority - class to encapsulate authority records in Koha >- >-=head1 SYNOPSIS >- >-Object-oriented class that encapsulates authority records in Koha. >- >-=head1 DESCRIPTION >- >-Authority data. >- >-=cut >- >-use strict; >-use warnings; >-use C4::Context; >-use MARC::Record; >-use MARC::File::XML; >-use C4::Charset; >- >-use base qw(Class::Accessor); >- >-__PACKAGE__->mk_accessors(qw( authid authtype record marcflavour )); >- >-=head2 new >- >- my $auth = Koha::Authority->new($record); >- >-Create a new Koha::Authority object based on the provided record. >- >-=cut >-sub new { >- my $class = shift; >- my $record = shift; >- >- my $self = $class->SUPER::new( { record => $record }); >- >- bless $self, $class; >- return $self; >-} >- >-=head2 get_from_authid >- >- my $auth = Koha::Authority->get_from_authid($authid); >- >-Create the Koha::Authority object associated with the provided authid. >- >-=cut >-sub get_from_authid { >- my $class = shift; >- my $authid = shift; >- my $marcflavour = C4::Context->preference("marcflavour"); >- >- my $dbh=C4::Context->dbh; >- my $sth=$dbh->prepare("select authtypecode, marcxml from auth_header where authid=?"); >- $sth->execute($authid); >- my ($authtypecode, $marcxml) = $sth->fetchrow; >- my $record=eval {MARC::Record->new_from_xml(StripNonXmlChars($marcxml),'UTF-8', >- (C4::Context->preference("marcflavour") eq "UNIMARC"?"UNIMARCAUTH":C4::Context->preference("marcflavour")))}; >- return undef if ($@); >- $record->encoding('UTF-8'); >- >- my $self = $class->SUPER::new( { authid => $authid, >- marcflavour => $marcflavour, >- authtype => $authtypecode, >- record => $record }); >- >- bless $self, $class; >- return $self; >-} >- >-1; >diff --git a/Koha/DataObject/Authority.pm b/Koha/DataObject/Authority.pm >new file mode 100644 >index 0000000..9a349aa >--- /dev/null >+++ b/Koha/DataObject/Authority.pm >@@ -0,0 +1,102 @@ >+package Koha::DataObject::Authority; >+ >+# Copyright 2012 C & P Bibliography Services >+# >+# This file is part of Koha. >+# >+# 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 2 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, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+=head1 NAME >+ >+Koha::DataObject::Authority - class to encapsulate authority records in Koha >+ >+=head1 SYNOPSIS >+ >+Object-oriented class that encapsulates authority records in Koha. >+ >+=head1 DESCRIPTION >+ >+Authority data. >+ >+=cut >+ >+use Modern::Perl; >+use C4::Context; >+use MARC::Record; >+use MARC::File::XML; >+use C4::Charset; >+use Class::Accessor "antlers"; >+ >+has authid => ( is => 'rw' ); >+has authtype => ( is => 'rw' ); >+has marcrecord => ( is => 'rw' ); >+has marcflavour => ( is => 'rw' ); >+ >+=head2 new >+ >+ my $auth = Koha::DataObject::Authority->new($args); >+ >+Create a new Koha::DataObject::Authority object based on the criteria in >+the provided hashref. If $args->{marcrecord} contains a MARC::Record >+object, create the Authority object based on that. If $args->{authid} >+is set, retrieve the authority with the specified authid. >+ >+=cut >+ >+sub new { >+ my $class = shift; >+ my $args = shift; >+ >+ my $self = $class->SUPER::new(); >+ if ( defined $args->{'marcrecord'} >+ && ref $args->{'marcrecord'} eq 'MARC::Record' ) >+ { >+ $self = $class->SUPER::new( { marcrecord => $args->{'marcrecord'} } ); >+ } >+ elsif ( defined $args->{'authid'} ) { >+ my $marcflavour = C4::Context->preference("marcflavour"); >+ my $dbh = C4::Context->dbh; >+ my $sth = $dbh->prepare( >+ "select authtypecode, marcxml from auth_header where authid=?"); >+ $sth->execute( $args->{'authid'} ); >+ my ( $authtypecode, $marcxml ) = $sth->fetchrow; >+ my $record = eval { >+ MARC::Record->new_from_xml( >+ StripNonXmlChars($marcxml), >+ 'UTF-8', >+ ( >+ C4::Context->preference("marcflavour") eq "UNIMARC" >+ ? "UNIMARCAUTH" >+ : C4::Context->preference("marcflavour") >+ ) >+ ); >+ }; >+ return if ($@); >+ $record->encoding('UTF-8'); >+ >+ $self = $class->SUPER::new( >+ { >+ authid => $args->{'authid'}, >+ marcflavour => $marcflavour, >+ authtype => $authtypecode, >+ marcrecord => $record >+ } >+ ); >+ } >+ >+ bless $self, $class; >+ return $self; >+} >+ >+1; >diff --git a/Koha/Filter/MARC/EmbedSeeFromHeadings.pm b/Koha/Filter/MARC/EmbedSeeFromHeadings.pm >index ea7e38b..52f8912 100644 >--- a/Koha/Filter/MARC/EmbedSeeFromHeadings.pm >+++ b/Koha/Filter/MARC/EmbedSeeFromHeadings.pm >@@ -30,13 +30,12 @@ Filter to embed see from headings into MARC records. > > =cut > >-use strict; >-use warnings; >+use Modern::Perl; > use Carp; >-use Koha::Authority; >+use Koha::DataObject::Authority; > > use base qw(Koha::RecordProcessor::Base); >-our $NAME = 'EmbedSeeFromHeadings'; >+our $NAME = 'EmbedSeeFromHeadings'; > our $VERSION = '1.0'; > > =head2 filter >@@ -49,20 +48,22 @@ In order to differentiate added headings from actual headings, a 'z' is > put in the first indicator. > > =cut >+ > sub filter { >- my $self = shift; >+ my $self = shift; > my $record = shift; > my $newrecord; > >- return undef unless defined $record; >+ return unless defined $record; > >- if (ref $record eq 'ARRAY') { >+ if ( ref $record eq 'ARRAY' ) { > my @recarray; > foreach my $thisrec (@$record) { > push @recarray, _processrecord($thisrec); > } > $newrecord = \@recarray; >- } elsif (ref $record eq 'MARC::Record') { >+ } >+ elsif ( ref $record eq 'MARC::Record' ) { > $newrecord = _processrecord($record); > } > >@@ -78,23 +79,25 @@ sub _processrecord { > > next unless $authid; > >- my $authority = Koha::Authority->get_from_authid($authid); >+ my $authority = >+ Koha::DataObject::Authority->new( { authid => $authid } ); > next unless $authority; >- my $auth_marc = $authority->record; >- my @seefrom = $auth_marc->field('4..'); >+ my $auth_marc = $authority->marcrecord; >+ my @seefrom = $auth_marc->field('4..'); > my @newfields; > foreach my $authfield (@seefrom) { >- my $tag = substr($field->tag(), 0, 1) . substr($authfield->tag(), 1, 2); >- my $newfield = MARC::Field->new($tag, >- 'z', >- $authfield->indicator(2) || ' ', >- '9' => '1'); >- foreach my $sub ($authfield->subfields()) { >- my ($code,$val) = @$sub; >+ my $tag = >+ substr( $field->tag(), 0, 1 ) . substr( $authfield->tag(), 1, 2 ); >+ my $newfield = >+ MARC::Field->new( $tag, 'z', $authfield->indicator(2) || ' ', >+ '9' => '1' ); >+ foreach my $sub ( $authfield->subfields() ) { >+ my ( $code, $val ) = @$sub; > $newfield->add_subfields( $code => $val ); > } > $newfield->delete_subfield( code => '9' ); >- push @newfields, $newfield if (scalar($newfield->subfields()) > 0); >+ push @newfields, $newfield >+ if ( scalar( $newfield->subfields() ) > 0 ); > } > $record->append_fields(@newfields); > } >diff --git a/Koha/Filter/MARC/Null.pm b/Koha/Filter/MARC/Null.pm >index 578781c..46fd30e 100644 >--- a/Koha/Filter/MARC/Null.pm >+++ b/Koha/Filter/MARC/Null.pm >@@ -31,12 +31,11 @@ RecordProcessor. > > =cut > >-use strict; >-use warnings; >+use Modern::Perl; > use Carp; > > use base qw(Koha::RecordProcessor::Base); >-our $NAME = 'Null'; >+our $NAME = 'Null'; > our $VERSION = '1.0'; > > =head2 filter >@@ -47,8 +46,9 @@ our $VERSION = '1.0'; > Return the original record. > > =cut >+ > sub filter { >- my $self = shift; >+ my $self = shift; > my $record = shift; > > return $record; >diff --git a/Koha/RecordProcessor.pm b/Koha/RecordProcessor.pm >index 3d4e1bf..3a30481 100644 >--- a/Koha/RecordProcessor.pm >+++ b/Koha/RecordProcessor.pm >@@ -57,14 +57,15 @@ clone it I<prior> to passing it off to the RecordProcessor. > > =cut > >-use strict; >-use warnings; >+use Modern::Perl; >+use Class::Accessor "antlers"; > use Module::Load::Conditional qw(can_load); > use Module::Pluggable::Object; > >-use base qw(Class::Accessor); >- >-__PACKAGE__->mk_accessors(qw( schema filters options record )); >+has schema => ( is => "rw" ); >+has filters => ( is => "rw" ); >+has options => ( is => "rw" ); >+has record => ( is => "rw" ); > > =head2 new > >@@ -89,28 +90,33 @@ Koha::Filter::${schema} namespace, as only the filter name, and > =back > > =cut >+ > sub new { > my $class = shift; > my $param = shift; > >- >- my $schema = $param->{schema} || 'MARC'; >+ my $schema = $param->{schema} || 'MARC'; > my $options = $param->{options} || ''; >- my @filters = ( ); >+ my @filters = (); > >- foreach my $filter ($param->{filters}) { >+ foreach my $filter ( $param->{filters} ) { > next unless $filter; >- my $filter_module = $filter =~ m/:/ ? $filter : "Koha::Filter::${schema}::${filter}"; >- if (can_load( modules => { $filter_module => undef } )) { >+ my $filter_module = >+ $filter =~ m/:/ ? $filter : "Koha::Filter::${schema}::${filter}"; >+ if ( can_load( modules => { $filter_module => undef } ) ) { > my $object = $filter_module->new(); > $filter_module->initialize($param); > push @filters, $object; > } > } > >- my $self = $class->SUPER::new( { schema => $schema, >- filters => \@filters, >- options => $options }); >+ my $self = $class->SUPER::new( >+ { >+ schema => $schema, >+ filters => \@filters, >+ options => $options >+ } >+ ); > bless $self, $class; > return $self; > } >@@ -122,8 +128,9 @@ sub new { > Bind a normalizer to a particular record. > > =cut >+ > sub bind { >- my $self = shift; >+ my $self = shift; > my $record = shift; > > $self->{record} = $record; >@@ -140,6 +147,7 @@ Note that $record may be either a scalar or an arrayref, and the > return value will be of the same type. > > =cut >+ > sub process { > my $self = shift; > my $record = shift || $self->record; >@@ -148,7 +156,7 @@ sub process { > > my $newrecord = $record; > >- foreach my $filterobj (@{$self->filters}) { >+ foreach my $filterobj ( @{ $self->filters } ) { > next unless $filterobj; > $newrecord = $filterobj->filter($newrecord); > } >@@ -159,7 +167,7 @@ sub process { > sub DESTROY { > my $self = shift; > >- foreach my $filterobj (@{$self->filters}) { >+ foreach my $filterobj ( @{ $self->filters } ) { > $filterobj->destroy(); > } > } >@@ -172,11 +180,12 @@ Get a list of available filters. Optionally specify the metadata schema. > At present only MARC is supported as a schema. > > =cut >+ > sub AvailableFilters { > my $schema = pop || ''; > my $path = 'Koha::Filter'; >- $path .= "::$schema" if ($schema eq 'MARC'); >- my $finder = Module::Pluggable::Object->new(search_path => $path); >+ $path .= "::$schema" if ( $schema eq 'MARC' ); >+ my $finder = Module::Pluggable::Object->new( search_path => $path ); > return $finder->plugins; > } > >diff --git a/Koha/RecordProcessor/Base.pm b/Koha/RecordProcessor/Base.pm >index 00bc623..efca01b 100644 >--- a/Koha/RecordProcessor/Base.pm >+++ b/Koha/RecordProcessor/Base.pm >@@ -58,17 +58,16 @@ clone it I<prior> to passing it off to the RecordProcessor. > > =cut > >-use strict; >-use warnings; >+use Modern::Perl; >+use Class::Accessor "antlers"; > >-use base qw(Class::Accessor); >+has name => ( is => "ro" ); >+has version => ( is => "ro" ); >+has params => ( is => "rw" ); > >-__PACKAGE__->mk_ro_accessors(qw( name version )); >-__PACKAGE__->mk_accessors(qw( params )); >-our $NAME = 'Base'; >+our $NAME = 'Base'; > our $VERSION = '1.0'; > >- > =head2 new > > my $filter = Koha::RecordProcessor::Base->new; >@@ -76,17 +75,16 @@ our $VERSION = '1.0'; > Create a new filter; > > =cut >+ > sub new { > my $class = shift; > >- my $self = $class->SUPER::new( { });#name => $class->NAME, >- #version => $class->VERSION }); >+ my $self = $class->SUPER::new( {} ); > > bless $self, $class; > return $self; > } > >- > =head2 initialize > > $filter->initalize(%params); >@@ -94,8 +92,9 @@ sub new { > Initialize a filter using the specified parameters. > > =cut >+ > sub initialize { >- my $self = shift; >+ my $self = shift; > my $params = shift; > > #$self->params = $params; >@@ -103,7 +102,6 @@ sub initialize { > return $self; > } > >- > =head2 destroy > > $filter->destroy(); >@@ -111,6 +109,7 @@ sub initialize { > Destroy the filter. > > =cut >+ > sub destroy { > my $self = shift; > return; >@@ -124,8 +123,9 @@ sub destroy { > Filter the specified record(s) and return the result. > > =cut >+ > sub filter { >- my $self = shift; >+ my $self = shift; > my $record = shift; > return $record; > } >diff --git a/t/AuthoritiesMarc.t b/t/AuthoritiesMarc.t >index d59b43b..59a9a18 100755 >--- a/t/AuthoritiesMarc.t >+++ b/t/AuthoritiesMarc.t >@@ -1,14 +1,35 @@ > #!/usr/bin/perl > # >-# This Koha test module is a stub! >+# This Koha test module is a stub! > # Add more tests here!!! > >-use strict; >-use warnings; >+use Modern::Perl; > >-use Test::More tests => 1; >+use C4::Context; >+use Test::More tests => 4; > > BEGIN { >- use_ok('C4::AuthoritiesMarc'); >+ use_ok('C4::AuthoritiesMarc'); > } > >+SKIP: >+{ >+ my $authority; >+ my $dbh = C4::Context->dbh; >+ my $sth = $dbh->prepare("SELECT authid FROM auth_header LIMIT 1;"); >+ $sth->execute(); >+ >+ my $authid; >+ for my $row ( $sth->fetchrow_hashref ) { >+ $authid = $row->{'authid'}; >+ } >+ skip 'No authorities', 4 unless $authid; >+ $authority = GetAuthority($authid); >+ >+ is( ref($authority), 'MARC::Record', 'Retrieved valid MARC::Record' ); >+ >+ is( $authority->field('001')->data(), $authid, 'Retrieved correct record' ); >+ >+ $authority = GetAuthority('alphabetsoup'); >+ is( $authority, undef, 'No invalid record is retrieved' ); >+} >diff --git a/t/RecordProcessor.t b/t/RecordProcessor.t >index 32acc6b..bf3de21 100755 >--- a/t/RecordProcessor.t >+++ b/t/RecordProcessor.t >@@ -25,56 +25,69 @@ use MARC::Record; > use Test::More; > > BEGIN { >- use_ok('Koha::RecordProcessor'); >+ use_ok('Koha::RecordProcessor'); > } > >-my $isbn = '0590353403'; >-my $title = 'Foundation'; >-my $marc_record=MARC::Record->new; >-my $field = MARC::Field->new('020','','','a' => $isbn); >+my $isbn = '0590353403'; >+my $title = 'Foundation'; >+my $marc_record = MARC::Record->new; >+my $field = MARC::Field->new( '020', '', '', 'a' => $isbn ); > $marc_record->append_fields($field); >-$field = MARC::Field->new('245','','','a' => $title); >+$field = MARC::Field->new( '245', '', '', 'a' => $title ); > $marc_record->append_fields($field); > >- > my $filterdir = File::Spec->rel2abs('Koha/Filter') . '/MARC'; > >-opendir(my $dh, $filterdir); >-my @installed_filters = map { ( /\.pm$/ && -f "$filterdir/$_" && s/\.pm$// ) ? "Koha::Filters::MARC::$_" : () } readdir($dh); >+opendir( my $dh, $filterdir ); >+my @installed_filters = map { >+ ( /\.pm$/ && -f "$filterdir/$_" && s/\.pm$// ) >+ ? "Koha::Filters::MARC::$_" >+ : () >+} readdir($dh); > my @available_filters = Koha::RecordProcessor::AvailableFilters(); > > foreach my $filter (@installed_filters) { >- ok(grep($filter, @available_filters), "Found filter $filter"); >+ ok( grep( $filter, @available_filters ), "Found filter $filter" ); > } > >-my $marc_filters = grep (/MARC/, @available_filters); >-is(scalar Koha::RecordProcessor::AvailableFilters('MARC'), $marc_filters, 'Retrieved list of MARC filters'); >+my $marc_filters = grep ( /MARC/, @available_filters ); >+is( scalar Koha::RecordProcessor::AvailableFilters('MARC'), >+ $marc_filters, 'Retrieved list of MARC filters' ); > >-my $processor = Koha::RecordProcessor->new( { filters => ( 'ABCD::EFGH::IJKL' ) } ); >+my $processor = >+ Koha::RecordProcessor->new( { filters => ('ABCD::EFGH::IJKL') } ); > >-is(ref($processor), 'Koha::RecordProcessor', 'Created record processor with invalid filter'); >+is( ref($processor), 'Koha::RecordProcessor', >+ 'Created record processor with invalid filter' ); > >-is($processor->process($marc_record), $marc_record, 'Process record with empty processor'); >+is( $processor->process($marc_record), >+ $marc_record, 'Process record with empty processor' ); > >-$processor = Koha::RecordProcessor->new( { filters => ( 'Null' ) } ); >-is(ref($processor->filters->[0]), 'Koha::Filter::MARC::Null', 'Created record processor with implicitly scoped Null filter'); >+$processor = Koha::RecordProcessor->new( { filters => ('Null') } ); >+is( ref( $processor->filters->[0] ), >+ 'Koha::Filter::MARC::Null', >+ 'Created record processor with implicitly scoped Null filter' ); > >-$processor = Koha::RecordProcessor->new( { filters => ( 'Koha::Filter::MARC::Null' ) } ); >-is(ref($processor->filters->[0]), 'Koha::Filter::MARC::Null', 'Created record processor with explicitly scoped Null filter'); >+$processor = >+ Koha::RecordProcessor->new( { filters => ('Koha::Filter::MARC::Null') } ); >+is( ref( $processor->filters->[0] ), >+ 'Koha::Filter::MARC::Null', >+ 'Created record processor with explicitly scoped Null filter' ); > >-is($processor->process($marc_record), $marc_record, 'Process record'); >+is( $processor->process($marc_record), $marc_record, 'Process record' ); > > $processor->bind($marc_record); > >-is($processor->record, $marc_record, 'Bound record to processor'); >+is( $processor->record, $marc_record, 'Bound record to processor' ); > >-is($processor->process(), $marc_record, 'Filter bound record'); >+is( $processor->process(), $marc_record, 'Filter bound record' ); > > eval { >- $processor = Koha::RecordProcessor->new( { filters => ( 'Koha::Filter::MARC::Null' ) } ); >+ $processor = >+ Koha::RecordProcessor->new( { filters => ('Koha::Filter::MARC::Null') } ); > undef $processor; > }; > >-ok(!$@, 'Destroyed processor successfully'); >+ok( !$@, 'Destroyed processor successfully' ); > > done_testing(); >diff --git a/t/RecordProcessor_EmbedSeeFromHeadings.t b/t/RecordProcessor_EmbedSeeFromHeadings.t >new file mode 100755 >index 0000000..ee60489 >--- /dev/null >+++ b/t/RecordProcessor_EmbedSeeFromHeadings.t >@@ -0,0 +1,127 @@ >+#!/usr/bin/perl >+ >+# Copyright 2012 C & P Bibliography Services >+# >+# This file is part of Koha. >+# >+# 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 2 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, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+use DBI; >+use File::Spec; >+use MARC::Record; >+use MARC::File::XML; >+ >+use Test::More tests => 9; >+use Test::MockModule; >+ >+use C4::Context; >+ >+BEGIN { >+ use_ok('Koha::RecordProcessor'); >+} >+ >+# Mock the call to create a database handler >+my $module = new Test::MockModule('C4::Context'); >+$module->mock( >+ '_new_dbh', >+ sub { >+ my $dbh = DBI->connect( 'DBI:Mock:', '', '' ) >+ || die "Cannot create handle: $DBI::errstr\n"; >+ return $dbh; >+ } >+); >+$module->mock( >+ 'preference', >+ sub { >+ return 'MARC21' if ( pop @_ eq 'marcflavour' ); >+ return 0; >+ } >+); >+ >+# Mock data >+my $auth = MARC::Record->new; >+$auth->add_fields( >+ [ '001', '1234' ], >+ [ '150', ' ', ' ', a => 'Cooking' ], >+ [ '450', ' ', ' ', a => 'Cookery' ], >+); >+ >+my $mockauthority = >+ [ [ 'authtypecode', 'marcxml' ], [ 'TOPIC', $auth->as_xml_record() ], ]; >+ >+my $dbh = C4::Context->dbh(); # since we mocked _new_dbh we get a mock handle >+ >+my $bib = MARC::Record->new; >+$bib->add_fields( >+ [ '245', '0', '4', a => 'The Ifrane cookbook' ], >+ [ '650', ' ', ' ', a => 'Cooking', 9 => '1234' ] >+); >+ >+my $resultbib = MARC::Record->new; >+$resultbib->add_fields( >+ [ '245', '0', '4', a => 'The Ifrane cookbook' ], >+ [ '650', ' ', ' ', a => 'Cooking', 9 => '1234' ], >+ [ '650', 'z', ' ', a => 'Cookery' ] >+); >+ >+my $processor = >+ Koha::RecordProcessor->new( { filters => ('EmbedSeeFromHeadings') } ); >+is( ref($processor), 'Koha::RecordProcessor', 'Created record processor' ); >+is( >+ ref( $processor->filters->[0] ), >+ 'Koha::Filter::MARC::EmbedSeeFromHeadings', >+ 'Loaded EmbedSeeFromHeadings filter' >+); >+ >+$dbh->{mock_add_resultset} = $mockauthority; >+ >+my $result = $processor->process(undef); >+ >+is( $result, undef, "Don't flip out when asked to process nothing" ); >+ >+$result = $processor->process($bib); >+ >+my $history = $dbh->{mock_all_history}; >+is( scalar( @{$history} ), 1, 'Correct number of statements executed' ); >+$dbh->{mock_clear_history} = 1; >+ >+is_deeply( $result, $resultbib, 'Inserted see-from heading to record' ); >+ >+my @bibs; >+$bib = MARC::Record->new; >+$bib->add_fields( >+ [ '245', '0', '4', a => 'The Ifrane cookbook' ], >+ [ '650', ' ', ' ', a => 'Cooking', 9 => '1234' ] >+); >+push @bibs, $bib; >+$bib = MARC::Record->new; >+$bib->add_fields( >+ [ '245', '0', '2', a => 'A story of great tragedy, and fish' ], >+ [ '650', ' ', ' ', a => 'Fish', 9 => '5432' ] ); >+push @bibs, $bib; >+my @resultbibs; >+push @resultbibs, $resultbib; >+push @resultbibs, $bib; >+ >+$dbh->{mock_add_resultset} = $mockauthority; >+ >+$result = $processor->process( \@bibs ); >+ >+is( scalar(@$result), 2, 'Processed two records' ); >+ >+$history = $dbh->{mock_all_history}; >+is( scalar( @{$history} ), 2, 'Correct number of statements executed' ); >+ >+is_deeply( $result, \@resultbibs, 'Handled both records correctly' ); >diff --git a/t/db_dependent/Koha_Authority.t b/t/db_dependent/Koha_Authority.t >index dc57774..08b01a5 100755 >--- a/t/db_dependent/Koha_Authority.t >+++ b/t/db_dependent/Koha_Authority.t >@@ -17,28 +17,28 @@ > # with Koha; if not, write to the Free Software Foundation, Inc., > # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. > >-use strict; >-use warnings; >+use Modern::Perl; > > use C4::Context; >-use Test::More; >+use Test::More tests => 7; > > BEGIN { >- use_ok('Koha::Authority'); >+ use_ok('Koha::DataObject::Authority'); > } > > my $record = MARC::Record->new; > > $record->add_fields( >- [ '001', '1234' ], >- [ '150', ' ', ' ', a => 'Cooking' ], >- [ '450', ' ', ' ', a => 'Cookery' ], >- ); >-my $authority = Koha::Authority->new($record); >+ [ '001', '1234' ], >+ [ '150', ' ', ' ', a => 'Cooking' ], >+ [ '450', ' ', ' ', a => 'Cookery' ], >+); >+my $authority = Koha::DataObject::Authority->new( { marcrecord => $record } ); > >-is(ref($authority), 'Koha::Authority', 'Created valid Koha::Authority object'); >+is( ref($authority), 'Koha::DataObject::Authority', >+ 'Created valid Koha::DataObject::Authority object' ); > >-is_deeply($authority->record, $record, 'Saved record'); >+is_deeply( $authority->marcrecord, $record, 'Saved record' ); > > SKIP: > { >@@ -47,20 +47,20 @@ SKIP: > $sth->execute(); > > my $authid; >- for my $row ($sth->fetchrow_hashref) { >+ for my $row ( $sth->fetchrow_hashref ) { > $authid = $row->{'authid'}; > } > skip 'No authorities', 3 unless $authid; >- $authority = Koha::Authority->get_from_authid($authid); >+ $authority = Koha::DataObject::Authority->new( { authid => $authid } ); > >- is(ref($authority), 'Koha::Authority', 'Retrieved valid Koha::Authority object'); >+ is( ref($authority), 'Koha::DataObject::Authority', >+ 'Retrieved valid Koha::DataObject::Authority object' ); > >- is($authority->authid, $authid, 'Object authid is correct'); >+ is( $authority->authid, $authid, 'Object authid is correct' ); > >- is($authority->record->field('001')->data(), $authid, 'Retrieved correct record'); >- >- $authority = Koha::Authority->get_from_authid('alphabetsoup'); >- is($authority, undef, 'No invalid record is retrieved'); >+ is( $authority->marcrecord->field('001')->data(), >+ $authid, 'Retrieved correct record' ); > } > >-done_testing(); >+$authority = Koha::DataObject::Authority->new( { authid => 'alphabetsoup' } ); >+is( $authority, undef, 'No invalid record is retrieved' ); >diff --git a/t/db_dependent/RecordProcessor_EmbedSeeFromHeadings.t b/t/db_dependent/RecordProcessor_EmbedSeeFromHeadings.t >deleted file mode 100755 >index 4742983..0000000 >--- a/t/db_dependent/RecordProcessor_EmbedSeeFromHeadings.t >+++ /dev/null >@@ -1,66 +0,0 @@ >-#!/usr/bin/perl >- >-# Copyright 2012 C & P Bibliography Services >-# >-# This file is part of Koha. >-# >-# 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 2 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, write to the Free Software Foundation, Inc., >-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >- >-use strict; >-use warnings; >-use File::Spec; >-use MARC::Record; >-use Koha::Authority; >- >-use Test::More; >-use Test::MockModule; >- >-BEGIN { >- use_ok('Koha::RecordProcessor'); >-} >- >-my $module = new Test::MockModule('MARC::Record'); >-$module->mock('new_from_xml', sub { >- my $record = MARC::Record->new; >- >- $record->add_fields( >- [ '001', '1234' ], >- [ '150', ' ', ' ', a => 'Cooking' ], >- [ '450', ' ', ' ', a => 'Cookery' ], >- ); >- >- return $record; >-}); >- >-my $bib = MARC::Record->new; >-$bib->add_fields( >- [ '245', '0', '4', a => 'The Ifrane cookbook' ], >- [ '650', ' ', ' ', a => 'Cooking', 9 => '1234' ] >- ); >- >-my $resultbib = MARC::Record->new; >-$resultbib->add_fields( >- [ '245', '0', '4', a => 'The Ifrane cookbook' ], >- [ '650', ' ', ' ', a => 'Cooking', 9 => '1234' ], >- [ '650', 'z', ' ', a => 'Cookery' ] >- ); >- >-my $processor = Koha::RecordProcessor->new( { filters => ( 'EmbedSeeFromHeadings' ) } ); >-is(ref($processor), 'Koha::RecordProcessor', 'Created record processor'); >- >-my $result = $processor->process($bib); >- >-is_deeply($result, $resultbib, 'Inserted see-from heading to record'); >- >-done_testing(); >-- >1.7.9.5
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 7417
:
11028
|
11253
|
11319
|
11362
|
11363
|
11364
|
11365
|
11366
|
11393
|
11419
|
11427
|
11441
|
11460
|
11465
|
12147
|
12148
|
12199
|
12200
|
12204