diff --git a/t/Asset/Template/packed.t b/t/Asset/Template/packed.t new file mode 100644 index 000000000..851937302 --- /dev/null +++ b/t/Asset/Template/packed.t @@ -0,0 +1,74 @@ +# vim:syntax=perl +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2009 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------ +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------ + +# Make sure the packed version of the default WebGUI templates works +# as it's supposed to +# +# + +use FindBin; +use strict; +use lib "$FindBin::Bin/../../lib"; +use Test::More; +use WebGUI::Test; # Must use this before any other WebGUI modules +use WebGUI::Session; +use HTML::Packer; +use CSS::Packer; +use JavaScript::Packer; +use WebGUI::Asset::Template; + +#---------------------------------------------------------------------------- +# Init +my $session = WebGUI::Test->session; +my $templates = WebGUI::Asset->getRoot( $session ) + ->getLineage( ['descendants'], { + includeOnlyClasses => [ 'WebGUI::Asset::Template' ], + } ); + +#---------------------------------------------------------------------------- +# Tests + +plan tests => @$templates * 4; # Increment this number for each test you create + +#---------------------------------------------------------------------------- +# Test every template to make sure packed doesn't cause ERROR +for my $templateId ( @$templates ) { + my $template = WebGUI::Asset::Template->new( $session, $templateId ); + + # Add a new revision to prevent changing anything + $template = $template->addRevision; + + # Make sure packed version is created + $template->update({ template => $template->get('template') . "
HOPE IS THE BEST OF THINGS
" }); + ok( $template->get('templatePacked'), "Packed template $templateId contains something" ); + like( $template->get('templatePacked'), qr{HOPE IS THE BEST OF THINGS
$}, "Packed template $templateId actually packed" ); + + # Make sure packed version is used + $template->update({ usePacked => 1 }); + + # Does it even work? + my $content = $template->process; + ok( $content, "Packed template $templateId gives back SOMETHING" ) + or diag( "URL: " . $template->getUrl . "\nPACKED: " . $template->get('templatePacked') ); + unlike( $content, qr/^ERROR/, "Packed template $templateId does not throw error" ) + or diag( "URL: " . $template->getUrl ); + + # Cleanup + $template->purgeRevision; +} + + +#---------------------------------------------------------------------------- +# Cleanup +END { + WebGUI::VersionTag->getWorking( $session )->rollback; +} +#vim:ft=perl