From 6034f9b3814cfbf95c0865968e30e16e2b0576f2 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 24 Jan 2020 13:24:45 +0000 Subject: [PATCH] Bug 24421: Unit tests Signed-off-by: Jonathan Druart --- t/db_dependent/Biblio.t | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Biblio.t b/t/db_dependent/Biblio.t index a3886789dd..cc38e07201 100755 --- a/t/db_dependent/Biblio.t +++ b/t/db_dependent/Biblio.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 12; +use Test::More tests => 13; use Test::MockModule; use List::MoreUtils qw( uniq ); use MARC::Record; @@ -643,6 +643,43 @@ subtest 'ModBiblio called from linker test' => sub { is($called,0,"We didn't call to link bibs because from linker"); }; +subtest "LinkBibHeadingsToAuthorities record generation tests" => sub { + plan tests => 3; + + # Set up mocks to ensure authorities are generated + my $biblio_mod = Test::MockModule->new( 'C4::Linker::Default' ); + $biblio_mod->mock( 'get_link', sub { + return (undef,undef); + }); + # UNIMARC valid headings are built from the marc_subfield_structure for bibs and + # include all subfields as valid, testing with MARC21 should be sufficient for now + t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); + t::lib::Mocks::mock_preference('AutoCreateAuthorities', '1'); + + my $linker = C4::Linker::Default->new(); + my $record = MARC::Record->new(); + + # Generate a record including all valid subfields and an invalid one 'e' + my $field = MARC::Field->new('650','','','a' => 'Beach city', 'b' => 'Weirdness', 'v' => 'Fiction', 'x' => 'Books', 'y' => '21st Century', 'z' => 'Fish Stew Pizza', 'e' => 'Depicted'); + + $record->append_fields($field); + my ( $num_headings_changed, $results ) = LinkBibHeadingsToAuthorities($linker, $record, "",undef); + + is( $num_headings_changed, 1, 'We changed the one we passed' ); + is_deeply( $results->{added}, + {"Beach city Weirdness--Fiction--Books--21st Century--Fish Stew Pizza" => 1 }, + "We added an authority record for the heading" + ); + + # Now we check the authority record itself + my $authority = GetAuthority( $record->subfield('650','9') ); + is( $authority->field('150')->as_string(), + "Beach city Weirdness Fiction Books 21st Century Fish Stew Pizza", + "The generated record contains the correct subfields" + ); + +}; + # Cleanup Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" ); $schema->storage->txn_rollback; -- 2.11.0