Lines 16-22
Link Here
|
16 |
|
16 |
|
17 |
use Modern::Perl; |
17 |
use Modern::Perl; |
18 |
|
18 |
|
19 |
use Test::More tests => 5; |
19 |
use Test::More tests => 6; |
20 |
use Test::Warn; |
20 |
use Test::Warn; |
21 |
|
21 |
|
22 |
use File::Basename; |
22 |
use File::Basename; |
Lines 137-139
subtest 'before_biblio_action() hooks tests' => sub {
Link Here
|
137 |
$schema->storage->txn_rollback; |
137 |
$schema->storage->txn_rollback; |
138 |
Koha::Plugins::Methods->delete; |
138 |
Koha::Plugins::Methods->delete; |
139 |
}; |
139 |
}; |
|
|
140 |
|
141 |
subtest 'elasticsearch_to_document() hooks tests' => sub { |
142 |
|
143 |
plan tests => 6; |
144 |
|
145 |
$schema->storage->txn_begin; |
146 |
|
147 |
my $plugins = Koha::Plugins->new; |
148 |
$plugins->InstallPlugins; |
149 |
|
150 |
my $plugin = Koha::Plugin::Test->new->enable; |
151 |
|
152 |
my $test_plugin1 = Test::MockModule->new('Koha::Plugin::Test'); |
153 |
$test_plugin1->mock( 'after_biblio_action', undef ); |
154 |
|
155 |
# Create a record |
156 |
my $record = MARC::Record->new(); |
157 |
$record->append_fields( MARC::Field->new('009', '123456789') ); |
158 |
|
159 |
my $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); |
160 |
my $documents; |
161 |
warning_like { $documents = $indexer->marc_records_to_documents([$record]); } |
162 |
qr/elasticsearch_to_document ref record: MARC::Record - ref document: HASH/, |
163 |
'ES marc_records_to_document calls the hook'; |
164 |
|
165 |
my $test_plugin2 = Test::MockModule->new('Koha::Plugin::Test'); |
166 |
$test_plugin2->mock( 'after_biblio_action', undef ); |
167 |
|
168 |
# Create an ES search field 'ppn' and populate it with 009 field |
169 |
$test_plugin2->mock( 'elasticsearch_to_document', sub { |
170 |
my ($self, $params) = @_; |
171 |
my $record = $params->{record}; |
172 |
my $document = $params->{document}; |
173 |
my $value = $record->field('009')->data; |
174 |
$document->{ppn} = [$value]; |
175 |
}); |
176 |
$documents = $indexer->marc_records_to_documents([$record]); |
177 |
ok(ref($documents) eq 'ARRAY', 'Indexer marc_records_to_documents returns an ARRAY'); |
178 |
ok(scalar(@$documents) == 1, 'This array contains one (1) document'); |
179 |
ok(ref($documents->[0]) eq 'HASH', 'The document is a HASH'); |
180 |
ok(exists($documents->[0]->{ppn}), 'Generated field ppn exists'); |
181 |
ok($documents->[0]->{ppn}->[0] eq '123456789', 'Field ppn contains 123456789'); |
182 |
}; |
183 |
|