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