Lines 17-25
Link Here
|
17 |
# You should have received a copy of the GNU General Public License |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
19 |
|
20 |
use warnings; |
20 |
use Modern::Perl; |
21 |
use strict; |
21 |
use Test::More tests => 3; |
22 |
use Test::More tests => 2; |
|
|
23 |
use File::Find; |
22 |
use File::Find; |
24 |
use Cwd; |
23 |
use Cwd; |
25 |
use C4::TTParser; |
24 |
use C4::TTParser; |
Lines 42-76
for my $theme ( grep { not /^\.|lib|js/ } readdir($dh) ) {
Link Here
|
42 |
} |
41 |
} |
43 |
close $dh; |
42 |
close $dh; |
44 |
|
43 |
|
45 |
my @files_with_directive_in_tag = do { |
44 |
my $checkers = [ |
46 |
my @files; |
45 |
{ |
47 |
find( sub { |
46 |
description => 'TT syntax: not using TT directive within HTML tag', |
48 |
my $dir = getcwd(); |
47 |
check => sub { |
49 |
return if $dir =~ /blib/; |
48 |
my ($self, $name, $token) = @_; |
50 |
return unless /\.(tt|inc)$/; |
|
|
51 |
my $name = $_; |
52 |
my $parser = C4::TTParser->new; |
53 |
$parser->build_tokens( $name ); |
54 |
my @lines; |
55 |
while ( my $token = $parser->next_token ) { |
56 |
my $attr = $token->{_attr}; |
49 |
my $attr = $token->{_attr}; |
57 |
next unless $attr; |
50 |
push @{$self->{errors}->{$name}}, $token->{_lc} if $attr->{'[%'} or $attr->{'[%-'}; |
58 |
push @lines, $token->{_lc} if $attr->{'[%'} or $attr->{'[%-'}; |
51 |
}, |
|
|
52 |
errors => {}, |
53 |
}, |
54 |
{ |
55 |
description => '<body> tag with id and class attributes', |
56 |
check => sub { |
57 |
my ($self, $name, $token) = @_; |
58 |
return if $name =~ /bodytag\.inc/; |
59 |
$_ = $token->{_string}; |
60 |
push @{$self->{errors}->{$name}}, $token->{_lc} |
61 |
if /^<body/ && ! /id=".+"/ && ! /class=".+"/; |
62 |
|
63 |
}, |
64 |
errors => {}, |
65 |
}, |
66 |
]; |
67 |
find( sub { |
68 |
my $dir = getcwd(); |
69 |
return if $dir =~ /blib/; |
70 |
return unless /\.(tt|inc)$/; |
71 |
($dir) = $dir =~ /koha-tmpl\/(.*)$/; |
72 |
my $name = $_; |
73 |
my $parser = C4::TTParser->new; |
74 |
$parser->build_tokens( $name ); |
75 |
while ( my $token = $parser->next_token ) { |
76 |
my $attr = $token->{_attr}; |
77 |
next unless $attr; |
78 |
for my $checker (@$checkers) { |
79 |
$checker->{check}->($_, "$dir/$name", $token); |
59 |
} |
80 |
} |
60 |
($dir) = $dir =~ /koha-tmpl\/(.*)$/; |
81 |
} |
61 |
push @files, { name => "$dir/$name", lines => \@lines } if @lines; |
82 |
}, @themes |
62 |
}, @themes |
83 |
); |
63 |
); |
84 |
|
64 |
@files; |
85 |
for my $check (@$checkers) { |
65 |
}; |
86 |
my @files = sort keys %{$check->{errors}}; |
66 |
|
87 |
ok( !@files, $check->{description} ) |
67 |
|
88 |
or diag( |
68 |
ok( !@files_with_directive_in_tag, "TT syntax: not using TT directive within HTML tag" ) |
89 |
"Files list: \n", |
69 |
or diag( |
90 |
join( "\n", map { "$_: " . join(', ', @{$check->{errors}->{$_}}) |
70 |
"Files list: \n", |
91 |
} @files ) |
71 |
join( "\n", map { $_->{name} . ': ' . join(', ', @{$_->{lines}}) |
92 |
); |
72 |
} @files_with_directive_in_tag ) |
93 |
} |
73 |
); |
|
|
74 |
|
94 |
|
75 |
my $testtoken = 0; |
95 |
my $testtoken = 0; |
76 |
my $ttparser = C4::TTParser->new(); |
96 |
my $ttparser = C4::TTParser->new(); |
77 |
- |
|
|