8 use Test::More tests => 2;
13 use t::lib::TestBuilder;
16 use_ok('C4::AuthoritiesMarc::MARC21');
19 my $schema = Koha::Database->new->schema;
20 $schema->storage->txn_begin;
21 my $dbh = C4::Context->dbh;
22 my $builder = t::lib::TestBuilder->new;
24 t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
26 subtest 'CompareFieldWithAuthority tests' => sub {
29 # We are now going to be testing the authorities hierarchy code, and
30 # therefore need to pretend that we have consistent data in our database
31 my $module = Test::MockModule->new('C4::AuthoritiesMarc');
32 $module->mock('GetHeaderAuthority', sub {
33 return {'authtrees' => ''};
35 $module->mock('AddAuthorityTrees', sub {
38 $module->mock('GetAuthority', sub {
40 my $record = MARC::Record->new();
44 [ '151', ' ', ' ', a => 'United States' ]
46 } elsif ($authid eq '2') {
49 [ '151', ' ', ' ', a => 'New York (State)' ],
50 [ '551', ' ', ' ', a => 'United States', w => 'g', 9 => '1' ]
52 } elsif ($authid eq '3') {
55 [ '151', ' ', ' ', a => 'New York (City)' ],
56 [ '551', ' ', ' ', a => 'New York (State)', w => 'g', 9 => '2' ]
58 } elsif ($authid eq '4') {
61 [ '151', ' ', ' ', a => 'New York (City)' ],
62 [ '551', ' ', ' ', a => 'New York (State)', w => 'g' ]
64 } elsif ($authid eq '5') {
67 [ '100', ' ', ' ', a => 'Lastname, Firstname', b => 'b', c => 'c', i => 'i' ]
75 $dbh->do('DELETE FROM auth_types');
76 $builder->build({ source => 'AuthType', value => { authtypecode => 'PERSO_NAME' }});
78 my $field = MARC::Field->new('100', 0, 0, a => 'Lastname, Firstname', b => 'b', c => 'c');
80 ok(C4::AuthoritiesMarc::CompareFieldWithAuthority({'field' => $field, 'authid' => 5}), 'Authority matches');
82 $field->add_subfields(i => 'X');
84 ok(C4::AuthoritiesMarc::CompareFieldWithAuthority({'field' => $field, 'authid' => 5}), 'Compare ignores unlisted subfields');
86 $field->add_subfields(d => 'd');
88 ok(!C4::AuthoritiesMarc::CompareFieldWithAuthority({'field' => $field, 'authid' => 5}), 'Authority does not match');
91 $schema->storage->txn_rollback;