use utf8;
-use YAML;
-
-use C4::Debug;
use C4::AuthoritiesMarc qw( SearchAuthorities );
use C4::XSLT;
require C4::Context;
# work around spurious wide character warnings
use open ':std', ':encoding(utf8)';
-use Test::More tests => 2;
+use Test::More tests => 3;
use Test::MockModule;
use Test::Warn;
+use t::lib::Mocks;
use Koha::Caches;
cleanup();
}
+sub matchesExplodedTerms {
+ my ($message, $query, @terms) = @_;
+ my $match = '(' . join ('|', map { " \@attr 1=Subject \@attr 4=1 \"$_\"" } @terms) . "){" . scalar(@terms) . "}";
+ like($query, qr/$match/, $message);
+}
+
our $QueryStemming = 0;
our $QueryAutoTruncate = 0;
our $QueryWeightFields = 0;
$htdocs[-2] = 'koha-tmpl';
$htdocs[-1] = 'opac-tmpl';
$htdocs = join '/', @htdocs;
-our $contextmodule = new Test::MockModule('C4::Context');
+our $contextmodule = Test::MockModule->new('C4::Context');
$contextmodule->mock('preference', sub {
my ($self, $pref) = @_;
if ($pref eq 'marcflavour') {
return '';
} elsif ($pref eq 'opacthemes') {
return 'bootstrap';
- } elsif ($pref eq 'opaclanguages') {
+ } elsif ($pref eq 'OPACLanguages') {
return 'en';
} elsif ($pref eq 'AlternateHoldingsField') {
return '490av';
return '1';
} elsif ($pref eq 'UseControlNumber') {
return '0';
- } elsif ($pref eq 'UseICU') {
+ } elsif ($pref eq 'UseICUStyleQuotes') {
return '0';
} elsif ($pref eq 'viewISBD') {
return '1';
return '0';
} elsif ($pref eq 'OPACPlayMusicalInscripts') {
return '0';
+ } elsif ($pref eq 'Reference_NFL_Statuses') {
+ 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;
}
});
-our $bibliomodule = new Test::MockModule('C4::Biblio');
+our $bibliomodule = Test::MockModule->new('C4::Biblio');
sub mock_GetMarcSubfieldStructure {
my $marc_type = shift;
'biblio.biblionumber' => [{ tagfield => '999', tagsubfield => 'c' }],
'biblio.isbn' => [{ tagfield => '020', tagsubfield => 'a' }],
'biblio.title' => [{ tagfield => '245', tagsubfield => 'a' }],
+ 'biblio.author' => [{ tagfield => '100', tagsubfield => 'a' }],
'biblio.notes' => [{ tagfield => '500', tagsubfield => 'a' }],
'items.barcode' => [{ tagfield => '952', tagsubfield => 'p' }],
'items.booksellerid' => [{ tagfield => '952', tagsubfield => 'e' }],
Koha::Caches->get_instance('config')->flush_all;
mock_GetMarcSubfieldStructure('marc21');
- my $context = new C4::Context("$datadir/etc/koha-conf.xml");
+ my $context = C4::Context->new("$datadir/etc/koha-conf.xml");
$context->set_context();
- use_ok('C4::Search');
+ use_ok('C4::Search', qw( getIndexes FindDuplicate SimpleSearch getRecords buildQuery searchResults ));
# set search syspreferences to a known starting point
$QueryStemming = 0;
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');
+ my $bibliomodule = Test::MockModule->new('C4::Biblio');
my %branches = (
'CPL' => { 'branchaddress1' => 'Jefferson Summit', 'branchcode' => 'CPL', 'branchname' => 'Centerville', },
'UPL' => { 'branchaddress1' => 'Chestnut Hollow', 'branchcode' => 'UPL', 'branchname' => 'Union', },
);
my %itemtypes = (
- 'BK' => { 'imageurl' => 'bridge/book.gif', 'summary' => '', 'itemtype' => 'BK', 'description' => 'Books' },
- 'CF' => { 'imageurl' => 'bridge/computer_file.gif', 'summary' => '', 'itemtype' => 'CF', 'description' => 'Computer Files' },
- 'CR' => { 'imageurl' => 'bridge/periodical.gif', 'summary' => '', 'itemtype' => 'CR', 'description' => 'Continuing Resources' },
- 'MP' => { 'imageurl' => 'bridge/map.gif', 'summary' => '', 'itemtype' => 'MP', 'description' => 'Maps' },
- 'MU' => { 'imageurl' => 'bridge/sound.gif', 'summary' => '', 'itemtype' => 'MU', 'description' => 'Music' },
- 'MX' => { 'imageurl' => 'bridge/kit.gif', 'summary' => '', 'itemtype' => 'MX', 'description' => 'Mixed Materials' },
+ 'BK' => { 'imageurl' => 'bridge/book.png', 'summary' => '', 'itemtype' => 'BK', 'description' => 'Books' },
+ 'CF' => { 'imageurl' => 'bridge/computer_file.png', 'summary' => '', 'itemtype' => 'CF', 'description' => 'Computer Files' },
+ 'CR' => { 'imageurl' => 'bridge/periodical.png', 'summary' => '', 'itemtype' => 'CR', 'description' => 'Continuing Resources' },
+ 'MP' => { 'imageurl' => 'bridge/map.png', 'summary' => '', 'itemtype' => 'MP', 'description' => 'Maps' },
+ 'MU' => { 'imageurl' => 'bridge/sound.png', 'summary' => '', 'itemtype' => 'MU', 'description' => 'Music' },
+ 'MX' => { 'imageurl' => 'bridge/kit.png', 'summary' => '', 'itemtype' => 'MX', 'description' => 'Mixed Materials' },
'REF' => { 'imageurl' => '', 'summary' => '', 'itemtype' => 'REF', 'description' => 'Reference' },
- 'VM' => { 'imageurl' => 'bridge/dvd.gif', 'summary' => '', 'itemtype' => 'VM', 'description' => 'Visual Materials' },
+ 'VM' => { 'imageurl' => 'bridge/dvd.png', 'summary' => '', 'itemtype' => 'VM', 'description' => 'Visual Materials' },
);
index_sample_records_and_launch_zebra($datadir, 'marc21');
}
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 {
+ my ($self, $xml) = @_;
+ return $xml;
+ });
+
+ @newresults = searchResults({'interface'=>'opac'}, $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 17, 0, 0,
+ $results_hashref->{'biblioserver'}->{"RECORDS"}, { anonymous_session => 1 });
+
+ like( $newresults[0]->{XSLTResultsRecord}, qr/<variable name="anonymous_session">1<\/variable>/, "Variable injected correctly" );
+
+ my $biblio_id = $newresults[0]->{biblionumber};
+ my $fw = C4::Biblio::GetFrameworkCode($biblio_id);
+
+ my $dbh = C4::Context->dbh;
+ # Hide subfield 'p' in OPAC
+ $dbh->do(qq{
+ UPDATE marc_subfield_structure
+ SET hidden=4
+ WHERE frameworkcode='$fw' AND
+ tagfield=952 AND
+ tagsubfield='p';
+ });
+
+ # Hide subfield 'y' in Staff
+ $dbh->do(qq{
+ UPDATE marc_subfield_structure
+ SET hidden=-7
+ WHERE frameworkcode='$fw' AND
+ tagfield=952 AND
+ tagsubfield='y';
+ });
+
+ Koha::Caches->get_instance->flush_all;
+
+ @newresults = searchResults(
+ { 'interface' => 'opac' },
+ $query_desc,
+ $results_hashref->{'biblioserver'}->{'hits'},
+ 17,
+ 0,
+ 0,
+ $results_hashref->{'biblioserver'}->{"RECORDS"}
+ );
+
+ unlike( $newresults[0]->{XSLTResultsRecord}, qr/<subfield code="p">TEST11111<\/subfield>/, '952\$p hidden in OPAC' );
+
+ @newresults = searchResults(
+ { 'interface' => 'intranet' },
+ $query_desc,
+ $results_hashref->{'biblioserver'}->{'hits'},
+ 17,
+ 0,
+ 0,
+ $results_hashref->{'biblioserver'}->{"RECORDS"}
+ );
+
+ unlike( $newresults[0]->{XSLTResultsRecord}, qr/<subfield code="y">Books<\/subfield>/, '952\$y hidden on staff interface' );
( $error, $query, $simple_query, $query_cgi,
$query_desc, $limit, $limit_cgi, $limit_desc,
( $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');
+ is($query, 'su,phr=(rk=(0)) ', 'buildQuery should keep 0 value');
+
+ # Bug 23086
+ ( $error, $query, $simple_query, $query_cgi,
+ $query_desc, $limit, $limit_cgi, $limit_desc,
+ $query_type ) = buildQuery([], [], [], [ 'mc-ccode:NF(IC'], [], 0, 'en');
+ like($query, qr/ccode="NF\(IC"/, "Limit quoted correctly");
# 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.
## Regression test for Bug 10741
# make one of the test items appear to be in transit
- my $circ_module = new Test::MockModule('C4::Circulation');
+ my $circ_module = Test::MockModule->new('C4::Circulation');
$circ_module->mock('GetTransfers', sub {
my $itemnumber = shift // -1;
if ($itemnumber == 11) {
"Warning is raised correctly for invalid tags in MARC::Record";
is(scalar(@newresults), 0, 'a record that cannot be parsed by MARC::Record is simply skipped (bug 10684)');
- # Testing exploding indexes
- my $term;
- my $searchmodule = new Test::MockModule('C4::Search');
- $searchmodule->mock('SimpleSearch', sub {
- my $query = shift;
-
- is($query, "he:$term", "Searching for expected term '$term' for exploding") or return '', [], 0;
-
- my $record = MARC::Record->new;
- if ($query =~ m/Arizona/) {
- $record->add_fields(
- [ '001', '1234' ],
- [ '151', ' ', ' ', a => 'Arizona' ],
- [ '551', ' ', ' ', a => 'United States', w => 'g' ],
- [ '551', ' ', ' ', a => 'Maricopa County', w => 'h' ],
- [ '551', ' ', ' ', a => 'Navajo County', w => 'h' ],
- [ '551', ' ', ' ', a => 'Pima County', w => 'h' ],
- [ '551', ' ', ' ', a => 'New Mexico' ],
- );
- }
- return '', [ $record->as_usmarc() ], 1;
- });
-
my ($auths, $count) = SearchAuthorities(
['mainentry'], ['and'], [''], ['starts'],
['shakespeare'], 0, 10, '', '', 1
Koha::Caches->get_instance('config')->flush_all;
mock_GetMarcSubfieldStructure('unimarc');
- my $context = new C4::Context("$datadir/etc/koha-conf.xml");
+ my $context = C4::Context->new("$datadir/etc/koha-conf.xml");
$context->set_context();
- use_ok('C4::Search');
+ use_ok('C4::Search', qw( getIndexes FindDuplicate SimpleSearch getRecords buildQuery searchResults ));
# set search syspreferences to a known starting point
$QueryStemming = 0;
is($total_hits, 1, 'UNIMARC generic item index (bug 10037)');
# authority records
- use_ok('C4::AuthoritiesMarc');
+ use_ok('C4::AuthoritiesMarc', qw( SearchAuthorities ));
my ($auths, $count) = SearchAuthorities(
['mainentry'], ['and'], [''], ['contains'],
}
subtest 'MARC21 + DOM' => sub {
- plan tests => 84;
+ plan tests => 88;
run_marc21_search_tests();
};
run_unimarc_search_tests();
};
+
+subtest 'FindDuplicate' => sub {
+ plan tests => 6;
+ Koha::Caches->get_instance('config')->flush_all;
+ t::lib::Mocks::mock_preference('marcflavour', 'marc21' );
+ mock_GetMarcSubfieldStructure('marc21');
+ my $z_searcher = Test::MockModule->new('C4::Search');
+ $z_searcher->mock('SimpleSearch', sub {
+ warn shift @_;
+ return 1;
+ });
+ my $e_searcher = Test::MockModule->new('Koha::SearchEngine::Elasticsearch::Search');
+ $e_searcher->mock('simple_search_compat', sub {
+ shift @_;
+ warn shift @_;
+ return 1;
+ });
+
+ my $record_1 = MARC::Record->new;
+ $record_1 ->add_fields(
+ [ '100', '0', '0', a => 'Morgenstern, Erin' ],
+ [ '245', '0', '0', a => 'The night circus /' ]
+ );
+ my $record_2 = MARC::Record->new;
+ $record_2 ->add_fields(
+ [ '245', '0', '0', a => 'The book of nothing /' ]
+ );
+ my $record_3 = MARC::Record->new;
+ $record_3->add_fields(
+ [ '245', '0', '0', a => 'Frog and toad all year /' ]
+ );
+
+ foreach my $engine ('Zebra','Elasticsearch'){
+ t::lib::Mocks::mock_preference('searchEngine', $engine );
+
+ warning_is { C4::Search::FindDuplicate($record_1);}
+ q/ti,ext:"The night circus \/" and au,ext:"Morgenstern, Erin"/,"Term correctly formed and passed to $engine";
+
+ warning_is { C4::Search::FindDuplicate($record_2);}
+ q/ti,ext:"The book of nothing \/"/,"Term correctly formed and passed to $engine";
+
+ warning_is { C4::Search::FindDuplicate($record_3);}
+ q/ti,ext:"Frog and toad all year \/"/,"Term correctly formed and passed to $engine";
+ }
+
+};
+
# Make sure that following tests are not using our config settings
Koha::Caches->get_instance('config')->flush_all;