Changelog: Reverse Charge für einige Steuerschlüssel
[kivitendo-erp.git] / t / Support / Templates.pm
1 # -*- Mode: perl; indent-tabs-mode: nil -*-
2 #
3 # The contents of this file are subject to the Mozilla Public
4 # License Version 1.1 (the "License"); you may not use this file
5 # except in compliance with the License. You may obtain a copy of
6 # the License at http://www.mozilla.org/MPL/
7 #
8 # Software distributed under the License is distributed on an "AS
9 # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10 # implied. See the License for the specific language governing
11 # rights and limitations under the License.
12 #
13 # The Original Code are the Bugzilla tests.
14 #
15 # The Initial Developer of the Original Code is Jacob Steenhagen.
16 # Portions created by Jacob Steenhagen are
17 # Copyright (C) 2001 Jacob Steenhagen. All
18 # Rights Reserved.
19 #
20 # Contributor(s): Jacob Steenhagen <jake@bugzilla.org>
21 #                 David D. Kilzer <ddkilzer@kilzer.net>
22 #                 Tobias Burnus <burnus@net-b.de>
23 #
24
25 package Support::Templates;
26
27 use strict;
28
29 use lib 't';
30 use base qw(Exporter);
31 @Support::Templates::EXPORT =
32          qw(@languages @include_paths %include_path @referenced_files
33             %actual_files $num_actual_files);
34 use vars qw(@languages @include_paths %include_path @referenced_files
35             %actual_files $num_actual_files);
36
37 use Support::Files;
38
39 use File::Find;
40 use File::Spec;
41
42 # The available template languages
43 @languages = ();
44
45 # The colon separated includepath per language
46 %include_path = ();
47
48 # All include paths
49 @include_paths = ();
50
51 # Files which are referenced in the cgi files
52 @referenced_files = ();
53
54 # All files sorted by include_path
55 %actual_files = ();
56
57 # total number of actual_files
58 $num_actual_files = 0;
59
60 # Scan for the template available languages and include paths
61 #{
62 #    opendir(DIR, "templates/webpages") || die "Can't open  'templates': $!";
63 #    my @files = grep { /^[a-z-]+$/i } readdir(DIR);
64 #    closedir DIR;
65 #
66 #    foreach my $langdir (@files) {
67 #        next if($langdir =~ /^CVS$/i);
68 #
69 #        my $path = File::Spec->catdir('templates', $langdir, 'custom');
70 #        my @dirs = ();
71 #        push(@dirs, $path) if(-d $path);
72 #        $path = File::Spec->catdir('templates', $langdir, 'extension');
73 #        push(@dirs, $path) if(-d $path);
74 #        $path = File::Spec->catdir('templates', $langdir, 'default');
75 #        push(@dirs, $path) if(-d $path);
76 #
77 #        next if(scalar(@dirs) == 0);
78 #        push(@languages, $langdir);
79 #        push(@include_paths, @dirs);
80 #        $include_path{$langdir} = join(":",@dirs);
81 #    }
82 #}
83
84 my @files;
85
86 # Local subroutine used with File::Find
87 sub find_templates {
88     # Prune CVS directories
89     if (-d $_ && $_ eq 'CVS') {
90         $File::Find::prune = 1;
91         return;
92     }
93
94     # Only include files ending in '.html'
95     if (-f $_ && $_ =~ m/\.html$/i) {
96         my $filename;
97         my $local_dir = File::Spec->abs2rel($File::Find::dir,
98                                             $File::Find::topdir);
99
100         # File::Spec 3.13 and newer return "." instead of "" if both
101         # arguments of abs2rel() are identical.
102         $local_dir = "" if ($local_dir eq ".");
103
104         if ($local_dir) {
105             $filename = File::Spec->catfile($local_dir, $_);
106         } else {
107             $filename = $_;
108         }
109
110         push(@files, $filename);
111     }
112 }
113
114 # Scan the given template include path for templates
115 sub find_actual_files {
116   my $include_path = $_[0];
117   @files = ();
118   find(\&find_templates, $include_path);
119   return @files;
120 }
121
122 @include_paths = qw(templates/webpages);
123
124 foreach my $include_path (@include_paths) {
125   $actual_files{$include_path} = [ find_actual_files($include_path) ];
126   $num_actual_files += scalar(@{$actual_files{$include_path}});
127 }
128
129 # Scan Bugzilla's perl code looking for templates used and put them
130 # in the @referenced_files array to be used by the 004template.t test.
131 my %seen;
132
133 foreach my $file (@Support::Files::testitems) {
134     open (FILE, $file);
135     my @lines = <FILE>;
136     close (FILE);
137     foreach my $line (@lines) {
138 #        if ($line =~ m/template->process\(\"(.+?)\", .+?\)/) {
139         if ($line =~ m/->parse_html_template\((['"])(.+?)\1/) {
140             my $template = $2;
141             # Ignore templates with $ in the name, since they're
142             # probably vars, not real files
143             next if $template =~ m/\$/;
144             next if $seen{$template};
145             push (@referenced_files, $template);
146             $seen{$template} = 1;
147         }
148     }
149 }
150
151 1;