relative-mixing.t 2.51 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
use warnings;
use strict;

##############################################################################
package SearchPlugin::View;

use base qw/Template::Declare/;
use Template::Declare::Tags;

template 'search' => sub {
    h1 {'SearchPlugin::View::search'};
};

##############################################################################
package ListPlugin::View;

use base qw/Template::Declare/;
use Template::Declare::Tags;

template 'listing' => sub {
    h1 {'ListPlugin::View::listing'};
};

mix SearchPlugin::View under '/';

##############################################################################
package MyApp::View;

use base qw/Template::Declare/;
use Template::Declare::Tags;

template 'toplevel' => sub {h1{'Toplevel'}};

mix ListPlugin::View under 'plugin/';

##############################################################################
package main;
Template::Declare->init( dispatch_to => ['MyApp::View'] );

use Test::More tests => 14;
use Test::Warn;
require "t/utils.pl";

ok( MyApp::View->has_template('toplevel'), 'Should have toplevel template' );
ok( !MyApp::View->has_template('listing'), "the listing template isn't imported to the top level");
ok( !MyApp::View->has_template('search'), "The search template isn't imported to the top level" );
ok( MyApp::View->has_template('/plugin/listing'), 'has listing template' );
ok( MyApp::View->has_template('/plugin/search'), 'has search template' );

{
    my $simple = ( Template::Declare->show('toplevel'));
    like( $simple, qr'Toplevel', 'Can execute toplevel template' );
}
{
    warning_like {
        my $simple = ( Template::Declare->show('listing') ||'');
        unlike( $simple, qr'listing',
            'Cannot call a toplevel "listing" template' );
        }
        qr/The template 'listing' could not be found/,
        "listing is private"

}
warning_like {
    my $simple = ( Template::Declare->show('search')||'');
    unlike( $simple, qr'search', "Cannot call a toplevel /search" );
} qr/The template 'search' could not be found/, "Search could not be found";

{

    my $simple = ( Template::Declare->show('/plugin/listing'));
    like( $simple, qr'listing', "Can call /plugin/listing" );
    $simple = ( Template::Declare->show('plugin/listing'));
    like( $simple, qr'listing', "Can call plugin/listing" );
}
{
    my $simple = ( Template::Declare->show('/plugin/search'));
    like( $simple, qr'search' , "Can call /plugin/search");
    $simple = ( Template::Declare->show('plugin/search'));
    like( $simple, qr'search' , "Can call plugin/search");
}

1;