From 69b6069309484aec4ef47f2565d238fe5d8b623a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 7 Feb 2024 09:16:33 +0100 Subject: [PATCH] Bug 34478: Add test to catch missing op in POST forms Signed-off-by: Jonathan Druart --- xt/find-missing-csrf.t | 34 +++++------------ xt/find-missing-op-in-forms.t | 71 +++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 25 deletions(-) create mode 100755 xt/find-missing-op-in-forms.t diff --git a/xt/find-missing-csrf.t b/xt/find-missing-csrf.t index 77820e6e76..95cbe07a5e 100755 --- a/xt/find-missing-csrf.t +++ b/xt/find-missing-csrf.t @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright 2021 Koha development team +# Copyright 2024 Koha development team # # This file is part of Koha. # @@ -19,39 +19,23 @@ use Modern::Perl; use Test::More tests => 1; -use File::Find; use File::Slurp; use Data::Dumper; -my @themes; - -# OPAC themes -my $opac_dir = 'koha-tmpl/opac-tmpl'; -opendir ( my $dh, $opac_dir ) or die "can't opendir $opac_dir: $!"; -for my $theme ( grep { not /^\.|lib|js|xslt/ } readdir($dh) ) { - push @themes, "$opac_dir/$theme/en"; -} -close $dh; +my @files; -# STAFF themes -my $staff_dir = 'koha-tmpl/intranet-tmpl'; -opendir ( $dh, $staff_dir ) or die "can't opendir $staff_dir: $!"; -for my $theme ( grep { not /^\.|lib|js/ } readdir($dh) ) { - push @themes, "$staff_dir/$theme/en"; -} -close $dh; +# OPAC +push @files, `git ls-files 'koha-tmpl/opac-tmpl/bootstrap/en/*.tt'`; +push @files, `git ls-files 'koha-tmpl/opac-tmpl/bootstrap/en/*.inc'`; -my @files; -sub wanted { - my $name = $File::Find::name; - push @files, $name - if $name =~ m[\.(tt|inc)$] and -f $name; -} +# Staff +push @files, `git ls-files 'koha-tmpl/intranet-tmpl/prog/en/*.tt'`; +push @files, `git ls-files 'koha-tmpl/intranet-tmpl/prog/en/*.inc'`; -find({ wanted => \&wanted, no_chdir => 1 }, @themes ); my @errors; for my $file ( @files ) { + chomp $file; my @e = check_csrf_in_forms($file); push @errors, sprintf "%s:%s", $file, join (",", @e) if @e; } diff --git a/xt/find-missing-op-in-forms.t b/xt/find-missing-op-in-forms.t new file mode 100755 index 0000000000..18098e8b35 --- /dev/null +++ b/xt/find-missing-op-in-forms.t @@ -0,0 +1,71 @@ +#!/usr/bin/perl + +# Copyright 2024 Koha development team +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; +use Test::More tests => 1; +use File::Slurp; +use Data::Dumper; + +my @files; + +# OPAC +push @files, `git ls-files 'koha-tmpl/opac-tmpl/bootstrap/en/*.tt'`; +push @files, `git ls-files 'koha-tmpl/opac-tmpl/bootstrap/en/*.inc'`; + +# Staff +push @files, `git ls-files 'koha-tmpl/intranet-tmpl/prog/en/*.tt'`; +push @files, `git ls-files 'koha-tmpl/intranet-tmpl/prog/en/*.inc'`; + +my @errors; +for my $file ( @files ) { + chomp $file; + my @e = catch_missing_op($file); + push @errors, sprintf "%s:%s", $file, join (",", @e) if @e; +} + +is( @errors, 0, "The
in the following files are missing it's corresponding op parameter (see bug 34478)" ) + or diag( Dumper @errors ); + +sub catch_missing_op { + my ($file) = @_; + + my @lines = read_file($file); + my @errors; + return unless grep { $_ =~ m|