Merge remote-tracking branch 'origin/new/bug_8251'
[koha.git] / t / searchengine / 004_config / load_config.t
1 use Modern::Perl;
2 use Test::More;
3 use FindBin qw($Bin);
4
5 use C4::Context;
6 use Koha::SearchEngine;
7 use t::lib::Mocks;
8
9 set_solr;
10
11 my $se = Koha::SearchEngine->new;
12 is( $se->name, "Solr", "Test searchengine name eq Solr" );
13
14 my $config = $se->config;
15 $config->set_config_filename( "$FindBin::Bin/../indexes.yaml" );
16 my $ressource_types = $config->ressource_types;
17 is ( grep ( /^biblio$/, @$ressource_types ), 1, "Ressource type biblio must to be defined" );
18 is ( grep ( /^authority$/, @$ressource_types ), 1, "Ressource type authority must to be defined" );
19
20 my $indexes = $config->indexes;
21 is ( scalar(@$indexes), 3, "There are 3 indexes configured" );
22
23 my $index1 = @$indexes[0];
24 is ( $index1->{code}, 'title', "My index first have code=title");
25 is ( $index1->{label}, 'Title', "My index first have label=Title");
26 is ( $index1->{type}, 'ste', "My index first have type=ste");
27 is ( $index1->{ressource_type}, 'biblio', "My index first have ressource_type=biblio");
28 is ( $index1->{sortable}, '1', "My index first have sortable=1");
29 is ( $index1->{mandatory}, '1', "My index first have mandatory=1");
30 eq_array ( $index1->{mappings}, ["200\$a", "4..\$t"], "My first index have mappings=[200\$a,4..\$t]");
31
32 system( qq{/bin/cp $FindBin::Bin/../indexes.yaml /tmp/indexes.yaml} );
33 $config->set_config_filename( "/tmp/indexes.yaml" );
34 $indexes = $config->indexes;
35 my $new_index = {
36     code => 'isbn',
37     label => 'ISBN',
38     type => 'str',
39     ressource_type => 'biblio',
40     sortable => 0,
41     mandatory => 0
42 };
43 push @$indexes, $new_index;
44 $config->indexes( $indexes );
45
46 $indexes = $config->indexes;
47
48 my $isbn_index = $config->index( 'isbn' );
49 is( $isbn_index->{code}, 'isbn', 'Index isbn has been written' );
50
51 my $sortable_indexes = $config->sortable_indexes;
52 is ( @$sortable_indexes, 2, "There are 2 sortable indexes" );
53
54 done_testing;