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' });
41 $suggestor = Koha::SuggestionEngine->new( { plugins => [ 'Koha::SuggestionEngine::Plugin::Null' ] } );
44 ok(!$@, 'Destroyed suggestor successfully');