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 => 7;
22 use_ok('Koha::BiblioUtils');
23 use_ok('Koha::BiblioUtils::Iterator');
26 use t::lib::TestBuilder;
29 my $schema = Koha::Database->new()->schema();
30 $schema->storage->txn_begin();
32 # Delete issues to prevent foreign constraint failures.
33 # blank all biblios, biblioitems, and items.
34 $schema->resultset('Issue')->delete();
35 $schema->resultset('Biblio')->delete();
37 my $location = 'My Location';
38 my $builder = t::lib::TestBuilder->new;
39 my $library = $builder->build({
42 my $itemtype = $builder->build({
46 # Create a biblio instance for testing
47 t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
48 my $biblio = $builder->build_sample_biblio();
51 $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
53 my $rs = $schema->resultset('Biblioitem')->search({});
54 my $iterator = Koha::BiblioUtils::Iterator->new($rs, items => 1 );
55 my $record = $iterator->next();
56 my $expected_tags = [ 100, 245, 942, 952, 999 ];
57 my @result_tags = map { $_->tag() } $record->field('...');
58 my @sorted_tags = sort @result_tags;
59 is_deeply(\@sorted_tags,$expected_tags, "Got the same tags as expected");
62 my $biblio_2 = $builder->build_sample_biblio();
63 my $biblio_3 = $builder->build_sample_biblio();
64 my $records = Koha::BiblioUtils->get_all_biblios_iterator();
65 is( $records->next->id, $biblio->biblionumber );
66 is( $records->next->id, $biblio_2->biblionumber );
67 is( $records->next->id, $biblio_3->biblionumber );
68 is( $records->next, undef, 'no more record' );
70 $schema->storage->txn_rollback();