root/branches/release-41/t/91-tagcoverage.t @ 2742

Revision 2742, 1.8 kB (checked in by bchoate, 17 months ago)

Updated POD for template tags; added test for template tag doc coverage.

Line 
1#!/usr/bin/perl
2
3use strict;
4use lib 't/extlib', 't/lib', 'extlib', 'lib';
5use Test::More;
6use MT::Test;
7use Data::Dumper;
8
9my @core_docs = qw(
10    lib/MT/Template/ContextHandlers.pm
11    lib/MT/Template/Context/Search.pm
12);
13
14my $mt = MT->instance;
15my $tags = $mt->component('core')->registry('tags');
16
17my $tag_count = (scalar keys(%{ $tags->{function} })
18    + scalar keys(%{ $tags->{modifier} })
19    + scalar keys(%{ $tags->{block} }))
20    - 3; # the registry gives us an extra 'plugin' key for each element
21plan tests => $tag_count;
22
23my $core_docs = '';
24{
25    local $/ = undef;
26    foreach my $file ( @core_docs ) {
27        # core tag docs are embedded as POD
28        open DOC, "< $file";
29        $core_docs .= <DOC>;
30        close DOC;
31    }
32}
33
34# Determine if the core tags have adequate documentation or not.
35my $doc_names = {};
36while ($core_docs =~ m/\n=head2[ ]+([\w:]+)[ ]*\n(.*?)?\n=cut[ ]*\n/gs) {
37    my $tag = $1;
38    my $docs = defined $2 ? $2 : '';
39    $docs =~ s/\r//g; # for windows newlines
40    # ignore comment lines
41    $docs =~ s/^#.*//gm;
42    # ignore empty lines
43    $docs =~ s/^\s*$//gm;
44    # strip any '=for ...', etc. directive. docs should be above this
45    $docs =~ s/(^|\n)=\w+.*//s;
46    # strip trailing/leading newlines
47    $docs =~ s/^\n+//s;
48    $docs =~ s/\n+$//s;
49    # if documentation block doesn't have anything left, the tag is undocumented
50    next if $docs eq '';
51    $doc_names->{lc $tag} = 1;
52}
53
54foreach my $tag ( keys %{ $tags->{function} } ) {
55    next if $tag eq 'plugin';
56    ok(exists $doc_names->{lc $tag}, "function tag $tag");
57}
58
59foreach my $tag ( keys %{ $tags->{block} } ) {
60    next if $tag eq 'plugin';
61    $tag =~ s/\?$//;
62    ok(exists $doc_names->{lc $tag}, "block tag $tag");
63}
64
65foreach my $tag ( keys %{ $tags->{modifier} } ) {
66    next if $tag eq 'plugin';
67    ok(exists $doc_names->{lc $tag}, "modifier $tag");
68}
69
Note: See TracBrowser for help on using the browser.