Bug 13274: t/00-load.t shouldn't depend on the DB
[koha.git] / t / 00-load.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use Test::More;
21 use File::Spec;
22 use File::Find;
23 use Test::MockModule;
24 use DBD::Mock;
25
26 =head1 DESCRIPTION
27
28 00-load.t: This script is called by the pre-commit git hook to test modules compile
29
30 =cut
31
32 # Mock the DB connexion and C4::Context
33 my $context = new Test::MockModule('C4::Context');
34 $context->mock( '_new_dbh', sub {
35         my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
36           || die "Cannot create handle: $DBI::errstr\n";
37         return $dbh;
38 });
39
40 # Loop through the C4:: modules
41 my $lib = File::Spec->rel2abs('C4');
42 find({
43     bydepth => 1,
44     no_chdir => 1,
45     wanted => sub {
46         my $m = $_;
47         return unless $m =~ s/[.]pm$//;
48         $m =~ s{^.*/C4/}{C4/};
49         $m =~ s{/}{::}g;
50         return if $m =~ /Auth_with_ldap/; # Dont test this, it will fail on use
51         return if $m =~ /SIP/; # SIP modules will not load clean
52         use_ok($m) || BAIL_OUT("***** PROBLEMS LOADING FILE '$m'");
53     },
54 }, $lib);
55
56 # Loop through the Koha:: modules
57 $lib = File::Spec->rel2abs('Koha');
58 find(
59     {
60         bydepth  => 1,
61         no_chdir => 1,
62         wanted   => sub {
63             my $m = $_;
64             return unless $m =~ s/[.]pm$//;
65             $m =~ s{^.*/Koha/}{Koha/};
66             $m =~ s{/}{::}g;
67             return if $m =~ /Koha::NorwegianPatronDB/; # uses non-mandatory modules
68             use_ok($m) || BAIL_OUT("***** PROBLEMS LOADING FILE '$m'");
69         },
70     },
71     $lib
72 );
73
74
75 done_testing();
76
77 1;