Merge pull request #19 from zylopfa/master

RFE: 9668 template variable "extensions" added,  for various assets containing fileloops in their templates
This commit is contained in:
Scott Walters 2011-07-22 17:32:43 -07:00
commit da6cf052da
9 changed files with 72 additions and 3 deletions

View file

@ -1,4 +1,6 @@
7.10.21
- added #9668 extension template variable to attachment loops for the following assets:
Article,Post,Event,File,Form::Attachments,Folder
- added the optional WebGUI::Content::PDFGenerator, not enabled by default
(see the module's documentation).
@ -4229,3 +4231,4 @@
- Made the Include macro more secure.
- Added Len's patch to fix some caching problems.

View file

@ -1249,6 +1249,7 @@ sub getTemplateVars {
url => $storage->getUrl($filename),
icon => $storage->getFileIconUrl($filename),
filename => $filename,
extension => WebGUI::Storage->getFileExtension($filename),
thumbnail => $storage->getThumbnailUrl($filename),
isImage => $storage->isImage($filename),
};

View file

@ -677,6 +677,8 @@ sub view {
$var{fileUrl} = $self->getFileUrl;
$var{fileIcon} = $self->getFileIconUrl;
$var{fileSize} = formatBytes($self->get("assetSize"));
$var{extension} = WebGUI::Storage->getFileExtension( $self->get("filename"));
my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate});
if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) {
WebGUI::Cache->new($self->session,"view_".$self->getId)->set($out,$self->get("cacheTimeout"));

View file

@ -813,6 +813,7 @@ sub getTemplateVars {
url => $fileUrl,
icon => $storage->getFileIconUrl($filename),
filename => $filename,
extension => WebGUI::Storage->getFileExtension($filename),
thumbnail => $isImage ? $storage->getThumbnailUrl($filename) : '',
isImage => $isImage,
});

View file

