Patch from zamolxes: MyApp->model/view now looks at MyApp->config->{default_view...
[catagits/Catalyst-Runtime.git] / t / unit_core_mvc.t
CommitLineData
72f87c4b 1use Test::More tests => 27;
af3ff00e 2use strict;
3use warnings;
4
5use_ok('Catalyst');
6
7my @complist =
8 map { "MyApp::$_"; }
8dc75d26 9 qw/C::Controller M::Model V::View Controller::C Model::M View::V Controller::Model::Dummy::Model Model::Dummy::Model/;
af3ff00e 10
8dc75d26 11my $thingie={};
12bless $thingie,'MyApp::Model::Test::Object';
13push @complist,$thingie;
af3ff00e 14{
15
16 package MyApp;
17
18 use base qw/Catalyst/;
19
3b88a455 20 __PACKAGE__->components( { map { ( ref($_)||$_ , $_ ) } @complist } );
af3ff00e 21}
22
23is( MyApp->view('View'), 'MyApp::V::View', 'V::View ok' );
24
25is( MyApp->controller('Controller'),
26 'MyApp::C::Controller', 'C::Controller ok' );
27
28is( MyApp->model('Model'), 'MyApp::M::Model', 'M::Model ok' );
29
8dc75d26 30is( MyApp->model('Dummy::Model'), 'MyApp::Model::Dummy::Model', 'Model::Dummy::Model ok' );
31
32isa_ok( MyApp->model('Test::Object'), 'MyApp::Model::Test::Object', 'Test::Object ok' );
33
34is( MyApp->controller('Model::Dummy::Model'), 'MyApp::Controller::Model::Dummy::Model', 'Controller::Model::Dummy::Model ok' );
35
af3ff00e 36is( MyApp->view('V'), 'MyApp::View::V', 'View::V ok' );
37
38is( MyApp->controller('C'), 'MyApp::Controller::C', 'Controller::C ok' );
39
40is( MyApp->model('M'), 'MyApp::Model::M', 'Model::M ok' );
3b88a455 41
42is_deeply( [ sort MyApp->views ],
43 [ qw/V View/ ],
44 'views ok' );
45
46is_deeply( [ sort MyApp->controllers ],
47 [ qw/C Controller Model::Dummy::Model/ ],
48 'controllers ok');
49
50is_deeply( [ sort MyApp->models ],
51 [ qw/Dummy::Model M Model Test::Object/ ],
52 'models ok');
a3b71f0f 53
54is (MyApp->view , 'MyApp::V::View', 'view() with no defaults ok');
55
56is ( bless ({stash=>{current_view=>'V'}}, 'MyApp')->view , 'MyApp::View::V', 'current_view ok');
57
58my $view = bless {} , 'MyApp::View::V';
59is ( bless ({stash=>{current_view_instance=> $view }}, 'MyApp')->view , $view, 'current_view_instance ok');
60
61is ( bless ({stash=>{current_view_instance=> $view, current_view=>'MyApp::V::View' }}, 'MyApp')->view , $view,
62 'current_view_instance precedes current_view ok');
63
64is (MyApp->model , 'MyApp::M::Model', 'model() with no defaults ok');
65
66is ( bless ({stash=>{current_model=>'M'}}, 'MyApp')->model , 'MyApp::Model::M', 'current_model ok');
67
68my $model = bless {} , 'MyApp::Model::M';
69is ( bless ({stash=>{current_model_instance=> $model }}, 'MyApp')->model , $model, 'current_model_instance ok');
70
71is ( bless ({stash=>{current_model_instance=> $model, current_model=>'MyApp::M::Model' }}, 'MyApp')->model , $model,
72 'current_model_instance precedes current_model ok');
73
74MyApp->config->{default_view} = 'V';
75is ( bless ({stash=>{}}, 'MyApp')->view , 'MyApp::View::V', 'default_view ok');
72f87c4b 76is ( MyApp->view , 'MyApp::View::V', 'default_view in class method ok');
a3b71f0f 77
78MyApp->config->{default_model} = 'M';
79is ( bless ({stash=>{}}, 'MyApp')->model , 'MyApp::Model::M', 'default_model ok');
72f87c4b 80is ( MyApp->model , 'MyApp::Model::M', 'default_model in class method ok');
81
82#checking @args passed to ACCEPT_CONTEXT
83my $args;
84{
85 no warnings;
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};
88}
89MyApp->model('M', qw/foo bar/);
90is_deeply($args, [qw/foo bar/], '$c->model args passed to ACCEPT_CONTEXT ok');
91MyApp->view('V', qw/baz moo/);
92is_deeply($args, [qw/baz moo/], '$c->view args passed to ACCEPT_CONTEXT ok');