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

(-)a/t/db_dependent/Koha_Elasticsearch. (-23 lines)
Lines 1-23 Link Here
1
# Copyright 2015 Catalyst IT
2
#
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>
17
18
use strict;
19
use warnings;
20
21
use Test::More tests => 1;                      # last test to print
22
23
use_ok('Koha::Search::Engine::Elasticsearch');
(-)a/t/db_dependent/Koha_Elasticsearch_Indexer.t (-55 lines)
Lines 1-55 Link Here
1
# Copyright 2015 Catalyst IT
2
#
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 5;
21
22
use MARC::Record;
23
24
use_ok('Koha::SearchEngine::Elasticsearch::Indexer');
25
26
my $indexer;
27
ok(
28
    $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'biblio' }),
29
    'Creating new indexer object'
30
);
31
32
my $marc_record = MARC::Record->new();
33
$marc_record->append_fields(
34
    MARC::Field->new( '001', '1234567' ),
35
    MARC::Field->new( '020', '', '', 'a' => '1234567890123' ),
36
    MARC::Field->new( '245', '', '', 'a' => 'Title' )
37
);
38
39
my $records = [$marc_record];
40
ok( my $converted = $indexer->_convert_marc_to_json($records),
41
    'Convert some records' );
42
43
is( $converted->count, 1, 'One converted record' );
44
45
SKIP: {
46
47
    eval { $indexer->get_elasticsearch_params; };
48
49
    skip 'ElasticSeatch configuration not available', 1
50
        if $@;
51
52
    ok( $indexer->update_index(undef,$records), 'Update Index' );
53
}
54
55
1;
(-)a/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t (-107 lines)
Lines 1-106 Link Here
1
# Copyright 2015 Catalyst IT
2
#
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 12;
21
use t::lib::Mocks;
22
23
use Koha::SearchEngine::Elasticsearch::QueryBuilder;
24
25
my $builder = Koha::SearchEngine::Elasticsearch::QueryBuilder->new( { index => 'mydb' } );
26
27
use_ok('Koha::SearchEngine::Elasticsearch::Search');
28
29
ok(
30
    my $searcher = Koha::SearchEngine::Elasticsearch::Search->new(
31
        { 'nodes' => ['localhost:9200'], 'index' => 'mydb' }
32
    ),
33
    'Creating a Koha::SearchEngine::Elasticsearch::Search object'
34
);
35
36
is( $searcher->index, 'mydb', 'Testing basic accessor' );
37
38
ok( my $query = $builder->build_query('easy'), 'Build a search query');
39
40
SKIP: {
41
42
    eval { $builder->get_elasticsearch_params; };
43
44
    skip 'ElasticSeatch configuration not available', 6
45
        if $@;
46
47
    ok( my $results = $searcher->search( $query) , 'Do a search ' );
48
49
    ok( my $marc = $searcher->json2marc( $results->first ), 'Convert JSON to MARC');
50
51
    is (my $count = $searcher->count( $query ), 0 , 'Get a count of the results, without returning results ');
52
53
    ok ($results = $searcher->search_compat( $query ), 'Test search_compat' );
54
55
    ok (($results,$count) = $searcher->search_auth_compat ( $query ), 'Test search_auth_compat' );
56
57
    is ( $count = $searcher->count_auth_use($searcher,1), 0, 'Testing count_auth_use');
58
59
}
60
61
subtest 'json2marc' => sub {
62
    plan tests => 4;
63
    my $leader = '00626nam a2200193   4500';
64
    my $_001 = 42;
65
    my $_010a = '123456789';
66
    my $_010d = 145;
67
    my $_200a = 'a title';
68
    my $json = [ # It's not a JSON, see the POD of json2marc
69
        [ 'LDR', undef, undef, '_', $leader ],
70
        [ '001', undef, undef, '_', $_001 ],
71
        [ '010', ' ', ' ', 'a', $_010a, 'd', $_010d ],
72
        [ '200', '1', ' ', 'a', $_200a, ], # Yes UNIMARC but we don't mind here
73
    ];
74
75
    my $marc = $searcher->json2marc( $json );
76
    is( $marc->leader, $leader, );
77
    is( $marc->field('001')->data, $_001, );
78
    is( $marc->subfield('010', 'a'), $_010a, );
79
    is( $marc->subfield('200', 'a'), $_200a, );
80
81
};
82
83
subtest 'build_query tests' => sub {
84
    plan tests => 6;
85
86
    t::lib::Mocks::mock_preference('DisplayLibraryFacets','both');
87
    my $query = $builder->build_query();
88
    ok( defined $query->{aggregations}{homebranch},
89
        'homebranch added to facets if DisplayLibraryFacets=both' );
90
    ok( defined $query->{aggregations}{holdingbranch},
91
        'holdingbranch added to facets if DisplayLibraryFacets=both' );
92
    t::lib::Mocks::mock_preference('DisplayLibraryFacets','holding');
93
    $query = $builder->build_query();
94
    ok( !defined $query->{aggregations}{homebranch},
95
        'homebranch not added to facets if DisplayLibraryFacets=holding' );
96
    ok( defined $query->{aggregations}{holdingbranch},
97
        'holdingbranch added to facets if DisplayLibraryFacets=holding' );
98
    t::lib::Mocks::mock_preference('DisplayLibraryFacets','home');
99
    $query = $builder->build_query();
100
    ok( defined $query->{aggregations}{homebranch},
101
        'homebranch added to facets if DisplayLibraryFacets=home' );
102
    ok( !defined $query->{aggregations}{holdingbranch},
103
        'holdingbranch not added to facets if DisplayLibraryFacets=home' );
104
};
105
106
1;
107
- 

Return to bug 19441