View | Details | Raw Unified | Return to bug 13941
Collapse All | Expand All

(-)a/xt/tt_valid.t (-32 / +50 lines)
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
use YAML;
46
    my @files;
45
47
    find( sub {
46
my $checkers = [
48
        my $dir = getcwd();
47
    {
49
        return if $dir =~ /blib/;
48
        description => 'TT syntax: not using TT directive within HTML tag',
50
        return unless /\.(tt|inc)$/;
49
        check => sub {
51
        my $name = $_;
50
            my ($self, $name, $token) = @_;
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};
51
            my $attr = $token->{_attr};
57
            next unless $attr;
52
            push @{$self->{errors}->{$name}}, $token->{_lc} if $attr->{'[%'} or $attr->{'[%-'};
58
            push @lines, $token->{_lc} if $attr->{'[%'} or $attr->{'[%-'};
53
        },
59
        }
54
        errors => {},
60
        ($dir) = $dir =~ /koha-tmpl\/(.*)$/;
55
    },
61
        push @files, { name => "$dir/$name", lines => \@lines } if @lines;
56
    {
62
      }, @themes
57
        description => '<body> tag with id and class attributes',
63
    );
58
        check => sub {
64
    @files;
59
            my ($self, $name, $token) = @_;
65
};
60
            my $_ = $token->{_string};
66
61
            push @{$self->{errors}->{$name}}, $token->{_lc}
67
62
              if /^<body/ && ! /id=".+"/ && ! /class=".+"/;
68
ok( !@files_with_directive_in_tag, "TT syntax: not using TT directive within HTML tag" )
63
69
    or diag(
64
        },
70
          "Files list: \n",
65
        errors => {},
71
          join( "\n", map { $_->{name} . ': ' . join(', ', @{$_->{lines}})
66
    },
72
              } @files_with_directive_in_tag )
67
];
73
       );
68
find( sub {
69
    my $dir = getcwd();
70
    return if $dir =~ /blib/;
71
    return unless /\.(tt|inc)$/;
72
    ($dir) = $dir =~ /koha-tmpl\/(.*)$/;
73
    my $name = $_;
74
    my $parser = C4::TTParser->new;
75
    $parser->build_tokens( $name );
76
    while ( my $token = $parser->next_token ) {
77
        my $attr = $token->{_attr};
78
        next unless $attr;
79
        $_->{check}->($_, "$dir/$name", $token)  for @$checkers;
80
    }
81
  }, @themes
82
);
83
84
for my $check (@$checkers) {
85
  my @files = sort keys %{$check->{errors}};
86
  ok( !@files, $check->{description} )
87
      or diag(
88
            "Files list: \n",
89
            join( "\n", map { "$_: " . join(', ', @{$check->{errors}->{$_}})
90
                } @files )
91
         );
92
}
74
93
75
my $testtoken = 0;
94
my $testtoken = 0;
76
my $ttparser = C4::TTParser->new();
95
my $ttparser = C4::TTParser->new();
77
- 

Return to bug 13941