Bugzilla – Attachment 65708 Details for
Bug 19049
Fix regression on stage-marc-import with to_marc plugin
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 19049: Testing RecordsFromMarcPlugin with a to_marc plugin
Bug-19049-Testing-RecordsFromMarcPlugin-with-a-tom.patch (text/plain), 5.72 KB, created by
Marcel de Rooy
on 2017-08-09 12:38:54 UTC
(
hide
)
Description:
Bug 19049: Testing RecordsFromMarcPlugin with a to_marc plugin
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2017-08-09 12:38:54 UTC
Size:
5.72 KB
patch
obsolete
>From e5f34a09010ff66d9a025941add0883598aca281 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Tue, 8 Aug 2017 14:51:41 +0200 >Subject: [PATCH] Bug 19049: Testing RecordsFromMarcPlugin with a to_marc > plugin >Content-Type: text/plain; charset=utf-8 > >This patch adds a simple to_marc plugin in t/Koha/Plugin that is used >in the added subtest in ImportBatch.t. > >Test plan: >[1] Run t/db_dependent/ImportBatch.t >[2] Copy the to_marc test plugin from t to your plugin directory. > Under Debian packages, you should do something like: > mkdir -p /var/lib/koha/master/plugins/Koha/Plugin/ > cp [yourclone]/t/Koha/Plugin/MarcFieldValues.pm /var/lib/koha/master/plugins/Koha/Plugin/ >[3] Check if you see this plugin on plugins/plugins-home.pl >[4] Create a text file with some fields like: > (Note: The plugin needs an empty line between both "records".) > 100,a = Test Author 1 > 245,a = Title One > > 100,a = Author 2 > 245,a = Title Two >[5] Go to stage-marc-import.pl. Upload the created file. Select the plugin > in the format combo and proceed. Did you create two records ? > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > t/Koha/Plugin/MarcFieldValues.pm | 86 ++++++++++++++++++++++++++++++++++++++++ > t/db_dependent/ImportBatch.t | 38 ++++++++++++++++-- > 2 files changed, 121 insertions(+), 3 deletions(-) > create mode 100644 t/Koha/Plugin/MarcFieldValues.pm > >diff --git a/t/Koha/Plugin/MarcFieldValues.pm b/t/Koha/Plugin/MarcFieldValues.pm >new file mode 100644 >index 0000000..ee763b8 >--- /dev/null >+++ b/t/Koha/Plugin/MarcFieldValues.pm >@@ -0,0 +1,86 @@ >+package Koha::Plugin::MarcFieldValues; >+ >+use Modern::Perl; >+use MARC::Field; >+use MARC::Record; >+ >+use base qw(Koha::Plugins::Base); >+ >+our $VERSION = 1.00; >+our $metadata = { >+ name => 'MarcFieldValues', >+ author => 'M. de Rooy', >+ class => 'Koha::Plugin::MarcFieldValues', >+ description => 'Convert MARC fields from plain text', >+ date_authored => '2017-08-08', >+ date_updated => '2017-08-08', >+ minimum_version => '16.11', >+ maximum_version => undef, >+ version => $VERSION, >+ input_format => 'MARC field/value pairs in plain text', >+}; >+ >+=head1 METHODS >+ >+=head2 new >+ >+ Create new object >+ >+=cut >+ >+sub new { >+ my ( $class, $args ) = @_; >+ $args->{'metadata'} = $metadata; >+ my $self = $class->SUPER::new($args); >+ return $self; >+} >+ >+=head2 to_marc >+ >+ Create string of MARC blobs from plain text lines in the form: >+ field [,ind1|,ind2|,subcode] = value >+ Example: >+ 003 = OrgCode >+ 100,a = Author >+ 245,ind2 = 0 >+ 245,a = Title >+ >+=cut >+ >+sub to_marc { >+ my ( $self, $args ) = @_; >+ # $args->{data} contains text to convert to MARC >+ my $retval = ''; >+ my @records = split /\r?\n\r?\n/, $args->{data}; >+ foreach my $rec ( @records ) { >+ my @lines = split /\r?\n/, $rec; >+ my $marc = MARC::Record->new; >+ my $inds = {}; >+ my $fldcount = 0; >+ foreach my $line ( @lines ) { >+ # each line is of the form field [,ind1|,ind2|,subcode] = value >+ my @temp = split /\s*=\s*/, $line, 2; >+ next if @temp < 2; >+ $temp[0] =~ s/^\s*//; >+ $temp[1] =~ s/\s*$//; >+ my $value = $temp[1]; >+ @temp = split /\s*,\s*/, $temp[0]; >+ if( @temp > 1 && $temp[1] =~ /ind[12]/ ) { >+ $inds->{$temp[0]}->{$temp[1]} = substr($value, 0, 1); >+ next; >+ } >+ $fldcount++; >+ $marc->append_fields( MARC::Field->new( >+ $temp[0], >+ $temp[0] < 10 >+ ? () >+ : ( ( $inds->{$temp[0]} ? $inds->{$temp[0]}->{ind1} // '' : '', $inds->{$temp[0]} ? $inds->{$temp[0]}->{ind2} // '' : ''), substr( $temp[1], 0, 1 ) ), >+ $value, >+ )); >+ } >+ $retval .= $marc->as_usmarc if $fldcount; >+ } >+ return $retval; >+} >+ >+1; >diff --git a/t/db_dependent/ImportBatch.t b/t/db_dependent/ImportBatch.t >index bdab996..607c71e 100644 >--- a/t/db_dependent/ImportBatch.t >+++ b/t/db_dependent/ImportBatch.t >@@ -1,13 +1,18 @@ > #!/usr/bin/perl > > use Modern::Perl; >-use Test::More tests => 13; >+use Test::More tests => 14; >+use File::Basename; >+use File::Temp qw/tempfile/; > >-use Koha::Database; >+use t::lib::Mocks; > use t::lib::TestBuilder; > >+use Koha::Database; >+use Koha::Plugins; >+ > BEGIN { >- use_ok('C4::ImportBatch'); >+ use_ok('C4::ImportBatch'); > } > > # Start transaction >@@ -162,4 +167,31 @@ C4::ImportBatch::DeleteBatch( $id_import_batch3 ); > my $batch3_results = $dbh->do('SELECT * FROM import_batches WHERE import_batch_id = "$id_import_batch3"'); > is( $batch3_results, "0E0", "Batch 3 has been deleted"); > >+subtest "RecordsFromMarcPlugin" => sub { >+ plan tests => 5; >+ >+ # Create a test file >+ my ( $fh, $name ) = tempfile(); >+ print $fh q| >+003 = NLAmRIJ >+100,a = Author >+245,ind2 = 0 >+245,a = Silence in the library >+500 , a= Some note >+ >+100,a = Another >+245,a = Noise in the library|; >+ close $fh; >+ t::lib::Mocks::mock_config( 'pluginsdir', dirname(__FILE__) . '/..' ); >+ my ( $plugin ) = Koha::Plugins->new->GetPlugins({ metadata => { name => 'MarcFieldValues' } }); >+ isnt( $plugin, undef, "Plugin found" ); >+ my $records = C4::ImportBatch::RecordsFromMarcPlugin( $name, ref $plugin, 'UTF-8' ); >+ is( @$records, 2, 'Two results returned' ); >+ is( ref $records->[0], 'MARC::Record', 'Returned MARC::Record object' ); >+ is( $records->[0]->subfield('245', 'a'), 'Silence in the library', >+ 'Checked one field in first record' ); >+ is( $records->[1]->subfield('100', 'a'), 'Another', >+ 'Checked one field in second record' ); >+}; >+ > $schema->storage->txn_rollback; >-- >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 19049
:
65595
|
65655
|
65656
|
65707
|
65708
|
65797
|
65802
|
65803
|
65804
|
65807
|
65808
|
65809
|
65810
|
65876
|
65877