Added 5 more tests for Style's process method, checking for meta tags

for default processing and for meta tags when cache busting is enabled.

Fixed a bug where the default meta tag Generator did not contain the
WebGUI version.

Added lots of POD to the Style module detailing how meta tags are
handled in various cases.
This commit is contained in:
Colin Kuskie 2006-10-11 04:15:21 +00:00
parent 4f0d117c9f
commit a86c34df84
2 changed files with 99 additions and 5 deletions

View file

@ -17,8 +17,9 @@ use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Asset;
use WebGUI::VersionTag;
use WebGUI;
use Test::More tests => 39; # increment this value for each test you create
use Test::More tests => 44; # increment this value for each test you create
use Test::Deep;
my $session = WebGUI::Test->session;
@ -177,6 +178,65 @@ like($styled,
qr/PERSONAL STYLE TEMPLATE/,
'process: personalStyleTemplate overrides submitted template');
my $head = $styled;
$head =~ s/(^HEAD=.+$)/$1/s;
my @metas = fetchMultipleMetas($head);
my $expectedMetas = [
{
'content' => 'WebGUI '.$WebGUI::VERSION,
'name' => 'generator'
},
{
'http-equiv' => 'Content-Type',
'content' => 'text/html; charset=UTF-8'
},
{
'http-equiv' => 'Content-Script-Type',
'content' => 'text/javascript'
},
{
'http-equiv' => 'Content-Style-Type',
'content' => 'text/css'
}
];
cmp_bag(\@metas, $expectedMetas, 'process:default meta tags');
is($session->http->{_http}{cacheControl}, undef, 'process: HTTP cacheControl undefined');
$session->user({userId=>3});
$styled = $style->process('body.content');
$head = $styled;
$head =~ s/(^HEAD=.+$)/$1/s;
@metas = fetchMultipleMetas($head);
push @{ $expectedMetas }, (
{
'http-equiv' => 'Pragma',
'content' => 'no-cache',
},
{
'http-equiv' => 'Cache-Control',
'content' => 'no-cache, must-revalidate, max-age=0, private',
},
{
'http-equiv' => 'Expires',
'content' => '0',
},
);
cmp_bag(\@metas, $expectedMetas, 'process:default meta tags with no caching head tags, group 2 user');
$session->user({userId=>1});
my $origPreventProxyCache = $session->setting->get('preventProxyCache');
$session->setting->set('preventProxyCache', 1);
$styled = $style->process('body.content');
$head = $styled;
$head =~ s/(^HEAD=.+$)/$1/s;
@metas = fetchMultipleMetas($head);
cmp_bag(\@metas, $expectedMetas, 'process:default meta tags with no caching head tags, preventProxyCache setting');
$session->setting->set('preventProxyCache', $origPreventProxyCache);
##No accessor
is($session->http->{_http}{cacheControl}, 'none', 'process: HTTP cacheControl set to none to prevent proxying');
sub simpleLinkParser {
my ($tokenName, $text) = @_;
my $p = HTML::TokeParser->new(\$text);
@ -197,6 +257,20 @@ sub simpleLinkParser {
return ($url, $params);
}
sub fetchMultipleMetas {
my ($text) = @_;
my $p = HTML::TokeParser->new(\$text);
my @metas = ();
while (my $token = $p->get_tag('meta')) {
my $params = $token->[1];
delete $params->{'/'}; ##delete unary slash from XHTML output
push @metas, $params;
}
return @metas;
}
sub setup_assets {
my $session = shift;
my $importNode = WebGUI::Asset->getImportNode($session);
@ -217,6 +291,7 @@ sub setup_assets {
}
END {
$session->setting->set('preventProxyCache', $origPreventProxyCache);
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') {
$versionTag->rollback;
}