File Coverage

blib/lib/App/ZofCMS/Test/Plugin.pm
Criterion Covered Total %
statement 41 49 83.6
branch 2 4 50.0
condition 3 6 50.0
subroutine 8 8 100.0
pod 1 1 100.0
total 55 68 80.8


line stmt bran cond sub pod time code
1             package App::ZofCMS::Test::Plugin;
2              
3 1     1   558 use warnings;
  1         1  
  1         35  
4 1     1   4 use strict;
  1         1  
  1         36  
5              
6             our $VERSION = '1.001007'; # VERSION
7              
8 1     1   3 use base 'Test::Builder::Module';
  1         1  
  1         136  
9              
10             my $Test = Test::Builder->new;
11              
12             sub import {
13 1     1   28 my $self = shift;
14 1         1 my $caller = caller;
15 1     1   4 no strict 'refs';
  1         2  
  1         256  
16 1         2 *{$caller.'::plugin_ok'} = \&plugin_ok;
  1         4  
17              
18 1         4 $Test->exported_to($caller);
19 1         9 $Test->plan( tests => 3);
20             }
21              
22             sub plugin_ok {
23 1     1 1 400 my ( $plugin_name, $template_with_input, $query, $config_hash ) = @_;
24              
25 1   50     4 $template_with_input ||= {};
26 1   50     2 $query ||= {};
27              
28 1     1   375 eval "use App::ZofCMS::Plugin::$plugin_name";
  1         2  
  1         16  
  1         50  
29 1 50       5 if ( $@ ) {
30 0         0 $Test->ok(1);
31 0         0 $Test->ok(1);
32 0         0 $Test->ok(1);
33 0         0 $Test->diag("Failed to use App::ZofCMS::Plugin::$plugin_name");
34 0         0 exit 0;
35             }
36 1         4 my $o = "App::ZofCMS::Plugin::$plugin_name"->new;
37 1         7 $Test->ok( $o->can('new'), "new() method is available");
38 1         432 $Test->ok( $o->can('process'), "process() method is available");
39              
40             SKIP: {
41 1     1   355 eval "use App::ZofCMS::Config";
  1         2  
  1         15  
  1         337  
  1         52  
42 1 50       4 if ( $@ ) {
43 0         0 $Test->ok (1);
44 0         0 $Test->diag ("App::ZofCMS::Config is required for process() testing");
45 0         0 last;
46             }
47              
48 1         3 my $config = App::ZofCMS::Config->new;
49 1   50     4 $config->conf( $config_hash || {} );
50              
51 1         3 $o->process( $template_with_input, $query, $config );
52              
53 1         3 delete @$template_with_input{ qw/t d conf plugins/ };
54 1         4 $Test->ok( 0 == keys %$template_with_input,
55             "Template must be empty after deleting {t}, {d}, {conf}"
56             . " and {plugins} keys"
57             );
58              
59 1         334 $Test->diag(
60             "Query ended up as: \n" . join "\n", map
61             "[$_] => [$query->{$_}]", keys %$query
62             );
63             }
64             }
65              
66             1;
67             __END__