Lines 30-35
use Test::More tests => 3;
Link Here
|
30 |
use Test::MockModule; |
30 |
use Test::MockModule; |
31 |
use Test::Warn; |
31 |
use Test::Warn; |
32 |
use t::lib::Mocks; |
32 |
use t::lib::Mocks; |
|
|
33 |
use t::lib::Mocks::Zebra; |
33 |
|
34 |
|
34 |
use Koha::Caches; |
35 |
use Koha::Caches; |
35 |
|
36 |
|
Lines 41-96
use File::Find;
Link Here
|
41 |
use File::Temp qw/ tempdir /; |
42 |
use File::Temp qw/ tempdir /; |
42 |
use File::Path; |
43 |
use File::Path; |
43 |
|
44 |
|
44 |
our $child; |
|
|
45 |
our $datadir; |
46 |
|
47 |
sub index_sample_records_and_launch_zebra { |
48 |
my ($datadir, $marc_type) = @_; |
49 |
|
50 |
my $sourcedir = dirname(__FILE__) . "/data"; |
51 |
unlink("$datadir/zebra.log"); |
52 |
if (-f "$sourcedir/${marc_type}/zebraexport/biblio/exported_records") { |
53 |
my $zebra_bib_cfg = 'zebra-biblios-dom.cfg'; |
54 |
system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_bib_cfg -v none,fatal -g iso2709 -d biblios init"); |
55 |
system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_bib_cfg -v none,fatal -g iso2709 -d biblios update $sourcedir/${marc_type}/zebraexport/biblio"); |
56 |
system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_bib_cfg -v none,fatal -g iso2709 -d biblios commit"); |
57 |
} |
58 |
# ... and add large bib records, if present |
59 |
if (-f "$sourcedir/${marc_type}/zebraexport/large_biblio/exported_records.xml") { |
60 |
my $zebra_bib_cfg = 'zebra-biblios-dom.cfg'; |
61 |
system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_bib_cfg -v none,fatal -g marcxml -d biblios update $sourcedir/${marc_type}/zebraexport/large_biblio"); |
62 |
system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_bib_cfg -v none,fatal -g marcxml -d biblios commit"); |
63 |
} |
64 |
if (-f "$sourcedir/${marc_type}/zebraexport/authority/exported_records") { |
65 |
my $zebra_auth_cfg = 'zebra-authorities-dom.cfg'; |
66 |
system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_auth_cfg -v none,fatal -g iso2709 -d authorities init"); |
67 |
system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_auth_cfg -v none,fatal -g iso2709 -d authorities update $sourcedir/${marc_type}/zebraexport/authority"); |
68 |
system("zebraidx -c $datadir/etc/koha/zebradb/$zebra_auth_cfg -v none,fatal -g iso2709 -d authorities commit"); |
69 |
} |
70 |
|
71 |
$child = fork(); |
72 |
if ($child == 0) { |
73 |
exec("zebrasrv -f $datadir/etc/koha-conf.xml -v none,request -l $datadir/zebra.log"); |
74 |
exit; |
75 |
} |
76 |
|
77 |
sleep(1); |
78 |
} |
79 |
|
80 |
sub cleanup { |
81 |
if ($child) { |
82 |
kill 9, $child; |
83 |
|
84 |
# Clean up the Zebra files since the child process was just shot |
85 |
rmtree $datadir; |
86 |
} |
87 |
} |
88 |
|
89 |
# Fall back to make sure that the Zebra process |
45 |
# Fall back to make sure that the Zebra process |
90 |
# and files get cleaned up |
46 |
# and files get cleaned up |
91 |
END { |
47 |
our @cleanup; |
92 |
cleanup(); |
|
|
93 |
} |
94 |
|
48 |
|
95 |
sub matchesExplodedTerms { |
49 |
sub matchesExplodedTerms { |
96 |
my ($message, $query, @terms) = @_; |
50 |
my ($message, $query, @terms) = @_; |
Lines 211-217
our $bibliomodule = Test::MockModule->new('C4::Biblio');
Link Here
|
211 |
|
165 |
|
212 |
sub mock_GetMarcSubfieldStructure { |
166 |
sub mock_GetMarcSubfieldStructure { |
213 |
my $marc_type = shift; |
167 |
my $marc_type = shift; |
214 |
if ($marc_type eq 'marc21') { |
168 |
if ($marc_type eq 'MARC21') { |
215 |
$bibliomodule->mock('GetMarcSubfieldStructure', sub { |
169 |
$bibliomodule->mock('GetMarcSubfieldStructure', sub { |
216 |
return { |
170 |
return { |
217 |
'biblio.biblionumber' => [{ tagfield => '999', tagsubfield => 'c' }], |
171 |
'biblio.biblionumber' => [{ tagfield => '999', tagsubfield => 'c' }], |
Lines 259-272
sub mock_GetMarcSubfieldStructure {
Link Here
|
259 |
} |
213 |
} |
260 |
|
214 |
|
261 |
sub run_marc21_search_tests { |
215 |
sub run_marc21_search_tests { |
262 |
$datadir = tempdir(); |
|
|
263 |
system(dirname(__FILE__) . "/zebra_config.pl $datadir marc21"); |
264 |
|
216 |
|
265 |
Koha::Caches->get_instance('config')->flush_all; |
217 |
$marcflavour = 'MARC21'; |
|
|
218 |
my $mock_zebra = t::lib::Mocks::Zebra->new({marcflavour => $marcflavour}); |
219 |
push @cleanup, $mock_zebra; |
266 |
|
220 |
|
267 |
mock_GetMarcSubfieldStructure('marc21'); |
221 |
mock_GetMarcSubfieldStructure($marcflavour); |
268 |
my $context = C4::Context->new("$datadir/etc/koha-conf.xml"); |
|
|
269 |
$context->set_context(); |
270 |
|
222 |
|
271 |
use_ok('C4::Search', qw( getIndexes FindDuplicate SimpleSearch getRecords buildQuery searchResults )); |
223 |
use_ok('C4::Search', qw( getIndexes FindDuplicate SimpleSearch getRecords buildQuery searchResults )); |
272 |
|
224 |
|
Lines 275-281
sub run_marc21_search_tests {
Link Here
|
275 |
$QueryAutoTruncate = 0; |
227 |
$QueryAutoTruncate = 0; |
276 |
$QueryWeightFields = 0; |
228 |
$QueryWeightFields = 0; |
277 |
$QueryFuzzy = 0; |
229 |
$QueryFuzzy = 0; |
278 |
$marcflavour = 'MARC21'; |
|
|
279 |
|
230 |
|
280 |
my $indexes = C4::Search::getIndexes(); |
231 |
my $indexes = C4::Search::getIndexes(); |
281 |
is(scalar(grep(/^ti$/, @$indexes)), 1, "Title index supported"); |
232 |
is(scalar(grep(/^ti$/, @$indexes)), 1, "Title index supported"); |
Lines 310-316
sub run_marc21_search_tests {
Link Here
|
310 |
'VM' => { 'imageurl' => 'bridge/dvd.png', 'summary' => '', 'itemtype' => 'VM', 'description' => 'Visual Materials' }, |
261 |
'VM' => { 'imageurl' => 'bridge/dvd.png', 'summary' => '', 'itemtype' => 'VM', 'description' => 'Visual Materials' }, |
311 |
); |
262 |
); |
312 |
|
263 |
|
313 |
index_sample_records_and_launch_zebra($datadir, 'marc21'); |
264 |
my $sourcedir = dirname(__FILE__) . "/data"; |
|
|
265 |
$mock_zebra->load_records( |
266 |
sprintf( "%s/%s/zebraexport/biblio", $sourcedir, lc($marcflavour) ), |
267 |
'iso2709', 'biblios', 1 ); |
268 |
$mock_zebra->load_records( |
269 |
sprintf( |
270 |
"%s/%s/zebraexport/large_biblio", |
271 |
$sourcedir, lc($marcflavour) |
272 |
), |
273 |
'marcxml', 'biblios', 0 |
274 |
); |
275 |
$mock_zebra->load_records( |
276 |
sprintf( "%s/%s/zebraexport/authority", $sourcedir, lc($marcflavour) ), |
277 |
'iso2709', 'authorities', 1 |
278 |
); |
279 |
|
280 |
$mock_zebra->launch_zebra; |
314 |
|
281 |
|
315 |
my ($biblionumber, $title); |
282 |
my ($biblionumber, $title); |
316 |
my $record = MARC::Record->new; |
283 |
my $record = MARC::Record->new; |
Lines 830-847
ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'
Link Here
|
830 |
is_deeply( $facets_info, $expected_facets_info_marc21, |
797 |
is_deeply( $facets_info, $expected_facets_info_marc21, |
831 |
"_get_facets_info returns the correct data"); |
798 |
"_get_facets_info returns the correct data"); |
832 |
|
799 |
|
833 |
cleanup(); |
800 |
$mock_zebra->cleanup; |
834 |
} |
801 |
} |
835 |
|
802 |
|
836 |
sub run_unimarc_search_tests { |
803 |
sub run_unimarc_search_tests { |
837 |
$datadir = tempdir(); |
|
|
838 |
system(dirname(__FILE__) . "/zebra_config.pl $datadir unimarc"); |
839 |
|
804 |
|
840 |
Koha::Caches->get_instance('config')->flush_all; |
805 |
$marcflavour = 'UNIMARC'; |
|
|
806 |
my $mock_zebra = t::lib::Mocks::Zebra->new({marcflavour => $marcflavour}); |
807 |
push @cleanup, $mock_zebra; |
841 |
|
808 |
|
842 |
mock_GetMarcSubfieldStructure('unimarc'); |
809 |
mock_GetMarcSubfieldStructure($marcflavour); |
843 |
my $context = C4::Context->new("$datadir/etc/koha-conf.xml"); |
|
|
844 |
$context->set_context(); |
845 |
|
810 |
|
846 |
use_ok('C4::Search', qw( getIndexes FindDuplicate SimpleSearch getRecords buildQuery searchResults )); |
811 |
use_ok('C4::Search', qw( getIndexes FindDuplicate SimpleSearch getRecords buildQuery searchResults )); |
847 |
|
812 |
|
Lines 850-858
sub run_unimarc_search_tests {
Link Here
|
850 |
$QueryAutoTruncate = 0; |
815 |
$QueryAutoTruncate = 0; |
851 |
$QueryWeightFields = 0; |
816 |
$QueryWeightFields = 0; |
852 |
$QueryFuzzy = 0; |
817 |
$QueryFuzzy = 0; |
853 |
$marcflavour = 'UNIMARC'; |
|
|
854 |
|
818 |
|
855 |
index_sample_records_and_launch_zebra($datadir, 'unimarc'); |
819 |
my $sourcedir = dirname(__FILE__) . "/data"; |
|
|
820 |
$mock_zebra->load_records( |
821 |
sprintf( "%s/%s/zebraexport/biblio", $sourcedir, lc($marcflavour) ), |
822 |
'iso2709', 'biblios', 1 ); |
823 |
$mock_zebra->load_records( |
824 |
sprintf( |
825 |
"%s/%s/zebraexport/large_biblio", |
826 |
$sourcedir, lc($marcflavour) |
827 |
), |
828 |
'marcxml', 'biblios', 0 |
829 |
); |
830 |
$mock_zebra->load_records( |
831 |
sprintf( "%s/%s/zebraexport/authority", $sourcedir, lc($marcflavour) ), |
832 |
'iso2709', 'authorities', 1 |
833 |
); |
834 |
$mock_zebra->launch_zebra; |
856 |
|
835 |
|
857 |
my ( $error, $marcresults, $total_hits ) = SimpleSearch("ti=Järnvägarnas efterfrågan och den svenska industrin", 0, 10); |
836 |
my ( $error, $marcresults, $total_hits ) = SimpleSearch("ti=Järnvägarnas efterfrågan och den svenska industrin", 0, 10); |
858 |
is($total_hits, 1, 'UNIMARC title search'); |
837 |
is($total_hits, 1, 'UNIMARC title search'); |
Lines 916-922
sub run_unimarc_search_tests {
Link Here
|
916 |
is_deeply( $facets_info, $expected_facets_info_unimarc, |
895 |
is_deeply( $facets_info, $expected_facets_info_unimarc, |
917 |
"_get_facets_info returns the correct data"); |
896 |
"_get_facets_info returns the correct data"); |
918 |
|
897 |
|
919 |
cleanup(); |
898 |
$mock_zebra->cleanup; |
920 |
} |
899 |
} |
921 |
|
900 |
|
922 |
subtest 'MARC21 + DOM' => sub { |
901 |
subtest 'MARC21 + DOM' => sub { |
Lines 933-940
subtest 'UNIMARC + DOM' => sub {
Link Here
|
933 |
subtest 'FindDuplicate' => sub { |
912 |
subtest 'FindDuplicate' => sub { |
934 |
plan tests => 6; |
913 |
plan tests => 6; |
935 |
Koha::Caches->get_instance('config')->flush_all; |
914 |
Koha::Caches->get_instance('config')->flush_all; |
936 |
t::lib::Mocks::mock_preference('marcflavour', 'marc21' ); |
915 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21' ); |
937 |
mock_GetMarcSubfieldStructure('marc21'); |
916 |
mock_GetMarcSubfieldStructure('MARC21'); |
938 |
my $z_searcher = Test::MockModule->new('C4::Search'); |
917 |
my $z_searcher = Test::MockModule->new('C4::Search'); |
939 |
$z_searcher->mock('SimpleSearch', sub { |
918 |
$z_searcher->mock('SimpleSearch', sub { |
940 |
warn shift @_; |
919 |
warn shift @_; |
Lines 980-985
subtest 'FindDuplicate' => sub {
Link Here
|
980 |
Koha::Caches->get_instance('config')->flush_all; |
959 |
Koha::Caches->get_instance('config')->flush_all; |
981 |
|
960 |
|
982 |
END { |
961 |
END { |
|
|
962 |
|
963 |
$_->cleanup for @cleanup; |
983 |
my $dbh = C4::Context->dbh; |
964 |
my $dbh = C4::Context->dbh; |
984 |
# Restore visibility of subfields in OPAC |
965 |
# Restore visibility of subfields in OPAC |
985 |
$dbh->do(q{ |
966 |
$dbh->do(q{ |