Mojolicious

 view release on metacpan or  search on metacpan

t/mojolicious/layouted_lite_app.t  view on Meta::CPAN

};

subtest 'Layout in render call' => sub {
  $t->get_ok('/outerlayout')
    ->status_is(200)
    ->header_is(Server => 'Mojolicious (Perl)')
    ->content_is("layouted <Hello>\n[\n  1,\n  2\n]\nthere<br>!\n\n\n");
};

subtest 'Extends in render call' => sub {
  $t->get_ok('/outerextends')
    ->status_is(200)
    ->header_is(Server => 'Mojolicious (Perl)')
    ->content_is("layouted <Hello>\n[\n  1,\n  2\n]\nthere<br>!\n\n\n");
};

subtest 'Layout in route' => sub {
  $t->get_ok('/outerlayouttwo')
    ->status_is(200)
    ->header_is(Server => 'Mojolicious (Perl)')
    ->content_is("layouted <Hello>\n[\n  1,\n  2\n]\nthere<br>!\n\n\n");
};

subtest 'Included template with layout' => sub {
  $t->get_ok('/outerinnerlayout')
    ->status_is(200)
    ->header_is(Server => 'Mojolicious (Perl)')
    ->content_is("layouted Hello\nlayouted [\n  1,\n  2\n]\nthere<br>!\n\n\n\n");
};

subtest 'Layout with block' => sub {
  $t->get_ok('/withblocklayout')
    ->status_is(200)
    ->header_is(Server => 'Mojolicious (Perl)')
    ->content_is("\nwith_block \n\nOne: one\nTwo: two\n\n");
};

subtest 'Content blocks' => sub {
  $t->get_ok('/content_for')
    ->status_is(200)
    ->header_is(Server => 'Mojolicious (Perl)')
    ->content_is("Content!This\n\nseems\nto\nHello    World!\n\nwork!\n\nShared content!\n\n");
  $t->get_ok('/content_with')
    ->status_is(200)
    ->header_is(Server => 'Mojolicious (Perl)')
    ->content_is("Default\n\nSomething <b>else</b>!\n\n\n<br>Hello World!\n\n");
};

subtest 'Inline template' => sub {
  $t->get_ok('/inline')->status_is(200)->header_is(Server => 'Mojolicious (Perl)')->content_is("inline!\n");
};

subtest '"0" inline template' => sub {
  $t->get_ok('/inline/again')->status_is(200)->header_is(Server => 'Mojolicious (Perl)')->content_is("0\n");
};

subtest '"0" data' => sub {
  $t->get_ok('/data')->status_is(200)->header_is(Server => 'Mojolicious (Perl)')->content_is(0);
};

subtest 'Variants (desktop)' => sub {
  $t->get_ok('/variants.txt')
    ->status_is(200)
    ->content_type_is('text/plain;charset=UTF-8')
    ->content_is('Variant: Desktop!');
};

subtest 'Variants (tablet)' => sub {
  $t->get_ok('/variants.txt?device=tablet')
    ->status_is(200)
    ->content_type_is('text/plain;charset=UTF-8')
    ->content_is('Variant: Tablet!');
};

subtest 'Variants (desktop fallback)' => sub {
  $t->get_ok('/variants.txt?device=phone')
    ->status_is(200)
    ->content_type_is('text/plain;charset=UTF-8')
    ->content_is('Variant: Desktop!');
};

subtest 'Variants ("0")' => sub {
  $t->get_ok('/variants.txt?device=0')
    ->status_is(200)
    ->content_type_is('text/plain;charset=UTF-8')
    ->content_is('Another variant: Desktop!');
};

done_testing();

__DATA__
@@ layouts/default.html.ep
Default<%= title %><%= content %>

@@ layouts/green.html.ep
Green<%= title %><%= content %>

@@ layouts/mixed.txt.ep
Mixed <%= content %>

@@ blue.html.ep
% layout undef;
Blue<%= title %><%= content %>

@@ works.html.ep
% title 'Just works';
% layout 'green' if param 'green';
% extends 'blue' if param 'blue';
This <template> just works!

@@ mixed.html.ep
% layout 'mixed', format => 'txt';
formats

@@ exception.html.ep
% title 'Exception happened';
% layout 'green' if param 'green';
% extends 'blue' if param 'blue';
Exception happened!

@@ not_found.html.ep
% title 'Not found happened';
% layout 'green' if param 'green';
% extends 'blue' if param 'blue';
Not found happened!

@@ first.html.ep
%= content header => begin
  Default header
% end
Stuff
%= content footer => begin
  Default footer
% end



( run in 0.641 second using v1.01-cache-2.11-cpan-af0e5977854 )