X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F20-mock_load.t;h=987dd236e34fe0bdb7e160ab18f0560eb3a6d1d4;hb=64443e1a85ef62db87cb664d948cfefe94cebf08;hp=7f19b8589f358b208447288ae0364cc450c5db43;hpb=79b66c823b2c12137c0e801d98c05c3784229fd7;p=catagits%2FCatalyst-Plugin-ConfigLoader.git diff --git a/t/20-mock_load.t b/t/20-mock_load.t index 7f19b85..987dd23 100644 --- a/t/20-mock_load.t +++ b/t/20-mock_load.t @@ -1,42 +1,29 @@ -use Test::More tests => 5; - -my $app = MockApp->new; -$app->setup; - -ok( $app->config ); -is( $app->config->{ 'Controller::Foo' }->{ foo }, 'bar' ); -is( $app->config->{ 'Controller::Foo' }->{ new }, 'key' ); -is( $app->config->{ 'Model::Baz' }->{ qux }, 'xyzzy' ); -is( $app->config->{ 'Model::Baz' }->{ another }, 'new key' ); - -package MockApp; - -use base qw( Catalyst::Plugin::ConfigLoader ); -use NEXT; -use Catalyst::Utils; - -sub new { - return bless { }, shift; -} - -sub path_to { - return 't/mockapp'; -} - -sub debug { - 0; -} - -sub config { - my $self = shift; - $self->{ _config } = {} unless $self->{ _config }; - if (@_) { - my $config = @_ > 1 ? {@_} : $_[0]; - while ( my ( $key, $val ) = each %$config ) { - $self->{ _config }->{$key} = $val; - } - } - return $self->{ _config }; -} - -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');