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

(-)a/t/db_dependent/Koha/SearchEngine/ElasticSearch.t (-2 / +15 lines)
Lines 21-34 use Modern::Perl qw(2014); Link Here
21
use utf8;
21
use utf8;
22
use Test::More;
22
use Test::More;
23
23
24
use Koha::Database;
24
use Koha::SearchEngine::Elasticsearch;
25
use Koha::SearchEngine::Elasticsearch;
25
use Koha::SearchMappingManager;
26
use Koha::SearchMappingManager;
26
27
28
my $schema = Koha::Database->schema;
27
29
28
subtest "Reset Elasticsearch mappings", \&reset_elasticsearch_mappings;
30
subtest "Reset Elasticsearch mappings", \&reset_elasticsearch_mappings;
29
sub reset_elasticsearch_mappings {
31
sub reset_elasticsearch_mappings {
30
    my ($rv, $mappings, $count, $mapping);
32
    my ($rv, $mappings, $count, $mapping);
31
33
34
    $schema->storage->txn_begin;
35
32
    ok(1, 'Scenario: Reset Elasticsearch mappings to an empty database');
36
    ok(1, 'Scenario: Reset Elasticsearch mappings to an empty database');
33
    #There might or might not be any mappings. Whatever the initial status is, make sure we start from empty tables
37
    #There might or might not be any mappings. Whatever the initial status is, make sure we start from empty tables
34
    $rv = Koha::SearchMappingManager::flush();
38
    $rv = Koha::SearchMappingManager::flush();
Lines 69-80 sub reset_elasticsearch_mappings { Link Here
69
    $mappings = Koha::SearchMappingManager::get_search_mappings({index_name => 'biblios'});
73
    $mappings = Koha::SearchMappingManager::get_search_mappings({index_name => 'biblios'});
70
    $count = $mappings->count();
74
    $count = $mappings->count();
71
    ok($count > 10, 'Then search mapping tables have been populated');
75
    ok($count > 10, 'Then search mapping tables have been populated');
76
77
    $schema->storage->txn_rollback;
72
}
78
}
73
79
74
subtest "Get Elasticsearch mappings", \&get_search_mappings;
80
subtest "Get Elasticsearch mappings", \&get_search_mappings;
75
sub get_search_mappings {
81
sub get_search_mappings {
76
    my ($mappings, $mapping);
82
    my ($mappings, $mapping);
77
83
84
    $schema->storage->txn_begin;
85
78
    ok(1, 'Scenario: Get a single search mapping by name');
86
    ok(1, 'Scenario: Get a single search mapping by name');
79
    $mappings = Koha::SearchMappingManager::get_search_mappings({index_name => 'biblios', name => 'ff7-00'});
87
    $mappings = Koha::SearchMappingManager::get_search_mappings({index_name => 'biblios', name => 'ff7-00'});
80
    ok($mappings, 'When a search mappings is fetched');
88
    ok($mappings, 'When a search mappings is fetched');
Lines 91-103 sub get_search_mappings { Link Here
91
    ok(1, 'Scenario: Get all search mappings');
99
    ok(1, 'Scenario: Get all search mappings');
92
    $mappings = Koha::SearchMappingManager::get_search_mappings({index_name => 'biblios'});
100
    $mappings = Koha::SearchMappingManager::get_search_mappings({index_name => 'biblios'});
93
    ok($mappings, 'When search mappings are fetched');
101
    ok($mappings, 'When search mappings are fetched');
94
    ok($mappings->count() > 10, 'Then we have "'.$mappings->count().'" search mappings :)')
102
    ok($mappings->count() > 10, 'Then we have "'.$mappings->count().'" search mappings :)');
103
104
    $schema->storage->txn_rollback;
95
}
105
}
96
106
97
subtest "Add a search mapping", \&add_mapping;
107
subtest "Add a search mapping", \&add_mapping;
98
sub add_mapping {
108
sub add_mapping {
99
    my ($rv, $mappings, $mapping, $count);
109
    my ($rv, $mappings, $mapping, $count);
100
110
111
    $schema->storage->txn_begin;
112
101
    ok(1, "Scenario: Add the same mapping twice and hope for no duplicate mappings");
113
    ok(1, "Scenario: Add the same mapping twice and hope for no duplicate mappings");
102
    $rv = Koha::SearchMappingManager::add_mapping({name => 'ln-test',
114
    $rv = Koha::SearchMappingManager::add_mapping({name => 'ln-test',
103
                                                   label => 'original language',
115
                                                   label => 'original language',
Lines 122-127 sub add_mapping { Link Here
122
    $mappings = Koha::SearchMappingManager::get_search_mappings({index_name => 'biblios', name => 'ln-test'});
134
    $mappings = Koha::SearchMappingManager::get_search_mappings({index_name => 'biblios', name => 'ln-test'});
123
    $count = $mappings->count();
135
    $count = $mappings->count();
124
    is($count, 1, "Then we received only one mapping from the database");
136
    is($count, 1, "Then we received only one mapping from the database");
137
138
    $schema->storage->txn_rollback;
125
}
139
}
126
140
127
done_testing;
141
done_testing;
128
- 

Return to bug 17897