|
Lines 1-70
Link Here
|
| 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 => 7; |
| 21 |
|
| 22 |
use_ok('Koha::BiblioUtils'); |
| 23 |
use_ok('Koha::BiblioUtils::Iterator'); |
| 24 |
|
| 25 |
use Koha::Database; |
| 26 |
use t::lib::TestBuilder; |
| 27 |
use t::lib::Mocks; |
| 28 |
|
| 29 |
my $schema = Koha::Database->new()->schema(); |
| 30 |
$schema->storage->txn_begin(); |
| 31 |
|
| 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(); |
| 36 |
|
| 37 |
my $location = 'My Location'; |
| 38 |
my $builder = t::lib::TestBuilder->new; |
| 39 |
my $library = $builder->build({ |
| 40 |
source => 'Branch', |
| 41 |
}); |
| 42 |
my $itemtype = $builder->build({ |
| 43 |
source => 'Itemtype', |
| 44 |
}); |
| 45 |
|
| 46 |
# Create a biblio instance for testing |
| 47 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
| 48 |
my $biblio = $builder->build_sample_biblio(); |
| 49 |
|
| 50 |
# Add an item. |
| 51 |
$builder->build_sample_item({ biblionumber => $biblio->biblionumber }); |
| 52 |
|
| 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"); |
| 60 |
|
| 61 |
|
| 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' ); |
| 69 |
|
| 70 |
$schema->storage->txn_rollback(); |
| 71 |
- |