Bug 20478: Have the cronjob script advance_notices.pl send digest messages per branch.
[koha.git] / t / db_dependent / Search.t
index bd20a2a..4ef1ebe 100644 (file)
@@ -22,6 +22,7 @@ use utf8;
 use YAML;
 
 use C4::Debug;
+use C4::XSLT;
 require C4::Context;
 
 # work around spurious wide character warnings
@@ -56,9 +57,9 @@ sub index_sample_records_and_launch_zebra {
         system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_bib_cfg  -v none,fatal -g iso2709 -d biblios commit");
     }
     # ... and add large bib records, if present
-    if (-f "$sourcedir/${marc_type}/zebraexport/large_biblio_${indexing_mode}/exported_records.xml") {
+    if (-f "$sourcedir/${marc_type}/zebraexport/large_biblio/exported_records.xml") {
         my $zebra_bib_cfg = 'zebra-biblios-dom.cfg';
-        system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_bib_cfg  -v none,fatal -g marcxml -d biblios update $sourcedir/${marc_type}/zebraexport/large_biblio_${indexing_mode}");
+        system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_bib_cfg  -v none,fatal -g marcxml -d biblios update $sourcedir/${marc_type}/zebraexport/large_biblio");
         system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_bib_cfg  -v none,fatal -g marcxml -d biblios commit");
     }
     if (-f "$sourcedir/${marc_type}/zebraexport/authority/exported_records") {
@@ -99,6 +100,11 @@ our $QueryFuzzy = 0;
 our $UseQueryParser = 0;
 our $SearchEngine = 'Zebra';
 our $marcflavour = 'MARC21';
+our $htdocs = File::Spec->rel2abs(dirname($0));
+my @htdocs = split /\//, $htdocs;
+$htdocs[-2] = 'koha-tmpl';
+$htdocs[-1] = 'opac-tmpl';
+$htdocs = join '/', @htdocs;
 our $contextmodule = new Test::MockModule('C4::Context');
 $contextmodule->mock('preference', sub {
     my ($self, $pref) = @_;
@@ -140,6 +146,40 @@ $contextmodule->mock('preference', sub {
         return '';
     } elsif ($pref eq 'template') {
         return 'prog';
+    } elsif ($pref eq 'OPACXSLTResultsDisplay') {
+        return C4::XSLT::_get_best_default_xslt_filename($htdocs, 'bootstrap','en',$marcflavour . 'slim2OPACResults.xsl');
+    } elsif ($pref eq 'BiblioDefaultView') {
+        return 'normal';
+    } elsif ($pref eq 'IdRef') {
+        return '0';
+    } elsif ($pref eq 'IntranetBiblioDefaultView') {
+        return 'normal';
+    } elsif ($pref eq 'OPACBaseURL') {
+        return 'http://library.mydnsname.org';
+    } elsif ($pref eq 'OPACResultsLibrary') {
+        return 'homebranch';
+    } elsif ($pref eq 'OpacSuppression') {
+        return '0';
+    } elsif ($pref eq 'OPACURLOpenInNewWindow') {
+        return '0';
+    } elsif ($pref eq 'TraceCompleteSubfields') {
+        return '0';
+    } elsif ($pref eq 'TraceSubjectSubdivisions') {
+        return '0';
+    } elsif ($pref eq 'TrackClicks') {
+        return '0';
+    } elsif ($pref eq 'URLLinkText') {
+        return q{};
+    } elsif ($pref eq 'UseAuthoritiesForTracings') {
+        return '1';
+    } elsif ($pref eq 'UseControlNumber') {
+        return '0';
+    } elsif ($pref eq 'UseICU') {
+        return '0';
+    } elsif ($pref eq 'viewISBD') {
+        return '1';
+    } elsif ($pref eq 'EasyAnalyticalRecords') {
+        return '0';
     } else {
         warn "The syspref $pref was requested but I don't know what to say; this indicates that the test requires updating"
             unless $pref =~ m/(XSLT|item|branch|holding|image)/i;
@@ -224,6 +264,8 @@ sub run_marc21_search_tests {
 
     my $indexes = C4::Search::getIndexes();
     is(scalar(grep(/^ti$/, @$indexes)), 1, "Title index supported");
+    is(scalar(grep(/^arl$/, @$indexes)), 1, "Accelerated reading level index supported");
+    is(scalar(grep(/^arp$/, @$indexes)), 1, "Accelerated reading point index supported");
 
     my $bibliomodule = new Test::MockModule('C4::Biblio');
 
@@ -373,7 +415,7 @@ ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'
     ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
     is($results_hashref->{biblioserver}->{hits}, 19, "getRecords generated keyword search for 'salud' matched right number of records");
 
-    my @newresults = searchResults('opac', $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 18, 0, 0,
+    my @newresults = searchResults({'interface' => 'opac'}, $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 18, 0, 0,
         $results_hashref->{'biblioserver'}->{"RECORDS"});
     is(scalar @newresults,18, "searchResults returns requested number of hits");
 
@@ -455,7 +497,7 @@ ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'
     ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
     is($results_hashref->{biblioserver}->{hits}, 26, "getRecords generated availability-limited search matched right number of records");
 
-    @newresults = searchResults('opac', $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 17, 0, 0,
+    @newresults = searchResults({'interface'=>'opac'}, $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 17, 0, 0,
         $results_hashref->{'biblioserver'}->{"RECORDS"});
     my $allavailable = 'true';
     foreach my $result (@newresults) {
@@ -593,7 +635,7 @@ ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'
     # Let's just test a few other bits and bobs, just for fun
 
     ($error, $results_hashref, $facets_loop) = getRecords("Godzina pąsowej róży","Godzina pąsowej róży",[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
-    @newresults = searchResults('intranet', $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 17, 0, 0,
+    @newresults = searchResults({'interface'=>'intranet'}, $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 17, 0, 0,
         $results_hashref->{'biblioserver'}->{"RECORDS"});
     is($newresults[0]->{'alternateholdings_count'}, 1, 'Alternate holdings filled in correctly');
 
@@ -612,7 +654,7 @@ ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'
     });
 
     ($error, $results_hashref, $facets_loop) = getRecords("TEST12121212","TEST12121212",[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
-    @newresults = searchResults('intranet', $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 17, 0, 0,
+    @newresults = searchResults({'interface'=>'intranet'}, $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 17, 0, 0,
         $results_hashref->{'biblioserver'}->{"RECORDS"});
     ok(!exists($newresults[0]->{norequests}), 'presence of a transit does not block hold request action (bug 10741)');
 
@@ -620,7 +662,7 @@ ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'
     ( undef, $results_hashref, $facets_loop ) =
         getRecords('ti:punctuation', 'punctuation', [], [ 'biblioserver' ], '19', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
     is($results_hashref->{biblioserver}->{hits}, 1, "search for ti:punctuation returned expected number of records");
-    warning_like { @newresults = searchResults('intranet', $query_desc,
+    warning_like { @newresults = searchResults({'intranet' => 'intranet'}, $query_desc,
                     $results_hashref->{'biblioserver'}->{'hits'}, 20, 0, 0,
                     $results_hashref->{'biblioserver'}->{"RECORDS"}) }
                 qr/^ERROR DECODING RECORD - Tag "50%" is not a valid tag/,
@@ -730,6 +772,16 @@ ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'
         ['沙士北亞威廉姆'], 0, 10, '', '', 1
     );
     is($count, 1, 'MARC21 authorities: one hit on match contains "沙士北亞威廉姆"');
+    ($auths, $count) = SearchAuthorities(
+        ['LC-card-number'], ['and'], [''], ['contains'],
+        ['99282477'], 0, 10, '', '', 1
+    );
+    is($count, 1, 'MARC21 authorities: one hit on LC-card-number contains "99282477"');
+    ($auths, $count) = SearchAuthorities(
+        ['all'], ['and'], [''], ['contains'],
+        ['professional wrestler'], 0, 10, '', '', 1
+    );
+    is($count, 1, 'MARC21 authorities: one hit on "all" (entire record) contains "professional wrestler"');
 
     $UseQueryParser = 1;
 
@@ -758,7 +810,7 @@ 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, 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('opac', $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 10, 0, 0,
+    @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)');
@@ -929,7 +981,7 @@ sub run_unimarc_search_tests {
 }
 
 subtest 'MARC21 + DOM' => sub {
-    plan tests => 108;
+    plan tests => 112;
     run_marc21_search_tests();
 };