rework component resolution methods (i.e. model(), models(), etc), plus add in some...
[catagits/Catalyst-Runtime.git] / t / unit_core_component.t
1 use Test::More tests => 10;
2 use strict;
3 use warnings;
4
5 use_ok('Catalyst');
6
7 my @complist = map { "MyApp::$_"; } qw/C::Controller M::Model V::View/;
8
9 {
10   package MyApp;
11
12   use base qw/Catalyst/;
13
14   __PACKAGE__->components({ map { ($_, $_) } @complist });
15 }
16
17 is(MyApp->comp('MyApp::V::View'), 'MyApp::V::View', 'Explicit return ok');
18
19 is(MyApp->comp('C::Controller'), 'MyApp::C::Controller', 'Two-part return ok');
20
21 is(MyApp->comp('Model'), 'MyApp::M::Model', 'Single part return ok');
22
23 # regexp fallback
24 is(MyApp->comp('::M::'), 'MyApp::M::Model', 'Regex return ok');
25
26 is_deeply([ MyApp->comp() ], \@complist, 'Empty return ok');
27
28 # Is this desired behaviour?
29 is_deeply([ MyApp->comp('Foo') ], \@complist, 'Fallthrough return ok');
30
31 # regexp behavior
32 {
33     is_deeply( [ MyApp->comp( qr{Model} ) ], [ 'MyApp::M::Model'], 'regexp ok' );
34 }
35
36 # multiple returns
37 {
38     my @expected = qw( MyApp::C::Controller MyApp::M::Model );
39     is_deeply( [ MyApp->comp( qr{::[MC]::} ) ], \@expected, 'multiple results fro regexp ok' );
40 }
41
42 # failed search
43 {
44     is_deeply( scalar MyApp->comp( qr{DNE} ), 0, 'no results for failed search' );
45 }
46