more tests, started Photo development, changed some naming

This commit is contained in:
Doug Bell 2007-10-25 06:20:20 +00:00
parent 320c2c07b0
commit 32b27d0954
14 changed files with 1261 additions and 150 deletions

View file

@ -297,10 +297,14 @@ sub prepareView {
sub processPropertiesFromFormPost {
my $self = shift;
my $session = $self->session;
$self->SUPER::processPropertiesFromFormPost;
my $errors = $self->SUPER::processPropertiesFromFormPost;
return $errors if $errors;
#Get the storage location out of memory. If you call getStorageLocation you risk creating another one.
# How can this EVER be true?
my $storageLocation = $self->{_storageLocation};
$session->errorHandler->error("Storage Location set magically") if defined $storageLocation;
my $storageId = undef;
$storageId = $storageLocation->getId if(defined $storageLocation);

View file

@ -16,6 +16,7 @@ package WebGUI::Asset::File::Image::Photo;
use strict;
use Tie::IxHash;
use Carp qw( croak );
use base 'WebGUI::Asset::File::Image';
use WebGUI::Utility;
@ -42,8 +43,7 @@ These methods are available from this class:
=head2 definition ( session, definition )
defines asset properties for New Asset instances. You absolutely need
this method in your new Assets.
Define the properties of the Photo asset.
=head3 session
@ -54,28 +54,251 @@ A hash reference passed in from a subclass definition.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = $class->i18n($session);
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = __PACKAGE__->i18n($session);
tie my %properties, 'Tie::IxHash', (
tie my %properties, 'Tie::IxHash', (
friendsOnly => {
defaultValue => 0,
},
rating => {
defaultValue => 0,
},
storageIdPhoto => {
defaultValue => undef,
},
);
# UserDefined Fields
for my $i (1 .. 5) {
$properties{"userDefined".$i} = {
defaultValue => undef,
};
}
);
push @{$definition}, {
assetName => $i18n->get('assetName'),
icon => 'Image.gif',
tableName => 'Photo',
className => 'WebGUI::Asset::File::Image::Photo',
i18n => 'Asset_Photo',
properties => \%properties,
};
return $class->SUPER::definition($session, $definition);
push @{$definition}, {
assetName => $i18n->get('assetName'),
icon => 'Image.gif',
tableName => 'Photo',
className => 'WebGUI::Asset::File::Image::Photo',
i18n => 'Asset_Photo',
properties => \%properties,
};
return $class->SUPER::definition($session, $definition);
}
#-------------------------------------------------------------------
#----------------------------------------------------------------------------
=head2 appendTemplateVarsForCommentForm ( vars )
Add the template variables necessary for the comment form to the given hash
reference. Returns the hash reference for convenience.
=cut
sub appendTemplateVarsForCommentForm {
my $self = shift;
my $vars = shift;
# ...
return $vars;
}
#----------------------------------------------------------------------------
=head2 applyConstraints ( )
Apply the constraints to the original file. Called automatically by C<setFile>
and C<processPropertiesFromFormPost>.
=cut
sub applyConstraints {
my $self = shift;
my $gallery = $self->getGallery;
# ...
}
#----------------------------------------------------------------------------
=head2 canEdit ( [userId] )
Returns true if the user can edit this asset. C<userId> is a WebGUI user ID.
If no userId is passed, check the current user.
Users can edit this Photo if they are the owner or if they are able to edit
the parent Album asset.
=cut
sub canEdit {
my $self = shift;
my $userId = shift || $self->session->user->userId;
my $album = $self->getParent;
return 1 if $userId eq $self->get("ownerUserId");
return $album->canEdit($userId);
}
#----------------------------------------------------------------------------
=head2 canView ( [userId] )
Returns true if the user can view this asset. C<userId> is a WebGUI user ID.
If no user is passed, checks the current user.
=cut
# Inherited from superclass
#----------------------------------------------------------------------------
=head2 deleteComment ( commentId )
Delete a comment from this asset. C<id> is the ID of the comment to delete.
=cut
sub deleteComment {
my $self = shift;
my $commentId = shift;
croak "Photo->deleteComment: No commentId specified."
unless $commentId;
return $self->session->db->do(
"DELETE FROM Photo_comment WHERE assetId=? AND commentId=?",
[$self->getId, $commentId],
);
}
#----------------------------------------------------------------------------
=head2 getComment ( commentId )
Get a comment from this asset. C<id> is the ID of the comment to get. Returns
a hash reference of comment information.
=cut
sub getComment {
my $self = shift;
my $commentId = shift;
return $self->session->db->quickHashRef(
"SELECT * FROM Photo_comment WHERE assetId=? AND commentId=?",
[$self->getId, $commentId],
);
}
#----------------------------------------------------------------------------
=head2 getCommentIds ( )
Get an array reference of comment IDs for this Photo, in chronological order.
=cut
sub getCommentIds {
my $self = shift;
return [
$self->session->db->buildArray(
"SELECT commentId FROM Photo_comment WHERE assetId=?",
[$self->getId],
)
];
}
#----------------------------------------------------------------------------
=head2 getCommentPaginator ( )
Get a WebGUI::Paginator for the comments for this Photo.
=cut
sub getCommentPaginator {
my $self = shift;
# ...
}
#----------------------------------------------------------------------------
=head2 getDownloadFileUrl ( resolution )
Get the absolute URL to download the requested resolution. Will croak if the
resolution doesn't exist.
=cut
sub getDownloadFileUrl {
my $self = shift;
my $resolution = shift;
croak "Photo->getDownloadFileUrl: resolution must be defined"
unless $resolution;
croak "Photo->getDownloadFileUrl: resolution doesn't exist for this Photo"
unless grep /$resolution/, @{ $self->getResolutions };
# ...
}
#----------------------------------------------------------------------------
=head2 getGallery ( )
Gets the Gallery asset this Photo is a member of.
=cut
sub getGallery {
my $self = shift;
my $gallery = $self->getParent->getParent;
return $gallery if $gallery->isa("WebGUI::Asset::Wobject::Gallery");
return undef;
}
#----------------------------------------------------------------------------
=head2 getResolutions ( )
Get an array reference of download resolutions that exist for this image.
Does not include the web view image or the thumbnail image.
=cut
sub getResolutions {
my $self = shift;
my $storage = $self->getStorageLocation;
# ...
}
#----------------------------------------------------------------------------
=head2 getTemplateVars ( )
Get a hash reference of template variables shared by all views of this asset.
=cut
sub getTemplateVars {
my $self = shift;
my $vars = $self->get;
# ...
return $vars;
}
#----------------------------------------------------------------------------
=head2 i18n ( [ session ] )
@ -84,10 +307,72 @@ Get a WebGUI::International object for this class.
Can be called as a class method, in which case a WebGUI::Session object
must be passed in.
Can be called as an object method, in which case the session is
filled in automatically.
NOTE: This method can NOT be inherited, due to a current limitation
in the i18n system. You must ALWAYS call this with C<__PACKAGE__>
#-------------------------------------------------------------------
=cut
sub i18n {
my $self = shift;
my $session = shift;
return WebGUI::International->new($session, "Asset_Photo");
}
#----------------------------------------------------------------------------
=head2 makeResolutions ( [resolutions] )
Create the specified resolutions for this Photo. If resolutions is not
defined, will get the resolutions to make from the Gallery this Photo is
contained in.
=cut
sub makeResolutions {
my $self = shift;
my $resolutions = shift;
croak "Photo->makeResolutions: resolutions must be an array reference"
if $resolutions && ref $resolutions ne "ARRAY";
# Get default if necessary
$resolutions ||= $self->getGallery->getImageResolutions;
for my $res ( @$resolutions ) {
# carp if resolution is bad
# ...
}
}
#----------------------------------------------------------------------------
=head2 makeShortcut ( parentId [, overrides ] )
Make a shortcut to this asset under the specified parent, optionally adding
the specified overrides.
=cut
sub makeShortcut {
my $self = shift;
my $parentId = shift;
my $overrides = shift;
my $session = $self->session;
croak "Photo->makeShortcut: parentId must be defined"
unless $parentId;
croak "Photo->makeShortcut: overrides must be hash reference"
if $overrides && ref $overrides ne "HASH";
my $parent = WebGUI::Asset->newByDynamicClass($session, $parentId)
|| croak "Photo->makeShortcut: Could not instanciate asset '$parentId'";
# ...
}
#----------------------------------------------------------------------------
=head2 processPropertiesFromFormPost ( )
@ -98,42 +383,36 @@ when /yourAssetUrl?func=editSave is requested/posted.
=cut
sub processPropertiesFromFormPost {
my $self = shift;
$self->SUPER::processPropertiesFromFormPost;
my $self = shift;
my $errors = $self->SUPER::processPropertiesFromFormPost || [];
}
#----------------------------------------------------------------------------
#-------------------------------------------------------------------
=head2 setComment ( commentId, properties )
=head2 purge ( )
This method is called when data is purged by the system.
removes collateral data associated with a NewAsset when the system
purges it's data. This method is unnecessary, but if you have
auxiliary, ancillary, or "collateral" data or files related to your
asset instances, you will need to purge them here.
Set a comment. If C<commentId> is C<"new">, create a new comment. C<properties>
is a hash reference of comment information.
=cut
sub purge {
my $self = shift;
return $self->SUPER::purge;
sub setComment {
my $self = shift;
my $commentId = shift;
my $properties = shift;
croak "Photo->setComment: commentId must be defined"
unless $commentId;
croak "Photo->setComment: properties must be a hash reference"
unless $properties && ref $properties eq "HASH";
# ...
}
#-------------------------------------------------------------------
#----------------------------------------------------------------------------
=head2 purgeRevision ( )
This method is called when data is purged by the system.
=cut
sub purgeRevision {
my $self = shift;
return $self->SUPER::purgeRevision;
}
#-------------------------------------------------------------------
=head2 view ( )
method called by the container www_view method.
@ -141,49 +420,175 @@ method called by the container www_view method.
=cut
sub view {
my $self = shift;
my $var = $self->get; # $var is a hash reference.
$var->{controls} = $self->getToolbar;
$var->{fileUrl} = $self->getFileUrl;
$var->{fileIcon} = $self->getFileIconUrl;
return $self->processTemplate($var,undef, $self->{_viewTemplate});
my $self = shift;
my $session = $self->session;
my $var = $self->getTemplateVars;
$var->{ controls } = $self->getToolbar;
$var->{ fileUrl } = $self->getFileUrl;
$var->{ fileIcon } = $self->getFileIconUrl;
return $self->processTemplate($var,undef, $self->{_viewTemplate});
}
#-------------------------------------------------------------------
#----------------------------------------------------------------------------
=head2 www_addCommentSave ( )
Save a new comment to the Photo.
=cut
sub www_addCommentSave {
my $self = shift;
my $form = $self->session;
# ...
}
#----------------------------------------------------------------------------
=head2 www_delete ( )
Show the page to confirm the deletion of this Photo. Show a list of albums
this Photo exists in.
=cut
sub www_delete {
my $self = shift;
# ...
}
#----------------------------------------------------------------------------
=head2 www_deleteConfirm ( )
Confirm the deletion of this Photo. Show a message and a link back to the
album.
=cut
sub www_deleteConfirm {
my $self = shift;
# ...
}
#----------------------------------------------------------------------------
=head2 www_download
Download the Photo with the specified resolution. If no resolution specified,
download the original file.
=cut
sub www_download {
my $self = shift;
# ...
}
#----------------------------------------------------------------------------
=head2 www_edit ( )
Web facing method which is the default edit page
This page is only available to those who can edit this Photo.
=cut
sub www_edit {
my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit;
return $self->session->privilege->locked() unless $self->canEditIfLocked;
return $self->getAdminConsole->render($self->getEditForm->print,WebGUI::International::get('edit asset',"Asset_NewAsset"));
my $self = shift;
return $self->session->privilege->insufficient unless $self->canEdit;
return $self->session->privilege->locked unless $self->canEditIfLocked;
# Prepare the template variables
my $var = $self->getTemplateVars;
$var->{ form_header } = WebGUI::Form::formHeader( $session );
$var->{ form_footer } = WebGUI::Form::formFooter( $session );
$var->{ form_title }
= WebGUI::Form::Text( $session, {
name => "title",
value => ( $form->get("title") || $self->get("title") ),
});
$var->{ form_synopsis }
= WebGUI::Form::HTMLArea( $session, {
name => "synopsis",
value => ( $form->get("synopsis") || $self->get("synopsis") ),
richEditId => $self->getGallery->get("assetIdRichEditFile"),
});
$var->{ form_storageIdPhoto }
= WebGUI::Form::Image( $session, {
name => "storageIdPhoto",
value => ( $form->get("storageIdPhoto") || $self->get("storageIdPhoto") ),
maxAttachments => 1,
});
$var->{ form_keywords }
= WebGUI::Form::Text( $session, {
name => "keywords",
value => ( $form->get("keywords") || $self->get("keywords") ),
});
$var->{ form_location }
= WebGUI::Form::Text( $session, {
name => "location",
value => ( $form->get("location") || $self->get("location") ),
});
$var->{ form_friendsOnly }
= WebGUI::Form::yesNo( $session, {
name => "friendsOnly",
value => ( $form->get("friendsOnly") || $self->get("friendsOnly") ),
defaultValue => undef,
});
}
#-------------------------------------------------------------------
#----------------------------------------------------------------------------
=head2 www_view ( )
=head2 www_makeShortcut ( )
Web facing method which is the default view page. This method does a
302 redirect to the "showPage" file in the storage location.
Display the form to make a shortcut.
This page is only available to those who can edit this Photo.
=cut
sub www_view {
my $self = shift;
return $self->session->privilege->noAccess() unless $self->canView;
if ($self->session->var->isAdminOn) {
return $self->getContainer->www_view;
}
$self->session->http->setRedirect($self->getFileUrl($self->getValue("showPage")));
return "";
sub www_makeShortcut {
my $self = shift;
return $self->session->privilege->insufficient unless $self->canEdit;
# ...
}
#----------------------------------------------------------------------------
=head2 www_makeShortcutSave ( )
Make the shortcut.
This page is only available to those who can edit this Photo.
=cut
sub www_makeShortcutSave {
my $self = shift;
my $form = $self->session->form;
return $self->session->privilege->insufficient unless $self->canEdit;
#...
}
1;

View file

@ -0,0 +1,304 @@
package WebGUI::Asset::Wobject::Gallery;
$VERSION = "1.0.0";
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2006 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
#-------------------------------------------------------------------
use strict;
use Tie::IxHash;
use WebGUI::International;
use WebGUI::Utility;
use base 'WebGUI::Asset::Wobject';
#-------------------------------------------------------------------
=head2 definition ( )
defines wobject properties for New Wobject instances. You absolutely need
this method in your new Wobjects. If you choose to "autoGenerateForms", the
getEditForm method is unnecessary/redundant/useless.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new($session, 'Asset_Gallery');
tie my %imageResolutionOptions, 'Tie::IxHash', (
'640' => '640',
'800' => '800',
'1024' => '1024',
'1260' => '1260',
'1440' => '1440',
'1600' => '1600',
'2880' => '2880',
);
tie my %properties, 'Tie::IxHash', (
groupIdAddComment => {
tab => "security",
fieldType => "group",
defaultValue => 2, # Registered Users
label => $i18n->get("groupIdAddComment label"),
hoverHelp => $i18n->get("groupIdAddComment description"),
},
groupIdAddFile => {
tab => "security",
fieldType => "group",
defaultValue => 2, # Registered Users
label => $i18n->get("groupIdAddFile label"),
hoverHelp => $i18n->get("groupIdAddFile description"),
},
groupIdModerator => {
tab => "security",
fieldType => "group",
defaultValue => 3, # Admins
label => $i18n->get("groupIdModerator label"),
hoverHelp => $i18n->get("groupIdModerator description"),
},
imageResolutions => {
tab => "properties",
fieldType => "checkList",
defaultValue => ['800','1024','1200','1600'],
options => \%imageResolutionOptions,
label => $i18n->get("imageResolutions label"),
hoverHelp => $i18n->get("imageResolutions description"),
},
imageViewSize => {
tab => "properties",
fieldType => "integer",
defaultValue => 0,
label => $i18n->get("imageViewSize label"),
hoverHelp => $i18n->get("imageViewSize description"),
},
imageViewCompression => {
tab => "properties",
fieldType => "integer",
defaultValue => 0,
label => $i18n->get("imageViewCompression label"),
hoverHelp => $i18n->get("imageViewCompression description"),
},
imageThumbnailSize => {
tab => "properties",
fieldType => "integer",
defaultValue => 0,
label => $i18n->get("imageThumbnailSize label"),
hoverHelp => $i18n->get("imageThumbnailSize description"),
},
maxSpacePerUser => {
tab => "properties",
fieldType => "integer",
defaultValue => 0,
label => $i18n->get("maxSpacePerUser label"),
hoverHelp => $i18n->get("maxSpacePerUser description"),
},
richEditIdFileComment => {
tab => "properties",
fieldType => "selectRichEditor",
defaultValue => undef, # Rich Editor for Posts
label => $i18n->get("richEditIdFileComment label"),
hoverHelp => $i18n->get("richEditIdFileComment description"),
},
templateIdAddArchive => {
tab => "display",
fieldType => "template",
defaultValue => "",
namespace => "GalleryAlbum/AddArchive",
label => $i18n->get("templateIdAddArchive label"),
hoverHelp => $i18n->get("templateIdAddArchive description"),
},
templateIdDeleteAlbum => {
tab => "display",
fieldType => "template",
defaultValue => "",
namespace => "GalleryAlbum/Delete",
label => $i18n->get("templateIdDeleteAlbum label"),
hoverHelp => $i18n->get("templateIdDeleteAlbum description"),
},
templateIdDeleteFile => {
tab => "display",
fieldType => "template",
defaultValue => "",
namespace => "GalleryFile/Delete",
label => $i18n->get("templateIdDeleteFile label"),
hoverHelp => $i18n->get("templateIdDeleteFile description"),
},
templateIdEditFile => {
tab => "display",
fieldType => "template",
defaultValue => "",
namespace => "GalleryFile/Edit",
label => $i18n->get("templateIdEditFile label"),
hoverHelp => $i18n->get("templateIdEditFile description"),
},
templateIdListAlbums => {
tab => "display",
fieldType => "template",
defaultValue => "",
namespace => "Gallery/ListAlbums",
label => $i18n->get("templateIdListAlbums label"),
hoverHelp => $i18n->get("templateIdListAlbums description"),
},
templateIdListAlbumsRss => {
tab => "display",
fieldType => "template",
defaultValue => "",
namespace => "Gallery/ListAlbumsRss",
label => $i18n->get("templateIdListAlbumsRss label"),
hoverHelp => $i18n->get("templateIdListAlbumsRss description"),
},
templateIdListUserFiles => {
tab => "display",
fieldType => "template",
defaultValue => "",
namespace => "Gallery/ListUserFiles",
label => $i18n->get("templateIdListUserFiles label"),
hoverHelp => $i18n->get("templateIdListUserFiles description"),
},
templateIdListUserFilesRss => {
tab => "display",
fieldType => "template",
defaultValue => "",
namespace => "Gallery/ListUserFilesRss",
label => $i18n->get("templateIdListUserFilesRss label"),
hoverHelp => $i18n->get("templateIdListUserFilesRss description"),
},
templateIdMakeShortcut => {
tab => "display",
fieldType => "template",
defaultValue => "",
namespace => "GalleryFile/MakeShortcut",
label => $i18n->get("templateIdMakeShortcut label"),
hoverHelp => $i18n->get("templateIdMakeShortcut description"),
},
templateIdSearch => {
tab => "display",
fieldType => "template",
defaultValue => "",
namespace => "Gallery/Search",
label => $i18n->get("templateIdSearch label"),
hoverHelp => $i18n->get("templateIdSearch description"),
},
templateIdSlideshow => {
tab => "display",
fieldType => "template",
defaultValue => "",
namespace => "GalleryAlbum/Slideshow",
label => $i18n->get("templateIdSlideshow label"),
hoverHelp => $i18n->get("templateIdSlideshow description"),
},
templateIdThumbnails => {
tab => "display",
fieldType => "template",
defaultValue => "",
namespace => "GalleryAlbum/Thumbnails",
label => $i18n->get("templateIdThumbnails label"),
hoverHelp => $i18n->get("templateIdThumbnails description"),
},
templateIdViewAlbum => {
tab => "display",
fieldType => "template",
defaultValue => "",
namespace => "GalleryAlbum/View",
label => $i18n->get("templateIdViewAlbum label"),
hoverHelp => $i18n->get("templateIdViewAlbum description"),
},
templateIdViewAlbumRss => {
tab => "display",
fieldType => "template",
defaultValue => "",
namespace => "GalleryAlbum/ViewRss",
label => $i18n->get("templateIdViewAlbumRss label"),
hoverHelp => $i18n->get("templateIdViewAlbumRss description"),
},
templateIdViewFile => {
tab => "display",
fieldType => "template",
defaultValue => "",
namespace => "GalleryFile/View",
label => $i18n->get("templateIdViewFile label"),
hoverHelp => $i18n->get("templateIdViewFile description"),
},
workflowIdCommit => {
tab => "security",
fieldType => "workflow",
defaultValue => "pbworkflow000000000003", # Commit without approval
type => 'WebGUI::VersionTag',
label => $i18n->get("workflowIdCommit label"),
hoverHelp => $i18n->get("workflowIdCommit description"),
},
);
push @{$definition}, {
assetName => $i18n->get('assetName'),
icon => 'newWobject.gif',
autoGenerateForms => 1,
tableName => 'Gallery',
className => __PACKAGE__,
properties => \%properties,
};
return $class->SUPER::definition($session, $definition);
}
#----------------------------------------------------------------------------
=head2 getTemplateEditFile ( )
Returns an instance of a WebGUI::Asset::Template for the template to edit
files in this gallery
NOTE: This may need to change in the future to take into account different
classes of files inside of a Gallery.
=cut
sub getTemplateEditFile {
my $self = shift;
return WebGUI::Asset::Template->new($self->session, $self->get("templateIdEditFile"));
}
#----------------------------------------------------------------------------
=head2 prepareView ( )
See WebGUI::Asset::prepareView() for details.
=cut
sub prepareView {
my $self = shift;
$self->SUPER::prepareView();
my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId"));
$template->prepare;
$self->{_viewTemplate} = $template;
}
#-------------------------------------------------------------------
=head2 view ( )
method called by the www_view method. Returns a processed template
to be displayed within the page style.
=cut
sub view {
my $self = shift;
my $session = $self->session;
my $var = $self->get;
return $self->processTemplate($var, undef, $self->{_viewTemplate});
}
1;

View file

@ -0,0 +1,118 @@
package WebGUI::Asset::Wobject::GalleryAlbum;
$VERSION = "1.0.0";
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2006 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
#-------------------------------------------------------------------
use strict;
use Tie::IxHash;
use WebGUI::International;
use WebGUI::Utility;
use base 'WebGUI::Asset::Wobject';
#-------------------------------------------------------------------
=head2 definition ( )
defines wobject properties for New Wobject instances. You absolutely need
this method in your new Wobjects. If you choose to "autoGenerateForms", the
getEditForm method is unnecessary/redundant/useless.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new($session, 'Asset_GalleryAlbum');
tie my %properties, 'Tie::IxHash', (
allowComments => {
fieldType => "yesNo",
defaultValue => 0,
label => $i18n->get("allowComments label"),
hoverHelp => $i18n->get("allowComments description"),
},
othersCanAdd => {
fieldType => "yesNo",
defaultValue => 0,
label => $i18n->get("othersCanAdd label"),
hoverHelp => $i18n->get("othersCanAdd description"),
},
);
push @{$definition}, {
assetName => $i18n->get('assetName'),
icon => 'newWobject.gif',
autoGenerateForms => 1,
tableName => 'GalleryAlbum',
className => __PACKAGE__,
properties => \%properties,
};
return $class->SUPER::definition($session, $definition);
}
#----------------------------------------------------------------------------
=head2 canEdit ( [userId] )
Returns true if the user can edit this asset. C<userId> is a WebGUI user ID.
If no userId is passed, check the current user.
Users can edit this GalleryAlbum if they are the owner, or if they can edit
the Gallery parent.
=cut
sub canEdit {
my $self = shift;
my $userId = shift || $self->session->user->userId;
my $gallery = $self->getParent;
return 1 if $userId eq $self->get("ownerUserId");
return $gallery->canEdit($userId);
}
#-------------------------------------------------------------------
=head2 prepareView ( )
See WebGUI::Asset::prepareView() for details.
=cut
sub prepareView {
my $self = shift;
$self->SUPER::prepareView();
my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId"));
$template->prepare;
$self->{_viewTemplate} = $template;
}
#-------------------------------------------------------------------
=head2 view ( )
method called by the www_view method. Returns a processed template
to be displayed within the page style.
=cut
sub view {
my $self = shift;
my $session = $self->session;
my $var = $self->get;
return $self->processTemplate($var, undef, $self->{_viewTemplate});
}
1;

View file

@ -25,6 +25,15 @@ my $session = WebGUI::Test->session;
my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Photo Test"});
print "hi";
my $gallery
= $node->addChild({
className => "WebGUI::Asset::Wobject::Gallery",
});
my $album
= $gallery->addChild({
className => "WebGUI::Asset::Wobject::GalleryAlbum",
});
#----------------------------------------------------------------------------
# Cleanup
@ -44,50 +53,6 @@ use_ok("WebGUI::Asset::File::Image::Photo");
#----------------------------------------------------------------------------
# Test creating a photo
my $photo
= $node->addChild({
className => "WebGUI::Asset::File::Image::Photo",
});
is(
blessed $photo, "WebGUI::Asset::File::Image::Photo",
"Photo is a WebGUI::Asset::File::Image::Photo object",
);
isa_ok(
$photo, "WebGUI::Asset::File::Image",
);
is(
$photo->getGallery, undef,
"Photo->getGallery returns undef if photo not part of a Photo Gallery",
);
#----------------------------------------------------------------------------
# Test deleting a photo
my $properties = $photo->get;
$photo->purge;
is(
$photo, undef
"Photo is undefined",
);
is(
WebGUI::Asset->newByDynamicClass($session, $properties->{assetId}), undef,
"Photo no longer able to be instanciated",
);
#----------------------------------------------------------------------------
# Test creating a photo as part of a photo album
my $gallery
= $node->addChild({
className => "WebGUI::Asset::Wobject::PhotoGallery",
});
my $album
= $gallery->addChild({
className => "WebGUI::Asset::Wobject::PhotoAlbum",
});
$photo
= $album->addChild({
className => "WebGUI::Asset::File::Image::Photo",
});
@ -102,6 +67,17 @@ isa_ok(
);
is(
blessed $photo->getGallery, "WebGUI::Asset::Wobject::PhotoGallery",
blessed $photo->getGallery, "WebGUI::Asset::Wobject::Gallery",
"Photo->getGallery gets the gallery containing this photo",
);
#----------------------------------------------------------------------------
# Test deleting a photo
my $properties = $photo->get;
$photo->purge;
is(
WebGUI::Asset->newByDynamicClass($session, $properties->{assetId}), undef,
"Photo no longer able to be instanciated",
);

View file

@ -0,0 +1,53 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2007 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
#-------------------------------------------------------------------
# The goal of this test is to test the AJAX methods of the Photo asset
use FindBin;
use strict;
use lib "$FindBin::Bin/../../../../lib";
use Scalar::Util qw( blessed );
use WebGUI::Test;
use WebGUI::Session;
use Test::More;
use WebGUI::Test::Maker::HTML;
use WebGUI::Asset::File::Image::Photo;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Photo Test"});
my $maker = WebGUI::Test::Maker::HTML->new;
my $gallery
= $node->addChild({
className => "WebGUI::Asset::Wobject::PhotoGallery",
});
my $album
= $gallery->addChild({
className => "WebGUI::Asset::Wobject::PhotoAlbum",
});
my $photo
= $gallery->addChild({
className => "WebGUI::Asset::File::Image::Photo",
});
#----------------------------------------------------------------------------
# Cleanup
END {
$versionTag->rollback();
}
#----------------------------------------------------------------------------
# Tests
plan tests => 0;

View file

@ -0,0 +1,53 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2007 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
#-------------------------------------------------------------------
# The goal of this test is to test the www_delete() and www_deleteConfirm()
# methods
use FindBin;
use strict;
use lib "$FindBin::Bin/../../../../lib";
use Scalar::Util qw( blessed );
use WebGUI::Test;
use WebGUI::Session;
use Test::More;
use WebGUI::Test::Maker::HTML;
use WebGUI::Asset::File::Image::Photo;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Photo Test"});
my $maker = WebGUI::Test::Maker::HTML->new;
my $gallery
= $node->addChild({
className => "WebGUI::Asset::Wobject::PhotoGallery",
});
my $album
= $gallery->addChild({
className => "WebGUI::Asset::Wobject::PhotoAlbum",
});
my $photo
= $gallery->addChild({
className => "WebGUI::Asset::File::Image::Photo",
});
#----------------------------------------------------------------------------
# Cleanup
END {
$versionTag->rollback();
}
#----------------------------------------------------------------------------
# Tests
plan tests => 0;

View file

@ -0,0 +1,52 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2007 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
#-------------------------------------------------------------------
# The goal of this test is to get sthe getDownloadFileUrl and www_download()
# methods
use FindBin;
use strict;
use lib "$FindBin::Bin/../../../../lib";
use Scalar::Util qw( blessed );
use WebGUI::Test;
use WebGUI::Session;
use Test::More;
use WebGUI::Asset::File::Image::Photo;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Photo Test"});
my $maker = WebGUI::Test::Maker::HTML->new;
my $gallery
= $node->addChild({
className => "WebGUI::Asset::Wobject::PhotoGallery",
});
my $album
= $gallery->addChild({
className => "WebGUI::Asset::Wobject::PhotoAlbum",
});
my $photo
= $gallery->addChild({
className => "WebGUI::Asset::File::Image::Photo",
});
#----------------------------------------------------------------------------
# Cleanup
END {
$versionTag->rollback();
}
#----------------------------------------------------------------------------
# Tests
plan tests => 0;

View file

@ -8,8 +8,8 @@
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
# The goal of this test is to test the editSave and
# processPropertiesFromFormPost methods.
# The goal of this test is to test the editSave,
# processPropertiesFromFormPost, and applyConstraints methods.
use FindBin;
use strict;
@ -28,14 +28,15 @@ my $session = WebGUI::Test->session;
my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Photo Test"});
$session->user( { userId => 3 } ); # Admins can do everything
my $maker = WebGUI::Test::Maker::HTML->new;
my $gallery
= $node->addChild({
className => "WebGUI::Asset::Wobject::PhotoGallery",
className => "WebGUI::Asset::Wobject::Gallery",
});
my $album
= $gallery->addChild({
className => "WebGUI::Asset::Wobject::PhotoAlbum",
className => "WebGUI::Asset::Wobject::GalleryAlbum",
});
my $photo
= $gallery->addChild({
@ -50,7 +51,7 @@ END {
#----------------------------------------------------------------------------
# Tests
plan tests => 0;
plan no_plan => 1;
#----------------------------------------------------------------------------
# Test permissions
@ -76,11 +77,11 @@ $maker->prepare({
# TODO: This test should use i18n.
# TODO: This error / test should occur in File, not Photo
$maker->prepare({
object => $album
object => $album,
method => "www_editSave",
formParams => {
assetId => "new",
className => "WebGUI::Asset::File::Image::Photo",
},
test_regex => [
qr/You must select a file/,
@ -90,5 +91,17 @@ $maker->prepare({
#----------------------------------------------------------------------------
# Test editSave success result
# TODO: This test should use i18n
$maker->prepare({
object => $album,
method => "www_editSave",
formParams => {
assetId => "new",
className => "WebGUI::Asset::File::Image::Photo",
},
test_regex => [
qr/awaiting approval and commit/,
],
})->run;
#----------------------------------------------------------------------------

View file

@ -26,6 +26,22 @@ my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Photo Test"});
my ($photo);
$session->user({ userId => 3 });
my $gallery
= $node->addChild({
className => "WebGUI::Asset::Wobject::Gallery",
groupIdView => "7",
groupIdEdit => "3",
ownerUserId => $session->user->userId,
});
my $album
= $gallery->addChild({
className => "WebGUI::Asset::Wobject::GalleryAlbum",
groupIdView => "",
groupIdEdit => "",
ownerUserId => $session->user->userId,
});
#----------------------------------------------------------------------------
# Cleanup
@ -35,14 +51,14 @@ END {
#----------------------------------------------------------------------------
# Tests
plan tests => 0;
plan no_plan => 1;
#----------------------------------------------------------------------------
# Photo assets outside of Gallery assets
# Everyone can view, Admins can edit, Owned by current user
$photo
= $node->addChild({
= $album->addChild({
className => "WebGUI::Asset::File::Image::Photo",
groupIdView => "7",
groupIdEdit => "3",
@ -58,9 +74,9 @@ ok( $photo->canEdit, "Current user can edit" );
# Admins can view, Admins can edit, Owned by Admin, current user is Visitor
my $oldUser = $session->user;
$session->user( WebGUI::User->new($session, "1") );
$session->user( { user => WebGUI::User->new($session, "1") } );
$photo
= $node->addChild({
= $album->addChild({
className => "WebGUI::Asset::File::Image::Photo",
groupIdView => "3",
groupIdEdit => "3",
@ -73,24 +89,7 @@ ok( !$photo->canView(2), "Registered Users cannot view" );
ok( !$photo->canEdit(2), "Registered Users cannot edit" );
ok( $photo->canView(3), "Admins can view" );
ok( $photo->canEdit(3), "Admins can edit" );
$session->user($oldUser);
#----------------------------------------------------------------------------
# Photo assets inside of Gallery assets
my $gallery
= $node->addChild({
className => "WebGUI::Asset::Wobject::PhotoGallery",
groupIdView => "7",
groupIdEdit => "3",
ownerUserId => $session->user->userId,
});
my $album
= $gallery->addChild({
className => "WebGUI::Asset::Wobject::PhotoAlbum",
groupIdView => "",
groupIdEdit => "",
ownerUserId => $session->user->userId,
});
$session->user( { user => $oldUser } );
# Photo without specific view/edit inherits from gallery properties
$photo

View file

@ -0,0 +1,53 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2007 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
#-------------------------------------------------------------------
# The goal of this test is to test the view and getTemplateVars methods
use FindBin;
use strict;
use lib "$FindBin::Bin/../../../../lib";
use Scalar::Util qw( blessed );
use WebGUI::Test;
use WebGUI::Session;
use Test::More;
use WebGUI::Test::Maker::HTML;
use WebGUI::Asset::File::Image::Photo;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Photo Test"});
my $maker = WebGUI::Test::Maker::HTML->new;
my $gallery
= $node->addChild({
className => "WebGUI::Asset::Wobject::PhotoGallery",
});
my $album
= $gallery->addChild({
className => "WebGUI::Asset::Wobject::PhotoAlbum",
});
my $photo
= $gallery->addChild({
className => "WebGUI::Asset::File::Image::Photo",
});
$photo->setFile( WebGUI::Test->getCollateralPath('page_title.jpg') );
#----------------------------------------------------------------------------
# Cleanup
END {
$versionTag->rollback();
}
#----------------------------------------------------------------------------
# Tests
plan tests => 0;

View file

@ -0,0 +1,78 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2007 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
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../../../../lib";
## The goal of this test is to test the creation and deletion of album assets
use Scalar::Util qw( blessed );
use WebGUI::Test;
use WebGUI::Session;
use Test::More;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Album Test"});
my $gallery
= $node->addChild({
className => "WebGUI::Asset::Wobject::Gallery",
});
#----------------------------------------------------------------------------
# Cleanup
END {
$versionTag->rollback();
}
#----------------------------------------------------------------------------
# Tests
plan tests => 5;
#----------------------------------------------------------------------------
# Test module compiles okay
# plan tests => 1
use_ok("WebGUI::Asset::Wobject::GalleryAlbum");
#----------------------------------------------------------------------------
# Test creating an album
my $album
= $gallery->addChild({
className => "WebGUI::Asset::Wobject::GalleryAlbum",
});
is(
blessed $album, "WebGUI::Asset::Wobject::GalleryAlbum",
"Album is a WebGUI::Asset::Wobject::GalleryAlbum object",
);
isa_ok(
$album, "WebGUI::Asset::Wobject",
);
#----------------------------------------------------------------------------
# Test deleting a album
my $properties = $album->get;
$album->purge;
is(
$album, undef,
"Album is undefined",
);
is(
WebGUI::Asset->newByDynamicClass($session, $properties->{assetId}), undef,
"Album no longer able to be instanciated",
);

View file

@ -9,6 +9,7 @@ use Config qw[];
use IO::Handle qw[];
use File::Spec qw[];
use Test::MockObject::Extends;
use WebGUI::PseudoRequest;
##Hack to get ALL test output onto STDOUT.
use Test::Builder;
@ -135,7 +136,8 @@ of options with keys outlined below.
=cut
sub getPage {
my $session = shift; # The session object
my $class = shift;
my $session = $SESSION; # The session object
my $asset = shift; # The asset object
my $page = shift; # The page subroutine
my $optionsRef = shift; # A hashref of options

View file

@ -2,6 +2,7 @@ package WebGUI::Test::Maker::HTML;
use base 'WebGUI::Test::Maker';
use Scalar::Util qw( blessed );
use Carp qw( croak );
use Test::More;
@ -187,7 +188,7 @@ sub prepare {
croak("Couldn't prepare: Test $test_num, test_regex is not an array reference")
if $test->{test_regex} && ref $test->{test_regex} ne "ARRAY";
croak("Couldn't prepare: Test $test_num, $test->{test_privilege} is not a valid test_privilege value (adminOnly, insufficient, noAccess, notMember, vitalComponent)")
if $test->{test_privilege} && $test->{test_privilege} =~ m/adminOnly|insufficient|noAccess|notMember|vitalComponent/;
if $test->{test_privilege} && $test->{test_privilege} !~ m/adminOnly|insufficient|noAccess|notMember|vitalComponent/;
push @{$self->{_tests}}, $test;
}