+ # retrieve records that are larger than the MARC limit of 99,999 octets
+ ( undef, $results_hashref, $facets_loop ) =
+ getRecords('ti:marc the large record', '', [], [ 'biblioserver' ], '20', 0, undef, \%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)');
+
+ # notforloancount should be returned as part of searchResults output
+ ok( defined $newresults[0]->{notforloancount},
+ '\'notforloancount\' defined in searchResults output (Bug 12419)');
+ is( $newresults[0]->{notforloancount}, 2,
+ '\'notforloancount\' == 2 (Bug 12419)');
+
+ # verify that we don't attempt to sort if no results were returned
+ # because of a query error
+ warning_like {( undef, $results_hashref, $facets_loop ) =
+ getRecords('ccl=( AND )', '', ['title_az'], [ 'biblioserver' ], '20', 0, undef, \%branches, \%itemtypes, 'ccl', undef)
+ } qr/WARNING: query problem with/, 'got warning instead of crash when attempting to run invalid query (bug 9578)';
+
+ # Test facet calculation
+ my $facets_counter = {};
+ my $facets = C4::Koha::getFacets();
+ # Create a record with a 100$z field
+ my $marc_record = MARC::Record->new;
+ $marc_record->add_fields(
+ [ '001', '1234' ],
+ [ '100', ' ', ' ', a => 'Cohen Arazi, Tomas' ],
+ [ '100', 'z', ' ', a => 'Tomasito' ],
+ [ '245', ' ', ' ', a => 'First try' ]
+ );
+ C4::Search::_get_facets_data_from_record( $marc_record, $facets, $facets_counter );
+ is_deeply( { au => { 'Cohen Arazi, Tomas' => 1 } }, $facets_counter,
+ "_get_facets_data_from_record doesn't count 100\$z (Bug 12788)");
+ $marc_record = MARC::Record->new;
+ $marc_record->add_fields(
+ [ '001', '1234' ],
+ [ '100', ' ', ' ', a => 'Cohen Arazi, Tomas' ],
+ [ '100', 'z', ' ', a => 'Tomasito' ],
+ [ '245', ' ', ' ', a => 'Second try' ]
+ );
+ C4::Search::_get_facets_data_from_record( $marc_record, $facets, $facets_counter );
+ is_deeply( { au => { 'Cohen Arazi, Tomas' => 2 } }, $facets_counter,
+ "_get_facets_data_from_record correctly counts author facet twice");
+
+ # Test _get_facets_info
+ my $facets_info = C4::Search::_get_facets_info( $facets );
+ my $expected_facets_info_marc21 = {
+ 'au' => { 'expanded' => undef,
+ 'label_value' => "Authors" },
+ 'ccode' => { 'expanded' => undef,
+ 'label_value' => "CollectionCodes" },
+ 'holdingbranch' => { 'expanded' => undef,
+ 'label_value' => "HoldingLibrary" },
+ 'itype' => { 'expanded' => undef,
+ 'label_value' => "ItemTypes" },
+ 'location' => { 'expanded' => undef,
+ 'label_value' => "Location" },
+ 'se' => { 'expanded' => undef,
+ 'label_value' => "Series" },
+ 'su-geo' => { 'expanded' => undef,
+ 'label_value' => "Places" },
+ 'su-to' => { 'expanded' => undef,
+ 'label_value' => "Topics" },
+ 'su-ut' => { 'expanded' => undef,
+ 'label_value' => "Titles" }
+ };
+ delete $expected_facets_info_marc21->{holdingbranch}
+ if Koha::Libraries->count == 1;
+ is_deeply( $facets_info, $expected_facets_info_marc21,
+ "_get_facets_info returns the correct data");