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 90-102
sub get_search_mappings {
Link Here
|
90 |
ok(1, 'Scenario: Get all search mappings'); |
98 |
ok(1, 'Scenario: Get all search mappings'); |
91 |
$mappings = Koha::SearchMappingManager::get_search_mappings({index_name => 'biblios'}); |
99 |
$mappings = Koha::SearchMappingManager::get_search_mappings({index_name => 'biblios'}); |
92 |
ok($mappings, 'When search mappings are fetched'); |
100 |
ok($mappings, 'When search mappings are fetched'); |
93 |
ok($mappings->count() > 10, 'Then we have "'.$mappings->count().'" search mappings :)') |
101 |
ok($mappings->count() > 10, 'Then we have "'.$mappings->count().'" search mappings :)'); |
|
|
102 |
|
103 |
$schema->storage->txn_rollback; |
94 |
} |
104 |
} |
95 |
|
105 |
|
96 |
subtest "Add a search mapping", \&add_mapping; |
106 |
subtest "Add a search mapping", \&add_mapping; |
97 |
sub add_mapping { |
107 |
sub add_mapping { |
98 |
my ($rv, $mappings, $mapping, $count); |
108 |
my ($rv, $mappings, $mapping, $count); |
99 |
|
109 |
|
|
|
110 |
$schema->storage->txn_begin; |
111 |
|
100 |
ok(1, "Scenario: Add the same mapping twice and hope for no duplicate mappings"); |
112 |
ok(1, "Scenario: Add the same mapping twice and hope for no duplicate mappings"); |
101 |
$rv = Koha::SearchMappingManager::add_mapping({name => 'ln-test', |
113 |
$rv = Koha::SearchMappingManager::add_mapping({name => 'ln-test', |
102 |
label => 'original language', |
114 |
label => 'original language', |
Lines 121-126
sub add_mapping {
Link Here
|
121 |
$mappings = Koha::SearchMappingManager::get_search_mappings({index_name => 'biblios', name => 'ln-test'}); |
133 |
$mappings = Koha::SearchMappingManager::get_search_mappings({index_name => 'biblios', name => 'ln-test'}); |
122 |
$count = $mappings->count(); |
134 |
$count = $mappings->count(); |
123 |
is($count, 1, "Then we received only one mapping from the database"); |
135 |
is($count, 1, "Then we received only one mapping from the database"); |
|
|
136 |
|
137 |
$schema->storage->txn_rollback; |
124 |
} |
138 |
} |
125 |
|
139 |
|
126 |
done_testing; |
140 |
done_testing; |
127 |
- |
|
|