Bug 30047: (follow-up) Fix failing tests
This patch updates the test files to correctly create authorities and/or correctly mock the needed data for authorities. the tests in t/db_dependent/Authority/Merge.t cover the case of 'Default' authorities which don't have valid headings - so I had to add handling for blanking the heading field when Default type is used. Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
aae125044d
commit
b7e5dab1e7
|
|
@ -687,6 +687,8 @@ sub AddAuthority {
|
|||
} else {
|
||||
$action = 'modify';
|
||||
$authority = Koha::Authorities->find($authid);
|
||||
$authority->authtypecode($authtypecode);
|
||||
# In the case we are changing type we need to set this to ensure heading field is correctly chosen
|
||||
}
|
||||
|
||||
# Insert/update the recordID in MARC record
|
||||
|
|
@ -701,7 +703,7 @@ sub AddAuthority {
|
|||
authtypecode => $authtypecode,
|
||||
marc => $record->as_usmarc,
|
||||
marcxml => $record->as_xml_record($format),
|
||||
heading => $heading->display_form,
|
||||
heading => $heading ? $heading->display_form : '',
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ sub new_from_field {
|
|||
my $marcflavour = C4::Context->preference('marcflavour');
|
||||
my $marc_handler = _marc_format_handler($marcflavour);
|
||||
|
||||
return unless $field;
|
||||
my $tag = $field->tag();
|
||||
return unless $marc_handler->valid_heading_tag( $tag, $frameworkcode, $auth );
|
||||
my $self = {};
|
||||
|
|
|
|||
|
|
@ -33,6 +33,14 @@ t::lib::Mocks::mock_preference( 'marcflavour', $marcflavour ) if $marcflavour;
|
|||
my $schema = Koha::Database->new->schema;
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
my $heading_module = Test::MockModule->new('C4::Heading::MARC21');
|
||||
$heading_module->mock(
|
||||
'valid_heading_tag',
|
||||
sub {
|
||||
return 1;
|
||||
}
|
||||
);
|
||||
|
||||
# Global variables, mocking and framework modifications
|
||||
our @linkedrecords;
|
||||
my $mocks = set_mocks();
|
||||
|
|
@ -183,7 +191,7 @@ subtest 'Test merge A1 to B1 (changing authtype)' => sub {
|
|||
my $authid1 = AddAuthority( $auth1, undef, $authtype1 );
|
||||
my $auth2 = MARC::Record->new;
|
||||
$auth2->append_fields( MARC::Field->new( '112', '0', '0', 'a' => 'Batman', c => 'cc' ));
|
||||
my $authid2 = AddAuthority($auth1, undef, $authtype2 );
|
||||
my $authid2 = AddAuthority($auth2, undef, $authtype2 );
|
||||
|
||||
# create a biblio with one 109 and two 609s to be touched
|
||||
# seems exceptional see bug 13760 comment10
|
||||
|
|
|
|||
|
|
@ -643,6 +643,10 @@ subtest 'UNIMARC' => sub {
|
|||
# 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;
|
||||
|
||||
$dbh->do(
|
||||
"UPDATE marc_subfield_structure SET tagfield = '106' WHERE authtypecode = 'PERSO_NAME' AND frameworkcode='' AND tagfield='100' "
|
||||
) or die $dbh->errstr;
|
||||
|
||||
run_tests('UNIMARC');
|
||||
$schema->storage->txn_rollback;
|
||||
$schema->storage->txn_begin;
|
||||
|
|
|
|||
|
|
@ -187,6 +187,12 @@ unimarc,*,ind1:auth2,ind2:auth1|);
|
|||
$record = MARC::Record->new;
|
||||
$record->append_fields( MARC::Field->new( '210', '1', '2', a => 'Name' ) );
|
||||
$type = $builder->build({ source => 'AuthType', value => { auth_tag_to_report => '210'} });
|
||||
my $dbh = C4::Context->dbh;
|
||||
$dbh->do(
|
||||
"INSERT INTO marc_subfield_structure (tagfield,authtypecode,frameworkcode) VALUES ('210',?,'')", undef,
|
||||
$type->{authtypecode}
|
||||
) or die $dbh->errstr;
|
||||
|
||||
$authid = C4::AuthoritiesMarc::AddAuthority( $record, undef, $type->{authtypecode} );
|
||||
$auth = Koha::Authorities->find( $authid );
|
||||
is( $auth->controlled_indicators({ biblio_tag => '345' })->{ind1}, '2', 'UNIMARC: Swapped ind2' );
|
||||
|
|
|
|||
|
|
@ -53,11 +53,15 @@ subtest 'after_authority_action hook' => sub {
|
|||
my $plugin = Koha::Plugin::Test->new->enable;
|
||||
my $id;
|
||||
|
||||
warnings_exist { ( $id ) = C4::AuthoritiesMarc::AddAuthority( MARC::Record->new, undef, 'PERSO_NAME' ); }
|
||||
my $record = MARC::Record->new;
|
||||
$record->append_fields( MARC::Field->new( '100', '1', '2', a => 'Name' ) );
|
||||
my $type = $builder->build( { source => 'AuthType', value => { auth_tag_to_report => '100' } } );
|
||||
|
||||
warnings_exist { ( $id ) = C4::AuthoritiesMarc::AddAuthority( $record, undef, $type->{authtypecode} ); }
|
||||
qr/after_authority_action called with action: create, id: \d+/,
|
||||
'AddAuthority calls the hook with action=create, id passed';
|
||||
|
||||
warnings_exist { C4::AuthoritiesMarc::ModAuthority( $id, MARC::Record->new, 'PERSO_NAME', { skip_merge => 1 } ); }
|
||||
warnings_exist { C4::AuthoritiesMarc::ModAuthority( $id, $record, $type->{authtypecode}, { skip_merge => 1 } ); }
|
||||
qr/after_authority_action called with action: modify, id: $id/,
|
||||
'ModAuthority calls the hook with action=modify, id passed';
|
||||
|
||||
|
|
|
|||
|
|
@ -252,16 +252,30 @@ subtest 'put() tests' => sub {
|
|||
$patron->set_password( { password => $password, skip_validation => 1 } );
|
||||
my $userid = $patron->userid;
|
||||
|
||||
my $authority = $builder->build_object({ 'class' => 'Koha::Authorities', value => {
|
||||
marcxml => q|<?xml version="1.0" encoding="UTF-8"?>
|
||||
my $authority_type = $builder->build_object(
|
||||
{
|
||||
'class' => 'Koha::Authority::Types',
|
||||
value => {
|
||||
auth_tag_to_report => '110',
|
||||
}
|
||||
}
|
||||
);
|
||||
my $authority = $builder->build_object(
|
||||
{
|
||||
'class' => 'Koha::Authorities',
|
||||
value => {
|
||||
marcxml => q|<?xml version="1.0" encoding="UTF-8"?>
|
||||
<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/MARC21/slim" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">
|
||||
<controlfield tag="001">1001</controlfield>
|
||||
<datafield tag="110" ind1=" " ind2=" ">
|
||||
<subfield code="9">102</subfield>
|
||||
<subfield code="a">My Corporation</subfield>
|
||||
</datafield>
|
||||
</record>|
|
||||
} });
|
||||
</record>|,
|
||||
authtypecode => $authority_type->authtypecode,
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
my $authid = $authority->id;
|
||||
my $authtypecode = $authority->authtypecode;
|
||||
|
|
|
|||
Loading…
Reference in New Issue