From b99770e5b5bae85a9b6bb76be7c2b253ae7ef61f Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 23 Nov 2020 18:37:39 +0000 Subject: [PATCH] Bug 26957: Unit tests Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart (cherry picked from commit a1f44a831e2c41da8074bca4fcf250335687135a) Signed-off-by: Fridolin Somers --- t/db_dependent/Search.t | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Search.t b/t/db_dependent/Search.t index 7065380840..93398ebfec 100755 --- a/t/db_dependent/Search.t +++ b/t/db_dependent/Search.t @@ -29,9 +29,10 @@ require C4::Context; # work around spurious wide character warnings use open ':std', ':encoding(utf8)'; -use Test::More tests => 2; +use Test::More tests => 3; use Test::MockModule; use Test::Warn; +use t::lib::Mocks; use Koha::Caches; @@ -211,6 +212,7 @@ sub mock_GetMarcSubfieldStructure { 'biblio.biblionumber' => [{ tagfield => '999', tagsubfield => 'c' }], 'biblio.isbn' => [{ tagfield => '020', tagsubfield => 'a' }], 'biblio.title' => [{ tagfield => '245', tagsubfield => 'a' }], + 'biblio.author' => [{ tagfield => '100', tagsubfield => 'a' }], 'biblio.notes' => [{ tagfield => '500', tagsubfield => 'a' }], 'items.barcode' => [{ tagfield => '952', tagsubfield => 'p' }], 'items.booksellerid' => [{ tagfield => '952', tagsubfield => 'e' }], @@ -921,6 +923,42 @@ subtest 'UNIMARC + DOM' => sub { run_unimarc_search_tests(); }; + +subtest 'FindDuplicate' => sub { + plan tests => 3; + Koha::Caches->get_instance('config')->flush_all; + t::lib::Mocks::mock_preference('marcflavour', 'marc21' ); + mock_GetMarcSubfieldStructure('marc21'); + my $searcher = Test::MockModule->new('C4::Search'); + $searcher->mock('SimpleSearch', sub { + warn shift @_; + return 1; + }); + + my $record = MARC::Record->new; + $record->add_fields( + [ '100', '0', '0', a => 'Morgenstern, Erin' ], + [ '245', '0', '0', a => 'The night circus /' ] + ); + warning_is { C4::Search::FindDuplicate($record);} + q/ti,ext:"The night circus \/" and au,ext:"Morgenstern, Erin"/,"Term correctly formed"; + + $record = MARC::Record->new; + $record->add_fields( + [ '245', '0', '0', a => 'The book of nothing /' ] + ); + warning_is { C4::Search::FindDuplicate($record);} + q/ti,ext:"The book of nothing \/"/,"Term correctly formed"; + + $record = MARC::Record->new; + $record->add_fields( + [ '245', '0', '0', a => 'Frog and toad all year /' ] + ); + warning_is { C4::Search::FindDuplicate($record);} + q/ti,ext:"Frog and toad all year \/"/,"Term correctly formed"; + +}; + # Make sure that following tests are not using our config settings Koha::Caches->get_instance('config')->flush_all; -- 2.39.5