Bug 15644 - City dropdown default selection when modifying a patron matches only...
[koha.git] / t / Installer_PerlModules.t
blobdad968fed60616ea4a7b6ec74f31b6813db0d551
1 #!/usr/bin/perl
3 # This Koha test module is a stub!
4 # Add more tests here!!!
6 use Modern::Perl;
8 use Test::More tests => 22;
10 BEGIN {
11 use_ok('C4::Installer::PerlModules');
14 $C4::Installer::PerlModules::PERL_DEPS->{'Local::Module::Upgraded'} = {
15 'required' => '1',
16 'min_ver' => '0.9.3',
17 'usage' => "Testing: make sure numbers are compared numerically and not lexicographically",
19 $Local::Module::Upgraded::VERSION = '0.9.13';
20 $INC{"Local/Module/Upgraded.pm"} = 1;
21 use_ok("Local::Module::Upgraded");
23 $C4::Installer::PerlModules::PERL_DEPS->{'Local::Module::NotUpgraded'} = {
24 'required' => '1',
25 'min_ver' => '0.9.3',
26 'usage' => "Testing: make sure numbers are compared numerically and not lexicographically",
28 $Local::Module::NotUpgraded::VERSION = '0.9.1';
29 $INC{"Local/Module/NotUpgraded.pm"} = 1;
30 use_ok("Local::Module::NotUpgraded");
32 my $modules;
33 ok ($modules = C4::Installer::PerlModules->new(), 'Tests modules object');
34 my $prereq_pm = $modules->prereq_pm();
35 ok (exists($prereq_pm->{"DBI"}), 'DBI required for installer to run');
36 ok (exists($prereq_pm->{"CGI"}), 'CGI required for installer to run' );
37 ok (exists($prereq_pm->{"YAML"}), 'YAML required for installer to run');
38 is ($modules->required('module'=>"DBI"),1, 'DBI should return 1 since required');
39 is ($modules->required('module'=>"thisdoesn'texist"),-1, 'string should return -1 since not in hash');
40 my $required = $modules->required('required'=>1);
41 my %params = map { $_ => 1 } @$required;
42 ok (exists($params{"DBI"}), 'DBI required for installer to run');
43 my $optional = $modules->required('optional'=>1);
44 %params = map { $_ => 1 } @$optional;
45 ok (exists($params{"Test::Strict"}), 'test::strict optional for installer to run');
46 is ($optional = $modules->required('spaghetti'=>1),-1, '-1 returned when parsing in unknown parameter');
47 my $version_info = $modules->version_info('DBI');
48 ok (exists($version_info->{"required"}), 'required exists');
49 ok (exists($version_info->{"upgrade"}), 'upgrade exists');
50 is ($modules->version_info("thisdoesn'texist"),-1, 'thisdoesntexist should return -1');
51 ok ($modules->module_count() >10 , 'count should be greater than 10');
52 my @module_list = $modules->module_list;
53 %params = map { $_ => 1 } @module_list;
54 ok (exists($params{"DBI"}), 'DBI exists in array');
55 is ($modules->required('module'=>"String::Random"),1, 'String::Random should return 1 since required');
56 is ($modules->version_info(), -1, "Testing empty modules");
58 is($modules->version_info("Local::Module::Upgraded")->{"upgrade"},0,"Version 0.9.13 is greater than 0.9.3, so no upgrade needed");
59 is($modules->version_info("Local::Module::NotUpgraded")->{"upgrade"},1,"Version 0.9.1 is smaller than 0.9.1, so no upgrade needed");
61 subtest 'versions_info' => sub {
62 plan tests => 4;
63 my $modules = C4::Installer::PerlModules->new;
64 $modules->versions_info;
65 ok( exists $modules->{missing_pm}, 'versions_info fills the missing_pm key' );
66 ok( exists $modules->{upgrade_pm}, 'versions_info fills the upgrade_pm key' );
67 ok( exists $modules->{current_pm}, 'versions_info fills the current_pm key' );
68 my $missing_modules = $modules->get_attr( 'missing_pm' );
69 my $upgrade_modules = $modules->get_attr( 'upgrade_pm' );
70 my $current_modules = $modules->get_attr( 'current_pm' );
71 my $dbi_is_missing = grep { exists $_->{DBI} ? 1 : () } @$missing_modules;
72 my $dbi_is_upgrade = grep { exists $_->{DBI} ? 1 : () } @$upgrade_modules;
73 my $dbi_is_current = grep { exists $_->{DBI} ? 1 : () } @$current_modules;
74 ok( $dbi_is_missing || $dbi_is_upgrade || $dbi_is_current, 'DBI should either be missing, upgrade or current' );