Bug 20581: (follow-up) Fix fallback status_alias
[koha.git] / t / SuggestionEngine.t
blobeed6fe85259deb8fa9cbec2c32944a7873510406
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
5 use File::Spec;
7 use Test::More;
9 BEGIN {
10 use_ok('Koha::SuggestionEngine');
13 my $plugindir = File::Spec->rel2abs('Koha/SuggestionEngine/Plugin');
15 opendir(my $dh, $plugindir);
16 my @installed_plugins = map { ( /\.pm$/ && -f "$plugindir/$_" && s/\.pm$// ) ? "Koha::SuggestionEngine::Plugin::$_" : () } readdir($dh);
17 my @available_plugins = Koha::SuggestionEngine::AvailablePlugins();
19 foreach my $plugin (@installed_plugins) {
20 ok(grep($plugin, @available_plugins), "Found plugin $plugin");
23 my $suggestor = Koha::SuggestionEngine->new( { plugins => [ 'ABCD::EFGH::IJKL' ] } );
25 is(ref($suggestor), 'Koha::SuggestionEngine', 'Created suggestion engine with invalid plugin');
26 is(scalar @{ $suggestor->get_suggestions({ 'search' => 'books' }) }, 0 , 'Request suggestions with empty suggestor');
28 $suggestor = Koha::SuggestionEngine->new( { plugins => [ 'Null' ] } );
29 is(ref($suggestor->plugins->[0]), 'Koha::SuggestionEngine::Plugin::Null', 'Created record suggestor with implicitly scoped Null filter');
31 $suggestor = Koha::SuggestionEngine->new( { plugins => [ 'Koha::SuggestionEngine::Plugin::Null' ] } );
32 is(ref($suggestor->plugins->[0]), 'Koha::SuggestionEngine::Plugin::Null', 'Created record suggestor with explicitly scoped Null filter');
34 my $suggestions = $suggestor->get_suggestions({ 'search' => 'books' });
36 is_deeply($suggestions->[0], { 'search' => 'book', label => 'Book!', relevance => 1 }, "Good suggestion");
38 $suggestions = $suggestor->get_suggestions({ 'search' => 'silliness' });
40 eval {
41 $suggestor = Koha::SuggestionEngine->new( { plugins => [ 'Koha::SuggestionEngine::Plugin::Null' ] } );
42 undef $suggestor;
44 ok(!$@, 'Destroyed suggestor successfully');
46 done_testing();