X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Funit_core_mvc.t;h=0dbbd80df6a815af9915016da2796fd99c81409f;hb=f3414019f472b55682ef3af53f761b6db7955887;hp=d79653e8c0265d37c3e1f2e7567735ccdf726aa5;hpb=3b88a4556575f18382261e47214bb281694d8f16;p=catagits%2FCatalyst-Runtime.git diff --git a/t/unit_core_mvc.t b/t/unit_core_mvc.t index d79653e..0dbbd80 100644 --- a/t/unit_core_mvc.t +++ b/t/unit_core_mvc.t @@ -1,4 +1,4 @@ -use Test::More tests => 13; +use Test::More tests => 27; use strict; use warnings; @@ -50,3 +50,43 @@ is_deeply( [ sort MyApp->controllers ], is_deeply( [ sort MyApp->models ], [ qw/Dummy::Model M Model Test::Object/ ], 'models ok'); + +is (MyApp->view , 'MyApp::V::View', 'view() with no defaults ok'); + +is ( bless ({stash=>{current_view=>'V'}}, 'MyApp')->view , 'MyApp::View::V', 'current_view ok'); + +my $view = bless {} , 'MyApp::View::V'; +is ( bless ({stash=>{current_view_instance=> $view }}, 'MyApp')->view , $view, 'current_view_instance ok'); + +is ( bless ({stash=>{current_view_instance=> $view, current_view=>'MyApp::V::View' }}, 'MyApp')->view , $view, + 'current_view_instance precedes current_view ok'); + +is (MyApp->model , 'MyApp::M::Model', 'model() with no defaults ok'); + +is ( bless ({stash=>{current_model=>'M'}}, 'MyApp')->model , 'MyApp::Model::M', 'current_model ok'); + +my $model = bless {} , 'MyApp::Model::M'; +is ( bless ({stash=>{current_model_instance=> $model }}, 'MyApp')->model , $model, 'current_model_instance ok'); + +is ( bless ({stash=>{current_model_instance=> $model, current_model=>'MyApp::M::Model' }}, 'MyApp')->model , $model, + 'current_model_instance precedes current_model ok'); + +MyApp->config->{default_view} = 'V'; +is ( bless ({stash=>{}}, 'MyApp')->view , 'MyApp::View::V', 'default_view ok'); +is ( MyApp->view , 'MyApp::View::V', 'default_view in class method ok'); + +MyApp->config->{default_model} = 'M'; +is ( bless ({stash=>{}}, 'MyApp')->model , 'MyApp::Model::M', 'default_model ok'); +is ( MyApp->model , 'MyApp::Model::M', 'default_model in class method ok'); + +#checking @args passed to ACCEPT_CONTEXT +my $args; +{ + no warnings; + *MyApp::Model::M::ACCEPT_CONTEXT = sub { my ($self, $c, @args) = @_; $args= \@args}; + *MyApp::View::V::ACCEPT_CONTEXT = sub { my ($self, $c, @args) = @_; $args= \@args}; +} +MyApp->model('M', qw/foo bar/); +is_deeply($args, [qw/foo bar/], '$c->model args passed to ACCEPT_CONTEXT ok'); +MyApp->view('V', qw/baz moo/); +is_deeply($args, [qw/baz moo/], '$c->view args passed to ACCEPT_CONTEXT ok');