Bug 24879: Adjust tests
[koha.git] / xt / find-missing-auth_checks.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 use Test::More;
20
21 use File::Spec;
22 use File::Find;
23
24 my @files;
25 sub wanted {
26     my $name = $File::Find::name;
27     push @files, $name
28       if $name =~ m{^\./(
29            acqui
30           |admin
31           |authorities
32           |basket
33           |catalogue
34           |cataloguing
35           |circ
36           |clubs
37           |course_reserves
38           |labels
39           |members
40           |patroncards
41           |pos
42           |reports
43           |reserve
44           |reviews
45           |rotating_collections
46           |serials
47           |services
48           |suggestion
49           |svc
50           |tags
51           |tools
52           |virtualshelves
53         )}xms
54       && $name =~ m{\.(pl)$}
55       && -f $name;
56 }
57
58 find({ wanted => \&wanted, no_chdir => 1 }, File::Spec->curdir());
59
60 my @missing_auth_check;
61 FILE: foreach my $name (@files) {
62     open( FILE, $name ) || die "cannot open file $name $!";
63     while ( my $line = <FILE> ) {
64         for my $routine ( qw( get_template_and_user check_cookie_auth checkauth check_api_auth C4::Service->init ) ) {
65             next FILE if $line =~ m|^[^#]*$routine|;
66         }
67     }
68     push @missing_auth_check, $name;
69 }
70 is( scalar @missing_auth_check, 0 ) or diag "No auth check in the following files:\n" . join "\n", @missing_auth_check;
71 done_testing;