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 |
}; |