View | Details | Raw Unified | Return to bug 15578
Collapse All | Expand All

(-)a/t/db_dependent/Koha_Authority.t (-22 / +36 lines)
Lines 17-34 Link Here
17
# You should have received a copy of the GNU General Public License
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>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use strict;
20
use Modern::Perl;
21
use warnings;
22
21
23
use C4::Context;
22
use C4::Context;
23
use C4::Charset;
24
use C4::AuthoritiesMarc;
25
use Koha::Database;
24
use Test::More;
26
use Test::More;
27
use File::Basename;
28
use MARC::Batch;
29
use MARC::File;
30
use IO::File;
25
31
26
BEGIN {
32
BEGIN {
27
        use_ok('Koha::Authority');
33
    use_ok('Koha::Authority');
28
}
34
}
29
35
30
my $record = MARC::Record->new;
36
my $schema = Koha::Database->new->schema;
37
$schema->storage->txn_begin;
38
39
# TODO Move this part to a t/lib packages
40
my $sourcedir = dirname(__FILE__) . "/data";
41
my $input_marc_file = "$sourcedir/marc21/zebraexport/authority/exported_records";
42
43
my $fh = IO::File->new($input_marc_file);
44
my $batch = MARC::Batch->new( 'USMARC', $fh );
45
while ( my $record = $batch->next ) {
46
    C4::Charset::MarcToUTF8Record($record, 'MARC21');
47
    AddAuthority($record, '', '');
48
}
31
49
50
my $record = MARC::Record->new;
32
$record->add_fields(
51
$record->add_fields(
33
        [ '001', '1234' ],
52
        [ '001', '1234' ],
34
        [ '150', ' ', ' ', a => 'Cooking' ],
53
        [ '150', ' ', ' ', a => 'Cooking' ],
Lines 42-69 is($authority->authorized_heading(), 'Cooking', 'Authorized heading was correct' Link Here
42
61
43
is_deeply($authority->record, $record, 'Saved record');
62
is_deeply($authority->record, $record, 'Saved record');
44
63
45
SKIP:
64
my $dbh = C4::Context->dbh;
46
{
65
my $sth = $dbh->prepare("SELECT authid FROM auth_header LIMIT 1;");
47
    my $dbh = C4::Context->dbh;
66
$sth->execute();
48
    my $sth = $dbh->prepare("SELECT authid FROM auth_header LIMIT 1;");
49
    $sth->execute();
50
67
51
    my $authid;
68
my $authid;
52
    for my $row ($sth->fetchrow_hashref) {
69
for my $row ($sth->fetchrow_hashref) {
53
        $authid = $row->{'authid'};
70
    $authid = $row->{'authid'};
54
    }
71
}
55
    skip 'No authorities', 3 unless $authid;
72
$authority = Koha::Authority->get_from_authid($authid);
56
    $authority = Koha::Authority->get_from_authid($authid);
57
73
58
    is(ref($authority), 'Koha::Authority', 'Retrieved valid Koha::Authority object');
74
is(ref($authority), 'Koha::Authority', 'Retrieved valid Koha::Authority object');
59
75
60
    is($authority->authid, $authid, 'Object authid is correct');
76
is($authority->authid, $authid, 'Object authid is correct');
61
77
62
    is($authority->record->field('001')->data(), $authid, 'Retrieved correct record');
78
is($authority->record->field('001')->data(), $authid, 'Retrieved correct record');
63
79
64
    $authority = Koha::Authority->get_from_authid('alphabetsoup');
80
$authority = Koha::Authority->get_from_authid('alphabetsoup');
65
    is($authority, undef, 'No invalid record is retrieved');
81
is($authority, undef, 'No invalid record is retrieved');
66
}
67
82
68
SKIP:
83
SKIP:
69
{
84
{
70
- 

Return to bug 15578