View | Details | Raw Unified | Return to bug 29368
Collapse All | Expand All

(-)a/t/db_dependent/Search.t (-69 / +50 lines)
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{
(-)a/t/lib/Mocks/Zebra.pm (-6 / +29 lines)
Lines 11-25 use C4::ImportBatch; Link Here
11
sub new {
11
sub new {
12
    my ( $class, $params ) = @_;
12
    my ( $class, $params ) = @_;
13
13
14
    my $marcflavour = lc($params->{marcflavour}) || 'marc21';
14
    my $datadir = tempdir();;
15
    my $datadir = tempdir();;
16
17
    system(dirname(__FILE__) . "/../../db_dependent/zebra_config.pl $datadir $marcflavour");
18
19
    Koha::Caches->get_instance('config')->flush_all;
20
    my $koha_conf = "$datadir/etc/koha-conf.xml";
21
    my $context = C4::Context->new($koha_conf);
22
    $context->set_context();
23
15
    my $self = {
24
    my $self = {
16
        datadir   => $datadir,
25
        datadir   => $datadir,
17
        koha_conf => $params->{koha_conf},
26
        koha_conf => $koha_conf,
18
        user      => $params->{user},
19
        password  => $params->{password},
20
        intranet  => $params->{intranet},
27
        intranet  => $params->{intranet},
21
        opac      => $params->{opac}
28
        opac      => $params->{opac}
22
    };
29
    };
30
23
    return bless $self, $class;
31
    return bless $self, $class;
24
}
32
}
25
33
Lines 30-35 sub launch_zebra { Link Here
30
    my $datadir = $self->{datadir};
38
    my $datadir = $self->{datadir};
31
    my $koha_conf = $self->{koha_conf};
39
    my $koha_conf = $self->{koha_conf};
32
40
41
    unlink("$datadir/zebra.log");
33
    my $zebra_pid = fork();
42
    my $zebra_pid = fork();
34
    if ( $zebra_pid == 0 ) {
43
    if ( $zebra_pid == 0 ) {
35
        exec("zebrasrv -f $koha_conf -v none,request -l $datadir/zebra.log");
44
        exec("zebrasrv -f $koha_conf -v none,request -l $datadir/zebra.log");
Lines 55-60 sub launch_indexer { Link Here
55
}
64
}
56
65
57
sub load_records {
66
sub load_records {
67
    my ( $self, $marc_dir, $marc_format, $record_type, $init ) = @_;
68
69
    my $datadir = $self->{datadir};
70
    my $zebra_cfg = $record_type eq 'biblios' ? 'zebra-biblios-dom.cfg' : 'zebra-authorities-dom.cfg';
71
    my @cmds;
72
    push @cmds, "zebraidx -c $datadir/etc/koha/zebradb/$zebra_cfg  -v none,fatal -g $marc_format -d $record_type init" if $init;
73
    push @cmds, "zebraidx -c $datadir/etc/koha/zebradb/$zebra_cfg  -v none,fatal -g $marc_format -d $record_type update $marc_dir";
74
    push @cmds, "zebraidx -c $datadir/etc/koha/zebradb/$zebra_cfg  -v none,fatal -g $marc_format -d $record_type commit";
75
76
    for my $cmd ( @cmds ) {
77
        system($cmd);
78
    }
79
}
80
81
sub load_records_ui {
58
    my ( $self, $file ) = @_;
82
    my ( $self, $file ) = @_;
59
    my $jsonresponse;
83
    my $jsonresponse;
60
    my $cgi_root = $self->{intranet} . '/cgi-bin/koha';
84
    my $cgi_root = $self->{intranet} . '/cgi-bin/koha';
Lines 62-69 sub load_records { Link Here
62
    our $agent = Test::WWW::Mechanize->new( autocheck => 1 );
86
    our $agent = Test::WWW::Mechanize->new( autocheck => 1 );
63
    $agent->get_ok( "$cgi_root/mainpage.pl", 'connect to intranet' );
87
    $agent->get_ok( "$cgi_root/mainpage.pl", 'connect to intranet' );
64
    $agent->form_name('loginform');
88
    $agent->form_name('loginform');
65
    $agent->field( 'password', $self->{password} );
89
    $agent->field( 'password', C4::Context->config('pass') );
66
    $agent->field( 'userid',   $self->{user} );
90
    $agent->field( 'userid',   C4::Context->config('user') );
67
    $agent->field( 'branch',   '' );
91
    $agent->field( 'branch',   '' );
68
    $agent->click_ok( '', 'login to staff interface' );
92
    $agent->click_ok( '', 'login to staff interface' );
69
93
70
- 

Return to bug 29368