@ -369,6 +369,7 @@ sub view {
}
push(@{$var{attachment_loop}}, {
filename => $file,
extension => WebGUI::Storage->getFileExtension($file),
isImage => $storage->isImage($file),
url=> $storage->getUrl($file),
thumbnailUrl => $storage->getThumbnailUrl($file),

View file

@ -313,6 +313,7 @@ sub view {
"icon.small" => $child->getIcon(1),
"icon.big" => $child->getIcon,
type => $child->getName,
extension => WebGUI::Storage->getFileExtension( $child->get("filename")),
url => $child->getUrl,
canEdit => $child->canEdit,
controls => $child->getToolbar,

View file

@ -302,6 +302,7 @@ sub www_upload {
title => $filename,
url => "attachments/".$filename,
filename => $filename,
extension => WebGUI::Storage->getFileExtension($filename),
ownerUserId => $owner,
groupIdEdit => "3",
groupIdView => "7",

View file

@ -19,7 +19,7 @@ use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use Test::More tests => 20; # increment this value for each test you create
use Test::More tests => 23; # increment this value for each test you create
use Test::Deep;
use WebGUI::Asset::Wobject::Collaboration;
use WebGUI::Asset::Post;
@ -175,6 +175,13 @@ $storage->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath('lamp.jpg'))
$storage->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath('littleTextFile'));
my $attachment_loop = $post1->getTemplateVars()->{attachment_loop};
ok ( $attachment_loop->[0]->{'extension'} eq 'jpg','Yup, extension template variable in attachment loop working for jpg');
ok ( $attachment_loop->[1]->{'extension'} eq 'jpg','Yup, extension template variable in attachment loop working for jpg');
ok ( $attachment_loop->[2]->{'extension'} eq '','Yup, extension template variable in attachment loop working for file with no extension');
cmp_bag(
$attachment_loop,
[
@ -183,6 +190,7 @@ cmp_bag(
url => $storage->getUrl('gooey.jpg'),
icon => $session->url->extras('fileIcons/jpg.gif'),
thumbnail => $storage->getThumbnailUrl('gooey.jpg'),
extension => 'jpg',
isImage => bool(1),
},
{
@ -190,6 +198,7 @@ cmp_bag(
url => $storage->getUrl('lamp.jpg'),
icon => $session->url->extras('fileIcons/jpg.gif'),
thumbnail => $storage->getThumbnailUrl('lamp.jpg'),
extension => 'jpg',
isImage => bool(1),
},
{
@ -197,6 +206,7 @@ cmp_bag(
url => $storage->getUrl('littleTextFile'),
icon => $session->url->extras('fileIcons/unknown.gif'),
thumbnail => '',
extension => '',
isImage => bool(0),
},
],

View file

@ -17,7 +17,7 @@ use lib "$FindBin::Bin/../../lib";
use WebGUI::Test;
use WebGUI::Session;
use Test::More tests => 23; # increment this value for each test you create
use Test::More tests => 28; # increment this value for each test you create
use WebGUI::Asset::Wobject::Article;
my $session = WebGUI::Test->session;
@ -66,9 +66,10 @@ foreach my $newSetting (keys %{$newArticleSettings}) {
}
# Test the duplicate method... not for assets, just the extended duplicate functionality of the article wobject
my $filename = "page_title.jpg";
my $filename = "extensions.tar";
my $pathedFile = WebGUI::Test->getTestCollateralPath($filename);
# Use some test collateral to create a storage location and assign it to our article
my $storage = WebGUI::Storage->create($session);
WebGUI::Test->addToCleanup($storage);
@ -80,6 +81,10 @@ diag(join("\n", @{ $storage->getErrors })) unless $filenameOK;
$article->update({storageId=>$storage->getId});
my $storageOK = is($article->get('storageId'), $storage->getId, 'correct storage id stored');
SKIP: {
skip 'storage test setup problem', 3 unless $filenameOK and $storageOK;
@ -122,6 +127,46 @@ $cachedOutput = WebGUI::Cache->new($session, 'view_'.$article->getId)->get; # C
isnt ($output, $cachedOutput, 'purgeCache method deletes cache');
# lets test that our new template variable for the fileloop in the main view method returns the
# right values for the new field in the attached files loop: <tmpl_var extension>
# first we create a new template with only the <tmpl_var extension> field in it
# --------------------------------------------------------------------------------------------------
my $viewTemplate = $node->addChild({className=>'WebGUI::Asset::Template'});
my $tmplContent = "<tmpl_if attachment_loop><tmpl_loop attachment_loop><tmpl_var extension>|</tmpl_loop></tmpl_if>";
my $newTemplateSettings = {
namespace => 'Article',
template => $tmplContent,
};
my @extTestFiles = ("rotation_test.png","littleTextFile","jquery.js","tooWide.gif");
foreach my $f (@extTestFiles) {
my $pathedFile = WebGUI::Test->getTestCollateralPath($f);
my $storedFilename = $storage->addFileFromFilesystem($pathedFile);
}
$viewTemplate->update($newTemplateSettings);
$article->update({templateId=>$viewTemplate->getId});
$article->prepareView;
my $newFieldoutput = $article->view;
$newFieldoutput =~ s/\|$//;
my @tmplExtensions = split /\|/,$newFieldoutput;
# rememer there is a tar file already stored from earlier test, we reuse this.
ok ( $tmplExtensions[0] eq "tar", 'Yup, extension template variable in fileLoop working for tar');
ok ( $tmplExtensions[1] eq "png", 'Yup, extension template variable in fileLoop working for png');
ok ( $tmplExtensions[2] eq "", 'Yup, extension template variable in fileLoop working for file with no extension');
ok ( $tmplExtensions[3] eq "js", 'Yup, extension template variable in fileLoop working for js');
ok ( $tmplExtensions[4] eq "gif", 'Yup, extension template variable in fileLoop working for gif');
TODO: {
local $TODO = "Tests to make later";
ok(0, 'Test exportAssetData method');
@ -131,3 +176,7 @@ TODO: {
ok(0, 'Test www_deleteFile method');
ok(0, 'Test www_view method... maybe?');
}