More tests for setup_components, some for locate_components
André Walker [Thu, 9 Jun 2011 21:58:28 +0000 (18:58 -0300)]
t/aggregate/unit_core_component_loading.t
t/aggregate/unit_core_component_setup.t

index 2c53144..2b3e205 100644 (file)
@@ -1,8 +1,8 @@
-# 2 initial tests, and 6 per component in the loop below
+# 3 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;
+use Test::More tests => 3 + 6 * 24 + 9 + 1;
 
 use strict;
 use warnings;
@@ -94,6 +94,11 @@ 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;
@@ -163,6 +168,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;
index aa0c4fc..f8511e8 100644 (file)
@@ -90,18 +90,36 @@ is_deeply(
 );
 
 is_deeply(
+    [ sort TestAppComponents->controllers ],
+    [ sort @controllers ],
+    'controllers are listed correctly by $c->controllers()',
+);
+
+is_deeply(
     [ sort $container->get_sub_container('model')->get_service_list ],
     [ sort @models ],
     'models are in the container',
 );
 
 is_deeply(
+    [ sort TestAppComponents->models ],
+    [ sort @models ],
+    'models are listed correctly by $c->models()',
+);
+
+is_deeply(
     [ sort $container->get_sub_container('view')->get_service_list ],
     [ sort @views ],
     'views are in the container',
 );
 
 is_deeply(
+    [ sort TestAppComponents->views ],
+    [ sort @views ],
+    'views are listed correctly by $c->views()',
+);
+
+is_deeply(
     [ sort keys %{ TestAppComponents->components } ],
     [ sort @comps ],
     'all components are in the components accessor'