| 1 | #!/usr/bin/perl |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use lib 't/extlib', 't/lib', 'extlib', 'lib'; |
|---|
| 5 | use Test::More; |
|---|
| 6 | use MT::Test; |
|---|
| 7 | use Data::Dumper; |
|---|
| 8 | |
|---|
| 9 | my @core_docs = qw( |
|---|
| 10 | lib/MT/Template/ContextHandlers.pm |
|---|
| 11 | lib/MT/Template/Context/Search.pm |
|---|
| 12 | ); |
|---|
| 13 | |
|---|
| 14 | my $mt = MT->instance; |
|---|
| 15 | my $tags = $mt->component('core')->registry('tags'); |
|---|
| 16 | |
|---|
| 17 | my $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 |
|---|
| 21 | plan tests => $tag_count; |
|---|
| 22 | |
|---|
| 23 | my $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. |
|---|
| 35 | my $doc_names = {}; |
|---|
| 36 | while ($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 | |
|---|
| 54 | foreach my $tag ( keys %{ $tags->{function} } ) { |
|---|
| 55 | next if $tag eq 'plugin'; |
|---|
| 56 | ok(exists $doc_names->{lc $tag}, "function tag $tag"); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | foreach 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 | |
|---|
| 65 | foreach my $tag ( keys %{ $tags->{modifier} } ) { |
|---|
| 66 | next if $tag eq 'plugin'; |
|---|
| 67 | ok(exists $doc_names->{lc $tag}, "modifier $tag"); |
|---|
| 68 | } |
|---|
| 69 | |
|---|