use Modern::Perl;
-use Test::More tests => 10;
+use Test::More tests => 12;
use Test::MockModule;
use Test::Warn;
+use MARC::Field;
use MARC::Record;
use t::lib::Mocks;
use Koha::Authority::Types;
BEGIN {
- use_ok('C4::AuthoritiesMarc');
+ use_ok('C4::AuthoritiesMarc', qw( GetHeaderAuthority AddAuthority AddAuthorityTrees GetAuthority BuildAuthHierarchies GenerateHierarchy BuildSummary DelAuthority CompareFieldWithAuthority ModAuthority merge ));
}
# We are now going to be testing the authorities hierarchy code, and
[ '151', ' ', ' ', a => 'New York (City)' ],
[ '551', ' ', ' ', a => 'New York (State)', w => 'g' ]
);
+ } elsif ($authid eq '5') {
+ $record->add_fields(
+ [ '001', '5' ],
+ [ '100', ' ', ' ', a => 'Lastname, Firstname', b => 'b', c => 'c', i => 'i' ]
+ );
} else {
undef $record;
}
is( $record->field('001')->data, $id3, 'Check updated 001' );
};
+subtest 'CompareFieldWithAuthority tests' => sub {
+ plan tests => 3;
+
+ t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
+
+ $builder->build({ source => 'AuthType', value => { authtypecode => 'PERSO_NAME' }});
+
+ my $field = MARC::Field->new('100', 0, 0, a => 'Lastname, Firstname', b => 'b', c => 'c');
+
+ ok(C4::AuthoritiesMarc::CompareFieldWithAuthority({'field' => $field, 'authid' => 5}), 'Authority matches');
+
+ $field->add_subfields(i => 'X');
+
+ ok(C4::AuthoritiesMarc::CompareFieldWithAuthority({'field' => $field, 'authid' => 5}), 'Compare ignores unlisted subfields');
+
+ $field->add_subfields(d => 'd');
+
+ ok(!C4::AuthoritiesMarc::CompareFieldWithAuthority({'field' => $field, 'authid' => 5}), 'Authority does not match');
+};
+
$schema->storage->txn_rollback;
$module->unmock('GetAuthority');
$schema->storage->txn_rollback;
};
+
+subtest 'DelAuthority() tests' => sub {
+
+ plan tests => 2;
+
+ $schema->storage->txn_begin;
+
+ my $auth_type = 'GEOGR_NAME';
+ my $record = MARC::Record->new;
+ $record->add_fields(
+ [ '001', '1' ],
+ [ '151', ' ', ' ', a => 'United States' ]
+ );
+;
+ my $auth_id = AddAuthority( $record, undef, $auth_type );
+
+ my $mocked_authorities_marc = Test::MockModule->new('C4::AuthoritiesMarc');
+ $mocked_authorities_marc->mock( 'merge', sub { warn 'merge called'; } );
+
+ warning_is
+ { DelAuthority({ authid => $auth_id }); }
+ 'merge called',
+ 'No param, merge called';
+
+ $auth_id = AddAuthority( $record, undef, $auth_type );
+
+ warning_is
+ { DelAuthority({ authid => $auth_id, skip_merge => 1 }); }
+ undef,
+ 'skip_merge passed, merge not called';
+
+ $schema->storage->txn_rollback;
+};