5b9c2d0eaa73830e6213888770f921abbdc64ef0
[catagits/Catalyst-Runtime.git] / t / inject_component_util.t
1 use strict;
2 use warnings; 
3 use Test::More;
4 use Catalyst::Utils;
5 use FindBin;
6 use lib "$FindBin::Bin/lib";
7
8 BEGIN {
9 package RoleTest1;
10
11 use Moose::Role;
12
13 sub aaa { 'aaa' }
14
15 package RoleTest2;
16
17 use Moose::Role;
18
19 sub bbb { 'bbb' }
20
21 package Model::Banana;
22  
23 use base qw/Catalyst::Model/;
24
25 package Model::BananaMoose;
26  
27 use Moose;
28 extends 'Catalyst::Model';
29
30 Model::BananaMoose->meta->make_immutable;
31
32 package TestCatalyst; $INC{'TestCatalyst.pm'} = 1;
33  
34 use Catalyst::Runtime '5.70';
35  
36 use Moose;
37 BEGIN { extends qw/Catalyst/ }
38  
39 use Catalyst;
40  
41 after 'setup_components' => sub {
42     my $self = shift;
43     Catalyst::Utils::inject_component( into => __PACKAGE__, component => 'Model::Banana' );
44     Catalyst::Utils::inject_component( into => __PACKAGE__, component => 'Test::Apple' );
45     Catalyst::Utils::inject_component( into => __PACKAGE__, component => 'Model::Banana', as => 'Cherry' );
46     Catalyst::Utils::inject_component( into => __PACKAGE__, component => 'Model::BananaMoose', as => 'CherryMoose', traits => ['RoleTest1', 'RoleTest2'] );
47     Catalyst::Utils::inject_component( into => __PACKAGE__, component => 'Test::Apple', as => 'Apple' );
48     Catalyst::Utils::inject_component( into => __PACKAGE__, component => 'Test::Apple', as => 'Apple2', traits => ['RoleTest1', 'RoleTest2'] );
49 };
50  
51 TestCatalyst->config( 'home' => '.' );
52  
53 TestCatalyst->setup;
54  
55 }
56  
57 package main;
58  
59 use Catalyst::Test qw/TestCatalyst/;
60  
61 ok( TestCatalyst->controller( $_ ) ) for qw/ Apple Test::Apple /;
62 ok( TestCatalyst->model( $_ ) ) for qw/ Banana Cherry /;
63 is( TestCatalyst->controller('Apple2')->aaa, 'aaa');
64 is( TestCatalyst->controller('Apple2')->bbb, 'bbb');
65 is( TestCatalyst->model('CherryMoose')->aaa, 'aaa');
66 is( TestCatalyst->model('CherryMoose')->bbb, 'bbb');
67
68 done_testing;