Line 0
Link Here
|
0 |
- |
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 => 1; |
21 |
use Data::Dumper qw/Dumper/; |
22 |
use MARC::Field; |
23 |
use MARC::Record; |
24 |
use Test::MockModule; |
25 |
|
26 |
use t::lib::TestBuilder; |
27 |
use t::lib::Mocks; |
28 |
use Koha::Database; |
29 |
use Koha::Biblios; |
30 |
use C4::Biblio; |
31 |
|
32 |
|
33 |
my $schema = Koha::Database->new->schema; |
34 |
$schema->storage->txn_begin; |
35 |
our $builder = t::lib::TestBuilder->new; |
36 |
our $marc; |
37 |
|
38 |
subtest 'host_record' => sub { |
39 |
plan tests => 9; |
40 |
|
41 |
t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); |
42 |
my $mod = Test::MockModule->new('C4::Biblio'); |
43 |
$mod->mock( 'GetMarcBiblio', sub { return $marc; } ); |
44 |
|
45 |
my $bib1 = $builder->build_object({ class => 'Koha::Biblios' }); |
46 |
my $bib2 = $builder->build_object({ class => 'Koha::Biblios' }); |
47 |
$marc = MARC::Record->new; |
48 |
|
49 |
is( $bib1->host_record, undef, 'Empty MARC record' ); |
50 |
$marc->append_fields( |
51 |
MARC::Field->new( '773', '', '', g => 'relpart', w => 'xyz' ), |
52 |
); |
53 |
is( $bib1->host_record, undef, 'No control number found' ); |
54 |
$marc->field('773')->update( w => 'xyz)' . ($bib2->biblionumber + 1) ); |
55 |
is( $bib1->host_record, undef, 'Control number does not exist' ); |
56 |
# Make it work now |
57 |
$marc->field('773')->update( w => 'xyz)' . $bib2->biblionumber ); |
58 |
my $host = $bib1->host_record; |
59 |
is( ref( $host ), 'Koha::Biblio', 'Correct object returned' ); |
60 |
is( $host->biblionumber, $bib2->biblionumber, 'Check biblionumber' ); |
61 |
# Add second 773 |
62 |
$marc->append_fields( MARC::Field->new( '773', '', '', w => 'second' ) ); |
63 |
$host = $bib1->host_record; |
64 |
is( $host->biblionumber, $bib2->biblionumber, 'Two 773s, record still found' ); |
65 |
# Test no_items flag |
66 |
$host = $bib1->host_record({ no_items => 1 }); |
67 |
is( $host->biblionumber, $bib2->biblionumber, 'Record found with no_items' ); |
68 |
$builder->build({ source => 'Item', value => { biblionumber => $bib1->biblionumber } }); |
69 |
is( $bib1->host_record({ no_items => 1 }), undef, 'Record not found with no_items flag after adding one item' ); |
70 |
# Test list context |
71 |
my @temp = $bib1->host_record; |
72 |
is( $temp[1], 'relpart', 'Return $g in list context' ); |
73 |
}; |
74 |
|
75 |
$schema->storage->txn_rollback(); |