3 # Copyright 2012 C & P Bibliography Services
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 use_ok
('Koha::Authority');
30 my $record = MARC
::Record
->new;
34 [ '150', ' ', ' ', a
=> 'Cooking' ],
35 [ '450', ' ', ' ', a
=> 'Cookery' ],
37 my $authority = Koha
::Authority
->new($record);
39 is
(ref($authority), 'Koha::Authority', 'Created valid Koha::Authority object');
41 is
($authority->authorized_heading(), 'Cooking', 'Authorized heading was correct');
43 is_deeply
($authority->record, $record, 'Saved record');
47 my $dbh = C4
::Context
->dbh;
48 my $sth = $dbh->prepare("SELECT authid FROM auth_header LIMIT 1;");
52 for my $row ($sth->fetchrow_hashref) {
53 $authid = $row->{'authid'};
55 skip
'No authorities', 3 unless $authid;
56 $authority = Koha
::Authority
->get_from_authid($authid);
58 is
(ref($authority), 'Koha::Authority', 'Retrieved valid Koha::Authority object');
60 is
($authority->authid, $authid, 'Object authid is correct');
62 is
($authority->record->field('001')->data(), $authid, 'Retrieved correct record');
64 $authority = Koha
::Authority
->get_from_authid('alphabetsoup');
65 is
($authority, undef, 'No invalid record is retrieved');
70 my $dbh = C4
::Context
->dbh;
71 my $sth = $dbh->prepare("SELECT import_record_id FROM import_records WHERE record_type = 'auth' LIMIT 1;");
75 for my $row ($sth->fetchrow_hashref) {
76 $import_record_id = $row->{'import_record_id'};
79 skip
'No authorities in reservoir', 3 unless $import_record_id;
80 $authority = Koha
::Authority
->get_from_breeding($import_record_id);
82 is
(ref($authority), 'Koha::Authority', 'Retrieved valid Koha::Authority object');
84 is
($authority->authid, undef, 'Records in reservoir do not have an authid');
86 is
(ref($authority->record), 'MARC::Record', 'MARC record attached to authority');
88 $authority = Koha
::Authority
->get_from_breeding('alphabetsoup');
89 is
($authority, undef, 'No invalid record is retrieved from reservoir');