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

(-)a/t/db_dependent/AuthoritiesMarc.t (-4 / +42 lines)
Lines 5-11 Link Here
5
5
6
use Modern::Perl;
6
use Modern::Perl;
7
7
8
use Test::More tests => 12;
8
use Test::More tests => 13;
9
use Test::MockModule;
9
use Test::MockModule;
10
use Test::Warn;
10
use Test::Warn;
11
use MARC::Field;
11
use MARC::Field;
Lines 15-20 use t::lib::Mocks; Link Here
15
use t::lib::TestBuilder;
15
use t::lib::TestBuilder;
16
use Koha::Database;
16
use Koha::Database;
17
use Koha::Authority::Types;
17
use Koha::Authority::Types;
18
use Koha::Libraries;
18
19
19
BEGIN {
20
BEGIN {
20
        use_ok('C4::AuthoritiesMarc');
21
        use_ok('C4::AuthoritiesMarc');
Lines 29-35 $module->mock('GetHeaderAuthority', sub { Link Here
29
$module->mock('AddAuthorityTrees', sub {
30
$module->mock('AddAuthorityTrees', sub {
30
    return;
31
    return;
31
});
32
});
32
$module->mock('GetAuthority', sub {
33
my $sub_get_authority = sub {
33
    my ($authid) = @_;
34
    my ($authid) = @_;
34
    my $record = MARC::Record->new();
35
    my $record = MARC::Record->new();
35
    if ($authid eq '1') {
36
    if ($authid eq '1') {
Lines 64-70 $module->mock('GetAuthority', sub { Link Here
64
        undef $record;
65
        undef $record;
65
    }
66
    }
66
    return $record;
67
    return $record;
67
});
68
};
69
$module->mock('GetAuthority', $sub_get_authority);
68
70
69
my $schema  = Koha::Database->new->schema;
71
my $schema  = Koha::Database->new->schema;
70
$schema->storage->txn_begin;
72
$schema->storage->txn_begin;
Lines 220-225 subtest 'AddAuthority should respect AUTO_INCREMENT (BZ 18104)' => sub { Link Here
220
    is( $record->field('001')->data, $id3, 'Check updated 001' );
222
    is( $record->field('001')->data, $id3, 'Check updated 001' );
221
};
223
};
222
224
225
subtest 'AddAuthority always updates 003' => sub {
226
    plan tests => 4;
227
228
    $module->unmock('GetAuthority');
229
230
    t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' );
231
232
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
233
    my $library_branchcode = $library->branchcode;
234
    my $library_orgcode = $library->marcorgcode;
235
236
    my $record = MARC::Record->new;
237
    $record->append_fields(
238
        MARC::Field->new( '001', 999 ),
239
        MARC::Field->new( '003', 'ORG_01' ),
240
        MARC::Field->new( '100', '', '', a => 'Marcel' ),
241
        MARC::Field->new( '942', '', '', a => 'PERSO_NAME' ),
242
    );
243
244
    t::lib::Mocks::mock_preference( 'MARCOrgCode', 'ORG_02' );
245
    t::lib::Mocks::mock_userenv({ branchcode => q{} });
246
    my $id = AddAuthority( $record, undef, 'PERSO_NAME' );
247
    is( C4::AuthoritiesMarc::GetAuthority($id)->field('003')->data, 'ORG_02', 'New record: Updated to pref value' );
248
    t::lib::Mocks::mock_userenv({ branchcode => $library_branchcode });
249
    $id = AddAuthority( $record, undef, 'PERSO_NAME' );
250
    is( C4::AuthoritiesMarc::GetAuthority($id)->field('003')->data, $library_orgcode, 'New record: Updated to library value' );
251
252
    t::lib::Mocks::mock_userenv({ branchcode => $library_branchcode });
253
    ModAuthority( $id, $record, 'PERSO_NAME' );
254
    is( C4::AuthoritiesMarc::GetAuthority($id)->field('003')->data, $library_orgcode, 'Changed record: Updated to library value' );
255
    t::lib::Mocks::mock_userenv({ branchcode => q{} });
256
    ModAuthority( $id, $record, 'PERSO_NAME' );
257
    is( C4::AuthoritiesMarc::GetAuthority($id)->field('003')->data, 'ORG_02', 'Changed record: Updated to pref value' );
258
259
    $module->mock('GetAuthority', $sub_get_authority);
260
};
261
223
subtest 'CompareFieldWithAuthority tests' => sub {
262
subtest 'CompareFieldWithAuthority tests' => sub {
224
    plan tests => 3;
263
    plan tests => 3;
225
264
226
- 

Return to bug 28491