Bug 24267: (QA follow-up) Remove two calls, add transaction
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 <m.de.rooy@rijksmuseum.nl> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
parent
42cca4afc7
commit
f480ca803b
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue