fix: GalleryAlbum and Photo were not showing correct confirmation messages on editSave
add: Ability to edit comments to Photos add: Ability to choose which rich editor for Albums
This commit is contained in:
parent
a69dff3dcf
commit
8af6f28988
10 changed files with 340 additions and 122 deletions
|
|
@ -2,6 +2,8 @@
|
|||
- fixed: Several typos in the new Calendar help documentation.
|
||||
- fix: List View now starts at the beginning of the day passed in.
|
||||
- Removed some spurious warnings from the calendar.
|
||||
- Added ability to edit comments. Entirely changed how comments work in prep
|
||||
for turning it into a mixin.
|
||||
|
||||
7.5.4
|
||||
- fixed: unable to remove calendar feeds in IE6
|
||||
|
|
|
|||
BIN
docs/upgrades/packages-7.5.5/root_import_gallery-templates.wgpkg
Normal file
BIN
docs/upgrades/packages-7.5.5/root_import_gallery-templates.wgpkg
Normal file
Binary file not shown.
|
|
@ -23,17 +23,44 @@ my $quiet; # this line required
|
|||
my $session = start(); # this line required
|
||||
|
||||
# upgrade functions go here
|
||||
addGalleryEditCommentTemplate( $session );
|
||||
addGalleryRichEditAlbum( $session );
|
||||
|
||||
finish($session); # this line required
|
||||
|
||||
|
||||
##-------------------------------------------------
|
||||
##---------------------------------------------------------------------------
|
||||
#sub exampleFunction {
|
||||
# my $session = shift;
|
||||
# print "\tWe're doing some stuff here that you should know about.\n" unless ($quiet);
|
||||
# # and here's our code
|
||||
#}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Add a column to the Gallery
|
||||
sub addGalleryEditCommentTemplate {
|
||||
my $session = shift;
|
||||
print "\tAdding Edit Comment Template... " unless $quiet;
|
||||
|
||||
$session->db->write( q{
|
||||
ALTER TABLE Gallery ADD COLUMN templateIdEditComment VARCHAR(22) BINARY
|
||||
} );
|
||||
|
||||
print "DONE!\n" unless $quiet;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Add a column to select rich editor for albums
|
||||
sub addGalleryRichEditAlbum {
|
||||
my $session = shift;
|
||||
print "\tAdding Select Rich Editor for Gallery Albums..." unless $quiet;
|
||||
|
||||
$session->db->write( q{
|
||||
ALTER TABLE Gallery ADD COLUMN richEditIdAlbum VARCHAR(22) BINARY
|
||||
} );
|
||||
|
||||
print "DONE!\n" unless $quiet;
|
||||
}
|
||||
|
||||
# --------------- DO NOT EDIT BELOW THIS LINE --------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -111,22 +111,53 @@ sub definition {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 appendTemplateVarsForCommentForm ( var )
|
||||
=head2 appendTemplateVarsCommentForm ( var [, comment ] )
|
||||
|
||||
Add the template variables necessary for the comment form to the given hash
|
||||
reference. Returns the hash reference for convenience.
|
||||
reference. Returns the hash reference for convenience. C<comment> is a hash
|
||||
reference of values to populate the form with.
|
||||
|
||||
=cut
|
||||
|
||||
sub appendTemplateVarsForCommentForm {
|
||||
sub appendTemplateVarsCommentForm {
|
||||
my $self = shift;
|
||||
my $var = shift;
|
||||
my $comment = shift || {};
|
||||
my $session = $self->session;
|
||||
|
||||
# Default comment
|
||||
$comment->{ commentId } ||= "new";
|
||||
|
||||
$var->{ commentForm_start }
|
||||
= WebGUI::Form::formHeader( $session )
|
||||
. WebGUI::Form::hidden( $session, { name => "func", value => "addCommentSave" } )
|
||||
. WebGUI::Form::hidden( $session, {
|
||||
name => "func",
|
||||
value => "editCommentSave"
|
||||
} )
|
||||
. WebGUI::Form::hidden( $session, {
|
||||
name => "commentId",
|
||||
value => $comment->{ commentId }
|
||||
} )
|
||||
;
|
||||
|
||||
# Add hidden fields for editing a comment
|
||||
if ( $comment->{ commentId } ne "new" ) {
|
||||
$var->{ commentForm_start }
|
||||
.= WebGUI::Form::hidden( $session, {
|
||||
name => "userId",
|
||||
value => $comment->{ userId }
|
||||
} )
|
||||
. WebGUI::Form::hidden( $session, {
|
||||
name => "visitorIp",
|
||||
value => $comment->{ visitorIp }
|
||||
} )
|
||||
. WebGUI::Form::hidden( $session, {
|
||||
name => "creationDate",
|
||||
value => $comment->{ creationDate }
|
||||
} )
|
||||
;
|
||||
}
|
||||
|
||||
$var->{ commentForm_end }
|
||||
= WebGUI::Form::formFooter( $session );
|
||||
|
||||
|
|
@ -134,6 +165,7 @@ sub appendTemplateVarsForCommentForm {
|
|||
= WebGUI::Form::HTMLArea( $session, {
|
||||
name => "bodyText",
|
||||
richEditId => $self->getGallery->get("richEditIdComment"),
|
||||
value => $comment->{ bodyText },
|
||||
});
|
||||
|
||||
$var->{ commentForm_submit }
|
||||
|
|
@ -605,6 +637,53 @@ sub prepareView {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 processCommentEditForm ( )
|
||||
|
||||
Process the Comment Add / Edit Form. Returns a hash reference of properties
|
||||
that can be passed to C<setComment>.
|
||||
|
||||
Will die with an i18n-friendly error message if something is missing or
|
||||
wrong.
|
||||
|
||||
=cut
|
||||
|
||||
sub processCommentEditForm {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
my $form = $self->session->form;
|
||||
my $now = WebGUI::DateTime->new( $session, time );
|
||||
my $i18n = __PACKAGE__->i18n( $session );
|
||||
|
||||
# Using die here to suppress line number and file path info
|
||||
die $i18n->get("commentForm error no commentId") . "\n"
|
||||
unless $form->get("commentId");
|
||||
die $i18n->get("commentForm error no bodyText") . "\n"
|
||||
unless $form->get("bodyText");
|
||||
|
||||
my $new = $form->get('commentId') eq "new"
|
||||
? 1
|
||||
: 0
|
||||
;
|
||||
|
||||
my $visitorIp = $session->user->userId eq "1"
|
||||
? $session->env->get("REMOTE_ADDR")
|
||||
: undef
|
||||
;
|
||||
|
||||
my $properties = {
|
||||
commentId => $form->get("commentId"),
|
||||
assetId => $self->getId,
|
||||
bodyText => $form->get("bodyText"),
|
||||
creationDate => ( $new ? $now->toDatabaseDate : $form->get("creationDate") ),
|
||||
userId => ( $new ? $session->user->userId : $form->get("userId") ),
|
||||
visitorIp => ( $new ? $visitorIp : $form->get("visitorIp") ),
|
||||
};
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 processPropertiesFromFormPost ( )
|
||||
|
||||
|
||||
|
|
@ -656,31 +735,37 @@ sub purge {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 setComment ( commentId, properties )
|
||||
=head2 setComment ( properties )
|
||||
|
||||
Set a comment. If C<commentId> is C<"new">, create a new comment. C<properties>
|
||||
is a hash reference of comment information.
|
||||
Set a comment. C<properties> is a hash reference of comment information with
|
||||
the following keys:
|
||||
|
||||
assetId - The assetId of the asset this comment is for
|
||||
commentId - The ID of the comment. If "new", will make a new comment.
|
||||
bodyText - The body of the comment
|
||||
userId - The userId of the user who made the comment
|
||||
visitorIp - If the user was a visitor, the IP address of the user
|
||||
creationDate - A MySQL-formatted date/time when the comment was posted
|
||||
|
||||
=cut
|
||||
|
||||
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";
|
||||
croak "Photo->setComment: commentId must be defined"
|
||||
unless $properties->{ commentId };
|
||||
croak "Photo->setComment: properties must contain a bodyText key"
|
||||
unless $properties->{ bodyText };
|
||||
|
||||
$properties->{ creationDate } ||= WebGUI::DateTime->new($self->session, time)->toDatabase;
|
||||
$properties->{ assetId } = $self->getId;
|
||||
|
||||
$self->session->db->setRow(
|
||||
return $self->session->db->setRow(
|
||||
"Photo_comment", "commentId",
|
||||
{ %$properties, commentId => $commentId }
|
||||
$properties,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -725,7 +810,7 @@ sub view {
|
|||
my $session = $self->session;
|
||||
my $var = $self->getTemplateVars;
|
||||
|
||||
$self->appendTemplateVarsForCommentForm( $var );
|
||||
$self->appendTemplateVarsCommentForm( $var );
|
||||
|
||||
# Keywords
|
||||
my $k = WebGUI::Keyword->new( $session );
|
||||
|
|
@ -743,6 +828,8 @@ sub view {
|
|||
for my $comment ( @{ $p->getPageData } ) {
|
||||
$comment->{ url_deleteComment }
|
||||
= $self->getUrl('func=deleteComment;commentId=' . $comment->{commentId} );
|
||||
$comment->{ url_editComment }
|
||||
= $self->getUrl('func=editComment;commentId=' . $comment->{commentId} );
|
||||
|
||||
my $user = WebGUI::User->new( $session, $comment->{userId} );
|
||||
$comment->{ username } = $user->username;
|
||||
|
|
@ -759,38 +846,6 @@ sub view {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_addCommentSave ( )
|
||||
|
||||
Save a new comment to the Photo.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_addCommentSave {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
return $session->privilege->insufficient unless $self->canComment;
|
||||
|
||||
my $i18n = __PACKAGE__->i18n( $session );
|
||||
my $form = $self->session->form;
|
||||
|
||||
my $properties = {
|
||||
assetId => $self->getId,
|
||||
creationDate => WebGUI::DateTime->new( $session, time )->toDatabase,
|
||||
userId => $session->user->userId,
|
||||
visitorIp => ( $session->user->userId eq "1" ? $session->env("REMOTE_ADDR") : undef ),
|
||||
bodyText => $form->get("bodyText"),
|
||||
};
|
||||
|
||||
$self->setComment( "new", $properties );
|
||||
|
||||
return $self->processStyle(
|
||||
sprintf $i18n->get('comment message'), $self->getUrl,
|
||||
);
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_delete ( )
|
||||
|
||||
Show the page to confirm the deletion of this Photo. Show a list of albums
|
||||
|
|
@ -1016,19 +1071,74 @@ sub www_edit {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_editSave ( )
|
||||
=head2 www_editComment ( params )
|
||||
|
||||
Save the edit form. Overridden to display a confirm message to the user.
|
||||
Form to edit a comment. C<params> is a hash reference of parameters
|
||||
with the following keys:
|
||||
|
||||
errors = An array reference of errors to show the user.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_editSave {
|
||||
sub www_editComment {
|
||||
my $self = shift;
|
||||
$self->SUPER::www_editSave;
|
||||
my $params = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
my $i18n = __PACKAGE__->i18n( $self->session );
|
||||
return $session->privilege->insufficient unless $self->canEdit;
|
||||
|
||||
sprintf $i18n->get("save message"), $self->getUrl,
|
||||
my $var = $self->getTemplateVars;
|
||||
|
||||
if ( $params->{ errors } ) {
|
||||
$var->{ errors } = [ map { { "error" => $_ } } @{ $params->{errors} } ];
|
||||
}
|
||||
|
||||
my $commentId = $session->form->get( "commentId" );
|
||||
my $comment = $self->getComment( $commentId );
|
||||
$self->appendTemplateVarsCommentForm( $var, $comment );
|
||||
|
||||
return $self->processStyle(
|
||||
$self->processTemplate( $var, $self->getGallery->get("templateIdEditComment") )
|
||||
);
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_editCommentSave ( )
|
||||
|
||||
Save a comment being edited
|
||||
|
||||
=cut
|
||||
|
||||
sub www_editCommentSave {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
return $session->privilege->insufficient unless $self->canEdit;
|
||||
|
||||
my $i18n = __PACKAGE__->i18n( $session );
|
||||
|
||||
my $comment = eval { $self->processCommentEditForm };
|
||||
if ( $@ ) {
|
||||
return $self->www_editComment( { errors => [ $@ ] } );
|
||||
}
|
||||
|
||||
# setComment changes commentId, so keep track if we're adding a new comment
|
||||
my $isNew = $comment->{commentId} eq "new";
|
||||
|
||||
$self->setComment( $comment );
|
||||
|
||||
# Return different message for adding and editing
|
||||
if ( $isNew ) {
|
||||
return $self->processStyle(
|
||||
sprintf $i18n->get('comment message'), $self->getUrl
|
||||
);
|
||||
}
|
||||
else {
|
||||
return $self->processStyle(
|
||||
sprintf $i18n->get('editCommentSave message'), $self->getUrl
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -118,6 +118,13 @@ sub definition {
|
|||
label => $i18n->get("maxSpacePerUser label"),
|
||||
hoverHelp => $i18n->get("maxSpacePerUser description"),
|
||||
},
|
||||
richEditIdAlbum => {
|
||||
tab => "properties",
|
||||
fieldType => "selectRichEditor",
|
||||
defaultValue => "PBrichedit000000000001", # Content Managers editor
|
||||
label => $i18n->get("richEditIdAlbum label"),
|
||||
hoverHelp => $i18n->get("richEditIdAlbum description"),
|
||||
},
|
||||
richEditIdComment => {
|
||||
tab => "properties",
|
||||
fieldType => "selectRichEditor",
|
||||
|
|
@ -157,6 +164,14 @@ sub definition {
|
|||
label => $i18n->get("templateIdEditAlbum label"),
|
||||
hoverHelp => $i18n->get("templateIdEditAlbum description"),
|
||||
},
|
||||
templateIdEditComment => {
|
||||
tab => "display",
|
||||
fieldType => "template",
|
||||
defaultValue => "OxJWQgnGsgyGohP2L3zJPQ",
|
||||
namespace => "GalleryFile/EditComment",
|
||||
label => $i18n->get("templateIdEditComment label"),
|
||||
hoverHelp => $i18n->get("templateIdEditComment description"),
|
||||
},
|
||||
templateIdEditFile => {
|
||||
tab => "display",
|
||||
fieldType => "template",
|
||||
|
|
|
|||
|
|
@ -814,29 +814,6 @@ sub www_edit {
|
|||
);
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_editSave ( )
|
||||
|
||||
Save the asset edit form. Overridden to give a nice message when a photo or
|
||||
album is added
|
||||
|
||||
=cut
|
||||
|
||||
sub www_editSave {
|
||||
my $self = shift;
|
||||
my $form = $self->session->form;
|
||||
my $i18n = __PACKAGE__->i18n($self->session);
|
||||
$self->SUPER::www_editSave;
|
||||
|
||||
if ( $form->get("assetId") eq "new" ) {
|
||||
return sprintf $i18n->get("addFile message"), $self->getUrl,
|
||||
}
|
||||
else {
|
||||
return sprintf $i18n->get("save message"), $self->getUrl,
|
||||
}
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_showConfirmation ( )
|
||||
|
|
|
|||
|
|
@ -260,6 +260,32 @@ our $HELP = {
|
|||
],
|
||||
},
|
||||
|
||||
'help editComment' => {
|
||||
title => 'help editComment title',
|
||||
body => 'help editComment body',
|
||||
isa => [
|
||||
{
|
||||
tag => 'help common',
|
||||
namespace => 'Asset_Photo',
|
||||
},
|
||||
{
|
||||
tag => 'help commentForm',
|
||||
namespace => 'Asset_Photo',
|
||||
},
|
||||
],
|
||||
variables => [
|
||||
{
|
||||
name => 'errors',
|
||||
description => 'helpvar errors',
|
||||
variables => [
|
||||
{
|
||||
name => 'error',
|
||||
description => 'helpvar error',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -77,6 +77,16 @@ our $I18N = {
|
|||
lastUpdated => 0,
|
||||
context => '',
|
||||
},
|
||||
"richEditIdAlbum label" => {
|
||||
message => "Rich Editor for Albums",
|
||||
lastUpdated => 0,
|
||||
context => 'Asset property label',
|
||||
},
|
||||
"richEditIdAlbum description" => {
|
||||
message => "The Rich Text Editor to use for Albums",
|
||||
lastUpdated => 0,
|
||||
context => 'Asset property description',
|
||||
},
|
||||
"richEditIdFileComment label" => {
|
||||
message => "Rich Editor for Comments",
|
||||
lastUpdated => 0,
|
||||
|
|
@ -147,6 +157,16 @@ our $I18N = {
|
|||
lastUpdated => 0,
|
||||
context => '',
|
||||
},
|
||||
"templateIdEditComment label" => {
|
||||
message => "Template to Edit Comments",
|
||||
lastUpdated => 0,
|
||||
context => '',
|
||||
},
|
||||
"templateIdEditComment description" => {
|
||||
message => "The template to edit a comment.",
|
||||
lastUpdated => 0,
|
||||
context => '',
|
||||
},
|
||||
"templateIdEditFile label" => {
|
||||
message => "Template to Edit Files",
|
||||
lastUpdated => 0,
|
||||
|
|
|
|||
|
|
@ -21,6 +21,12 @@ our $I18N = {
|
|||
lastUpdated => 0,
|
||||
},
|
||||
|
||||
'editCommentSave message' => {
|
||||
message => q{The comment has been updated. <a href="%s">Back to Photo</a>.},
|
||||
lastUpdated => 0,
|
||||
context => q{Message after a comment is edited.},
|
||||
},
|
||||
|
||||
'help commentForm title' => {
|
||||
message => 'Photo -- Comment Form',
|
||||
lastUpdated => 0,
|
||||
|
|
@ -463,6 +469,48 @@ our $I18N = {
|
|||
context => 'Label for "save" button',
|
||||
},
|
||||
|
||||
'help editComment title' => {
|
||||
message => 'Photo Edit Comment Template',
|
||||
lastUpdated => 0,
|
||||
context => 'Help page title',
|
||||
},
|
||||
|
||||
'help editComment body' => {
|
||||
message => 'These variables are available to the Photo Edit Comment page',
|
||||
lastUpdated => 0,
|
||||
context => 'Help page body text',
|
||||
},
|
||||
|
||||
'helpvar errors' => {
|
||||
message => 'A loop of error messages to show the user',
|
||||
lastUpdated => 0,
|
||||
context => 'Description of template variable',
|
||||
},
|
||||
|
||||
'helpvar error' => {
|
||||
message => 'The i18n error message',
|
||||
lastUpdated => 0,
|
||||
context => 'Description of template variable',
|
||||
},
|
||||
|
||||
'template error happened' => {
|
||||
message => q{An error occurred while processing your request.},
|
||||
lastUpdated => 0,
|
||||
context => "Text shown when friendly error messages are being displayed",
|
||||
},
|
||||
|
||||
'commentForm error no commentId' => {
|
||||
message => q{No comment ID was given. This indicates a problem with the template. Please notify an administrator.},
|
||||
lastUpdated => 0,
|
||||
context => q{Error message when no comment ID was given. This should never happen unless the template is made wrong.},
|
||||
},
|
||||
|
||||
'commentForm error no bodyText' => {
|
||||
message => q{No text was entered. Please enter some text to create a comment.},
|
||||
lastUpdated => 0,
|
||||
context => q{Error message for Photo comments},
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ my @versionTags = ();
|
|||
push @versionTags, WebGUI::VersionTag->getWorking($session);
|
||||
$versionTags[-1]->set({name=>"Photo Test, add Gallery, Album and 1 Photo"});
|
||||
|
||||
my @addArguments = ( undef, undef, { skipAutoCommitWorkflows => 1 } );
|
||||
my $gallery
|
||||
= $node->addChild({
|
||||
className => "WebGUI::Asset::Wobject::Gallery",
|
||||
|
|
@ -39,21 +40,11 @@ my $gallery
|
|||
my $album
|
||||
= $gallery->addChild({
|
||||
className => "WebGUI::Asset::Wobject::GalleryAlbum",
|
||||
},
|
||||
undef,
|
||||
undef,
|
||||
{
|
||||
skipAutoCommitWorkflows => 1,
|
||||
});
|
||||
}, @addArguments );
|
||||
my $photo
|
||||
= $album->addChild({
|
||||
className => "WebGUI::Asset::File::Image::Photo",
|
||||
},
|
||||
undef,
|
||||
undef,
|
||||
{
|
||||
skipAutoCommitWorkflows => 1,
|
||||
});
|
||||
}, @addArguments );
|
||||
|
||||
$versionTags[-1]->commit;
|
||||
|
||||
|
|
@ -81,17 +72,12 @@ ok(
|
|||
);
|
||||
|
||||
ok(
|
||||
!eval{ $photo->setComment("new"); 1 },
|
||||
"Photo->setComment fails when no second argument given",
|
||||
!eval{ $photo->setComment("lulz"); 1 },
|
||||
"Photo->setComment fails when first argument is not a hashref",
|
||||
);
|
||||
|
||||
ok(
|
||||
!eval{ $photo->setComment("new", "lulz"); 1 },
|
||||
"Photo->setComment fails when second argument is not a hashref",
|
||||
);
|
||||
|
||||
ok(
|
||||
!eval{ $photo->setComment("new", { lulz => "ohai" }); 1 },
|
||||
!eval{ $photo->setComment({ lulz => "ohai" }); 1 },
|
||||
"Photo->setComment fails when hashref does not contain a bodyText key",
|
||||
);
|
||||
|
||||
|
|
@ -101,9 +87,10 @@ ok(
|
|||
# - All else is defaults
|
||||
my $commentId;
|
||||
ok(
|
||||
eval{ $commentId = $photo->setComment("new", { userId => 1, assetId => $photo->getId, bodyText => "bodyText", }); 1 },
|
||||
eval{ $commentId = $photo->setComment({ commentId => "new", userId => 1, bodyText => "bodyText", }); 1 },
|
||||
"Photo->setComment succeeds",
|
||||
);
|
||||
if ( $@ ) { diag $@; }
|
||||
|
||||
is_deeply(
|
||||
$photo->getCommentIds, [$commentId],
|
||||
|
|
@ -142,9 +129,10 @@ like(
|
|||
# - userId is visitor
|
||||
# - all else is defaults
|
||||
ok(
|
||||
eval{ $commentId = $photo->setComment("new", { userId => 1, bodyText => "bodyText", }); 1 },
|
||||
eval{ $commentId = $photo->setComment({ commentId => "new", userId => 1, bodyText => "bodyText", }); 1 },
|
||||
"Photo->setComment succeeds",
|
||||
);
|
||||
if ( $@ ) { diag $@; }
|
||||
|
||||
cmp_deeply(
|
||||
$photo->getCommentIds, superbagof( $commentId ),
|
||||
|
|
@ -156,6 +144,7 @@ ok(
|
|||
eval{ $comment = $photo->getComment($commentId); 1},
|
||||
"Photo->getComment does not croak.",
|
||||
);
|
||||
if ( $@ ) { diag $@; }
|
||||
|
||||
is(
|
||||
ref $comment, "HASH",
|
||||
|
|
@ -202,63 +191,67 @@ TODO: {
|
|||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test www_addCommentSave page sanity checks
|
||||
# Test www_editCommentSave page sanity checks
|
||||
my $html;
|
||||
$photo
|
||||
= $album->addChild({
|
||||
className => "WebGUI::Asset::File::Image::Photo",
|
||||
},
|
||||
undef,
|
||||
undef,
|
||||
{
|
||||
skipAutoCommitWorkflows => 1,
|
||||
});
|
||||
}, @addArguments );
|
||||
|
||||
# Permissions
|
||||
$html = WebGUI::Test->getPage($photo, "www_addCommentSave", {
|
||||
$html = WebGUI::Test->getPage($photo, "www_editCommentSave", {
|
||||
userId => 1,
|
||||
formParams => { bodyText => "yes?" },
|
||||
});
|
||||
|
||||
like(
|
||||
$html, qr/permission denied/i,
|
||||
"www_addCommentSave -- Permission denied if not Gallery->canAddComment",
|
||||
"www_editCommentSave -- Permission denied if not Gallery->canAddComment",
|
||||
);
|
||||
|
||||
my $i18n = $photo->i18n($session);
|
||||
my $i18n = $photo->i18n($session);
|
||||
my $errorMessage;
|
||||
|
||||
SKIP: {
|
||||
skip "www_addCommentSave needs to check for bodyText", 1;
|
||||
|
||||
# Required fields
|
||||
$html = WebGUI::Test->getPage($photo, "www_addCommentSave", {
|
||||
userId => 1,
|
||||
formParams => { },
|
||||
# Required: commentId
|
||||
$html = WebGUI::Test->getPage($photo, "www_editCommentSave", {
|
||||
userId => 3,
|
||||
formParams => { bodyText => "bodyText" },
|
||||
});
|
||||
|
||||
$errorMessage = $i18n->get("commentForm error no commentId");
|
||||
like(
|
||||
$html, $i18n->get("www_addCommentSave error missing required"),
|
||||
"www_addCommentSave -- Must have bodyText defined",
|
||||
$html, qr/$errorMessage/,
|
||||
"www_editCommentSave -- Must have commentId defined",
|
||||
);
|
||||
|
||||
}
|
||||
# Required: bodyText
|
||||
$html = WebGUI::Test->getPage($photo, "www_editCommentSave", {
|
||||
userId => 3,
|
||||
formParams => { commentId => "new" },
|
||||
});
|
||||
|
||||
$errorMessage = $i18n->get("commentForm error no bodyText");
|
||||
like(
|
||||
$html, qr/$errorMessage/,
|
||||
"www_editCommentSave -- Must have bodyText defined",
|
||||
);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test www_addCommentSave functionality
|
||||
$html = WebGUI::Test->getPage($photo, "www_addCommentSave", {
|
||||
# Test www_editCommentSave functionality
|
||||
$html = WebGUI::Test->getPage($photo, "www_editCommentSave", {
|
||||
userId => 3,
|
||||
formParams => { bodyText => "YES!", },
|
||||
formParams => { commentId => "new", bodyText => "YES!", },
|
||||
});
|
||||
my $successMessage = sprintf($i18n->get("comment message"), $photo->getUrl);
|
||||
like(
|
||||
$html, qr/$successMessage/,
|
||||
"www_addCommentSave -- page shows success message",
|
||||
"www_editCommentSave -- page shows success message",
|
||||
);
|
||||
|
||||
my $ids = $photo->getCommentIds;
|
||||
is(
|
||||
scalar @$ids, 1,
|
||||
"www_addCommentSave -- Comment was added",
|
||||
"www_editCommentSave -- Comment was added",
|
||||
);
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue