Bug 34943: Unit tests
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit ddb2ab7a9f
)
Signed-off-by: Frédéric Demians <f.demians@tamil.fr>
This commit is contained in:
parent
f09b359cb7
commit
bb83e98c11
2 changed files with 66 additions and 1 deletions
|
@ -16,11 +16,12 @@
|
|||
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::More tests => 4;
|
||||
use Test::More tests => 5;
|
||||
use Test::Warn;
|
||||
|
||||
use File::Basename;
|
||||
|
||||
use C4::Biblio qw(AddBiblio ModBiblio);
|
||||
use C4::Items;
|
||||
|
||||
use t::lib::Mocks;
|
||||
|
@ -86,3 +87,53 @@ subtest 'after_biblio_action() and after_item_action() hooks tests' => sub {
|
|||
$schema->storage->txn_rollback;
|
||||
Koha::Plugins::Methods->delete;
|
||||
};
|
||||
|
||||
subtest 'before_biblio_metadata_store() hooks tests' => sub {
|
||||
|
||||
plan tests => 5;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
my $plugins = Koha::Plugins->new;
|
||||
$plugins->InstallPlugins;
|
||||
|
||||
my $plugin = Koha::Plugin::Test->new->enable;
|
||||
|
||||
my $subfield_contents = 'Arte club';
|
||||
|
||||
my $test_plugin = Test::MockModule->new('Koha::Plugin::Test');
|
||||
$test_plugin->mock( 'after_biblio_action', undef );
|
||||
|
||||
# Defaults to avoid noise
|
||||
my $options = {
|
||||
disable_autolink => 1,
|
||||
skip_holds_queue => 1,
|
||||
skip_record_index => 1,
|
||||
};
|
||||
|
||||
# Add a record
|
||||
my ( $biblio_id, undef ) = C4::Biblio::AddBiblio( MARC::Record->new(), '' );
|
||||
|
||||
my $record = Koha::Biblios->find($biblio_id)->metadata->record;
|
||||
|
||||
my @fields_990 = $record->field('990');
|
||||
|
||||
is( scalar @fields_990, 1, 'One field added' );
|
||||
is( $fields_990[0]->subfield('a'), $subfield_contents );
|
||||
|
||||
# Simulate editing the record
|
||||
ModBiblio( $record, $biblio_id, '', $options );
|
||||
|
||||
$record = Koha::Biblios->find($biblio_id)->record;
|
||||
|
||||
@fields_990 = $record->field('990');
|
||||
# This is to highlight that is the plugin responsibility to choose what to do on the record
|
||||
is( scalar @fields_990, 2, 'Two saves, two fields' );
|
||||
|
||||
foreach my $index (qw(0 1)) {
|
||||
is( $fields_990[$index]->subfield('a'), $subfield_contents );
|
||||
}
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
Koha::Plugins::Methods->delete;
|
||||
};
|
||||
|
|
|
@ -6,6 +6,7 @@ use Modern::Perl;
|
|||
use Koha::Exception;
|
||||
use Koha::Plugins::Tab;
|
||||
|
||||
use MARC::Field;
|
||||
use Mojo::JSON qw( decode_json );
|
||||
|
||||
## Required for all plugins
|
||||
|
@ -148,6 +149,19 @@ sub after_hold_create {
|
|||
Koha::Exception->throw("after_hold_create called with parameter " . ref($param) );
|
||||
}
|
||||
|
||||
sub before_biblio_metadata_store {
|
||||
my ( $self, $record ) = @_;
|
||||
|
||||
$record->insert_fields_ordered(
|
||||
MARC::Field->new(
|
||||
'990', '', '',
|
||||
'a' => 'Arte club'
|
||||
)
|
||||
);
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
sub after_biblio_action {
|
||||
my ( $self, $params ) = @_;
|
||||
my $action = $params->{action} // '';
|
||||
|
|
Loading…
Reference in a new issue