Koha/t/searchengine/004_config/load_config.t
Jonathan Druart 623f3a2c84 Bug 8233 : SearchEngine: Add a Koha::SearchEngine module
First draft introducing solr into Koha :-)

List of files :
  $ tree t/searchengine/
  t/searchengine
  |-- 000_conn
  |   `-- conn.t
  |-- 001_search
  |   `-- search_base.t
  |-- 002_index
  |   `-- index_base.t
  |-- 003_query
  |   `-- buildquery.t
  |-- 004_config
  |   `-- load_config.t
  `-- indexes.yaml
  just do `prove -r t/searchengine/**/*.t`

  t/lib
  |-- Mocks
  |   `-- Context.pm
  `-- Mocks.pm
  provide a mock to SearchEngine syspref (set_zebra and set_solr).

  $ tree Koha/SearchEngine
  Koha/SearchEngine
  |-- Config.pm
  |-- ConfigRole.pm
  |-- FacetsBuilder.pm
  |-- FacetsBuilderRole.pm
  |-- Index.pm
  |-- IndexRole.pm
  |-- QueryBuilder.pm
  |-- QueryBuilderRole.pm
  |-- Search.pm
  |-- SearchRole.pm
  |-- Solr
  |   |-- Config.pm
  |   |-- FacetsBuilder.pm
  |   |-- Index.pm
  |   |-- QueryBuilder.pm
  |   `-- Search.pm
  |-- Solr.pm
  |-- Zebra
  |   |-- QueryBuilder.pm
  |   `-- Search.pm
  `-- Zebra.pm

How to install and configure Solr ?
  See the wiki page: http://wiki.koha-community.org/wiki/SearchEngine_Layer_RFC

http://bugs.koha-community.org/show_bug.cgi?id=8233
Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
2012-07-06 16:51:58 +02:00

54 lines
1.8 KiB
Perl

use Modern::Perl;
use Test::More;
use FindBin qw($Bin);
use C4::Context;
use Koha::SearchEngine;
use t::lib::Mocks;
set_solr;
my $se = Koha::SearchEngine->new;
is( $se->name, "Solr", "Test searchengine name eq Solr" );
my $config = $se->config;
$config->set_config_filename( "$FindBin::Bin/../indexes.yaml" );
my $ressource_types = $config->ressource_types;
is ( grep ( /^biblio$/, @$ressource_types ), 1, "Ressource type biblio must to be defined" );
is ( grep ( /^authority$/, @$ressource_types ), 1, "Ressource type authority must to be defined" );
my $indexes = $config->indexes;
is ( scalar(@$indexes), 3, "There are 3 indexes configured" );
my $index1 = @$indexes[0];
is ( $index1->{code}, 'title', "My index first have code=title");
is ( $index1->{label}, 'Title', "My index first have label=Title");
is ( $index1->{type}, 'ste', "My index first have type=ste");
is ( $index1->{ressource_type}, 'biblio', "My index first have ressource_type=biblio");
is ( $index1->{sortable}, '1', "My index first have sortable=1");
is ( $index1->{mandatory}, '1', "My index first have mandatory=1");
eq_array ( $index1->{mappings}, ["200\$a", "4..\$t"], "My first index have mappings=[200\$a,4..\$t]");
system( qq{/bin/cp $FindBin::Bin/../indexes.yaml /tmp/indexes.yaml} );
$config->set_config_filename( "/tmp/indexes.yaml" );
$indexes = $config->indexes;
my $new_index = {
code => 'isbn',
label => 'ISBN',
type => 'str',
ressource_type => 'biblio',
sortable => 0,
mandatory => 0
};
push @$indexes, $new_index;
$config->indexes( $indexes );
$indexes = $config->indexes;
my $isbn_index = $config->index( 'isbn' );
is( $isbn_index->{code}, 'isbn', 'Index isbn has been written' );
my $sortable_indexes = $config->sortable_indexes;
is ( @$sortable_indexes, 2, "There are 2 sortable indexes" );
done_testing;