Template Preview button

This commit is contained in:
Paul Driver 2011-01-05 12:34:55 -06:00
parent ad8f1231fc
commit 41ac1f153e
5 changed files with 283 additions and 56 deletions

View file

@ -16,7 +16,7 @@ use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Asset::Template;
use Exception::Class;
use Test::More tests => 57; # increment this value for each test you create
use Test::More tests => 58; # increment this value for each test you create
use Test::Deep;
use Data::Dumper;
use Test::Exception;
@ -51,7 +51,10 @@ ok($output =~ m/true/, "process() - conditionals");
ok($output =~ m/\b(?:XY){5}\b/, "process() - loops");
# See if template listens the Accept header
$session->request->headers_in->{Accept} = 'application/json';
my $request = $session->request;
my $in = $request->headers_in;
my $out = $request->headers_out;
$in->{Accept} = 'application/json';
my $json = $template->process(\%var);
my $andNowItsAPerlHashRef = eval { from_json( $json ) };
@ -61,6 +64,29 @@ cmp_deeply( \%var, $andNowItsAPerlHashRef, 'Accept = json, The correct JSON is r
# Done, so remove the json Accept header.
delete $session->request->headers_in->{Accept};
# Testing the stuff-your-variables-into-the-body-with-delimiters header
my $oldUser = $session->user;
# log in as admin so we pass canEdit
$session->user({ userId => 3 });
my $hname = 'X-Webgui-Template-Variables';
$in->{$hname} = $template->getId;
# processRaw sets some session variables (including username), so we need to
# re-do it.
WebGUI::Asset::Template->processRaw($session,$tmplText,\%var);
my $output = $template->process(\%var);
delete $in->{$hname};
my $start = delete $out->{"$hname-Start"};
my $end = delete $out->{"$hname-End"};
my ($json) = $output =~ /\Q$start\E(.*)\Q$end\E/;
$andNowItsAPerlHashRef = eval { from_json( $json ) };
cmp_deeply( $andNowItsAPerlHashRef, \%var, "$hname: json returned correctly" )
or diag "output: $output";
$session->user({ user => $oldUser });
# done testing the header stuff
my $newList = WebGUI::Asset::Template->getList($session, 'WebGUI Test Template');
ok(exists $newList->{$template->getId}, 'Uncommitted template exists returned from getList');