From e3c77d4e80eab6cb8c770eb3ebdbcff11131fab2 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 12 Jan 2009 22:23:41 +0000 Subject: [PATCH] Add a test for evaluating templates and macros in the right order in the Snippet. Fix a bug with that. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Snippet.pm | 15 ++++++++------- t/Asset/Snippet.t | 20 +++++++++++++++++++- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index ca805abff..b42f3552b 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,5 +1,6 @@ 7.6.9 - marked sbin scripts as executable + - Problem #9492: in passing form variables to Macro SQL inside a snippet 7.6.8 - added #!/usr/bin/env perl to all utility scripts diff --git a/lib/WebGUI/Asset/Snippet.pm b/lib/WebGUI/Asset/Snippet.pm index d7e3fd8c9..c028463b2 100644 --- a/lib/WebGUI/Asset/Snippet.pm +++ b/lib/WebGUI/Asset/Snippet.pm @@ -194,23 +194,24 @@ sub purgeCache { sub view { my $self = shift; my $calledAsWebMethod = shift; - my $versionTag = WebGUI::VersionTag->getWorking($self->session, 1); + my $session = $self->session; + my $versionTag = WebGUI::VersionTag->getWorking($session, 1); my $noCache = - $self->session->var->isAdminOn + $session->var->isAdminOn || $self->get("cacheTimeout") <= 10 || ($versionTag && $versionTag->getId eq $self->get("tagId")); unless ($noCache) { - my $out = WebGUI::Cache->new($self->session,"view_".$calledAsWebMethod."_".$self->getId)->get; + my $out = WebGUI::Cache->new($session,"view_".$calledAsWebMethod."_".$self->getId)->get; return $out if $out; } my $output = $self->get("snippet"); - WebGUI::Macro::process($self->session,\$output); - $output = $self->getToolbar.$output if ($self->session->var->isAdminOn && !$calledAsWebMethod); + $output = $self->getToolbar.$output if ($session->var->isAdminOn && !$calledAsWebMethod); if ($self->getValue("processAsTemplate")) { - $output = WebGUI::Asset::Template->processRaw($self->session, $output, $self->get); + $output = WebGUI::Asset::Template->processRaw($session, $output, $self->get); } + WebGUI::Macro::process($session,\$output); unless ($noCache) { - WebGUI::Cache->new($self->session,"view_".$calledAsWebMethod."_".$self->getId)->set($output,$self->get("cacheTimeout")); + WebGUI::Cache->new($session,"view_".$calledAsWebMethod."_".$self->getId)->set($output,$self->get("cacheTimeout")); } return $output; } diff --git a/t/Asset/Snippet.t b/t/Asset/Snippet.t index e465ff9b5..67de84ee7 100644 --- a/t/Asset/Snippet.t +++ b/t/Asset/Snippet.t @@ -16,7 +16,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; -use Test::More tests => 14; # increment this value for each test you create +use Test::More tests => 15; # increment this value for each test you create use WebGUI::Asset::Snippet; my $session = WebGUI::Test->session; @@ -70,6 +70,24 @@ isnt ($wwwViewOutput, undef, 'www_view returns something'); my $editOutput = $snippet->www_edit; isnt ($editOutput, undef, 'www_edit returns something'); +$snippet->update({ + title => "authMethod", + processAsTemplate => 1, + cacheTimeout => 1, + snippet => q|^SQL(select value from settings where name="");| +}); + +my $sqlMacroAdded = exists $session->config->get('macros')->{'SQL'}; +if (! $sqlMacroAdded) { + $session->config->addToHash('macros', 'SQL', 'SQL'); +} + +is($snippet->view(), 'WebGUI', 'Interpolating macros in works with template in the correct order'); + +if (! $sqlMacroAdded) { + $session->config->deleteFromHash('macros', 'SQL'); +} + TODO: { local $TODO = "Tests to make later"; ok(0, 'Test indexContent method');