3 # This file is part of Koha.
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.
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.
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>.
20 use Test::More tests => 5;
22 use t::lib::TestBuilder;
28 use_ok('Koha::Biblio');
29 use_ok('Koha::Biblios');
32 my $schema = Koha::Database->new->schema;
33 my $builder = t::lib::TestBuilder->new;
35 subtest 'metadata() tests' => sub {
39 $schema->storage->txn_begin;
41 my $title = 'Oranges and Peaches';
43 my $record = MARC::Record->new();
44 my $field = MARC::Field->new('245','','','a' => $title);
45 $record->append_fields( $field );
46 my ($biblionumber) = C4::Biblio::AddBiblio($record, '');
48 my $biblio = Koha::Biblios->find( $biblionumber );
49 is( ref $biblio, 'Koha::Biblio', 'Found a Koha::Biblio object' );
51 my $metadata = $biblio->metadata;
52 is( ref $metadata, 'Koha::Biblio::Metadata', 'Method metadata() returned a Koha::Biblio::Metadata object' );
54 my $record2 = $metadata->record;
55 is( ref $record2, 'MARC::Record', 'Method record() returned a MARC::Record object' );
57 is( $record2->field('245')->subfield("a"), $title, 'Title in 245$a matches title from original record object' );
59 $schema->storage->txn_rollback;
62 subtest 'hidden_in_opac() tests' => sub {
66 $schema->storage->txn_begin;
68 my $biblio = $builder->build_sample_biblio();
69 my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
70 my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
72 $item_1->withdrawn( 1 )->store->discard_changes;
73 $item_2->withdrawn( 1 )->store->discard_changes;
75 ok( !$biblio->hidden_in_opac({ rules => { withdrawn => [ 2 ] } }), 'Biblio not hidden' );
77 $item_2->withdrawn( 2 )->store->discard_changes;
78 $biblio->discard_changes; # refresh
80 ok( !$biblio->hidden_in_opac({ rules => { withdrawn => [ 2 ] } }), 'Biblio not hidden' );
82 $item_1->withdrawn( 2 )->store->discard_changes;
83 $biblio->discard_changes; # refresh
85 ok( $biblio->hidden_in_opac({ rules => { withdrawn => [ 2 ] } }), 'Biblio hidden' );
87 $schema->storage->txn_rollback;
90 subtest 'items() tests' => sub {
94 $schema->storage->txn_begin;
96 my $biblio = $builder->build_sample_biblio();
97 my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
98 my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
100 my $items = $biblio->items;
101 is( ref($items), 'Koha::Items', 'Returns a Koha::Items resultset' );
102 is( $items->count, 2, 'Two items in resultset' );
104 my @items = $biblio->items->as_list;
105 is( scalar @items, 2, 'Same result, but in list context' );
107 $schema->storage->txn_rollback;