Bug 12744 - Set language in staff client should have 'Cancel' link
[koha.git] / t / db_dependent / Koha_Authority.t
blob6373fb75f83cf2bf48a73e9f1ca20426f95e1532
1 #!/usr/bin/perl
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
10 # version.
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.
20 use strict;
21 use warnings;
23 use C4::Context;
24 use Test::More;
26 BEGIN {
27 use_ok('Koha::Authority');
30 my $record = MARC::Record->new;
32 $record->add_fields(
33 [ '001', '1234' ],
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');
45 SKIP:
47 my $dbh = C4::Context->dbh;
48 my $sth = $dbh->prepare("SELECT authid FROM auth_header LIMIT 1;");
49 $sth->execute();
51 my $authid;
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');
68 SKIP:
70 my $dbh = C4::Context->dbh;
71 my $sth = $dbh->prepare("SELECT import_record_id FROM import_records WHERE record_type = 'auth' LIMIT 1;");
72 $sth->execute();
74 my $import_record_id;
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');
92 done_testing();