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; |
31 |
use Koha::Authorities; |
25 |
|
32 |
|
26 |
BEGIN { |
33 |
BEGIN { |
27 |
use_ok('Koha::MetadataRecord::Authority'); |
34 |
use_ok('Koha::MetadataRecord::Authority'); |
28 |
} |
35 |
} |
29 |
|
36 |
|
30 |
my $record = MARC::Record->new; |
37 |
my $schema = Koha::Database->new->schema; |
|
|
38 |
$schema->storage->txn_begin; |
39 |
|
40 |
# TODO Move this part to a t/lib packages |
41 |
my $sourcedir = dirname(__FILE__) . "/data"; |
42 |
my $input_marc_file = "$sourcedir/marc21/zebraexport/authority/exported_records"; |
43 |
|
44 |
my $fh = IO::File->new($input_marc_file); |
45 |
my $batch = MARC::Batch->new( 'USMARC', $fh ); |
46 |
while ( my $record = $batch->next ) { |
47 |
C4::Charset::MarcToUTF8Record($record, 'MARC21'); |
48 |
AddAuthority($record, '', ''); |
49 |
} |
31 |
|
50 |
|
|
|
51 |
my $record = MARC::Record->new; |
32 |
$record->add_fields( |
52 |
$record->add_fields( |
33 |
[ '001', '1234' ], |
53 |
[ '001', '1234' ], |
34 |
[ '150', ' ', ' ', a => 'Cooking' ], |
54 |
[ '150', ' ', ' ', a => 'Cooking' ], |
Lines 42-69
is($authority->authorized_heading(), 'Cooking', 'Authorized heading was correct'
Link Here
|
42 |
|
62 |
|
43 |
is_deeply($authority->record, $record, 'Saved record'); |
63 |
is_deeply($authority->record, $record, 'Saved record'); |
44 |
|
64 |
|
45 |
SKIP: |
65 |
my $authid = Koha::Authorities->search->next->authid; |
46 |
{ |
|
|
47 |
my $dbh = C4::Context->dbh; |
48 |
my $sth = $dbh->prepare("SELECT authid FROM auth_header LIMIT 1;"); |
49 |
$sth->execute(); |
50 |
|
66 |
|
51 |
my $authid; |
67 |
$authority = Koha::MetadataRecord::Authority->get_from_authid($authid); |
52 |
for my $row ($sth->fetchrow_hashref) { |
|
|
53 |
$authid = $row->{'authid'}; |
54 |
} |
55 |
skip 'No authorities', 3 unless $authid; |
56 |
$authority = Koha::MetadataRecord::Authority->get_from_authid($authid); |
57 |
|
68 |
|
58 |
is(ref($authority), 'Koha::MetadataRecord::Authority', 'Retrieved valid Koha::MetadataRecord::Authority object'); |
69 |
is(ref($authority), 'Koha::MetadataRecord::Authority', 'Retrieved valid Koha::MetadataRecord::Authority object'); |
59 |
|
70 |
|
60 |
is($authority->authid, $authid, 'Object authid is correct'); |
71 |
is($authority->authid, $authid, 'Object authid is correct'); |
61 |
|
72 |
|
62 |
is($authority->record->field('001')->data(), $authid, 'Retrieved correct record'); |
73 |
is($authority->record->field('001')->data(), $authid, 'Retrieved correct record'); |
63 |
|
74 |
|
64 |
$authority = Koha::MetadataRecord::Authority->get_from_authid('alphabetsoup'); |
75 |
$authority = Koha::MetadataRecord::Authority->get_from_authid('alphabetsoup'); |
65 |
is($authority, undef, 'No invalid record is retrieved'); |
76 |
is($authority, undef, 'No invalid record is retrieved'); |
66 |
} |
|
|
67 |
|
77 |
|
68 |
SKIP: |
78 |
SKIP: |
69 |
{ |
79 |
{ |
70 |
- |
|
|