Bugzilla – Attachment 59334 Details for
Bug 17909
Add unit tests for authority merge
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17909: Add unit tests for C4::AuthoritiesMarc::merge
Bug-17909-Add-unit-tests-for-C4AuthoritiesMarcmerg.patch (text/plain), 5.82 KB, created by
Julian Maurice
on 2017-01-20 11:24:36 UTC
(
hide
)
Description:
Bug 17909: Add unit tests for C4::AuthoritiesMarc::merge
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2017-01-20 11:24:36 UTC
Size:
5.82 KB
patch
obsolete
>From b6b87958bb12d350f268d344daaff352eefda179 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Wed, 19 Feb 2014 11:31:13 +0100 >Subject: [PATCH] Bug 17909: Add unit tests for C4::AuthoritiesMarc::merge > >Original patch from Julian Maurice on bug 11700. >With sign offs by: >Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> > >Amended by Marcel de Rooy on report 17909. > >EDIT (January 2017): >Removed some tests not related to merge. >Put remaining tests in a subtest, made them working on current merge. >Slightly revised the mocking. > >Note: I plan to move the zebra retrieval stuff outside merge in one of >the next stages, and replace it by calling Koha::SearchEngine. This will >reduce mocking complexity here. > >Test plan: >Just run t/db_dependent/Authorities/Merge.t > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> >Signed-off-by: Julian Maurice <julian.maurice@biblibre.com> >--- > t/db_dependent/Authorities/Merge.t | 99 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 99 insertions(+) > create mode 100755 t/db_dependent/Authorities/Merge.t > >diff --git a/t/db_dependent/Authorities/Merge.t b/t/db_dependent/Authorities/Merge.t >new file mode 100755 >index 0000000000..a07fcd54a6 >--- /dev/null >+++ b/t/db_dependent/Authorities/Merge.t >@@ -0,0 +1,99 @@ >+#!/usr/bin/perl >+ >+# Tests for C4::AuthoritiesMarc::merge >+ >+use Modern::Perl; >+ >+use Test::More tests => 2; >+ >+use MARC::Record; >+use Test::MockModule; >+use Test::MockObject; >+ >+use C4::Biblio; >+use Koha::Database; >+ >+BEGIN { >+ use_ok('C4::AuthoritiesMarc'); >+} >+ >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+my $dbh = C4::Context->dbh; >+ >+# Some advanced mocking :) >+my ( @zebrarecords, $index ); >+my $auth_mod = Test::MockModule->new( 'C4::AuthoritiesMarc' ); >+my $context_mod = Test::MockModule->new( 'C4::Context' ); >+my $search_mod = Test::MockModule->new( 'C4::Search' ); >+my $zoom_mod = Test::MockModule->new( 'ZOOM::Query::CCL2RPN', no_auto => 1 ); >+my $conn_obj = Test::MockObject->new; >+my $zoom_obj = Test::MockObject->new; >+my $zoom_record_obj = Test::MockObject->new; >+set_mocks(); >+ >+subtest 'Test merge A1 to A2 (withing same authtype)' => sub { >+# Tests originate from bug 11700 >+ plan tests => 5; >+ >+ # Create authority type TEST_PERSO >+ $dbh->do("INSERT INTO auth_types(authtypecode, authtypetext, auth_tag_to_report, summary) VALUES('TEST_PERSO', 'Personal Name', '109', 'Personal Names');"); >+ $dbh->do("INSERT INTO auth_tag_structure (authtypecode, tagfield, liblibrarian, libopac, repeatable, mandatory, authorised_value) VALUES('TEST_PERSO', '109', 'HEADING--PERSONAL NAME', 'HEADING--PERSONAL NAME', 0, 0, NULL)"); >+ $dbh->do("INSERT INTO auth_subfield_structure (authtypecode, tagfield, tagsubfield, liblibrarian, libopac, repeatable, mandatory, tab, authorised_value, value_builder, seealso, isurl, hidden, linkid, kohafield, frameworkcode) VALUES ('TEST_PERSO', '109', 'a', 'Personal name', 'Personal name', 0, 0, 1, NULL, NULL, '', 0, 0, '', '', '')"); >+ >+ my $auth1 = new MARC::Record; >+ $auth1->append_fields(new MARC::Field('109', '0', '0', 'a' => 'George Orwell')); >+ my $authid1 = AddAuthority($auth1, undef, 'TEST_PERSO'); >+ my $auth2 = new MARC::Record; >+ $auth2->append_fields(new MARC::Field('109', '0', '0', 'a' => 'G. Orwell')); >+ my $authid2 = AddAuthority($auth2, undef, 'TEST_PERSO'); >+ >+ $dbh->do("INSERT IGNORE INTO marc_subfield_structure(tagfield, tagsubfield, liblibrarian, libopac, repeatable, mandatory, kohafield, tab, authorised_value, authtypecode, value_builder, isurl, hidden, frameworkcode, seealso, link, defaultvalue) VALUES('609', 'a', 'Personal name', 'Personal name', 0, 0, '', 6, '', 'TEST_PERSO', '', NULL, 0, '', '', '', NULL)"); >+ $dbh->do("UPDATE marc_subfield_structure SET authtypecode = 'TEST_PERSO' WHERE tagfield='609' AND tagsubfield='a' AND frameworkcode='';"); >+ my $tagfields = $dbh->selectcol_arrayref("select distinct tagfield from marc_subfield_structure where authtypecode='TEST_PERSO'"); >+ my $biblio1 = new MARC::Record; >+ $biblio1->append_fields( >+ new MARC::Field('609', '0', '0', '9' => $authid1, 'a' => 'George Orwell') >+ ); >+ my ( $biblionumber1 ) = AddBiblio($biblio1, ''); >+ my $biblio2 = new MARC::Record; >+ $biblio2->append_fields( >+ new MARC::Field('609', '0', '0', '9' => $authid2, 'a' => 'G. Orwell') >+ ); >+ my ( $biblionumber2 ) = AddBiblio($biblio2, ''); >+ >+ @zebrarecords = ( $biblio1, $biblio2 ); >+ $index = 0; >+ my $rv = C4::AuthoritiesMarc::merge( $authid2, $auth2, $authid1, $auth1 ); >+ is( $rv, 1, 'We expect one biblio record (out of two) to be updated' ); >+ >+ $biblio1 = GetMarcBiblio($biblionumber1); >+ is($biblio1->subfield('609', '9'), $authid1, 'Check biblio1 609$9' ); >+ is($biblio1->subfield('609', 'a'), 'George Orwell', >+ 'Check biblio1 609$a' ); >+ $biblio2 = GetMarcBiblio($biblionumber2); >+ is($biblio2->subfield('609', '9'), $authid1, 'Check biblio2 609$9' ); >+ is($biblio2->subfield('609', 'a'), 'George Orwell', >+ 'Check biblio2 609$a' ); >+}; >+ >+sub set_mocks { >+ # Mock ZOOM objects: They do nothing actually >+ # Get new_record_from_zebra to return the records >+ >+ $context_mod->mock( 'Zconn', sub { $conn_obj; } ); >+ $search_mod->mock( 'new_record_from_zebra', sub { >+ return if $index >= @zebrarecords; >+ return $zebrarecords[ $index++ ]; >+ }); >+ $zoom_mod->mock( 'new', sub {} ); >+ >+ $conn_obj->mock( 'search', sub { $zoom_obj; } ); >+ $zoom_obj->mock( 'destroy', sub {} ); >+ $zoom_obj->mock( 'record', sub { $zoom_record_obj; } ); >+ $zoom_obj->mock( 'search', sub {} ); >+ $zoom_obj->mock( 'size', sub { @zebrarecords } ); >+ $zoom_record_obj->mock( 'raw', sub {} ); >+} >+ >+$schema->storage->txn_rollback; >-- >2.11.0
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 17909
:
59005
|
59006
|
59007
|
59008
|
59011
|
59012
|
59013
|
59014
|
59015
|
59077
|
59088
|
59323
|
59324
| 59334 |
59335
|
59336
|
59337
|
59338
|
59339
|
59340