From 73bde2cca346b911aafff2b0011b3f0acdf720ba Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 31 Aug 2022 12:31:46 -0300 Subject: [PATCH] Bug 29697: (QA follow-up) Make tests less fragile This patch makes the tests less fragile to existing data. It does so by making sure that when checking if the item would be hidden by OpacHiddenItems and lost status, the item is not skipped, and thus the notforloan value, as retrieved from the search engine is picked for the notforloan_count calculation. Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Search.t | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/t/db_dependent/Search.t b/t/db_dependent/Search.t index fc40bdde6d..5c34356ac8 100755 --- a/t/db_dependent/Search.t +++ b/t/db_dependent/Search.t @@ -467,13 +467,17 @@ ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0); is($results_hashref->{biblioserver}->{hits}, 2, "getRecords generated availability-limited search matched right number of records"); - @newresults = searchResults({'interface'=>'opac'}, $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 17, 0, 0, - $results_hashref->{'biblioserver'}->{"RECORDS"}); - my $allavailable = 'true'; - foreach my $result (@newresults) { - $allavailable = 'false' unless $result->{availablecount} > 0; + { + my $mock_items = Test::MockModule->new('Koha::Items'); + $mock_items->mock( 'count', 1 ); + @newresults = searchResults({'interface'=>'opac'}, $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 17, 0, 0, + $results_hashref->{'biblioserver'}->{"RECORDS"}); + my $allavailable = 'true'; + foreach my $result (@newresults) { + $allavailable = 'false' unless $result->{availablecount} > 0; + } + is ($allavailable, 'true', 'All records have at least one item available'); } - is ($allavailable, 'true', 'All records have at least one item available'); my $mocked_xslt = Test::MockModule->new('Koha::XSLT::Base'); $mocked_xslt->mock( 'transform', sub { @@ -751,11 +755,16 @@ ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' ( undef, $results_hashref, $facets_loop ) = getRecords('ti:marc the large record', '', [], [ 'biblioserver' ], '20', 0, \%branches, \%itemtypes, 'ccl', undef); is($results_hashref->{biblioserver}->{hits}, 1, "Can do a search that retrieves an over-large bib record (bug 11096)"); - @newresults = searchResults({'interface' =>'opac'}, $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 10, 0, 0, - $results_hashref->{'biblioserver'}->{"RECORDS"}); - is($newresults[0]->{title}, 'Marc the Large Record', 'Able to render the title for over-large bib record (bug 11096)'); - is($newresults[0]->{biblionumber}, '300', 'Over-large bib record has the correct biblionumber (bug 11096)'); - like($newresults[0]->{notes}, qr/This is large note #550/, 'Able to render the notes field for over-large bib record (bug 11096)'); + + { + my $mock_items = Test::MockModule->new('Koha::Items'); + $mock_items->mock( 'count', 1 ); + @newresults = searchResults({'interface' =>'opac'}, $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 10, 0, 0, + $results_hashref->{'biblioserver'}->{"RECORDS"}); + is($newresults[0]->{title}, 'Marc the Large Record', 'Able to render the title for over-large bib record (bug 11096)'); + is($newresults[0]->{biblionumber}, '300', 'Over-large bib record has the correct biblionumber (bug 11096)'); + like($newresults[0]->{notes}, qr/This is large note #550/, 'Able to render the notes field for over-large bib record (bug 11096)'); + } # notforloancount should be returned as part of searchResults output ok( defined $newresults[0]->{notforloancount}, -- 2.34.1