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 <tomascohen@theke.io>
This commit is contained in:
Tomas Cohen Arazi 2022-08-31 12:31:46 -03:00
parent 6e127ad894
commit 73bde2cca3
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
1 changed files with 20 additions and 11 deletions

View File

@ -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},