From 242493899b042d15c4655b89f2c1465f0ecb2a38 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Sat, 14 May 2022 12:07:17 +0000 Subject: [PATCH] Bug 30756: Further adjustments to Koha_Authority.t Content-Type: text/plain; charset=utf-8 Remove use of exported_records file in favor of TestBuilder. Remove conditional tests with SKIP block. Create reservoir record. Test plan: Run t/db_dependent/Koha_Authority.t Signed-off-by: Marcel de Rooy --- t/db_dependent/Koha_Authority.t | 107 ++++++++---------- .../zebraexport/authority/exported_records | 1 - 2 files changed, 47 insertions(+), 61 deletions(-) delete mode 100644 t/db_dependent/data/marc21/zebraexport/authority/exported_records diff --git a/t/db_dependent/Koha_Authority.t b/t/db_dependent/Koha_Authority.t index 159bb3bb20..4369df3195 100755 --- a/t/db_dependent/Koha_Authority.t +++ b/t/db_dependent/Koha_Authority.t @@ -1,5 +1,6 @@ #!/usr/bin/perl +# Copyright 2022 Koha Development Team, Marcel de Rooy # Copyright 2012 C & P Bibliography Services # # This file is part of Koha. @@ -19,15 +20,12 @@ use Modern::Perl; use Test::More tests => 3; +use Data::Dumper qw/Dumper/; -use File::Basename; -use MARC::Batch; -use MARC::File; -use IO::File; +use MARC::File::XML; + +use t::lib::TestBuilder; -use C4::Context; -use C4::Charset qw( MarcToUTF8Record ); -use C4::AuthoritiesMarc qw( AddAuthority ); use Koha::Database; use Koha::Authorities; @@ -37,71 +35,60 @@ BEGIN { our $schema = Koha::Database->new->schema; $schema->storage->txn_begin; -our $dbh = C4::Context->dbh; - -subtest 'Part 1' => sub { - # TODO Move this part to a t/lib packages - my $sourcedir = dirname(__FILE__) . "/data"; - my $input_marc_file = "$sourcedir/marc21/zebraexport/authority/exported_records"; - - my $fh = IO::File->new($input_marc_file); - my $batch = MARC::Batch->new( 'USMARC', $fh ); - while ( my $record = $batch->next ) { - C4::Charset::MarcToUTF8Record($record, 'MARC21'); - AddAuthority($record, '', ''); - } - - my $record = MARC::Record->new; - $record->add_fields( - [ '001', '1234' ], - [ '150', ' ', ' ', a => 'Cooking' ], - [ '450', ' ', ' ', a => 'Cookery' ], - ); - my $authority = Koha::MetadataRecord::Authority->new($record); - +our $builder = t::lib::TestBuilder->new; + +our $record1 = MARC::Record->new; +$record1->add_fields( + [ '001', '1234' ], + [ '150', ' ', ' ', a => 'Cooking' ], + [ '450', ' ', ' ', a => 'Cookery' ], +); +our $record2 = MARC::Record->new; +$record2->add_fields( + [ '001', '2345' ], + [ '150', ' ', ' ', a => 'Baking' ], + [ '450', ' ', ' ', a => 'Bakery' ], +); + +subtest 'Test new, authorized_heading, authid, get_from_authid' => sub { + plan tests => 7; + + my $auth1 = $builder->build_object({ class => 'Koha::Authorities', + value => { marcxml => $record1->as_xml }, + }); + my $auth2 = $builder->build_object({ class => 'Koha::Authorities', + value => { marcxml => $record2->as_xml }, + }); + + my $authority = Koha::MetadataRecord::Authority->new( $record1 ); is(ref($authority), 'Koha::MetadataRecord::Authority', 'Created valid Koha::MetadataRecord::Authority object'); - is($authority->authorized_heading(), 'Cooking', 'Authorized heading was correct'); + is_deeply($authority->record, $record1, 'Saved record'); - is_deeply($authority->record, $record, 'Saved record'); - - my $authid = Koha::Authorities->search->next->authid; - - $authority = Koha::MetadataRecord::Authority->get_from_authid($authid); - + $authority = Koha::MetadataRecord::Authority->get_from_authid( $auth2->id ); is(ref($authority), 'Koha::MetadataRecord::Authority', 'Retrieved valid Koha::MetadataRecord::Authority object'); - - is($authority->authid, $authid, 'Object authid is correct'); - - is($authority->record->field('001')->data(), $authid, 'Retrieved correct record'); + is($authority->authid, $auth2->id, 'Object authid is correct'); + is($authority->record->field('001')->data(), '2345', 'Retrieved original 001'); # Note: not created via AddAuthority $authority = Koha::MetadataRecord::Authority->get_from_authid('alphabetsoup'); is($authority, undef, 'No invalid record is retrieved'); }; -subtest 'Part2' => sub { - SKIP: { - my $sth = $dbh->prepare("SELECT import_record_id FROM import_records WHERE record_type = 'auth' LIMIT 1;"); - $sth->execute(); - - my $import_record_id; - for my $row ($sth->fetchrow_hashref) { - $import_record_id = $row->{'import_record_id'}; - } +subtest 'Test get_from_breeding' => sub { + plan tests => 4; - skip 'No authorities in reservoir', 3 unless $import_record_id; - my $authority = Koha::MetadataRecord::Authority->get_from_breeding($import_record_id); + my $import = $builder->build({ source => 'ImportRecord', + value => { marcxml => $record1->as_xml, record_type => 'auth' }, + }); + my $import_record_id = $import->{import_record_id}; - is(ref($authority), 'Koha::MetadataRecord::Authority', 'Retrieved valid Koha::MetadataRecord::Authority object'); - - is($authority->authid, undef, 'Records in reservoir do not have an authid'); - - is(ref($authority->record), 'MARC::Record', 'MARC record attached to authority'); + my $authority = Koha::MetadataRecord::Authority->get_from_breeding($import_record_id); + is(ref($authority), 'Koha::MetadataRecord::Authority', 'Retrieved valid Koha::MetadataRecord::Authority object'); + is($authority->authid, undef, 'Records in reservoir do not have an authid'); + is(ref($authority->record), 'MARC::Record', 'MARC record attached to authority'); - $authority = Koha::MetadataRecord::Authority->get_from_breeding('alphabetsoup'); - is($authority, undef, 'No invalid record is retrieved from reservoir'); - } - done_testing(); + $authority = Koha::MetadataRecord::Authority->get_from_breeding('alphabetsoup'); + is($authority, undef, 'No invalid record is retrieved from reservoir'); }; $schema->storage->txn_rollback; diff --git a/t/db_dependent/data/marc21/zebraexport/authority/exported_records b/t/db_dependent/data/marc21/zebraexport/authority/exported_records deleted file mode 100644 index 930c9451af..0000000000 --- a/t/db_dependent/data/marc21/zebraexport/authority/exported_records +++ /dev/null @@ -1 +0,0 @@ -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 \ No newline at end of file -- 2.20.1