|
Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Koha is free software; you can redistribute it and/or modify it |
| 6 |
# under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# Koha is distributed in the hope that it will be useful, but |
| 11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 17 |
|
| 18 |
use Modern::Perl; |
| 19 |
|
| 20 |
use Test::More tests => 5; |
| 21 |
use Test::MockModule; |
| 22 |
use Test::Warn; |
| 23 |
use t::lib::Mocks; |
| 24 |
use t::lib::TestBuilder; |
| 25 |
|
| 26 |
use File::Basename; |
| 27 |
|
| 28 |
use MARC::Record; |
| 29 |
|
| 30 |
use Koha::Database; |
| 31 |
use Koha::Biblios; |
| 32 |
|
| 33 |
BEGIN { |
| 34 |
# Mock pluginsdir before loading Plugins module |
| 35 |
my $path = dirname(__FILE__) . '/../../../lib/plugins'; |
| 36 |
t::lib::Mocks::mock_config( 'pluginsdir', $path ); |
| 37 |
|
| 38 |
use_ok('Koha::Plugins'); |
| 39 |
use_ok('Koha::Plugins::Handler'); |
| 40 |
use_ok('Koha::Plugin::Test'); |
| 41 |
} |
| 42 |
|
| 43 |
my $schema = Koha::Database->schema(); |
| 44 |
|
| 45 |
use_ok('Koha::SearchEngine::Elasticsearch::Indexer'); |
| 46 |
|
| 47 |
SKIP: { |
| 48 |
|
| 49 |
eval { Koha::SearchEngine::Elasticsearch->get_elasticsearch_params; }; |
| 50 |
|
| 51 |
skip 'Elasticsearch configuration not available', 2 |
| 52 |
if $@; |
| 53 |
|
| 54 |
my $builder = t::lib::TestBuilder->new; |
| 55 |
my $biblio = $builder->build_sample_biblio; # create biblio before we start mocking to avoid trouble indexing on creation |
| 56 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
| 57 |
|
| 58 |
subtest 'before_index_action hook' => sub { |
| 59 |
plan tests => 1; |
| 60 |
|
| 61 |
$schema->storage->txn_begin; |
| 62 |
my $plugins = Koha::Plugins->new; |
| 63 |
$plugins->InstallPlugins; |
| 64 |
|
| 65 |
my $plugin = Koha::Plugin::Test->new->enable; |
| 66 |
my $test_plugin = Test::MockModule->new('Koha::Plugin::Test'); |
| 67 |
$test_plugin->mock( 'after_biblio_action', undef ); |
| 68 |
|
| 69 |
my $biblio = $builder->build_sample_biblio; |
| 70 |
my $biblionumber = $biblio->biblionumber; |
| 71 |
|
| 72 |
my $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'biblios' }); |
| 73 |
warning_like { |
| 74 |
$indexer->update_index([$biblionumber]); |
| 75 |
} |
| 76 |
qr/before_index_action called with action: update, engine: Elasticsearch, ref: ARRAY/, |
| 77 |
'-> update_index calls the before_index_action hook'; |
| 78 |
|
| 79 |
$schema->storage->txn_rollback; |
| 80 |
Koha::Plugins::Methods->delete; |
| 81 |
}; |
| 82 |
|
| 83 |
} |