3 # Copyright 2015 Koha Development team
5 # This file is part of Koha
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use Test::More tests => 5;
29 use Koha::Authorities;
30 use Koha::Authority::MergeRequest;
31 use Koha::Authority::MergeRequests;
32 use Koha::Authority::Type;
33 use Koha::Authority::Types;
36 use t::lib::TestBuilder;
38 my $schema = Koha::Database->new->schema;
39 $schema->storage->txn_begin;
41 my $builder = t::lib::TestBuilder->new;
42 my $nb_of_authorities = Koha::Authorities->search->count;
43 my $nb_of_authority_types = Koha::Authority::Types->search->count;
44 my $new_authority_type_1 = Koha::Authority::Type->new(
45 { authtypecode => 'my_ac_1',
46 authtypetext => 'my authority type text 1',
47 auth_tag_to_report => '100',
48 summary => 'my summary for authority 1',
51 my $new_authority_1 = Koha::Authority->new( { authtypecode => $new_authority_type_1->authtypecode, } )->store;
52 my $new_authority_2 = Koha::Authority->new( { authtypecode => $new_authority_type_1->authtypecode, } )->store;
54 is( Koha::Authority::Types->search->count, $nb_of_authority_types + 1, 'The authority type should have been added' );
55 is( Koha::Authorities->search->count, $nb_of_authorities + 2, 'The 2 authorities should have been added' );
57 $new_authority_1->delete;
58 is( Koha::Authorities->search->count, $nb_of_authorities + 1, 'Delete should have deleted the authority' );
60 subtest 'New merge request, method oldmarc' => sub {
63 my $marc = MARC::Record->new;
65 MARC::Field->new( '100', '', '', a => 'a', b => 'b_findme' ),
66 MARC::Field->new( '200', '', '', a => 'aa' ),
68 my $req = Koha::Authority::MergeRequest->new({
69 authid => $new_authority_2->authid,
70 reportxml => 'Should be discarded',
72 is( $req->reportxml, undef, 'Reportxml is undef without oldrecord' );
74 $req = Koha::Authority::MergeRequest->new({
75 authid => $new_authority_2->authid,
78 like( $req->reportxml, qr/b_findme/, 'Reportxml initialized' );
80 # Check if oldmarc is a MARC::Record and has one field
81 is( ref( $req->oldmarc ), 'MARC::Record', 'Check oldmarc method' );
82 is( scalar $req->oldmarc->fields, 1, 'Contains one field' );
85 subtest 'Testing reporting_tag_xml in MergeRequests' => sub {
88 my $record = MARC::Record->new;
89 $record->append_fields(
90 MARC::Field->new( '024', '', '', a => 'aaa' ),
91 MARC::Field->new( '100', '', '', a => 'Best author' ),
92 MARC::Field->new( '234', '', '', a => 'Just a field' ),
94 my $xml = Koha::Authority::MergeRequests->reporting_tag_xml({
95 record => $record, tag => '110',
97 is( $xml, undef, 'Expected no result for wrong tag' );
98 $xml = Koha::Authority::MergeRequests->reporting_tag_xml({
99 record => $record, tag => '100',
101 my $newrecord = MARC::Record->new_from_xml(
103 C4::Context->preference('marcflavour') eq 'UNIMARC' ?
106 ); # MARC format does not actually matter here
107 cmp_deeply( $record->field('100')->subfields,
108 $newrecord->field('100')->subfields,
109 'Compare reporting tag in both records',
113 $schema->storage->txn_rollback;