Changelog for torbjorn's patches
[catagits/Catalyst-Plugin-ConfigLoader.git] / t / 20-mock_load.t
index 7f19b85..987dd23 100644 (file)
@@ -1,42 +1,29 @@
-use Test::More tests => 5;\r
-\r
-my $app = MockApp->new;\r
-$app->setup;\r
-\r
-ok( $app->config );\r
-is( $app->config->{ 'Controller::Foo' }->{ foo }, 'bar' );\r
-is( $app->config->{ 'Controller::Foo' }->{ new }, 'key' );\r
-is( $app->config->{ 'Model::Baz' }->{ qux }, 'xyzzy' );\r
-is( $app->config->{ 'Model::Baz' }->{ another }, 'new key' );\r
-\r
-package MockApp;\r
-\r
-use base qw( Catalyst::Plugin::ConfigLoader );\r
-use NEXT;\r
-use Catalyst::Utils;\r
-\r
-sub new {\r
-    return bless { }, shift;\r
-}\r
-\r
-sub path_to {\r
-    return 't/mockapp';\r
-}\r
-\r
-sub debug {\r
-    0;\r
-}\r
-\r
-sub config {\r
-    my $self = shift;\r
-    $self->{ _config } = {} unless $self->{ _config };\r
-    if (@_) {\r
-        my $config = @_ > 1 ? {@_} : $_[0];\r
-        while ( my ( $key, $val ) = each %$config ) {\r
-            $self->{ _config }->{$key} = $val;\r
-        }\r
-    }\r
-    return $self->{ _config };\r
-}\r
-\r
-1;
\ No newline at end of file
+package MockApp;
+
+use Test::More tests => 10;
+use Cwd;
+
+# Remove all relevant env variables to avoid accidental fail
+foreach my $name ( grep { m{^(CATALYST)} } keys %ENV ) {
+    delete $ENV{ $name };
+}
+
+$ENV{ CATALYST_HOME } = cwd . '/t/mockapp';
+
+use_ok( 'Catalyst', qw( ConfigLoader ) );
+
+__PACKAGE__->config->{ 'Plugin::ConfigLoader' }->{ substitutions } = {
+    foo => sub { shift; join( '-', @_ ); }
+};
+
+__PACKAGE__->setup;
+
+ok( __PACKAGE__->config );
+is( __PACKAGE__->config->{ 'Controller::Foo' }->{ foo }, 'bar' );
+is( __PACKAGE__->config->{ 'Controller::Foo' }->{ new }, 'key' );
+is( __PACKAGE__->config->{ 'Model::Baz' }->{ qux },      'xyzzy' );
+is( __PACKAGE__->config->{ 'Model::Baz' }->{ another },  'new key' );
+is( __PACKAGE__->config->{ 'view' },                     'View::TT::New' );
+is( __PACKAGE__->config->{ 'foo_sub' },                  'x-y' );
+is( __PACKAGE__->config->{ 'literal_macro' },            '__DATA__' );
+is( __PACKAGE__->config->{ 'Plugin::Zot' }->{ zoot },    'zooot');