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

(-)a/t/db_dependent/Koha_Authority.t (-60 / +47 lines)
Lines 1-5 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
# Copyright 2022 Koha Development Team, Marcel de Rooy
3
# Copyright 2012 C & P Bibliography Services
4
# Copyright 2012 C & P Bibliography Services
4
#
5
#
5
# This file is part of Koha.
6
# This file is part of Koha.
Lines 19-33 Link Here
19
20
20
use Modern::Perl;
21
use Modern::Perl;
21
use Test::More tests => 3;
22
use Test::More tests => 3;
23
use Data::Dumper qw/Dumper/;
22
24
23
use File::Basename;
25
use MARC::File::XML;
24
use MARC::Batch;
26
25
use MARC::File;
27
use t::lib::TestBuilder;
26
use IO::File;
27
28
28
use C4::Context;
29
use C4::Charset qw( MarcToUTF8Record );
30
use C4::AuthoritiesMarc qw( AddAuthority );
31
use Koha::Database;
29
use Koha::Database;
32
use Koha::Authorities;
30
use Koha::Authorities;
33
31
Lines 37-107 BEGIN { Link Here
37
35
38
our $schema = Koha::Database->new->schema;
36
our $schema = Koha::Database->new->schema;
39
$schema->storage->txn_begin;
37
$schema->storage->txn_begin;
40
our $dbh = C4::Context->dbh;
38
our $builder = t::lib::TestBuilder->new;
41
39
42
subtest 'Part 1' => sub {
40
our $record1 = MARC::Record->new;
43
    # TODO Move this part to a t/lib packages
41
$record1->add_fields(
44
    my $sourcedir = dirname(__FILE__) . "/data";
42
    [ '001', '1234' ],
45
    my $input_marc_file = "$sourcedir/marc21/zebraexport/authority/exported_records";
43
    [ '150', ' ', ' ', a => 'Cooking' ],
46
44
    [ '450', ' ', ' ', a => 'Cookery' ],
47
    my $fh = IO::File->new($input_marc_file);
45
);
48
    my $batch = MARC::Batch->new( 'USMARC', $fh );
46
our $record2 = MARC::Record->new;
49
    while ( my $record = $batch->next ) {
47
$record2->add_fields(
50
        C4::Charset::MarcToUTF8Record($record, 'MARC21');
48
    [ '001', '2345' ],
51
        AddAuthority($record, '', '');
49
    [ '150', ' ', ' ', a => 'Baking' ],
52
    }
50
    [ '450', ' ', ' ', a => 'Bakery' ],
53
51
);
54
    my $record = MARC::Record->new;
52
55
    $record->add_fields(
53
subtest 'Test new, authorized_heading, authid, get_from_authid' => sub {
56
            [ '001', '1234' ],
54
    plan tests => 7;
57
            [ '150', ' ', ' ', a => 'Cooking' ],
55
58
            [ '450', ' ', ' ', a => 'Cookery' ],
56
    my $auth1 = $builder->build_object({ class => 'Koha::Authorities',
59
            );
57
        value => { marcxml => $record1->as_xml },
60
    my $authority = Koha::MetadataRecord::Authority->new($record);
58
    });
61
59
    my $auth2 = $builder->build_object({ class => 'Koha::Authorities',
60
        value => { marcxml => $record2->as_xml },
61
    });
62
63
    my $authority = Koha::MetadataRecord::Authority->new( $record1 );
62
    is(ref($authority), 'Koha::MetadataRecord::Authority', 'Created valid Koha::MetadataRecord::Authority object');
64
    is(ref($authority), 'Koha::MetadataRecord::Authority', 'Created valid Koha::MetadataRecord::Authority object');
63
64
    is($authority->authorized_heading(), 'Cooking', 'Authorized heading was correct');
65
    is($authority->authorized_heading(), 'Cooking', 'Authorized heading was correct');
66
    is_deeply($authority->record, $record1, 'Saved record');
65
67
66
    is_deeply($authority->record, $record, 'Saved record');
68
    $authority = Koha::MetadataRecord::Authority->get_from_authid( $auth2->id );
67
68
    my $authid = Koha::Authorities->search->next->authid;
69
70
    $authority = Koha::MetadataRecord::Authority->get_from_authid($authid);
71
72
    is(ref($authority), 'Koha::MetadataRecord::Authority', 'Retrieved valid Koha::MetadataRecord::Authority object');
69
    is(ref($authority), 'Koha::MetadataRecord::Authority', 'Retrieved valid Koha::MetadataRecord::Authority object');
73
70
    is($authority->authid, $auth2->id, 'Object authid is correct');
74
    is($authority->authid, $authid, 'Object authid is correct');
71
    is($authority->record->field('001')->data(), '2345', 'Retrieved original 001'); # Note: not created via AddAuthority
75
76
    is($authority->record->field('001')->data(), $authid, 'Retrieved correct record');
77
72
78
    $authority = Koha::MetadataRecord::Authority->get_from_authid('alphabetsoup');
73
    $authority = Koha::MetadataRecord::Authority->get_from_authid('alphabetsoup');
79
    is($authority, undef, 'No invalid record is retrieved');
74
    is($authority, undef, 'No invalid record is retrieved');
80
};
75
};
81
76
82
subtest 'Part2' => sub {
77
subtest 'Test get_from_breeding' => sub {
83
    SKIP: {
78
    plan tests => 4;
84
        my $sth = $dbh->prepare("SELECT import_record_id FROM import_records WHERE record_type = 'auth' LIMIT 1;");
85
        $sth->execute();
86
87
        my $import_record_id;
88
        for my $row ($sth->fetchrow_hashref) {
89
            $import_record_id = $row->{'import_record_id'};
90
        }
91
79
92
        skip 'No authorities in reservoir', 3 unless $import_record_id;
80
    my $import = $builder->build({ source => 'ImportRecord',
93
        my $authority = Koha::MetadataRecord::Authority->get_from_breeding($import_record_id);
81
        value => { marcxml => $record1->as_xml, record_type => 'auth' },
82
    });
83
    my $import_record_id = $import->{import_record_id};
94
84
95
        is(ref($authority), 'Koha::MetadataRecord::Authority', 'Retrieved valid Koha::MetadataRecord::Authority object');
85
    my $authority = Koha::MetadataRecord::Authority->get_from_breeding($import_record_id);
96
86
    is(ref($authority), 'Koha::MetadataRecord::Authority', 'Retrieved valid Koha::MetadataRecord::Authority object');
97
        is($authority->authid, undef, 'Records in reservoir do not have an authid');
87
    is($authority->authid, undef, 'Records in reservoir do not have an authid');
98
88
    is(ref($authority->record), 'MARC::Record', 'MARC record attached to authority');
99
        is(ref($authority->record), 'MARC::Record', 'MARC record attached to authority');
100
89
101
        $authority = Koha::MetadataRecord::Authority->get_from_breeding('alphabetsoup');
90
    $authority = Koha::MetadataRecord::Authority->get_from_breeding('alphabetsoup');
102
        is($authority, undef, 'No invalid record is retrieved from reservoir');
91
    is($authority, undef, 'No invalid record is retrieved from reservoir');
103
    }
104
    done_testing();
105
};
92
};
106
93
107
$schema->storage->txn_rollback;
94
$schema->storage->txn_rollback;
(-)a/t/db_dependent/data/marc21/zebraexport/authority/exported_records (-2 lines)
Line 1 Link Here
1
08502cz  a2201729n  45000010002000000030004000020050017000060080041000230100031000640350023000950400145001180460037002630460023003000530019003231000037003423700080003793720012004593740017004713740022004883740018005103750009005283770008005374000036005454000037005814000037006184000035006554000036006904000033007264000028007594000041007874000034008284000031008624000031008934000027009244000037009514000037009884000031010254000047010564000034011034000039011374000038011764000024012144000026012384000033012644000039012974000035013364000039013714000025014104000039014354000034014744000040015084000042015484000030015904000041016204000043016614000038017044000029017424000028017714000026017994000045018254000045018704000061019154000052019764000047020284000045020754000057021204000055021774000053022324000035022854000061023204000049023814000061024304000062024914000052025534000031026054000037026364000059026734000047027324000049027794000061028284000050028894000057029394000059029964000048030554000031031034000047031344000029031814000035032104000045032454000057032904000055033474000041034024000043034434000055034864000055035414000041035964000053036374000042036904000042037324000042037744000040038164000053038564000035039094000040039444000044039844000044040284000058040724000042041304000040041724000038042124000038042504000038042884000038043264000035043644000029043996670056044286670047044846700052045316700097045836700084046806700094047646700049048586700070049076700031049776700058050086700134050666700066052006700056052666700054053226700068053766700071054446700091055156700051056066700026056576700106056836700122057896700055059116700134059666700067061006700071061676700044062386700045062826700040063276700310063676780080066779420015067576DLC20131010200219.0831215n| azannaabn          |b aaa        an  78095332 zsh 85120820   a(OCoLC)oca00230409  aDLCbengerdacDLCdDLCdMHdOCoLCdNjPdIUdWUdDLCdOCoLCdWUdDLCdDLC-OKdUkdSG-SiILAdCU-HEdUkdDLCdInUdOCoLCdCStdOCoLCdCStdUPB  f[..1564-04-26]g1616-04-232edtf  f15640426g16160423 0aPR2750bPR31121 aShakespeare, William,d1564-1616  aStratford-upon-Avon, EnglandbStratford-upon-Avon, EnglandeLondon, England  aTheatre  aPoet2itoamc  aDramatist2itoamc  aActor2itoamc  amale  aeng1 aShakspeare, William,d1564-16161 aŠekʻspiri, Uiliam,d1564-16161 aSaixpēr, Gouilliam,d1564-16161 aShakspere, William,d1564-16161 aShikisbīr, Wilyam,d1564-16161 aSzekspir, Wiliam,d1564-16161 aŠekspyras,d1564-16161 aShekspir, Vilʹi︠a︡m,d1564-16161 aŠekspir, Viljem,d1564-16161 aTsikinya-chaka,d1564-16161 aSha-shih-pi-ya,d1564-16161 aShashibiya,d1564-16161 aSheḳspir, Ṿilyam,d1564-16161 aShaḳspir, Ṿilyam,d1564-16161 aSyeiksŭpʻio,d1564-16161 aShekspir, V.q(Vilʹi︠a︡m),d1564-16161 aSzekspir, William,d1564-16161 aShakespeare, Guglielmo,d1564-16161 aShake-speare, William,d1564-16160 aSha-ō,d1564-16161 aŞekspir,d1564-16161 aShekspir, Uiliam,d1564-16161 aShekspir, U.q(Uiliam),d1564-16161 aŠekspir, Vilijam,d1564-16161 aṢēkspiyar, Viliyam,d1564-16161 aShakspir,d1564-16161 aShekspyr, Vyli︠e︡m,d1564-16161 aŞekspir, Velyam,d1564-16161 aṢēkspiyar, Villiyam,d1564-16161 aShēkʻspʻiyr, Vlilliam,d1564-16161 aṢēkspiyar,d1564-16161 aṢēkspiyar Mahākavi,d1564-16161 aṢēkspiyar Mahākaviya,d1564-16161 aSheḳspier, Ṿilyam,d1564-16161 aShēkʻspir,d1564-16161 aShakespeare,d1564-16160 aŚeksper,d1564-16161 aШекспир, Вильям,d1564-16161 aШекспир, Уильям,d1564-16161 aשייקספיר, וויליאם,d1564-16161 aשייקספיר, וו.,d1564-16161 aשיקספיר, וויליאם1 aשיקספיר, ויליאם1 aשיקספיר, ויליאם,d1564-16161 aשכספיר, ויליאם,d1564-16161 aשכספיר, וילים,d1564-16161 aשכספיר, ו׳1 aשעפקספיר, וויליאם,d1564-16161 aשעקספיער, וויליאם1 aשעקספיער, וויליאם,d1564-16161 aשעקספיער, ווילליאםd1564-16161 aשעקספיער, וו.,d1564-16161 aשעקספיר1 aשעקספיר, וו1 aשעקספיר, וויליאם,d1564-16161 aשעקספיר, וויליאמ1 aשעקספיר, ווילליאם1 aשעקספיר, ווילליאם,d1564-16161 aשעקספיר, וו.,d1564-16161 aשעקספיר, װיליאם,d1564-16161 aשעקספיר, װילליאם,d1564-16161 aשעקספיר, װ.,d1564-16161 aשעקספער1 aשעקספער, וויליאמ1 aשקספיר1 aשקספיר, וו1 aשקספיר, וויליאם1 aשקספיר, וויליאם,d1564-16161 aשקספיר, ווילים,d1564-16161 aשקספיר, וילאם1 aשקספיר, ויליאם1 aשקספיר, ויליאם,d1564-16161 aשקספיר, ויליים,d1564-16161 aשקספיר, וילים1 aשקספיר, וילים,d1564-16161 aشاكسبير، وليم1 aشاكسپير، وليم1 aشكسبير، وليام1 aشكسبير، وليم1 aشكسبير، وليم،d1564-16161 aشكسبير، و.1 aشكسپير، وليم1 aشكسپير، ويليام1 aشيكسبير، وليام1 aشيكسبير، وليام.،d1564-16161 aشيكسبير، وليم1 aشکسبير، وليم1 aوليم شکسبير1 a沙士北亞威廉姆,d1564-16161 a沙士比亞威廉姆,d1564-16161 a莎士比亞威廉姆,d1564-16161 a莎士比亞威廉,d1564-16161 a莎士比亞,d1564-1616  aMachine-derived non-Latin script reference project.  aNon-Latin script references not evaluated.  aPlessow, G. L. Um Shakespeares nordentum, 1937.  aSha-shih-pi-ya yen chiu wen chi, 1982 (subj.)bt.p. (Sha-shih-pi-ya) cover p. 4 (Shashibiya)  aHis The plays and poems of William Shakspeare, 1966:bt.p. (William Shakspeare)  aHamleṭ ṿe-Sheḳspir, c1983:bp. 19 (Ṿilyam Sheḳspir; b. 4-26-1564; d. 4-25-1616)  aSyeiksŭpʻio, 1978:bt.p. (Syeiksŭpʻio)  aIskusstvo klassicheskogo monologa [SR] 19--:blabel (V. Shekspir)  aUiliam Šekʻspiri, 1996.  aHelsztyński, S. Wizerunek Williama Szekspira, 1947.  anuc86-2792: Doccioli, M. Fonti italiane dei drammi di Guglielmo Shakespeare [MI] 1914b(hdg.: on NIC rept.: Shakespeare, William)  aHis Shake-speares sonnets, 1984:bt.p. (William Shake-speare)  aHis Toroirasu to Kureshida, 1927:bp. 290 (Sha-ō)  aNihon kokugo d.j.b(Sha-ō: Shakespeare William)  aHis Kral Lir, 1912:bt.p. (Şekspir; W. Shakespeare [in rom.])  aUiliam Shekspir, 1982:bt.p. (Uiliam Shekspir) cover (U. Shekspir)  aObradović, M. "Narodna demokratija" u Jugoslaviji, 1995:bp. [5] (Vilijam Šekspir)  aHāmleṭ, 1962:bt.p (Viliyam Ṣēkspiyar)  aNāy Shakspir, 1972.  aBL auth. file, 10 Nov. 2004b(refs.: Shekspyr, Vyli︠e︡m, 1564-1616; Şekspir, Velyam, 1564-1616)  aSILAS database, Dec. 28, 2004b(hdg.: Shakespeare, William, 1564-1616; usages: Villiyam Ṣēkspiyar; Ṣēkspiyar)  aRu̇miyoo Ju̇liy-e qoyar, 1988:bt.p. (Śeksper)  aLC database, Dec. 28, 2004b(hdg.: Shakespeare, William, 1564-1616; usages: Ṣēkspiyar Mahākavi; Ṣēkspiyar Mahākaviya)  aYulius Tsezar, 1918:bt.p. (Ṿilyam Sheḳspier [part. voc.])  aHṛomēos ew Ciwleēdda, 1866:bp. 9 (Vlilliam Shēkʻspʻiyr)  aArkʻay Lir, 2006:bt.p. (Shēkʻspir)  aHark, hark the lark, 1934b(Shakespeare)  aHis My cellphone number is 99282477  aEncyclopedia Britannica, via WWW, Aug. 31, 2012b(William Shakespeare; William Shakspere; byname Bard of Avon or Swan of Avon; baptized Apr. 26, 1564 in Stratford-upon-Avon, Warwickshire, Eng.; d. Apr. 23, 1616 in Stratford-upon-Avon; English poet, dramatist, and actor; worked in London from around 1592)0 aWilliam Shakespeare (1564-1616) was an English poet, playwright, and actor.  aPERSO_NAME00789cz  a2200217n  45000010005000000030004000050050017000090080041000260100017000670400023000840530018001071000016001254000012001414000016001534000014001694000027001836700192002106700084004026700070004869420015005561709DLC20181024104214.0991028n| acannaabn          |a aaa        an  99282477   aDLCbengcDLCdDLC 0aPS3556.O391731 aFoley, Mick0 aMankind0 aCactus Jack0 aDude Love1 aFoley, Michael Francis  aHis Have a nice day! 2000:bCIP t.p. (Mankind) galley (Mick Foley; professional wrestler who has taken on various names in his career: Dude Love, Cactus Jack, and, most recently, Mankind)  aMick Foley tribute page (WWW), Oct. 28, 1999b(Cactus Jack, Dude Love, Mankind)  aMick Foley, c2000:bp. 7 (Michael Francis Foley, b. July 7, 1965)  aPERSO_NAME
2
- 

Return to bug 30756