View | Details | Raw Unified | Return to bug 34943
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Plugins/Biblio_and_Items_plugin_hooks.t (-1 / +52 lines)
Lines 16-26 Link Here
16
16
17
use Modern::Perl;
17
use Modern::Perl;
18
18
19
use Test::More tests => 4;
19
use Test::More tests => 5;
20
use Test::Warn;
20
use Test::Warn;
21
21
22
use File::Basename;
22
use File::Basename;
23
23
24
use C4::Biblio qw(AddBiblio ModBiblio);
24
use C4::Items;
25
use C4::Items;
25
26
26
use t::lib::Mocks;
27
use t::lib::Mocks;
Lines 86-88 subtest 'after_biblio_action() and after_item_action() hooks tests' => sub { Link Here
86
    $schema->storage->txn_rollback;
87
    $schema->storage->txn_rollback;
87
    Koha::Plugins::Methods->delete;
88
    Koha::Plugins::Methods->delete;
88
};
89
};
90
91
subtest 'before_biblio_metadata_store() hooks tests' => sub {
92
93
    plan tests => 5;
94
95
    $schema->storage->txn_begin;
96
97
    my $plugins = Koha::Plugins->new;
98
    $plugins->InstallPlugins;
99
100
    my $plugin = Koha::Plugin::Test->new->enable;
101
102
    my $subfield_contents = 'Arte club';
103
104
    my $test_plugin = Test::MockModule->new('Koha::Plugin::Test');
105
    $test_plugin->mock( 'after_biblio_action', undef );
106
107
    # Defaults to avoid noise
108
    my $options = {
109
        disable_autolink  => 1,
110
        skip_holds_queue  => 1,
111
        skip_record_index => 1,
112
    };
113
114
    # Add a record
115
    my ( $biblio_id, undef ) = C4::Biblio::AddBiblio( MARC::Record->new(), '' );
116
117
    my $record = Koha::Biblios->find($biblio_id)->metadata->record;
118
119
    my @fields_990 = $record->field('990');
120
121
    is( scalar @fields_990, 1, 'One field added' );
122
    is( $fields_990[0]->subfield('a'), $subfield_contents );
123
124
    # Simulate editing the record
125
    ModBiblio( $record, $biblio_id, '', $options );
126
127
    $record = Koha::Biblios->find($biblio_id)->record;
128
129
    @fields_990 = $record->field('990');
130
    # This is to highlight that is the plugin responsibility to choose what to do on the record
131
    is( scalar @fields_990, 2, 'Two saves, two fields' );
132
133
    foreach my $index (qw(0 1)) {
134
        is( $fields_990[$index]->subfield('a'), $subfield_contents );
135
    }
136
137
    $schema->storage->txn_rollback;
138
    Koha::Plugins::Methods->delete;
139
};
(-)a/t/lib/plugins/Koha/Plugin/Test.pm (-1 / +14 lines)
Lines 6-11 use Modern::Perl; Link Here
6
use Koha::Exception;
6
use Koha::Exception;
7
use Koha::Plugins::Tab;
7
use Koha::Plugins::Tab;
8
8
9
use MARC::Field;
9
use Mojo::JSON qw( decode_json );
10
use Mojo::JSON qw( decode_json );
10
11
11
## Required for all plugins
12
## Required for all plugins
Lines 148-153 sub after_hold_create { Link Here
148
    Koha::Exception->throw("after_hold_create called with parameter " . ref($param) );
149
    Koha::Exception->throw("after_hold_create called with parameter " . ref($param) );
149
}
150
}
150
151
152
sub before_biblio_metadata_store {
153
    my ( $self, $record ) = @_;
154
155
    $record->insert_fields_ordered(
156
        MARC::Field->new(
157
            '990', '', '',
158
            'a' => 'Arte club'
159
        )
160
    );
161
162
    return $record;
163
}
164
151
sub after_biblio_action {
165
sub after_biblio_action {
152
    my ( $self, $params ) = @_;
166
    my ( $self, $params ) = @_;
153
    my $action    = $params->{action} // '';
167
    my $action    = $params->{action} // '';
154
- 

Return to bug 34943