Bug 8728 : Adjust Reserves.t test for resdate and expdate and test setup/teardown
[koha.git] / t / db_dependent / Koha_Authority.t
1 #!/usr/bin/perl
2
3 # Copyright 2012 C & P Bibliography Services
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
15 #
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.
19
20 use strict;
21 use warnings;
22
23 use C4::Context;
24 use Test::More;
25
26 BEGIN {
27         use_ok('Koha::Authority');
28 }
29
30 my $record = MARC::Record->new;
31
32 $record->add_fields(
33         [ '001', '1234' ],
34         [ '150', ' ', ' ', a => 'Cooking' ],
35         [ '450', ' ', ' ', a => 'Cookery' ],
36         );
37 my $authority = Koha::Authority->new($record);
38
39 is(ref($authority), 'Koha::Authority', 'Created valid Koha::Authority object');
40
41 is_deeply($authority->record, $record, 'Saved record');
42
43 SKIP:
44 {
45     my $dbh = C4::Context->dbh;
46     my $sth = $dbh->prepare("SELECT authid FROM auth_header LIMIT 1;");
47     $sth->execute();
48
49     my $authid;
50     for my $row ($sth->fetchrow_hashref) {
51         $authid = $row->{'authid'};
52     }
53     skip 'No authorities', 3 unless $authid;
54     $authority = Koha::Authority->get_from_authid($authid);
55
56     is(ref($authority), 'Koha::Authority', 'Retrieved valid Koha::Authority object');
57
58     is($authority->authid, $authid, 'Object authid is correct');
59
60     is($authority->record->field('001')->data(), $authid, 'Retrieved correct record');
61
62     $authority = Koha::Authority->get_from_authid('alphabetsoup');
63     is($authority, undef, 'No invalid record is retrieved');
64 }
65
66 done_testing();