|
Lines 22-27
use File::Basename;
Link Here
|
| 22 |
use File::Spec; |
22 |
use File::Spec; |
| 23 |
use File::Temp qw( tempdir tempfile ); |
23 |
use File::Temp qw( tempdir tempfile ); |
| 24 |
use FindBin qw($Bin); |
24 |
use FindBin qw($Bin); |
|
|
25 |
use List::MoreUtils qw(none); |
| 25 |
use Module::Load::Conditional qw(can_load); |
26 |
use Module::Load::Conditional qw(can_load); |
| 26 |
use Test::MockModule; |
27 |
use Test::MockModule; |
| 27 |
use Test::NoWarnings; |
28 |
use Test::NoWarnings; |
|
Lines 194-200
subtest 'GetPlugins() tests' => sub {
Link Here
|
| 194 |
|
195 |
|
| 195 |
subtest 'InstallPlugins() tests' => sub { |
196 |
subtest 'InstallPlugins() tests' => sub { |
| 196 |
|
197 |
|
| 197 |
plan tests => 6; |
198 |
plan tests => 8; |
| 198 |
|
199 |
|
| 199 |
$schema->storage->txn_begin; |
200 |
$schema->storage->txn_begin; |
| 200 |
|
201 |
|
|
Lines 204-224
subtest 'InstallPlugins() tests' => sub {
Link Here
|
| 204 |
|
205 |
|
| 205 |
# Tests for the exclude parameter |
206 |
# Tests for the exclude parameter |
| 206 |
# Test the returned plugins of the InstallPlugins subroutine |
207 |
# Test the returned plugins of the InstallPlugins subroutine |
|
|
208 |
my $excluded_plugins = [ "Koha::Plugin::Test", "Koha::Plugin::MarcFieldValues" ]; |
| 207 |
my $plugins = Koha::Plugins->new( { enable_plugins => 1 } ); |
209 |
my $plugins = Koha::Plugins->new( { enable_plugins => 1 } ); |
| 208 |
my @installed_plugins = $plugins->InstallPlugins( { exclude => [ "Koha::Plugin::Test", "Koha::Plugin::MarcFieldValues" ] } ); |
210 |
my @installed_plugins = $plugins->InstallPlugins( { exclude => $excluded_plugins } ); |
| 209 |
my $plugin_classes = join( " ", map { $_->{class} } @installed_plugins ); |
|
|
| 210 |
|
211 |
|
| 211 |
my $result = grep { $plugin_classes !~ $_ } [ ":Test |:Test\$", ":MarcFieldValues |:MarcFieldValues\$" ] |
212 |
foreach my $excluded_plugin ( @{$excluded_plugins} ) { |
| 212 |
&& $plugin_classes =~ ":TestItemBarcodeTransform |:TestItemBarcodeTransform\$"; |
213 |
ok( |
| 213 |
ok( $result, "Excluded plugins are not returned" ); |
214 |
none { $_ eq $excluded_plugin } ( map { $_->{class} } @installed_plugins ), |
|
|
215 |
"Excluded plugin not returned ($excluded_plugin)" |
| 216 |
); |
| 217 |
} |
| 214 |
|
218 |
|
| 215 |
# Test the plugins in the database |
219 |
# Test the plugins in the database |
| 216 |
my @plugins = $plugins->GetPlugins( { all => 1, error => 1 } ); |
220 |
my @plugins = $plugins->GetPlugins( { all => 1, error => 1 } ); |
| 217 |
$plugin_classes = join( " ", map { $_->{class} } @plugins ); |
221 |
foreach my $excluded_plugin ( @{$excluded_plugins} ) { |
| 218 |
|
222 |
ok( |
| 219 |
$result = grep { $plugin_classes !~ $_ } [ ":Test |:Test\$", ":MarcFieldValues |:MarcFieldValues\$" ] |
223 |
none { $_ eq $excluded_plugin } ( map { $_->{class} } @plugins ), |
| 220 |
&& $plugin_classes =~ ":TestItemBarcodeTransform |:TestItemBarcodeTransform\$"; |
224 |
"Excluded plugin not installed ($excluded_plugin)" |
| 221 |
ok( $result, "Excluded plugins are not installed" ); |
225 |
); |
|
|
226 |
} |
| 222 |
|
227 |
|
| 223 |
# Remove installed plugins data |
228 |
# Remove installed plugins data |
| 224 |
Koha::Plugins::Methods->delete; |
229 |
Koha::Plugins::Methods->delete; |
|
Lines 226-234
subtest 'InstallPlugins() tests' => sub {
Link Here
|
| 226 |
|
231 |
|
| 227 |
# Tests for the include parameter |
232 |
# Tests for the include parameter |
| 228 |
# Test the returned plugins of the InstallPlugins subroutine |
233 |
# Test the returned plugins of the InstallPlugins subroutine |
| 229 |
@installed_plugins = $plugins->InstallPlugins( { include => [ "Koha::Plugin::Test", "Koha::Plugin::MarcFieldValues" ] } ); |
234 |
@installed_plugins = |
|
|
235 |
$plugins->InstallPlugins( { include => [ "Koha::Plugin::Test", "Koha::Plugin::MarcFieldValues" ] } ); |
| 230 |
|
236 |
|
| 231 |
$result = 1; |
237 |
my $result = 1; |
| 232 |
foreach my $plugin_class ( map { $_->{class} } @installed_plugins ) { |
238 |
foreach my $plugin_class ( map { $_->{class} } @installed_plugins ) { |
| 233 |
$result = 0 unless ( "$plugin_class" =~ ":Test\$" || "$plugin_class" =~ ":MarcFieldValues\$" ); |
239 |
$result = 0 unless ( "$plugin_class" =~ ":Test\$" || "$plugin_class" =~ ":MarcFieldValues\$" ); |
| 234 |
} |
240 |
} |
|
Lines 244-260
subtest 'InstallPlugins() tests' => sub {
Link Here
|
| 244 |
ok( $result, "Only included plugins are installed" ); |
250 |
ok( $result, "Only included plugins are installed" ); |
| 245 |
|
251 |
|
| 246 |
# Tests when both include and exclude parameter are used simultaneously |
252 |
# Tests when both include and exclude parameter are used simultaneously |
| 247 |
throws_ok |
253 |
throws_ok { |
| 248 |
{ |
254 |
$plugins->InstallPlugins( { exclude => ["Koha::Plugin::Test"], include => ["Koha::Plugin::Test"] } ); |
| 249 |
$plugins->InstallPlugins( { exclude => [ "Koha::Plugin::Test" ], include => [ "Koha::Plugin::Test" ] } ); |
255 |
} |
| 250 |
} |
256 |
'Koha::Exceptions::BadParameter'; |
| 251 |
'Koha::Exceptions::BadParameter'; |
257 |
|
| 252 |
# Tests when the plugin to be installled is not found |
258 |
# Tests when the plugin to be installled is not found |
| 253 |
throws_ok |
259 |
throws_ok { |
| 254 |
{ |
260 |
$plugins->InstallPlugins( { include => ["Koha::Plugin::NotfoundPlugin"] } ); |
| 255 |
$plugins->InstallPlugins( { include => [ "Koha::Plugin::NotfoundPlugin" ] } ); |
261 |
} |
| 256 |
} |
262 |
'Koha::Exceptions::BadParameter'; |
| 257 |
'Koha::Exceptions::BadParameter'; |
|
|
| 258 |
|
263 |
|
| 259 |
$schema->storage->txn_rollback; |
264 |
$schema->storage->txn_rollback; |
| 260 |
}; |
265 |
}; |
| 261 |
- |
|
|