Bug 20478: Have the cronjob script advance_notices.pl send digest messages per branch.
[koha.git] / t / db_dependent / Search.t
index aeec564..4ef1ebe 100644 (file)
@@ -22,18 +22,23 @@ use utf8;
 use YAML;
 
 use C4::Debug;
+use C4::XSLT;
 require C4::Context;
 
 # work around spurious wide character warnings
 use open ':std', ':encoding(utf8)';
 
-use Test::More tests => 4;
+use Test::More tests => 2;
 use Test::MockModule;
+use Test::Warn;
+
+use Koha::Caches;
+
 use MARC::Record;
 use File::Spec;
 use File::Basename;
 use File::Find;
-use Test::Warn;
+
 use File::Temp qw/ tempdir /;
 use File::Path;
 
@@ -41,27 +46,27 @@ our $child;
 our $datadir;
 
 sub index_sample_records_and_launch_zebra {
-    my ($datadir, $indexing_mode, $marc_type) = @_;
+    my ($datadir, $marc_type) = @_;
 
     my $sourcedir = dirname(__FILE__) . "/data";
     unlink("$datadir/zebra.log");
     if (-f "$sourcedir/${marc_type}/zebraexport/biblio/exported_records") {
-        my $zebra_bib_cfg = ($indexing_mode eq 'dom') ? 'zebra-biblios-dom.cfg' : 'zebra-biblios.cfg';
-        system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_bib_cfg  -v none,fatal,warn  -g iso2709 -d biblios init");
-        system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_bib_cfg  -v none,fatal,warn   -g iso2709 -d biblios update $sourcedir/${marc_type}/zebraexport/biblio");
-        system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_bib_cfg  -v none,fatal,warn  -g iso2709 -d biblios commit");
+        my $zebra_bib_cfg = 'zebra-biblios-dom.cfg';
+        system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_bib_cfg  -v none,fatal -g iso2709 -d biblios init");
+        system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_bib_cfg  -v none,fatal -g iso2709 -d biblios update $sourcedir/${marc_type}/zebraexport/biblio");
+        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") {
-        my $zebra_bib_cfg = ($indexing_mode eq 'dom') ? 'zebra-biblios-dom.cfg' : 'zebra-biblios.cfg';
-        system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_bib_cfg  -v none,fatal,warn   -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,warn  -g marcxml -d biblios commit");
+    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");
+        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") {
-        my $zebra_auth_cfg = ($indexing_mode eq 'dom') ? 'zebra-authorities-dom.cfg' : 'zebra-authorities.cfg';
-        system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_auth_cfg  -v none,fatal,warn  -g iso2709 -d authorities init");
-        system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_auth_cfg  -v none,fatal,warn   -g iso2709 -d authorities update $sourcedir/${marc_type}/zebraexport/authority");
-        system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_auth_cfg  -v none,fatal,warn  -g iso2709 -d authorities commit");
+        my $zebra_auth_cfg = 'zebra-authorities-dom.cfg';
+        system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_auth_cfg  -v none,fatal -g iso2709 -d authorities init");
+        system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_auth_cfg  -v none,fatal -g iso2709 -d authorities update $sourcedir/${marc_type}/zebraexport/authority");
+        system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_auth_cfg  -v none,fatal -g iso2709 -d authorities commit");
     }
 
     $child = fork();
@@ -95,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) = @_;
@@ -132,6 +142,44 @@ $contextmodule->mock('preference', sub {
         return 'holding';
     } elsif ($pref eq 'UNIMARCAuthorsFacetsSeparator') {
         return '--';
+    } elsif ($pref eq 'casAuthentication' or $pref eq 'casLogout' or $pref eq 'casServerUrl' ) {
+        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;
@@ -144,67 +192,66 @@ $contextmodule->mock('queryparser', sub {
     return $QParser;
 });
 
-sub mock_marcfromkohafield {
+our $bibliomodule = new Test::MockModule('C4::Biblio');
+
+sub mock_GetMarcSubfieldStructure {
     my $marc_type = shift;
     if ($marc_type eq 'marc21') {
-        $contextmodule->mock('marcfromkohafield', sub {
+        $bibliomodule->mock('GetMarcSubfieldStructure', sub {
             return {
-                '' => {
-                    'biblio.biblionumber' => [ '999', 'c' ],
-                    'items.barcode' => ['952', 'p' ],
-                    'items.booksellerid' => ['952', 'e' ],
-                    'items.ccode' => ['952', '8' ],
-                    'items.cn_sort' => ['952', '6' ],
-                    'items.cn_source' => ['952', '2' ],
-                    'items.coded_location_qualifier' => ['952', 'f' ],
-                    'items.copynumber' => ['952', 't' ],
-                    'items.damaged' => ['952', '4' ],
-                    'items.dateaccessioned' => ['952', 'd' ],
-                    'items.datelastborrowed' => ['952', 's' ],
-                    'items.datelastseen' => ['952', 'r' ],
-                    'items.enumchron' => ['952', 'h' ],
-                    'items.holdingbranch' => ['952', 'b' ],
-                    'items.homebranch' => ['952', 'a' ],
-                    'items.issues' => ['952', 'l' ],
-                    'items.itemcallnumber' => ['952', 'o' ],
-                    'items.itemlost' => ['952', '1' ],
-                    'items.itemnotes' => ['952', 'z' ],
-                    'items.itemnumber' => ['952', '9' ],
-                    'items.itype' => ['952', 'y' ],
-                    'items.location' => ['952', 'c' ],
-                    'items.materials' => ['952', '3' ],
-                    'items.nonpublicnote' => ['952', 'x' ],
-                    'items.notforloan' => ['952', '7' ],
-                    'items.onloan' => ['952', 'q' ],
-                    'items.price' => ['952', 'g' ],
-                    'items.renewals' => ['952', 'm' ],
-                    'items.replacementprice' => ['952', 'v' ],
-                    'items.replacementpricedate' => ['952', 'w' ],
-                    'items.reserves' => ['952', 'n' ],
-                    'items.restricted' => ['952', '5' ],
-                    'items.stack' => ['952', 'j' ],
-                    'items.uri' => ['952', 'u' ],
-                    'items.withdrawn' => ['952', '0' ]
-                    }
+                    'biblio.biblionumber' => [{ tagfield =>  '999', tagsubfield => 'c' }],
+                    'biblio.isbn' => [{ tagfield => '020', tagsubfield => 'a' }],
+                    'biblio.title' => [{ tagfield => '245', tagsubfield => 'a' }],
+                    'biblio.notes' => [{ tagfield => '500', tagsubfield => 'a' }],
+                    'items.barcode' => [{ tagfield => '952', tagsubfield => 'p' }],
+                    'items.booksellerid' => [{ tagfield => '952', tagsubfield => 'e' }],
+                    'items.ccode' => [{ tagfield => '952', tagsubfield => '8' }],
+                    'items.cn_sort' => [{ tagfield => '952', tagsubfield => '6' }],
+                    'items.cn_source' => [{ tagfield => '952', tagsubfield => '2' }],
+                    'items.coded_location_qualifier' => [{ tagfield => '952', tagsubfield => 'f' }],
+                    'items.copynumber' => [{ tagfield => '952', tagsubfield => 't' }],
+                    'items.damaged' => [{ tagfield => '952', tagsubfield => '4' }],
+                    'items.dateaccessioned' => [{ tagfield => '952', tagsubfield => 'd' }],
+                    'items.datelastborrowed' => [{ tagfield => '952', tagsubfield => 's' }],
+                    'items.datelastseen' => [{ tagfield => '952', tagsubfield => 'r' }],
+                    'items.enumchron' => [{ tagfield => '952', tagsubfield => 'h' }],
+                    'items.holdingbranch' => [{ tagfield => '952', tagsubfield => 'b' }],
+                    'items.homebranch' => [{ tagfield => '952', tagsubfield => 'a' }],
+                    'items.issues' => [{ tagfield => '952', tagsubfield => 'l' }],
+                    'items.itemcallnumber' => [{ tagfield => '952', tagsubfield => 'o' }],
+                    'items.itemlost' => [{ tagfield => '952', tagsubfield => '1' }],
+                    'items.itemnotes' => [{ tagfield => '952', tagsubfield => 'z' }],
+                    'items.itemnumber' => [{ tagfield => '952', tagsubfield => '9' }],
+                    'items.itype' => [{ tagfield => '952', tagsubfield => 'y' }],
+                    'items.location' => [{ tagfield => '952', tagsubfield => 'c' }],
+                    'items.materials' => [{ tagfield => '952', tagsubfield => '3' }],
+                    'items.nonpublicnote' => [{ tagfield => '952', tagsubfield => 'x' }],
+                    'items.notforloan' => [{ tagfield => '952', tagsubfield => '7' }],
+                    'items.onloan' => [{ tagfield => '952', tagsubfield => 'q' }],
+                    'items.price' => [{ tagfield => '952', tagsubfield => 'g' }],
+                    'items.renewals' => [{ tagfield => '952', tagsubfield => 'm' }],
+                    'items.replacementprice' => [{ tagfield => '952', tagsubfield => 'v' }],
+                    'items.replacementpricedate' => [{ tagfield => '952', tagsubfield => 'w' }],
+                    'items.reserves' => [{ tagfield => '952', tagsubfield => 'n' }],
+                    'items.restricted' => [{ tagfield => '952', tagsubfield => '5' }],
+                    'items.stack' => [{ tagfield => '952', tagsubfield => 'j' }],
+                    'items.uri' => [{ tagfield => '952', tagsubfield => 'u' }],
+                    'items.withdrawn' => [{ tagfield => '952', tagsubfield => '0' }],
                 };
         });
     }
 }
 
 sub run_marc21_search_tests {
-    my $indexing_mode = shift;
     $datadir = tempdir();
-    system(dirname(__FILE__) . "/zebra_config.pl $datadir marc21 $indexing_mode");
+    system(dirname(__FILE__) . "/zebra_config.pl $datadir marc21");
 
-    mock_marcfromkohafield('marc21');
+    Koha::Caches->get_instance('config')->flush_all;
+
+    mock_GetMarcSubfieldStructure('marc21');
     my $context = new C4::Context("$datadir/etc/koha-conf.xml");
     $context->set_context();
 
-    is($context->config('zebra_bib_index_mode'),$indexing_mode,
-        "zebra_bib_index_mode is properly set to '$indexing_mode' in the created koha-conf.xml file (BZ11499)");
-    is($context->config('zebra_auth_index_mode'),$indexing_mode,
-        "zebra_auth_index_mode is properly set to '$indexing_mode' in the created koha-conf.xml file (BZ11499)");
-
     use_ok('C4::Search');
 
     # set search syspreferences to a known starting point
@@ -217,34 +264,10 @@ 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');
-    $bibliomodule->mock('_get_inverted_marc_field_map', sub {
-        my %hash = (
-            '' => {
-                '245' => { 'sfs' => { 'a' => [ [ 'biblio', 'title' ] ], 'b' => [ [ 'bibliosubtitle', 'subtitle' ] ] },
-                    'list' => [ [ 'a', 'biblio', 'title' ], [ 'b', 'bibliosubtitle', 'subtitle' ] ]
-                },
-                '100' => {
-                    'sfs' => { 'a' => [ [ 'biblio', 'author' ] ] },
-                    'list' => [ [ 'a', 'biblio', 'author' ] ]
-                },
-                '999' => {
-                    'sfs' => { 'c' => [ [ 'biblio', 'biblionumber' ] ], 'd' => [ [ 'biblioitems', 'biblioitemnumber' ] ] },
-                    'list' => [ [ 'd', 'biblioitems', 'biblioitemnumber' ], [ 'c', 'biblio', 'biblionumber' ] ]
-                },
-                '020' => {
-                    'sfs' => { 'a' => [ [ 'biblioitems', 'isbn' ] ] },
-                    'list' => [ [ 'a', 'biblioitems', 'isbn' ] ]
-                },
-                '500' => {
-                    'sfs' => { 'a' => [ [ 'biblioitems', 'notes' ] ] },
-                    'list' => [ [ 'a', 'biblioitems', 'notes' ] ]
-                },
-            }
-        );
-        return \%hash;
-    });
 
     my %branches = (
         'CPL' => { 'branchaddress1' => 'Jefferson Summit', 'branchcode' => 'CPL', 'branchname' => 'Centerville', },
@@ -272,7 +295,7 @@ sub run_marc21_search_tests {
         'VM' => { 'imageurl' => 'bridge/dvd.gif', 'summary' => '', 'itemtype' => 'VM', 'description' => 'Visual Materials' },
     );
 
-    index_sample_records_and_launch_zebra($datadir, $indexing_mode, 'marc21');
+    index_sample_records_and_launch_zebra($datadir, 'marc21');
 
     my ($biblionumber, $title);
     my $record = MARC::Record->new;
@@ -339,78 +362,40 @@ sub run_marc21_search_tests {
         getRecords('au:Lessig', 'au:Lessig', [], [ 'biblioserver' ], '20', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
     is($results_hashref->{biblioserver}->{hits}, 4, "getRecords title search for 'Australia' matched right number of records");
 
-if ( $indexing_mode eq 'dom' ) {
-    ( undef, $results_hashref, $facets_loop ) =
-        getRecords('salud', 'salud', [], [ 'biblioserver' ], '19', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
-    ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() =~ m/^Efectos del ambiente/ &&
-        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[7],'UTF-8')->title_proper() eq 'Salud y seguridad de los trabajadores del sector salud: manual para gerentes y administradores^ies' &&
-        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() =~ m/^Indicadores de resultados identificados/
-        , "Simple relevance sorting in getRecords matches old behavior");
-
-    ( undef, $results_hashref, $facets_loop ) =
-        getRecords('salud', 'salud', [ 'author_az' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
-    ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() =~ m/la enfermedad laboral\^ies$/ &&
-        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[6],'UTF-8')->title_proper() =~ m/^Indicadores de resultados identificados/ &&
-        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() eq 'World health statistics 2009^ien'
-        , "Simple ascending author sorting in getRecords matches old behavior");
-
-    ( undef, $results_hashref, $facets_loop ) =
-        getRecords('salud', 'salud', [ 'author_za' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
-    ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() eq 'World health statistics 2009^ien' &&
-        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[12],'UTF-8')->title_proper() =~ m/^Indicadores de resultados identificados/ &&
-        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() =~ m/la enfermedad laboral\^ies$/
-        , "Simple descending author sorting in getRecords matches old behavior");
-
-    ( undef, $results_hashref, $facets_loop ) =
-        getRecords('salud', 'salud', [ 'pubdate_asc' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
-    ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() eq 'Manual de higiene industrial^ies' &&
-        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[7],'UTF-8')->title_proper() =~ m/seguridad e higiene del trabajo\^ies$/ &&
-        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() =~ m/^Indicadores de resultados identificados/
-        , "Simple ascending publication date sorting in getRecords matches old behavior");
-
-    ( undef, $results_hashref, $facets_loop ) =
-        getRecords('salud', 'salud', [ 'pubdate_dsc' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
-    ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() =~ m/^Estado de salud/ &&
-        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[7],'UTF-8')->title_proper() eq 'World health statistics 2009^ien' &&
-        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() eq 'Manual de higiene industrial^ies'
-        , "Simple descending publication date sorting in getRecords matches old behavior");
-
-} elsif ( $indexing_mode eq 'grs1' ){
-    ( undef, $results_hashref, $facets_loop ) =
-        getRecords('salud', 'salud', [], [ 'biblioserver' ], '19', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
-    ok(MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[0])->title_proper() =~ m/^Efectos del ambiente/ &&
-        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[7])->title_proper() eq 'Salud y seguridad de los trabajadores del sector salud: manual para gerentes y administradores^ies' &&
-        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[18])->title_proper() =~ m/^Indicadores de resultados identificados/
-        , "Simple relevance sorting in getRecords matches old behavior");
-
-    ( undef, $results_hashref, $facets_loop ) =
-        getRecords('salud', 'salud', [ 'author_az' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
-    ok(MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[0])->title_proper() =~ m/la enfermedad laboral\^ies$/ &&
-        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[6])->title_proper() =~ m/^Indicadores de resultados identificados/ &&
-        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[18])->title_proper() eq 'World health statistics 2009^ien'
-        , "Simple ascending author sorting in getRecords matches old behavior");
-
-    ( undef, $results_hashref, $facets_loop ) =
-        getRecords('salud', 'salud', [ 'author_za' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
-    ok(MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[0])->title_proper() eq 'World health statistics 2009^ien' &&
-        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[12])->title_proper() =~ m/^Indicadores de resultados identificados/ &&
-        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[18])->title_proper() =~ m/la enfermedad laboral\^ies$/
-        , "Simple descending author sorting in getRecords matches old behavior");
-
-    ( undef, $results_hashref, $facets_loop ) =
-        getRecords('salud', 'salud', [ 'pubdate_asc' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
-    ok(MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[0])->title_proper() eq 'Manual de higiene industrial^ies' &&
-        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[7])->title_proper() =~ m/seguridad e higiene del trabajo\^ies$/ &&
-        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[18])->title_proper() =~ m/^Indicadores de resultados identificados/
-        , "Simple ascending publication date sorting in getRecords matches old behavior");
-
-    ( undef, $results_hashref, $facets_loop ) =
-        getRecords('salud', 'salud', [ 'pubdate_dsc' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
-    ok(MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[0])->title_proper() =~ m/^Estado de salud/ &&
-        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[7])->title_proper() eq 'World health statistics 2009^ien' &&
-        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[18])->title_proper() eq 'Manual de higiene industrial^ies'
-        , "Simple descending publication date sorting in getRecords matches old behavior");
-}
+( undef, $results_hashref, $facets_loop ) =
+    getRecords('salud', 'salud', [], [ 'biblioserver' ], '19', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
+ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() =~ m/^Efectos del ambiente/ &&
+    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[7],'UTF-8')->title_proper() eq 'Salud y seguridad de los trabajadores del sector salud: manual para gerentes y administradores^ies' &&
+    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() =~ m/^Indicadores de resultados identificados/
+    , "Simple relevance sorting in getRecords matches old behavior");
+
+( undef, $results_hashref, $facets_loop ) =
+    getRecords('salud', 'salud', [ 'author_az' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
+ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() =~ m/la enfermedad laboral\^ies$/ &&
+    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[6],'UTF-8')->title_proper() =~ m/^Indicadores de resultados identificados/ &&
+    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() eq 'World health statistics 2009^ien'
+    , "Simple ascending author sorting in getRecords matches old behavior");
+
+( undef, $results_hashref, $facets_loop ) =
+    getRecords('salud', 'salud', [ 'author_za' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
+ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() eq 'World health statistics 2009^ien' &&
+    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[12],'UTF-8')->title_proper() =~ m/^Indicadores de resultados identificados/ &&
+    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() =~ m/la enfermedad laboral\^ies$/
+    , "Simple descending author sorting in getRecords matches old behavior");
+
+( undef, $results_hashref, $facets_loop ) =
+    getRecords('salud', 'salud', [ 'pubdate_asc' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
+ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() eq 'Manual de higiene industrial^ies' &&
+    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[7],'UTF-8')->title_proper() =~ m/seguridad e higiene del trabajo\^ies$/ &&
+    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() =~ m/^Indicadores de resultados identificados/
+    , "Simple ascending publication date sorting in getRecords matches old behavior");
+
+( undef, $results_hashref, $facets_loop ) =
+    getRecords('salud', 'salud', [ 'pubdate_dsc' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
+ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() =~ m/^Estado de salud/ &&
+    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[7],'UTF-8')->title_proper() eq 'World health statistics 2009^ien' &&
+    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() eq 'Manual de higiene industrial^ies'
+    , "Simple descending publication date sorting in getRecords matches old behavior");
 
     ( undef, $results_hashref, $facets_loop ) =
         getRecords('books', 'books', [ 'relevance' ], [ 'biblioserver' ], '20', 0, undef, \%branches, \%itemtypes, undef, 1);
@@ -430,7 +415,7 @@ if ( $indexing_mode eq 'dom' ) {
     ($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");
 
@@ -512,7 +497,7 @@ if ( $indexing_mode eq 'dom' ) {
     ($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) {
@@ -557,12 +542,7 @@ if ( $indexing_mode eq 'dom' ) {
 
     ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
     is($results_hashref->{biblioserver}->{hits}, 19, "Weighted query returned correct number of results");
-    if ($indexing_mode eq 'grs1') {
-        is(MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[0])->title_proper(), 'Salud y seguridad de los trabajadores del sector salud: manual para gerentes y administradores^ies', "Weighted query returns best match first");
-    } else {
-        local $TODO = "Query weighting does not behave exactly the same in DOM vs. GRS";
-        is(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper(), 'Salud y seguridad de los trabajadores del sector salud: manual para gerentes y administradores^ies', "Weighted query returns best match first");
-    }
+    is(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper(), 'Salud y seguridad de los trabajadores del sector salud: manual para gerentes y administradores^ies', "Weighted query returns best match first");
 
     $QueryStemming = $QueryWeightFields = $QueryFuzzy = 0;
     $QueryAutoTruncate = 1;
@@ -626,6 +606,17 @@ if ( $indexing_mode eq 'dom' ) {
     ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
     is($results_hashref->{biblioserver}->{hits}, undef, "Search for 'pressed' returns no matches when stemming is off");
 
+    ( $error, $query, $simple_query, $query_cgi,
+    $query_desc, $limit, $limit_cgi, $limit_desc,
+    $query_type ) = buildQuery([], [ 'ccl=an:42' ], [], ['available'], [], 0, 'en');
+    is( $query, "an:42 and ( ( allrecords,AlwaysMatches:'' not onloan,AlwaysMatches:'') and (lost,st-numeric=0) )", 'buildQuery should add the available part to the query if requested with ccl' );
+    is( $query_desc, 'an:42', 'buildQuery should remove the available part from the query' );
+
+    ( $error, $query, $simple_query, $query_cgi,
+    $query_desc, $limit, $limit_cgi, $limit_desc,
+    $query_type ) = buildQuery([], [ 0 ], [ 'su,phr' ], [], [], 0, 'en');
+    is($query, 'su,phr=0 ', 'buildQuery should keep 0 value');
+
     # Let's see what happens when we pass bad data into these routines.
     # We have to catch warnings since we're not very good about returning errors.
 
@@ -644,7 +635,7 @@ if ( $indexing_mode eq 'dom' ) {
     # 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');
 
@@ -663,7 +654,7 @@ if ( $indexing_mode eq 'dom' ) {
     });
 
     ($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)');
 
@@ -671,7 +662,7 @@ if ( $indexing_mode eq 'dom' ) {
     ( 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/,
@@ -781,6 +772,16 @@ if ( $indexing_mode eq 'dom' ) {
         ['沙士北亞威廉姆'], 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;
 
@@ -809,7 +810,7 @@ if ( $indexing_mode eq 'dom' ) {
     ( 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)');
@@ -857,6 +858,8 @@ if ( $indexing_mode eq 'dom' ) {
     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,
@@ -872,6 +875,8 @@ if ( $indexing_mode eq 'dom' ) {
                 '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");
 
@@ -879,11 +884,12 @@ if ( $indexing_mode eq 'dom' ) {
 }
 
 sub run_unimarc_search_tests {
-    my $indexing_mode = shift;
     $datadir = tempdir();
-    system(dirname(__FILE__) . "/zebra_config.pl $datadir unimarc $indexing_mode");
+    system(dirname(__FILE__) . "/zebra_config.pl $datadir unimarc");
+
+    Koha::Caches->get_instance('config')->flush_all;
 
-    mock_marcfromkohafield('unimarc');
+    mock_GetMarcSubfieldStructure('unimarc');
     my $context = new C4::Context("$datadir/etc/koha-conf.xml");
     $context->set_context();
 
@@ -897,7 +903,7 @@ sub run_unimarc_search_tests {
     $UseQueryParser = 0;
     $marcflavour = 'UNIMARC';
 
-    index_sample_records_and_launch_zebra($datadir, $indexing_mode, 'unimarc');
+    index_sample_records_and_launch_zebra($datadir, 'unimarc');
 
     my ( $error, $marcresults, $total_hits ) = SimpleSearch("ti=Järnvägarnas efterfrågan och den svenska industrin", 0, 10);
     is($total_hits, 1, 'UNIMARC title search');
@@ -951,6 +957,8 @@ sub run_unimarc_search_tests {
     my $expected_facets_info_unimarc = {
                    'au' => { 'expanded'    => undef,
                              'label_value' => "Authors" },
+                'ccode' => { 'expanded'    => undef,
+                             'label_value' => "CollectionCodes" },
         'holdingbranch' => { 'expanded'    => undef,
                              'label_value' => "HoldingLibrary" },
              'location' => { 'expanded'    => undef,
@@ -964,30 +972,24 @@ sub run_unimarc_search_tests {
                 'su-ut' => { 'expanded'    => undef,
                              'label_value' => "Titles" }
     };
+    delete $expected_facets_info_unimarc->{holdingbranch}
+        if Koha::Libraries->count == 1;
     is_deeply( $facets_info, $expected_facets_info_unimarc,
         "_get_facets_info returns the correct data");
 
     cleanup();
 }
 
-subtest 'MARC21 + GRS-1' => sub {
-    plan tests => 107;
-    run_marc21_search_tests('grs1');
-};
-
 subtest 'MARC21 + DOM' => sub {
-    plan tests => 107;
-    run_marc21_search_tests('dom');
-};
-
-subtest 'UNIMARC + GRS-1' => sub {
-    plan tests => 14;
-    run_unimarc_search_tests('grs1');
+    plan tests => 112;
+    run_marc21_search_tests();
 };
 
 subtest 'UNIMARC + DOM' => sub {
     plan tests => 14;
-    run_unimarc_search_tests('dom');
+    run_unimarc_search_tests();
 };
 
-1;
+# Make sure that following tests are not using our config settings
+Koha::Caches->get_instance('config')->flush_all;
+