| 1 | #!/usr/bin/perl -w |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | |
|---|
| 6 | use lib 'extlib'; |
|---|
| 7 | use lib 'lib'; |
|---|
| 8 | use lib 't/lib'; |
|---|
| 9 | |
|---|
| 10 | use Test::More qw(no_plan); |
|---|
| 11 | |
|---|
| 12 | use MT; |
|---|
| 13 | |
|---|
| 14 | use vars qw( $DB_DIR $T_CFG ); |
|---|
| 15 | use MT::Test qw(:db :data); |
|---|
| 16 | |
|---|
| 17 | my $mt = MT->instance( Config => $T_CFG ) or die MT->errstr; |
|---|
| 18 | isa_ok($mt, 'MT'); |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | my $blog = MT->model('blog')->load(1); |
|---|
| 22 | |
|---|
| 23 | my $include = MT->model('template')->new; |
|---|
| 24 | $include->blog_id($blog->id); |
|---|
| 25 | $include->name('Included Template'); |
|---|
| 26 | $include->type('custom'); |
|---|
| 27 | $include->text('template was included at <mt:date format="%X %x"> <mt:getvar name="woot">'); |
|---|
| 28 | $include->save; |
|---|
| 29 | |
|---|
| 30 | my $tmpl = MT->model('template')->new; |
|---|
| 31 | $tmpl->blog_id($blog->id); |
|---|
| 32 | $tmpl->text(q(hi <mt:include module="Included Template"> bye)); |
|---|
| 33 | |
|---|
| 34 | require MT::Template::Context; |
|---|
| 35 | my $ctx = MT::Template::Context->new; |
|---|
| 36 | my $out = $tmpl->build($ctx, {}); |
|---|
| 37 | |
|---|
| 38 | ok(defined $out, 'test template built'); |
|---|
| 39 | diag($tmpl->errstr) if !defined $out; |
|---|
| 40 | like($out, qr{ template \s was \s included }xms, 'test template included included template'); |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | $tmpl = MT->model('template')->new; |
|---|
| 44 | $tmpl->blog_id($blog->id); |
|---|
| 45 | $tmpl->text(q(hi <mt:include module="Included Template" key="woot" ttl="1000"> bye)); |
|---|
| 46 | |
|---|
| 47 | $ctx = MT::Template::Context->new; |
|---|
| 48 | $ctx->{__stash}{vars}{woot} = 'awesome'; |
|---|
| 49 | $out = $tmpl->build($ctx, {}); |
|---|
| 50 | |
|---|
| 51 | ok(defined $out, 'test template built'); |
|---|
| 52 | diag($tmpl->errstr) if !defined $out; |
|---|
| 53 | like($out, qr{ template \s was \s included }xms, 'test template included cached included template'); |
|---|
| 54 | like($out, qr{ awesome }xms, 'test template included variable value'); |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | my $first_text = $out; |
|---|
| 58 | |
|---|
| 59 | $tmpl = MT->model('template')->new; |
|---|
| 60 | $tmpl->blog_id($blog->id); |
|---|
| 61 | $tmpl->text(q(hi <mt:include module="Included Template" key="woot" ttl="1000"> bye)); |
|---|
| 62 | |
|---|
| 63 | $ctx = MT::Template::Context->new; |
|---|
| 64 | $ctx->{__stash}{vars}{woot} = 'terrible'; |
|---|
| 65 | $out = $tmpl->build($ctx, {}); |
|---|
| 66 | |
|---|
| 67 | ok(defined $out, 'test template built'); |
|---|
| 68 | like($out, qr{ template \s was \s included }xms, 'test template included cached included template again'); |
|---|
| 69 | like($out, qr{ awesome }xms, 'test template included old cached variable value'); |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | $blog->include_system('shtml'); |
|---|
| 73 | $blog->save; |
|---|
| 74 | |
|---|
| 75 | $tmpl = MT->model('template')->new; |
|---|
| 76 | $tmpl->blog_id($blog->id); |
|---|
| 77 | $tmpl->text(q(hi <mt:include module="Included Template" key="woot" ttl="1000" ssi="1"> bye)); |
|---|
| 78 | |
|---|
| 79 | $ctx = MT::Template::Context->new; |
|---|
| 80 | $ctx->{__stash}{vars}{woot} = 'terrible'; |
|---|
| 81 | $out = $tmpl->build($ctx, {}); |
|---|
| 82 | |
|---|
| 83 | ok(defined $out, 'test template built'); |
|---|
| 84 | my $sitepath = $blog->site_path; |
|---|
| 85 | like($out, qr(\Ahi <!--#include file="${sitepath}includes_c/woo/woot.html" --> bye\z)ms, |
|---|
| 86 | 'test template included template by ssi'); |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | $tmpl = MT->model('template')->new; |
|---|
| 90 | $tmpl->blog_id($blog->id); |
|---|
| 91 | $tmpl->text(q(hi <mt:include module="Included Template" key="w" ttl="1000" ssi="1"> bye)); |
|---|
| 92 | |
|---|
| 93 | $ctx = MT::Template::Context->new; |
|---|
| 94 | $ctx->{__stash}{vars}{woot} = 'terrible'; |
|---|
| 95 | $out = $tmpl->build($ctx, {}); |
|---|
| 96 | |
|---|
| 97 | ok(defined $out, 'test template built'); |
|---|
| 98 | $sitepath = $blog->site_path; |
|---|
| 99 | like($out, qr(\Ahi <!--#include file="${sitepath}includes_c/w/w.html" --> bye\z)ms, |
|---|
| 100 | 'test template included template by ssi'); |
|---|
| 101 | |
|---|