Bugzilla – Attachment 82963 Details for
Bug 21826
Automatic authority record generation improvements
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21826: Add tests
Bug-21826-Add-tests.patch (text/plain), 6.86 KB, created by
Ere Maijala
on 2018-12-07 12:50:53 UTC
(
hide
)
Description:
Bug 21826: Add tests
Filename:
MIME Type:
Creator:
Ere Maijala
Created:
2018-12-07 12:50:53 UTC
Size:
6.86 KB
patch
obsolete
>From 383b59f4481020c03eff82cc619e7158088978cc Mon Sep 17 00:00:00 2001 >From: Ere Maijala <ere.maijala@helsinki.fi> >Date: Mon, 19 Nov 2018 14:26:00 +0200 >Subject: [PATCH] Bug 21826: Add tests > >Adds tests for new Heading::valid_bib_heading_subfield and ModBiblio with auto-created authorities. > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > t/Heading.t | 55 ++++++++++++++++++++++++++-- > t/db_dependent/Biblio.t | 81 +++++++++++++++++++++++++++++++++++++++-- > 2 files changed, 129 insertions(+), 7 deletions(-) > >diff --git a/t/Heading.t b/t/Heading.t >index d7809443c4..bcbbe515ec 100755 >--- a/t/Heading.t >+++ b/t/Heading.t >@@ -1,14 +1,61 @@ > #!/usr/bin/perl > # >-# This Koha test module is a stub! >-# Add more tests here!!! >+# 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 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 Test::More tests => 1; >+use Test::More tests => 3; >+ >+use t::lib::Mocks; > > BEGIN { >- use_ok('C4::Heading'); >+ use_ok('C4::Heading'); > } > >+subtest "MARC21 tests" => sub { >+ plan tests => 7; >+ >+ t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); >+ >+ ok(C4::Heading::valid_bib_heading_subfield('100', 'a'), '100a valid'); >+ ok(!C4::Heading::valid_bib_heading_subfield('100', 'e'), '100e not valid'); >+ >+ ok(C4::Heading::valid_bib_heading_subfield('110', 'a'), '110a valid'); >+ ok(!C4::Heading::valid_bib_heading_subfield('110', 'e'), '110e not valid'); >+ >+ ok(C4::Heading::valid_bib_heading_subfield('600', 'a'), '600a valid'); >+ ok(!C4::Heading::valid_bib_heading_subfield('600', 'e'), '600e not valid'); >+ >+ ok(!C4::Heading::valid_bib_heading_subfield('012', 'a'), '012a invalid field'); >+}; >+ >+subtest "UNIMARC tests" => sub { >+ plan tests => 7; >+ >+ t::lib::Mocks::mock_preference('marcflavour', 'UNIMARC'); >+ >+ ok(C4::Heading::valid_bib_heading_subfield('100', 'a'), '100a valid'); >+ ok(!C4::Heading::valid_bib_heading_subfield('100', 'i'), '100i not valid'); >+ >+ ok(C4::Heading::valid_bib_heading_subfield('110', 'a'), '110a valid'); >+ ok(!C4::Heading::valid_bib_heading_subfield('110', 'i'), '110i not valid'); >+ >+ ok(C4::Heading::valid_bib_heading_subfield('600', 'a'), '600a valid'); >+ ok(!C4::Heading::valid_bib_heading_subfield('600', 'i'), '600i not valid'); >+ >+ ok(!C4::Heading::valid_bib_heading_subfield('012', 'a'), '012a invalid field'); >+} >diff --git a/t/db_dependent/Biblio.t b/t/db_dependent/Biblio.t >index 1f954dcca0..60ccde3a18 100755 >--- a/t/db_dependent/Biblio.t >+++ b/t/db_dependent/Biblio.t >@@ -348,6 +348,54 @@ sub run_tests { > like( $marcurl->[0]->{MARCURL}, qr/^https/, 'GetMarcUrls did not stumble over a preceding space' ); > ok( $marcflavour ne 'MARC21' || $marcurl->[1]->{MARCURL} =~ /^http:\/\//, > 'GetMarcUrls prefixed a MARC21 URL with http://' ); >+ >+ # Automatic authority creation >+ t::lib::Mocks::mock_preference('BiblioAddsAuthorities', 1); >+ t::lib::Mocks::mock_preference('AutoCreateAuthorities', 1); >+ my $authorities_mod = Test::MockModule->new( 'C4::AuthoritiesMarc' ); >+ $authorities_mod->mock( >+ 'SearchAuthorities', >+ sub { >+ my @results; >+ return \@results, 0; >+ } >+ ); >+ $success = 0; >+ $field = create_author_field('Author Name'); >+ eval { >+ $marc_record->append_fields($field); >+ $success = ModBiblio($marc_record,$biblionumber,''); >+ } or do { >+ diag($@); >+ $success = 0; >+ }; >+ ok($success, "ModBiblio handles authority addition for author"); >+ >+ my ($author_field, $author_subfield, $author_relator_subfield) = get_author_field(); >+ $field = $marc_record->field($author_field); >+ ok($field->subfield($author_subfield), "ModBiblio keeps $author_field$author_subfield intact"); >+ >+ my $authid = $field->subfield('9'); >+ ok($authid, 'ModBiblio adds authority id'); >+ >+ use_ok('C4::AuthoritiesMarc'); >+ my $auth_record = C4::AuthoritiesMarc::GetAuthority($authid); >+ ok($auth_record, 'Authority record successfully retrieved'); >+ >+ >+ my ($auth_author_field, $auth_author_subfield) = get_auth_author_field(); >+ $field = $auth_record->field($auth_author_field); >+ ok($field, "Authority record contains field $auth_author_field"); >+ is( >+ $field->subfield($auth_author_subfield), >+ 'Author Name', >+ 'Authority $auth_author_field$auth_author_subfield contains author name' >+ ); >+ is($field->subfield($author_relator_subfield), undef, 'Authority does not contain relator subfield'); >+ >+ # Reset settings >+ t::lib::Mocks::mock_preference('BiblioAddsAuthorities', 0); >+ t::lib::Mocks::mock_preference('AutoCreateAuthorities', 0); > } > > sub get_title_field { >@@ -370,6 +418,16 @@ sub get_itemnumber_field { > return ( $marc_flavour eq 'UNIMARC' ) ? ( '995', '9' ) : ( '952', '9' ); > } > >+sub get_author_field { >+ my $marc_flavour = C4::Context->preference('marcflavour'); >+ return ( $marc_flavour eq 'UNIMARC' ) ? ( '700', 'a', '4' ) : ( '100', 'a', 'e' ); >+} >+ >+sub get_auth_author_field { >+ my $marc_flavour = C4::Context->preference('marcflavour'); >+ return ( $marc_flavour eq 'UNIMARC' ) ? ( '106', 'a' ) : ( '100', 'a' ); >+} >+ > sub create_title_field { > my ( $title, $marcflavour ) = @_; > >@@ -401,22 +459,39 @@ sub create_issn_field { > return $field; > } > >+sub create_author_field { >+ my ( $author ) = @_; >+ >+ my ( $author_field, $author_subfield, $author_relator_subfield ) = get_author_field(); >+ my $field = MARC::Field->new( >+ $author_field, '', '', >+ $author_subfield => $author, >+ $author_relator_subfield => 'aut' >+ ); >+ >+ return $field; >+} >+ > subtest 'MARC21' => sub { >- plan tests => 34; >+ plan tests => 42; > run_tests('MARC21'); > $schema->storage->txn_rollback; > $schema->storage->txn_begin; > }; > > subtest 'UNIMARC' => sub { >- plan tests => 34; >+ plan tests => 42; >+ >+ # Mock the auth type data for UNIMARC >+ $dbh->do("UPDATE auth_types SET auth_tag_to_report = '106' WHERE auth_tag_to_report = '100'") or die $dbh->errstr; >+ > run_tests('UNIMARC'); > $schema->storage->txn_rollback; > $schema->storage->txn_begin; > }; > > subtest 'NORMARC' => sub { >- plan tests => 34; >+ plan tests => 42; > run_tests('NORMARC'); > $schema->storage->txn_rollback; > $schema->storage->txn_begin; >-- >2.17.1
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 21826
:
82310
|
82311
|
82479
|
82480
|
82481
|
82514
|
82515
|
82516
|
82517
|
82535
|
82536
|
82537
|
82576
|
82577
|
82578
|
82579
|
82580
|
82634
|
82635
|
82636
|
82637
|
82638
|
82961
|
82962
| 82963 |
82964
|
82965