Lines 15-23
Link Here
|
15 |
# You should have received a copy of the GNU General Public License |
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> |
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses> |
17 |
|
17 |
|
18 |
use strict; |
18 |
use Modern::Perl; |
19 |
use warnings; |
|
|
20 |
|
19 |
|
21 |
use Test::More tests => 1; # last test to print |
20 |
use Test::More tests => 2; |
|
|
21 |
use Test::MockModule; |
22 |
|
23 |
use t::lib::Mocks; |
24 |
|
25 |
my $schema = Koha::Database->schema; |
22 |
|
26 |
|
23 |
use_ok('Koha::SearchEngine::Elasticsearch'); |
27 |
use_ok('Koha::SearchEngine::Elasticsearch'); |
24 |
- |
28 |
|
|
|
29 |
subtest 'get_fixer_rules() tests' => sub { |
30 |
|
31 |
plan tests => 26; |
32 |
|
33 |
$schema->storage->txn_begin; |
34 |
|
35 |
t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); |
36 |
|
37 |
my $name; |
38 |
my $type; |
39 |
my $facet; |
40 |
my $suggestible; |
41 |
my $sort; |
42 |
my $marc_type; |
43 |
my $marc_field; |
44 |
|
45 |
my $se = Test::MockModule->new( 'Koha::SearchEngine::Elasticsearch' ); |
46 |
$se->mock( '_foreach_mapping', sub { |
47 |
my ($self, $sub ) = @_; |
48 |
|
49 |
return $sub->( |
50 |
$name, |
51 |
$type, |
52 |
$facet, |
53 |
$suggestible, |
54 |
$sort, |
55 |
$marc_type, |
56 |
$marc_field |
57 |
); |
58 |
}); |
59 |
|
60 |
my $see = Koha::SearchEngine::Elasticsearch->new({ index => 'biblios' }); |
61 |
|
62 |
$name = 'author'; |
63 |
$type = 'string'; |
64 |
$facet = 1; |
65 |
$suggestible = 1; |
66 |
$sort = '~'; |
67 |
$marc_type = 'marc21'; |
68 |
$marc_field = '100a'; |
69 |
|
70 |
my $result = $see->get_fixer_rules(); |
71 |
is( $result->[0], q{marc_map('} . $marc_field . q{','} . $name . q{.$append' , -split => 1)}); |
72 |
is( $result->[1], q{marc_map('} . $marc_field . q{','} . $name . q{__facet' , -split => 1)}); |
73 |
is( $result->[2], q{marc_map('} . $marc_field . q{','} . $name . q{__suggestion.input.$append')}); |
74 |
is( $result->[3], q{marc_map('} . $marc_field . q{','} . $name . q{__sort' , -split => 1)}); |
75 |
is( $result->[4], q{move_field(_id,es_id)}); |
76 |
|
77 |
$type = 'boolean'; |
78 |
$result = $see->get_fixer_rules(); |
79 |
is( $result->[0], q{marc_map('} . $marc_field . q{','} . $name . q{.$append' , -split => 1)}); |
80 |
is( $result->[1], q{marc_map('} . $marc_field . q{','} . $name . q{__facet' , -split => 1)}); |
81 |
is( $result->[2], q{marc_map('} . $marc_field . q{','} . $name . q{__suggestion.input.$append')}); |
82 |
is( $result->[3], q{unless exists('} . $name . q{') add_field('} . $name . q{', 0) end}); |
83 |
is( $result->[4], q{marc_map('} . $marc_field . q{','} . $name . q{__sort' , -split => 1)}); |
84 |
is( $result->[5], q{move_field(_id,es_id)}); |
85 |
|
86 |
$type = 'sum'; |
87 |
$result = $see->get_fixer_rules(); |
88 |
is( $result->[0], q{marc_map('} . $marc_field . q{','} . $name . q{.$append' )}); |
89 |
is( $result->[1], q{marc_map('} . $marc_field . q{','} . $name . q{__facet' )}); |
90 |
is( $result->[2], q{marc_map('} . $marc_field . q{','} . $name . q{__suggestion.input.$append')}); |
91 |
is( $result->[3], q{sum('} . $name . q{')}); |
92 |
is( $result->[4], q{marc_map('} . $marc_field . q{','} . $name . q{__sort' )}); |
93 |
is( $result->[5], q{move_field(_id,es_id)}); |
94 |
|
95 |
$type = 'string'; |
96 |
$facet = 0; |
97 |
|
98 |
$result = $see->get_fixer_rules(); |
99 |
is( $result->[0], q{marc_map('} . $marc_field . q{','} . $name . q{.$append' , -split => 1)}); |
100 |
is( $result->[1], q{marc_map('} . $marc_field . q{','} . $name . q{__suggestion.input.$append')}); |
101 |
is( $result->[2], q{marc_map('} . $marc_field . q{','} . $name . q{__sort' , -split => 1)}); |
102 |
is( $result->[3], q{move_field(_id,es_id)}); |
103 |
|
104 |
$suggestible = 0; |
105 |
|
106 |
$result = $see->get_fixer_rules(); |
107 |
is( $result->[0], q{marc_map('} . $marc_field . q{','} . $name . q{.$append' , -split => 1)}); |
108 |
is( $result->[1], q{marc_map('} . $marc_field . q{','} . $name . q{__sort' , -split => 1)}); |
109 |
is( $result->[2], q{move_field(_id,es_id)}); |
110 |
|
111 |
t::lib::Mocks::mock_preference( 'marcflavour', 'UNIMARC' ); |
112 |
|
113 |
$result = $see->get_fixer_rules(); |
114 |
is( $result->[0], q{move_field(_id,es_id)}); |
115 |
is( $result->[1], undef, q{No mapping when marc_type doesn't match marchflavour} ); |
116 |
|
117 |
$schema->storage->txn_rollback; |
118 |
|
119 |
}; |
120 |
|
121 |
1; |