| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::ZofCMS::Test::Plugin; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 599 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 33 |  | 
| 4 | 1 |  |  | 1 |  | 6 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 35 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | our $VERSION = '1.001008'; # VERSION | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 1 |  |  | 1 |  | 5 | use base 'Test::Builder::Module'; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 123 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | my $Test = Test::Builder->new; | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | sub import { | 
| 13 | 1 |  |  | 1 |  | 24 | my $self = shift; | 
| 14 | 1 |  |  |  |  | 3 | my $caller = caller; | 
| 15 | 1 |  |  | 1 |  | 7 | no strict 'refs'; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 299 |  | 
| 16 | 1 |  |  |  |  | 2 | *{$caller.'::plugin_ok'}   = \&plugin_ok; | 
|  | 1 |  |  |  |  | 4 |  | 
| 17 |  |  |  |  |  |  |  | 
| 18 | 1 |  |  |  |  | 4 | $Test->exported_to($caller); | 
| 19 | 1 |  |  |  |  | 13 | $Test->plan( tests => 3); | 
| 20 |  |  |  |  |  |  | } | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | sub plugin_ok { | 
| 23 | 1 |  |  | 1 | 1 | 748 | my ( $plugin_name, $template_with_input, $query, $config_hash ) = @_; | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 1 |  | 50 |  |  | 4 | $template_with_input ||= {}; | 
| 26 | 1 |  | 50 |  |  | 3 | $query ||= {}; | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 1 |  |  | 1 |  | 436 | eval "use App::ZofCMS::Plugin::$plugin_name"; | 
|  | 1 |  |  |  |  | 17 |  | 
|  | 1 |  |  |  |  | 22 |  | 
|  | 1 |  |  |  |  | 60 |  | 
| 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 |  |  |  |  | 6 | my $o = "App::ZofCMS::Plugin::$plugin_name"->new; | 
| 37 | 1 |  |  |  |  | 9 | $Test->ok( $o->can('new'), "new() method is available"); | 
| 38 | 1 |  |  |  |  | 355 | $Test->ok( $o->can('process'), "process() method is available"); | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | SKIP: { | 
| 41 | 1 |  |  | 1 |  | 448 | eval "use App::ZofCMS::Config"; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 27 |  | 
|  | 1 |  |  |  |  | 252 |  | 
|  | 1 |  |  |  |  | 62 |  | 
| 42 | 1 | 50 |  |  |  | 6 | 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 |  |  |  |  | 4 | my $config = App::ZofCMS::Config->new; | 
| 49 | 1 |  | 50 |  |  | 5 | $config->conf( $config_hash || {} ); | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 1 |  |  |  |  | 6 | $o->process( $template_with_input, $query, $config ); | 
| 52 |  |  |  |  |  |  |  | 
| 53 | 1 |  |  |  |  | 4 | delete @$template_with_input{ qw/t d conf plugins/ }; | 
| 54 | 1 |  |  |  |  | 11 | $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 |  |  |  |  | 447 | $Test->diag( | 
| 60 |  |  |  |  |  |  | "Query ended up as: \n" . join "\n", map | 
| 61 |  |  |  |  |  |  | "[$_] => [$query->{$_}]", keys %$query | 
| 62 |  |  |  |  |  |  | ); | 
| 63 |  |  |  |  |  |  | } | 
| 64 |  |  |  |  |  |  | } | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | 1; | 
| 67 |  |  |  |  |  |  | __END__ |