From 24dee2d269d6f90a85a81efa283594f70a02020b Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 20 Dec 2019 07:14:32 +0000 Subject: [PATCH] Bug 24267: (QA follow-up) Remove two calls, add transaction Content-Type: text/plain; charset=utf-8 Call to GetAuthorizedHeading is already done just before calling ImportBreedingAuth. Call to GuessAuthTypeCode is not used. Adding transaction to test (check your database, kidclamp ;) Test plan: Add new authority via Z3950 in the interface. Run t/db_dependent/Breeding.t Signed-off-by: Marcel de Rooy --- C4/Breeding.pm | 16 ++++------------ t/db_dependent/Breeding.t | 27 ++++++++++++++++----------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/C4/Breeding.pm b/C4/Breeding.pm index 59cad532c7..a93189c13f 100644 --- a/C4/Breeding.pm +++ b/C4/Breeding.pm @@ -483,34 +483,26 @@ sub _translate_query { #SRU query adjusted per server cf. srufields column =head2 ImportBreedingAuth -ImportBreedingAuth($marcrecords,$overwrite_auth,$filename,$encoding); +ImportBreedingAuth( $marcrecord, $filename, $encoding, $heading ); ImportBreedingAuth imports MARC records in the reservoir (import_records table) or returns their id if they already exist. =cut sub ImportBreedingAuth { - my ($marcrecord,$filename,$encoding) = @_; + my ( $marcrecord, $filename, $encoding, $heading ) = @_; my $dbh = C4::Context->dbh; my $batch_id = GetZ3950BatchId($filename); my $searchbreeding = $dbh->prepare("select import_record_id from import_auths where control_number=? and authorized_heading=?"); - my $marcflavour = C4::Context->preference('marcflavour'); - my $marc_type = $marcflavour eq 'UNIMARC' ? 'UNIMARCAUTH' : $marcflavour; - - my $heading = C4::AuthoritiesMarc::GetAuthorizedHeading({ record => $marcrecord }); - - my $heading_authtype_code = GuessAuthTypeCode($marcrecord); - my $controlnumber = $marcrecord->field('001')->data; - my $breedingid; # Normalize the record so it doesn't have separated diacritics SetUTF8Flag($marcrecord); $searchbreeding->execute($controlnumber,$heading); - ($breedingid) = $searchbreeding->fetchrow; + my ($breedingid) = $searchbreeding->fetchrow; return $breedingid if $breedingid; $breedingid = AddAuthToBatch($batch_id, 0, $marcrecord, $encoding); @@ -614,7 +606,7 @@ sub Z3950SearchAuth { $heading_authtype_code = GuessAuthTypeCode($marcrecord); $heading = C4::AuthoritiesMarc::GetAuthorizedHeading({ record => $marcrecord }); - my $breedingid = ImportBreedingAuth( $marcrecord, $serverhost[$k], $encoding[$k]); + my $breedingid = ImportBreedingAuth( $marcrecord, $serverhost[$k], $encoding[$k], $heading ); my %row_data; $row_data{server} = $servers[$k]->{'servername'}; $row_data{breedingid} = $breedingid; diff --git a/t/db_dependent/Breeding.t b/t/db_dependent/Breeding.t index 4703929f81..2114f52771 100755 --- a/t/db_dependent/Breeding.t +++ b/t/db_dependent/Breeding.t @@ -17,6 +17,13 @@ # with Koha; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# Main object of this unit test is the Breeding module and its subroutines +# A start has been made to define tests for subroutines of Z3950Search. +# These subroutines are actually internal, but these tests may pave the way for +# a more comprehensive test of Z3950Search itself. +# +# TODO We need additional tests for Z3950SearchAuth, BreedingSearch + use Modern::Perl; use FindBin; @@ -26,15 +33,11 @@ use t::lib::Mocks qw( mock_preference ); use C4::Context; use C4::Breeding; +use Koha::Database; use Koha::XSLT_Handler; -#Main object of this unit test is the Breeding module and its subroutines -#A start has been made to define tests for subroutines of Z3950Search. -#These subroutines are actually internal, but these tests may pave the way for -#a more comprehensive test of Z3950Search itself. -#TODO -#Furthermore, we need additional tests for: -#Z3950SearchAuth, BreedingSearch, ImportBreedingAuth +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; #Group 1: testing _build_query and _translate_query (part of Z3950Search) subtest '_build_query' => sub { @@ -66,21 +69,23 @@ subtest ImportBreedingAuth => sub { MARC::Field->new('100', ' ', ' ', a => 'Jansson, Tove'), ); - my $breedingid = C4::Breeding::ImportBreedingAuth($record,"kidclamp","UTF8"); + my $breedingid = C4::Breeding::ImportBreedingAuth($record,"kidclamp","UTF-8",'Jansson, Tove' ); ok( $breedingid, "We got a breeding id back"); - my $breedingid_1 = C4::Breeding::ImportBreedingAuth($record,"kidclamp","UTF8"); + my $breedingid_1 = C4::Breeding::ImportBreedingAuth($record,"kidclamp","UTF-8",'Jansson, Tove' ); is( $breedingid, $breedingid_1, "For the same record, we get the same id"); - $breedingid_1 = C4::Breeding::ImportBreedingAuth($record,"marcelr","UTF8"); + $breedingid_1 = C4::Breeding::ImportBreedingAuth($record,"marcelr","UTF-8",'Jansson, Tove' ); is( $breedingid, $breedingid_1, "For the same record in a different file, we get a new id"); my $record_1 = MARC::Record->new(); $record_1->append_fields( MARC::Field->new('001', '8675309'), MARC::Field->new('100', ' ', ' ', a => 'Cooper, Susan'), ); - my $breedingid_2 = C4::Breeding::ImportBreedingAuth($record_1,"kidclamp","UTF8"); + my $breedingid_2 = C4::Breeding::ImportBreedingAuth($record_1,"kidclamp","UTF-8",'Cooper, Susan' ); isnt( $breedingid, $breedingid_2, "For a new record, we get a new id"); }; +$schema->storage->txn_rollback; + #------------------------------------------------------------------------------- sub test_build_translate_query { -- 2.11.0