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:
parent
4f0d117c9f
commit
a86c34df84
2 changed files with 99 additions and 5 deletions
|
|
@ -20,6 +20,7 @@ use Tie::CPHash;
|
|||
use WebGUI::International;
|
||||
use WebGUI::Macro;
|
||||
use WebGUI::Asset::Template;
|
||||
use WebGUI;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -71,6 +72,7 @@ sub DESTROY {
|
|||
=head2 generateAdditionalHeadTags ( )
|
||||
|
||||
Creates tags that were set using setLink, setMeta, setScript, extraHeadTags, and setRawHeadTags.
|
||||
Macros are processed in the tags if processed by this method.
|
||||
|
||||
=cut
|
||||
|
||||
|
|
@ -240,7 +242,12 @@ sub sent {
|
|||
|
||||
=head2 setLink ( url, params )
|
||||
|
||||
Sets a <link> tag into the <head> of this rendered page for this page view. This is typically used for dynamically adding references to CSS and RSS documents.
|
||||
Sets a <link> tag into the <head> of this rendered page for this page
|
||||
view. This is typically used for dynamically adding references to CSS
|
||||
and RSS documents. Tags are normally cached until the $style->sent
|
||||
flag is set to be true. If this method is called after that sent is
|
||||
true, then the tag will be sent immediately, but will not be processed
|
||||
for macros.
|
||||
|
||||
=head3 url
|
||||
|
||||
|
|
@ -291,7 +298,10 @@ sub setPrintableStyleId {
|
|||
|
||||
=head2 setMeta ( params )
|
||||
|
||||
Sets a <meta> tag into the <head> of this rendered page for this page view.
|
||||
Sets a <meta> tag into the <head> of this rendered page for this
|
||||
page view. Tags are normally cached until the $style->sent flag is
|
||||
set to be true. If this method is called after that sent is true,
|
||||
then the tag will be sent immediately, but will not be processed
|
||||
|
||||
=head3 params
|
||||
|
||||
|
|
@ -316,7 +326,11 @@ sub setMeta {
|
|||
|
||||
=head2 setRawHeadTags ( tags )
|
||||
|
||||
Sets data to be output into the <head> of the current rendered page for this page view.
|
||||
Sets data to be output into the <head> of the current rendered page
|
||||
for this page view. Tags are normally cached until the $style->sent
|
||||
flag is set to be true. If this method is called after that sent is
|
||||
true, then the tag will be sent immediately, but will not be processed
|
||||
for macros.
|
||||
|
||||
=head3 tags
|
||||
|
||||
|
|
@ -336,7 +350,12 @@ sub setRawHeadTags {
|
|||
|
||||
=head2 setScript ( url, params )
|
||||
|
||||
Sets a <script> tag into the <head> of this rendered page for this page view. This is typically used for dynamically adding references to Javascript or ECMA script.
|
||||
Sets a <script> tag into the <head> of this rendered page for this
|
||||
page view. This is typically used for dynamically adding references
|
||||
to Javascript or ECMA script. Tags are normally cached until the
|
||||
$style->sent flag is set to be true. If this method is called after
|
||||
that sent is true, then the tag will be sent immediately, but will
|
||||
not be processed for macros.
|
||||
|
||||
=head3 url
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue