Bug 22144: Add method metadata() to Koha::Biblio
[koha.git] / t / db_dependent / Koha / Biblio.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use Test::More tests => 3;
21
22 use C4::Biblio;
23 use Koha::Database;
24
25 BEGIN {
26     use_ok('Koha::Biblio');
27     use_ok('Koha::Biblios');
28 }
29
30 my $schema = Koha::Database->new->schema;
31
32 subtest 'metadata() tests' => sub {
33
34     plan tests => 4;
35
36     $schema->storage->txn_begin;
37
38     my $title = 'Oranges and Peaches';
39
40     my $record = MARC::Record->new();
41     my $field = MARC::Field->new('245','','','a' => $title);
42     $record->append_fields( $field );
43     my ($biblionumber) = C4::Biblio::AddBiblio($record, '');
44
45     my $biblio = Koha::Biblios->find( $biblionumber );
46     is( ref $biblio, 'Koha::Biblio', 'Found a Koha::Biblio object' );
47
48     my $metadata = $biblio->metadata;
49     is( ref $metadata, 'Koha::Biblio::Metadata', 'Method metadata() returned a Koha::Biblio::Metadata object' );
50
51     my $record2 = $metadata->record;
52     is( ref $record2, 'MARC::Record', 'Method record() returned a MARC::Record object' );
53
54     is( $record2->field('245')->subfield("a"), $title, 'Title in 245$a matches title from original record object' );
55
56     $schema->storage->txn_rollback;
57 };