Refactored Regex actions
[catagits/Catalyst-Runtime.git] / t / unit_core_plugin.t
CommitLineData
836e1134 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 20;
7
8use lib 't/lib';
9
10{
11
12 package Faux::Plugin;
13
14 sub new { bless {}, shift }
15 my $count = 1;
16 sub count { $count++ }
17}
18
19{
20
21 package PluginTestApp;
22 use Test::More;
23
24 use Catalyst qw(
25 Test::Plugin
26 +TestApp::Plugin::FullyQualified
27 );
28
29 sub compile_time_plugins : Local {
30 my ( $self, $c ) = @_;
31
32 isa_ok $c, 'Catalyst::Plugin::Test::Plugin';
33 isa_ok $c, 'TestApp::Plugin::FullyQualified';
34
35 can_ok $c, 'registered_plugins';
36 $c->_test_plugins;
37
38 $c->res->body("ok");
39 }
40
41 sub run_time_plugins : Local {
42 my ( $self, $c ) = @_;
43
44 $c->_test_plugins;
45 my $faux_plugin = 'Faux::Plugin';
46
47 # Trick perl into thinking the plugin is already loaded
48 $INC{'Faux/Plugin.pm'} = 1;
49
50 __PACKAGE__->plugin( faux => $faux_plugin );
51
52 isa_ok $c, 'Catalyst::Plugin::Test::Plugin';
53 isa_ok $c, 'TestApp::Plugin::FullyQualified';
54 ok !$c->isa($faux_plugin),
55 '... and it should not inherit from the instant plugin';
56 can_ok $c, 'faux';
57 is $c->faux->count, 1, '... and it should behave correctly';
58 is_deeply [ $c->registered_plugins ],
59 [
60 qw/Catalyst::Plugin::Test::Plugin
61 Faux::Plugin
62 TestApp::Plugin::FullyQualified/
63 ],
64 'registered_plugins() should report all plugins';
65 ok $c->registered_plugins('Faux::Plugin'),
66 '... and even the specific instant plugin';
67
68 $c->res->body("ok");
69 }
70
71 sub _test_plugins {
72 my $c = shift;
73 is_deeply [ $c->registered_plugins ],
74 [
75 qw/Catalyst::Plugin::Test::Plugin
76 TestApp::Plugin::FullyQualified/
77 ],
78 '... and it should report the correct plugins';
79 ok $c->registered_plugins('Catalyst::Plugin::Test::Plugin'),
80 '... or if we have a particular plugin';
81 ok $c->registered_plugins('Test::Plugin'),
82 '... even if it is not fully qualified';
83 ok !$c->registered_plugins('No::Such::Plugin'),
84 '... and it should return false if the plugin does not exist';
85 }
86
87 __PACKAGE__->setup;
88}
89
90use Catalyst::Test qw/PluginTestApp/;
91
92ok( get("/compile_time_plugins"), "get ok" );
93ok( get("/run_time_plugins"), "get ok" );