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_deeply($authority->record, $record, 'Saved record');
45 my $dbh = C4::Context->dbh;
46 my $sth = $dbh->prepare("SELECT authid FROM auth_header LIMIT 1;");
50 for my $row ($sth->fetchrow_hashref) {
51 $authid = $row->{'authid'};
53 skip 'No authorities', 3 unless $authid;
54 $authority = Koha::Authority->get_from_authid($authid);
56 is(ref($authority), 'Koha::Authority', 'Retrieved valid Koha::Authority object');
58 is($authority->authid, $authid, 'Object authid is correct');
60 is($authority->record->field('001')->data(), $authid, 'Retrieved correct record');
62 $authority = Koha::Authority->get_from_authid('alphabetsoup');
63 is($authority, undef, 'No invalid record is retrieved');