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

(-)a/t/Heading.t (-4 / +51 lines)
Lines 1-14 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
#
2
#
3
# This Koha test module is a stub!  
3
# This file is part of Koha.
4
# Add more tests here!!!
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>.
5
17
6
use strict;
18
use strict;
7
use warnings;
19
use warnings;
8
20
9
use Test::More tests => 1;
21
use Test::More tests => 3;
22
23
use t::lib::Mocks;
10
24
11
BEGIN {
25
BEGIN {
12
        use_ok('C4::Heading');
26
    use_ok('C4::Heading');
13
}
27
}
14
28
29
subtest "MARC21 tests" => sub {
30
    plan tests => 7;
31
32
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
33
34
    ok(C4::Heading::valid_bib_heading_subfield('100', 'a'), '100a valid');
35
    ok(!C4::Heading::valid_bib_heading_subfield('100', 'e'), '100e not valid');
36
37
    ok(C4::Heading::valid_bib_heading_subfield('110', 'a'), '110a valid');
38
    ok(!C4::Heading::valid_bib_heading_subfield('110', 'e'), '110e not valid');
39
40
    ok(C4::Heading::valid_bib_heading_subfield('600', 'a'), '600a valid');
41
    ok(!C4::Heading::valid_bib_heading_subfield('600', 'e'), '600e not valid');
42
43
    ok(!C4::Heading::valid_bib_heading_subfield('012', 'a'), '012a invalid field');
44
};
45
46
subtest "UNIMARC tests" => sub {
47
    plan tests => 7;
48
49
    t::lib::Mocks::mock_preference('marcflavour', 'UNIMARC');
50
51
    ok(C4::Heading::valid_bib_heading_subfield('100', 'a'), '100a valid');
52
    ok(!C4::Heading::valid_bib_heading_subfield('100', 'i'), '100i not valid');
53
54
    ok(C4::Heading::valid_bib_heading_subfield('110', 'a'), '110a valid');
55
    ok(!C4::Heading::valid_bib_heading_subfield('110', 'i'), '110i not valid');
56
57
    ok(C4::Heading::valid_bib_heading_subfield('600', 'a'), '600a valid');
58
    ok(!C4::Heading::valid_bib_heading_subfield('600', 'i'), '600i not valid');
59
60
    ok(!C4::Heading::valid_bib_heading_subfield('012', 'a'), '012a invalid field');
61
}
(-)a/t/db_dependent/Biblio.t (-4 / +78 lines)
Lines 348-353 sub run_tests { Link Here
348
    like( $marcurl->[0]->{MARCURL}, qr/^https/, 'GetMarcUrls did not stumble over a preceding space' );
348
    like( $marcurl->[0]->{MARCURL}, qr/^https/, 'GetMarcUrls did not stumble over a preceding space' );
349
    ok( $marcflavour ne 'MARC21' || $marcurl->[1]->{MARCURL} =~ /^http:\/\//,
349
    ok( $marcflavour ne 'MARC21' || $marcurl->[1]->{MARCURL} =~ /^http:\/\//,
350
        'GetMarcUrls prefixed a MARC21 URL with http://' );
350
        'GetMarcUrls prefixed a MARC21 URL with http://' );
351
352
    # Automatic authority creation
353
    t::lib::Mocks::mock_preference('BiblioAddsAuthorities', 1);
354
    t::lib::Mocks::mock_preference('AutoCreateAuthorities', 1);
355
    my $authorities_mod = Test::MockModule->new( 'C4::AuthoritiesMarc' );
356
    $authorities_mod->mock(
357
        'SearchAuthorities',
358
        sub {
359
            my @results;
360
            return \@results, 0;
361
        }
362
    );
363
    $success = 0;
364
    $field = create_author_field('Author Name');
365
    eval {
366
        $marc_record->append_fields($field);
367
        $success = ModBiblio($marc_record,$biblionumber,'');
368
    } or do {
369
        diag($@);
370
        $success = 0;
371
    };
372
    ok($success, "ModBiblio handles authority addition for author");
373
374
    my ($author_field, $author_subfield, $author_relator_subfield) = get_author_field();
375
    $field = $marc_record->field($author_field);
376
    ok($field->subfield($author_subfield), "ModBiblio keeps $author_field$author_subfield intact");
377
378
    my $authid = $field->subfield('9');
379
    ok($authid, 'ModBiblio adds authority id');
380
381
    use_ok('C4::AuthoritiesMarc');
382
    my $auth_record = C4::AuthoritiesMarc::GetAuthority($authid);
383
    ok($auth_record, 'Authority record successfully retrieved');
384
385
386
    my ($auth_author_field, $auth_author_subfield) = get_auth_author_field();
387
    $field = $auth_record->field($auth_author_field);
388
    ok($field, "Authority record contains field $auth_author_field");
389
    is(
390
        $field->subfield($auth_author_subfield),
391
        'Author Name',
392
        'Authority $auth_author_field$auth_author_subfield contains author name'
393
    );
394
    is($field->subfield($author_relator_subfield), undef, 'Authority does not contain relator subfield');
395
396
    # Reset settings
397
    t::lib::Mocks::mock_preference('BiblioAddsAuthorities', 0);
398
    t::lib::Mocks::mock_preference('AutoCreateAuthorities', 0);
351
}
399
}
352
400
353
sub get_title_field {
401
sub get_title_field {
Lines 370-375 sub get_itemnumber_field { Link Here
370
    return ( $marc_flavour eq 'UNIMARC' ) ? ( '995', '9' ) : ( '952', '9' );
418
    return ( $marc_flavour eq 'UNIMARC' ) ? ( '995', '9' ) : ( '952', '9' );
371
}
419
}
372
420
421
sub get_author_field {
422
    my $marc_flavour = C4::Context->preference('marcflavour');
423
    return ( $marc_flavour eq 'UNIMARC' ) ? ( '700', 'a', '4' ) : ( '100', 'a', 'e' );
424
}
425
426
sub get_auth_author_field {
427
    my $marc_flavour = C4::Context->preference('marcflavour');
428
    return ( $marc_flavour eq 'UNIMARC' ) ? ( '106', 'a' ) : ( '100', 'a' );
429
}
430
373
sub create_title_field {
431
sub create_title_field {
374
    my ( $title, $marcflavour ) = @_;
432
    my ( $title, $marcflavour ) = @_;
375
433
Lines 401-422 sub create_issn_field { Link Here
401
    return $field;
459
    return $field;
402
}
460
}
403
461
462
sub create_author_field {
463
    my ( $author ) = @_;
464
465
    my ( $author_field, $author_subfield, $author_relator_subfield ) = get_author_field();
466
    my $field = MARC::Field->new(
467
        $author_field, '', '',
468
        $author_subfield => $author,
469
        $author_relator_subfield => 'aut'
470
    );
471
472
    return $field;
473
}
474
404
subtest 'MARC21' => sub {
475
subtest 'MARC21' => sub {
405
    plan tests => 34;
476
    plan tests => 42;
406
    run_tests('MARC21');
477
    run_tests('MARC21');
407
    $schema->storage->txn_rollback;
478
    $schema->storage->txn_rollback;
408
    $schema->storage->txn_begin;
479
    $schema->storage->txn_begin;
409
};
480
};
410
481
411
subtest 'UNIMARC' => sub {
482
subtest 'UNIMARC' => sub {
412
    plan tests => 34;
483
    plan tests => 42;
484
485
    # Mock the auth type data for UNIMARC
486
    $dbh->do("UPDATE auth_types SET auth_tag_to_report = '106' WHERE auth_tag_to_report = '100'") or die $dbh->errstr;
487
413
    run_tests('UNIMARC');
488
    run_tests('UNIMARC');
414
    $schema->storage->txn_rollback;
489
    $schema->storage->txn_rollback;
415
    $schema->storage->txn_begin;
490
    $schema->storage->txn_begin;
416
};
491
};
417
492
418
subtest 'NORMARC' => sub {
493
subtest 'NORMARC' => sub {
419
    plan tests => 34;
494
    plan tests => 42;
420
    run_tests('NORMARC');
495
    run_tests('NORMARC');
421
    $schema->storage->txn_rollback;
496
    $schema->storage->txn_rollback;
422
    $schema->storage->txn_begin;
497
    $schema->storage->txn_begin;
423
- 

Return to bug 21826