Merge branch 'master' into gsoc_breadboard
[catagits/Catalyst-Runtime.git] / t / aggregate / unit_core_component_loading.t
index 2c53144..ba62ff6 100644 (file)
@@ -1,8 +1,5 @@
-# 2 initial tests, and 6 per component in the loop below
-# (do not forget to update the number of components in test 3 as well)
-# 5 extra tests for the loading options
-# One test for components in inner packages
-use Test::More tests => 2 + 6 * 24 + 8 + 1;
+# way too many tests to count
+use Test::More;
 
 use strict;
 use warnings;
@@ -94,10 +91,16 @@ my $shut_up_deprecated_warnings = q{
 
 eval "package $appclass; use Catalyst; $shut_up_deprecated_warnings __PACKAGE__->setup";
 
+is_deeply(
+    [ sort $appclass->locate_components ],
+    [ map { $appclass . '::' . $_->{prefix} . '::' . $_->{name} } @components ],    'locate_components finds the components correctly'
+);
+
 can_ok( $appclass, 'components');
 
 my $complist = $appclass->components;
 
+# FIXME should the app class really be included in ->components?
 # the +1 below is for the app class itself
 is(scalar keys %$complist, 24+1, "Correct number of components loaded");
 
@@ -163,6 +166,24 @@ __PACKAGE__->config->{ setup_components } = {
 __PACKAGE__->setup;
 );
 
+{
+    my $config = {
+        search_extra => [ '::Extra' ],
+        except       => [ "${appclass}::Controller::Foo" ]
+    };
+    my @components_located = $appclass->locate_components($config);
+    my @components_expected;
+    for (@components) {
+        my $name = $appclass . '::' . $_->{prefix} . '::' . $_->{name};
+        push @components_expected, $name if $name ne "${appclass}::Controller::Foo";
+    }
+    is_deeply(
+        [ sort @components_located ],
+        [ sort @components_expected ],
+        'locate_components finds the components correctly'
+    );
+}
+
 can_ok( $appclass, 'components');
 
 $complist = $appclass->components;
@@ -215,8 +236,8 @@ eval "package $appclass; use Catalyst; __PACKAGE__->setup";
 is($@, '', "Didn't load component twice");
 is($appclass->model('TopLevel::Nested')->called,1, 'COMPONENT called once');
 
-ok($appclass->model('TopLevel::Generated'), 'Have generated model');
-is(ref($appclass->model('TopLevel::Generated')), 'FooBarBazQuux',
+ok($appclass->model('TopLevel::GENERATED'), 'Have generated model');
+is(ref($appclass->model('TopLevel::GENERATED')), 'FooBarBazQuux',
     'ACCEPT_CONTEXT in generated inner package fired as expected');
 
 $appclass = "InnerComponent";
@@ -233,3 +254,5 @@ eval "package $appclass; use Catalyst; __PACKAGE__->setup";
 isa_ok($appclass->controller('Test'), 'Catalyst::Controller');
 
 rmtree($libdir);
+
+done_testing;