1 use Test::More tests => 27;
9 qw/C::Controller M::Model V::View Controller::C Model::M View::V Controller::Model::Dummy::Model Model::Dummy::Model/;
12 bless $thingie,'MyApp::Model::Test::Object';
13 push @complist,$thingie;
18 use base qw/Catalyst/;
20 __PACKAGE__->components( { map { ( ref($_)||$_ , $_ ) } @complist } );
23 is( MyApp->view('View'), 'MyApp::V::View', 'V::View ok' );
25 is( MyApp->controller('Controller'),
26 'MyApp::C::Controller', 'C::Controller ok' );
28 is( MyApp->model('Model'), 'MyApp::M::Model', 'M::Model ok' );
30 is( MyApp->model('Dummy::Model'), 'MyApp::Model::Dummy::Model', 'Model::Dummy::Model ok' );
32 isa_ok( MyApp->model('Test::Object'), 'MyApp::Model::Test::Object', 'Test::Object ok' );
34 is( MyApp->controller('Model::Dummy::Model'), 'MyApp::Controller::Model::Dummy::Model', 'Controller::Model::Dummy::Model ok' );
36 is( MyApp->view('V'), 'MyApp::View::V', 'View::V ok' );
38 is( MyApp->controller('C'), 'MyApp::Controller::C', 'Controller::C ok' );
40 is( MyApp->model('M'), 'MyApp::Model::M', 'Model::M ok' );
42 is_deeply( [ sort MyApp->views ],
46 is_deeply( [ sort MyApp->controllers ],
47 [ qw/C Controller Model::Dummy::Model/ ],
50 is_deeply( [ sort MyApp->models ],
51 [ qw/Dummy::Model M Model Test::Object/ ],
54 is (MyApp->view , 'MyApp::V::View', 'view() with no defaults ok');
56 is ( bless ({stash=>{current_view=>'V'}}, 'MyApp')->view , 'MyApp::View::V', 'current_view ok');
58 my $view = bless {} , 'MyApp::View::V';
59 is ( bless ({stash=>{current_view_instance=> $view }}, 'MyApp')->view , $view, 'current_view_instance ok');
61 is ( bless ({stash=>{current_view_instance=> $view, current_view=>'MyApp::V::View' }}, 'MyApp')->view , $view,
62 'current_view_instance precedes current_view ok');
64 is (MyApp->model , 'MyApp::M::Model', 'model() with no defaults ok');
66 is ( bless ({stash=>{current_model=>'M'}}, 'MyApp')->model , 'MyApp::Model::M', 'current_model ok');
68 my $model = bless {} , 'MyApp::Model::M';
69 is ( bless ({stash=>{current_model_instance=> $model }}, 'MyApp')->model , $model, 'current_model_instance ok');
71 is ( bless ({stash=>{current_model_instance=> $model, current_model=>'MyApp::M::Model' }}, 'MyApp')->model , $model,
72 'current_model_instance precedes current_model ok');
74 MyApp->config->{default_view} = 'V';
75 is ( bless ({stash=>{}}, 'MyApp')->view , 'MyApp::View::V', 'default_view ok');
76 is ( MyApp->view , 'MyApp::View::V', 'default_view in class method ok');
78 MyApp->config->{default_model} = 'M';
79 is ( bless ({stash=>{}}, 'MyApp')->model , 'MyApp::Model::M', 'default_model ok');
80 is ( MyApp->model , 'MyApp::Model::M', 'default_model in class method ok');
82 #checking @args passed to ACCEPT_CONTEXT
86 *MyApp::Model::M::ACCEPT_CONTEXT = sub { my ($self, $c, @args) = @_; $args= \@args};
87 *MyApp::View::V::ACCEPT_CONTEXT = sub { my ($self, $c, @args) = @_; $args= \@args};
89 MyApp->model('M', qw/foo bar/);
90 is_deeply($args, [qw/foo bar/], '$c->model args passed to ACCEPT_CONTEXT ok');
91 MyApp->view('V', qw/baz moo/);
92 is_deeply($args, [qw/baz moo/], '$c->view args passed to ACCEPT_CONTEXT ok');