View | Details | Raw Unified | Return to bug 17909
Collapse All | Expand All

(-)a/t/db_dependent/Authorities/Merge.t (-2 / +113 lines)
Lines 4-15 Link Here
4
4
5
use Modern::Perl;
5
use Modern::Perl;
6
6
7
use Test::More tests => 3;
7
use Test::More tests => 4;
8
8
9
use MARC::Record;
9
use MARC::Record;
10
use Test::MockModule;
10
use Test::MockModule;
11
use Test::MockObject;
11
use Test::MockObject;
12
12
13
use t::lib::TestBuilder;
14
13
use C4::Biblio;
15
use C4::Biblio;
14
use Koha::Database;
16
use Koha::Database;
15
17
Lines 20-25 BEGIN { Link Here
20
my $schema  = Koha::Database->new->schema;
22
my $schema  = Koha::Database->new->schema;
21
$schema->storage->txn_begin;
23
$schema->storage->txn_begin;
22
my $dbh = C4::Context->dbh;
24
my $dbh = C4::Context->dbh;
25
my $builder = t::lib::TestBuilder->new;
23
26
24
# Some advanced mocking :)
27
# Some advanced mocking :)
25
my ( @zebrarecords, $index );
28
my ( @zebrarecords, $index );
Lines 117-122 subtest 'Test merge A1 to modified A1' => sub { Link Here
117
    is( $biblio1->field(109)->subfield('b'), $MARC1->field(109)->subfield('b'), 'Record not overwritten while merging');
120
    is( $biblio1->field(109)->subfield('b'), $MARC1->field(109)->subfield('b'), 'Record not overwritten while merging');
118
};
121
};
119
122
123
subtest 'Test merge A1 to B1 (changing authtype)' => sub {
124
# Tests were aimed for bug 9988, moved to 17909 in adjusted form
125
# Would not encourage this type of merge, but we should test what we offer
126
# The merge routine still needs the fixes on bug 17913
127
    plan tests => 8;
128
129
    # create another authtype
130
    my $authtype2 = $builder->build({
131
        source => 'AuthType',
132
        value  => {
133
            auth_tag_to_report => '112',
134
        },
135
    });
136
    # create two fields linked to this auth type
137
    $schema->resultset('MarcSubfieldStructure')->search({ tagfield => [ '112', '712' ] })->delete;
138
    $builder->build({
139
        source => 'MarcSubfieldStructure',
140
        value  => {
141
            tagfield => '112',
142
            tagsubfield => 'a',
143
            authtypecode => $authtype2->{authtypecode},
144
            frameworkcode => '',
145
        },
146
    });
147
    $builder->build({
148
        source => 'MarcSubfieldStructure',
149
        value  => {
150
            tagfield => '712',
151
            tagsubfield => 'a',
152
            authtypecode => $authtype2->{authtypecode},
153
            frameworkcode => '',
154
        },
155
    });
156
157
    # create auth1 (from the earlier type)
158
    my $auth1 = MARC::Record->new;
159
    $auth1->append_fields( MARC::Field->new( '109', '0', '0', 'a' => 'George Orwell', b => 'bb' ));
160
    my $authid1 = AddAuthority($auth1, undef, 'TEST_PERSO');
161
    # create auth2 (new type)
162
    my $auth2 = MARC::Record->new;
163
    $auth2->append_fields( MARC::Field->new( '112', '0', '0', 'a' => 'Batman', c => 'cc' ));
164
    my $authid2 = AddAuthority($auth1, undef, $authtype2->{authtypecode} );
165
166
    # create a biblio with one 109 and two 609s to be touched
167
    # seems exceptional see bug 13760 comment10
168
    my $marc = MARC::Record->new;
169
    $marc->append_fields(
170
        MARC::Field->new( '003', 'some_003' ),
171
        MARC::Field->new( '109', '', '', a => 'G. Orwell', b => 'bb', d => 'd', 9 => $authid1 ),
172
        MARC::Field->new( '245', '', '', a => 'My title' ),
173
        MARC::Field->new( '609', '', '', a => 'Orwell', 9 => "$authid1" ),
174
        MARC::Field->new( '609', '', '', a => 'Orwell', x => 'xx', 9 => "$authid1" ),
175
        MARC::Field->new( '611', '', '', a => 'Added for testing order' ),
176
        MARC::Field->new( '612', '', '', a => 'unrelated', 9 => 'other' ),
177
    );
178
    my ( $biblionumber ) = C4::Biblio::AddBiblio( $marc, '' );
179
    my $oldbiblio = C4::Biblio::GetMarcBiblio( $biblionumber );
180
181
    @zebrarecords = ( $marc );
182
    $index = 0;
183
    my $retval = C4::AuthoritiesMarc::merge( $authid1, $auth1, $authid2, $auth2 );
184
    is( $retval, 1, 'We touched only one biblio' );
185
186
    # Get new marc record for compares
187
    my $newbiblio = C4::Biblio::GetMarcBiblio( $biblionumber );
188
    compare_field_count( $oldbiblio, $newbiblio, 1 );
189
    # TODO The following test will still fail; refined after 17913
190
    compare_field_order( $oldbiblio, $newbiblio, 0 );
191
192
    # Check some fields
193
    is( $newbiblio->field('003')->data,
194
        $oldbiblio->field('003')->data,
195
        'Check contents of a control field not expected to be touched' );
196
    is( $newbiblio->subfield( '245', 'a' ),
197
        $oldbiblio->subfield( '245', 'a' ),
198
        'Check contents of a data field not expected to be touched' );
199
    is( $newbiblio->subfield( '112', 'a' ),
200
        $auth2->subfield( '112', 'a' ), 'Check modified 112a' );
201
    is( $newbiblio->subfield( '112', 'c' ),
202
        $auth2->subfield( '112', 'c' ), 'Check new 112c' );
203
204
    #TODO Check the new 612s (after fix on 17913, they are 112s now)
205
    is( $newbiblio->subfield( '612', 'a' ),
206
        $oldbiblio->subfield( '612', 'a' ), 'Check untouched 612a' );
207
};
208
120
sub set_mocks {
209
sub set_mocks {
121
    # Mock ZOOM objects: They do nothing actually
210
    # Mock ZOOM objects: They do nothing actually
122
    # Get new_record_from_zebra to return the records
211
    # Get new_record_from_zebra to return the records
Lines 136-139 sub set_mocks { Link Here
136
    $zoom_record_obj->mock( 'raw', sub {} );
225
    $zoom_record_obj->mock( 'raw', sub {} );
137
}
226
}
138
227
228
sub compare_field_count {
229
    my ( $oldmarc, $newmarc, $pass ) = @_;
230
    my $t;
231
    if( $pass ) {
232
        is( scalar $newmarc->fields, $t = $oldmarc->fields, "Number of fields still equal to $t" );
233
    } else {
234
        isnt( scalar $newmarc->fields, $t = $oldmarc->fields, "Number of fields not equal to $t" );
235
    }
236
}
237
238
sub compare_field_order {
239
    my ( $oldmarc, $newmarc, $pass ) = @_;
240
    if( $pass ) {
241
        is( ( join q/,/, map { $_->tag; } $newmarc->fields ),
242
            ( join q/,/, map { $_->tag; } $oldmarc->fields ),
243
            'Order of fields unchanged' );
244
    } else {
245
        isnt( ( join q/,/, map { $_->tag; } $newmarc->fields ),
246
            ( join q/,/, map { $_->tag; } $oldmarc->fields ),
247
            'Order of fields changed' );
248
    }
249
}
250
139
$schema->storage->txn_rollback;
251
$schema->storage->txn_rollback;
140
- 

Return to bug 17909