3 use Test::More tests => 19;
7 use Support::TestSetup;
10 use SL::Controller::Base;
11 use SL::Layout::Javascript;
13 no warnings 'uninitialized';
15 Support::TestSetup::login();
18 $ENV{HTTP_USER_AGENT} = 'Perl Tests';
20 $::request = Support::TestSetup->create_new_request(
21 layout => SL::Layout::Javascript->new,
24 $::myconfig{menustyle} = 'javascript';
26 delete @{ $::form }{qw(header footer)};
29 my $ctrl = SL::Controller::Base->new;
31 # Passing invalid parameters:
32 throws_ok { $ctrl->render(\'dummy', { unknown => 1 }) } qr/unsupported option/i, 'string ref, unknown parameter';
33 throws_ok { $ctrl->render(\'dummy', { type => "excel" }) } qr/unsupported type/i, 'string ref, unsupported "type"';
34 throws_ok { $ctrl->render({}) } qr/unsupported.*template.*reference.*type/i, 'string ref, unsupported template argument reference type';
35 throws_ok { $ctrl->render('does/not/exist') } qr/template.*file.*not.*found/i, 'non-existing template file name';
38 stdout_is { $ctrl->render(\'Hallo', { output => 0 }) } '', 'no output';
40 # Type of return value:
41 is(ref($ctrl->render(\'Hallo', { output => 0 })), 'SL::Presenter::EscapedText', 'render returns SL::Presenter::EscapedText');
43 # Actual return value for string ref parameters (enforce stringification from SL::Presenter::EscapedText before comparison):
44 is("" . $ctrl->render(\'Hallo [% world %]', { output => 0 }, world => 'Welt'), 'Hallo Welt', 'render string ref, no output');
45 is("" . $ctrl->render(\'Hallo [% world %]', { output => 0, process => 0 }, world => 'Welt'), 'Hallo [% world %]', 'render string ref, no output, no processing');
46 is("" . $ctrl->render(\'Hallo [% world %]', { output => 0, type => 'js' }, world => 'Welt'), 'Hallo Welt', 'render string ref, no output, different type');
48 # Actual return value for template file name parameters (enforce stringification from SL::Presenter::EscapedText before comparison):
49 is("" . $ctrl->render('t/render', { output => 0 }, world => 'Welt'), "Hallo Welt\n", 'render template file, no args');
50 is("" . $ctrl->render('t/render', { output => 0, process => 0 }, world => 'Welt'), "[\% USE HTML \%]Hallo [\% HTML.escape(world) \%]\n", 'render template file, no processing');
51 is("" . $ctrl->render('t/render', { output => 0, type => 'js' }, thingy => 'jungle'), "Welcome to the jungle\n", 'render template file, different type');
53 # No HTTP header in screen output:
55 stdout_unlike { $ctrl->render(\'Hallo [% world %]', { header => 0 }, world => 'Welt') } qr/content-type/i, 'no HTTP header with header=0';
58 stdout_unlike { $ctrl->render(\'Hallo [% world %]', { header => 0 }, world => 'Welt') } qr/<html>/i, 'no HTML header with header=0';
60 # With HTTP header in screen output:
62 stdout_like { $ctrl->render(\'Hallo [% world %]', world => 'Welt') } qr/content-type/i, 'HTTP header with header=1';
65 stdout_like { $ctrl->render(\'Hallo [% world %]', world => 'Welt') } qr/<html>/i, 'HTML header with header=1';
69 stdout_like { $ctrl->render(\'Hallo [% world %]', world => 'Welt') } qr/<div.*id="main_menu_div".*<ul.*id="main_menu_model"/is, 'HTML header & menu with header=1';
72 stdout_unlike { $ctrl->render(\'Hallo [% world %]', { header => 0 }, world => 'Welt') } qr/<div.*id="main_menu_div".*<ul.*id="main_menu_model"/is, 'HTML header & menu with header=0';
75 stdout_unlike { $ctrl->render(\'Hallo [% world %]', { layout => 0 }, world => 'Welt') } qr/<div.*id="main_menu_div".*<ul.*id="main_menu_model"/is, 'HTML header & menu with layout=0';