more tests
This commit is contained in:
parent
2accef7a9d
commit
983a725558
9 changed files with 678 additions and 47 deletions
|
|
@ -389,6 +389,7 @@ sub setFile {
|
|||
# NOTE: We should not croak here, the WebGUI::Storage should croak for us.
|
||||
|
||||
$self->updatePropertiesFromStorage;
|
||||
$self->applyConstraints;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
189
lib/WebGUI/Asset/File/Image/Photo.pm
Normal file
189
lib/WebGUI/Asset/File/Image/Photo.pm
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
package WebGUI::Asset::File::Image::Photo;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
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
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use Tie::IxHash;
|
||||
use base 'WebGUI::Asset::File::Image';
|
||||
use WebGUI::Utility;
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
WebGUI::Asset::File::Image::Photo
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use WebGUI::Asset::File::Image::Photo
|
||||
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
These methods are available from this class:
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( session, definition )
|
||||
|
||||
defines asset properties for New Asset instances. You absolutely need
|
||||
this method in your new Assets.
|
||||
|
||||
=head3 session
|
||||
|
||||
=head3 definition
|
||||
|
||||
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);
|
||||
|
||||
tie my %properties, 'Tie::IxHash', (
|
||||
|
||||
|
||||
);
|
||||
|
||||
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 i18n ( [ session ] )
|
||||
|
||||
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.
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 processPropertiesFromFormPost ( )
|
||||
|
||||
Used to process properties from the form posted. Do custom things with
|
||||
noFormPost fields here, or do whatever you want. This method is called
|
||||
when /yourAssetUrl?func=editSave is requested/posted.
|
||||
|
||||
=cut
|
||||
|
||||
sub processPropertiesFromFormPost {
|
||||
my $self = shift;
|
||||
$self->SUPER::processPropertiesFromFormPost;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=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.
|
||||
|
||||
=cut
|
||||
|
||||
sub purge {
|
||||
my $self = shift;
|
||||
return $self->SUPER::purge;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=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.
|
||||
|
||||
=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});
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_edit ( )
|
||||
|
||||
Web facing method which is the default edit page
|
||||
|
||||
=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"));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_view ( )
|
||||
|
||||
Web facing method which is the default view page. This method does a
|
||||
302 redirect to the "showPage" file in the storage location.
|
||||
|
||||
=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 "";
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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 correct function of the editSave and
|
||||
# processPropertiesFromFormPost methods
|
||||
|
||||
use Scalar::Util qw( blessed );
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use Test::More;
|
||||
use WebGUI::Asset::File;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
my $node = WebGUI::Asset->getImportNode($session);
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||
$versionTag->set({name=>"File Test"});
|
||||
my $file
|
||||
= $node->addChild({
|
||||
className => "WebGUI::Asset::File",
|
||||
});
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Cleanup
|
||||
END {
|
||||
$versionTag->rollback();
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
plan tests => 0;
|
||||
|
|
@ -43,7 +43,6 @@ use_ok("WebGUI::Asset::File::Image::Photo");
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test creating a photo
|
||||
# plan tests => 2
|
||||
my $photo
|
||||
= $node->addChild({
|
||||
className => "WebGUI::Asset::File::Image::Photo",
|
||||
|
|
@ -58,9 +57,13 @@ 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
|
||||
# plan tests => 2
|
||||
my $properties = $photo->get;
|
||||
$photo->purge;
|
||||
|
||||
|
|
@ -74,3 +77,31 @@ is(
|
|||
"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",
|
||||
});
|
||||
|
||||
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(
|
||||
blessed $photo->getGallery, "WebGUI::Asset::Wobject::PhotoGallery",
|
||||
"Photo->getGallery gets the gallery containing this photo",
|
||||
);
|
||||
|
|
@ -27,8 +27,17 @@ my $session = WebGUI::Test->session;
|
|||
my $node = WebGUI::Asset->getImportNode($session);
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||
$versionTag->set({name=>"Photo Test"});
|
||||
my $photo
|
||||
my $gallery
|
||||
= $node->addChild({
|
||||
className => "WebGUI::Asset::Wobject::PhotoGallery",
|
||||
groupIdAddComment => "2",
|
||||
});
|
||||
my $album
|
||||
= $gallery->addChild({
|
||||
className => "WebGUI::Asset::Wobject::PhotoAlbum",
|
||||
});
|
||||
my $photo
|
||||
= $album->addChild({
|
||||
className => "WebGUI::Asset::File::Image::Photo",
|
||||
});
|
||||
|
||||
|
|
@ -43,6 +52,199 @@ END {
|
|||
plan tests => 0;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
#
|
||||
# Test with no comments
|
||||
is(
|
||||
blessed $photo->getCommentPaginator, "WebGUI::Paginator",
|
||||
"Photo with no comments still provides comments paginator",
|
||||
);
|
||||
|
||||
is_deeply(
|
||||
$photo->getCommentIds, [],
|
||||
"Photo->getCommentIds returns an empty arrayref when no comments",
|
||||
);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test the setComment requires two arguments
|
||||
ok(
|
||||
!eval{ $photo->setComment(); 1 },
|
||||
"Photo->setComment fails when no arguments given",
|
||||
);
|
||||
|
||||
ok(
|
||||
!eval{ $photo->setComment("new"); 1 },
|
||||
"Photo->setComment fails when no second argument given",
|
||||
);
|
||||
|
||||
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 },
|
||||
"Photo->setComment fails when hashref does not contain a bodyText key",
|
||||
);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test adding a comment
|
||||
# - bodyText is defined
|
||||
# - All else is defaults
|
||||
my $commentId;
|
||||
ok(
|
||||
eval{ $commentId = $photo->setComment("new", { bodyText => "bodyText", }); 1 },
|
||||
"Photo->setComment succeeds",
|
||||
);
|
||||
|
||||
is_deeply(
|
||||
$photo->getCommentIds, [$commentId],
|
||||
"Photo->getCommentIds returns newly added comment's ID",
|
||||
);
|
||||
|
||||
my $comment;
|
||||
ok(
|
||||
eval{ $comment = $photo->getComment($commentId); 1},
|
||||
"Photo->getComment does not croak.",
|
||||
);
|
||||
|
||||
is(
|
||||
ref $comment, "HASH",
|
||||
"Photo->getComment returns a hash reference",
|
||||
);
|
||||
|
||||
is(
|
||||
$comment->{assetId}, $photo->getId,
|
||||
"Comment has correct assetId",
|
||||
);
|
||||
|
||||
is(
|
||||
$comment->{userId}, $session->user->userId,
|
||||
"Comment has correct userId",
|
||||
);
|
||||
|
||||
is(
|
||||
$comment->{visitorIp}, undef,
|
||||
"visitorIp is not defined if the user is not a visitor",
|
||||
);
|
||||
|
||||
like(
|
||||
$comment->{creationDate}, /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/,
|
||||
"creationDate is defined and is a MySQL-formatted date",
|
||||
);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test adding a comment
|
||||
# - bodyText is defined
|
||||
# - userId is visitor
|
||||
# - all else is defaults
|
||||
ok(
|
||||
eval{ $commentId = $photo->setComment("new", { userId => 1, bodyText => "bodyText", }); 1 },
|
||||
"Photo->setComment succeeds",
|
||||
);
|
||||
|
||||
ok(
|
||||
grep { $_ eq $commentId } @{ $photo->getCommentIds },
|
||||
"Photo->getCommentIds returns newly added comment's ID",
|
||||
);
|
||||
|
||||
my $comment;
|
||||
ok(
|
||||
eval{ $comment = $photo->getComment($commentId); 1},
|
||||
"Photo->getComment does not croak.",
|
||||
);
|
||||
|
||||
is(
|
||||
ref $comment, "HASH",
|
||||
"Photo->getComment returns a hash reference",
|
||||
);
|
||||
|
||||
is(
|
||||
$comment->{assetId}, $photo->getId,
|
||||
"Comment has correct assetId",
|
||||
);
|
||||
|
||||
is(
|
||||
$comment->{userId}, 1,
|
||||
"Comment has correct userId",
|
||||
);
|
||||
|
||||
ok(
|
||||
$comment->{visitorIp},
|
||||
"visitorIp is defined since user is visitor",
|
||||
);
|
||||
|
||||
like(
|
||||
$comment->{creationDate}, /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/,
|
||||
"creationDate is defined and is a MySQL-formatted date",
|
||||
);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test deleting comment
|
||||
$photo->deleteComment($commentId);
|
||||
ok(
|
||||
!grep { $_ eq $commentId } @{ $photo->getCommentIds },
|
||||
"Photo->getCommentIds no longer contains deleted comment",
|
||||
);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test deleting asset deletes comments
|
||||
my $assetId = $photo->getId;
|
||||
$photo->purge;
|
||||
ok(
|
||||
!$session->db->quickScalar("SELECT commentId FROM Photo_comment WHERE assetId=?",[$assetId]),
|
||||
"Comments are purged along with asset",
|
||||
);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test appendTemplateVarsForCommentForm
|
||||
TODO: {
|
||||
local $TODO = "Test appendTemplateVarsForCommentForm";
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test www_addCommentSave page sanity checks
|
||||
my $html;
|
||||
$photo
|
||||
= $album->addChild({
|
||||
className => "WebGUI::Asset::File::Image::Photo",
|
||||
});
|
||||
|
||||
# Permissions
|
||||
$html = WebGUI::Test->getPage($photo, "www_addCommentSave", {
|
||||
userId => 1,
|
||||
formParams => { bodyText => "yes?" },
|
||||
});
|
||||
|
||||
like(
|
||||
$html, qr/permission denied/i,
|
||||
"www_addCommentSave -- Permission denied if not Gallery->canAddComment",
|
||||
);
|
||||
|
||||
# Required fields
|
||||
$html = WebGUI::Test->getPage($photo, "www_addCommentSave", {
|
||||
userId => 2,
|
||||
formParams => { },
|
||||
});
|
||||
|
||||
like(
|
||||
$html, WebGUI::International->get($session, "Asset_Photo", "www_addCommentSave error missing required"),
|
||||
"www_addCommentSave -- Must have bodyText defined",
|
||||
);
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test www_addCommentSave functionality
|
||||
$html = WebGUI::Test->getPage($photo, "www_addCommentSave", {
|
||||
userId => 2,
|
||||
formParams => { bodyText => "YES!", },
|
||||
});
|
||||
|
||||
like(
|
||||
$html, WebGUI::International->get($session, "Asset_Photo", "www_addCommentSave success"),
|
||||
"www_addCommentSave -- page shows success message",
|
||||
);
|
||||
|
||||
my $ids = $photo->getCommentIds;
|
||||
is(
|
||||
scalar @$ids, 1,
|
||||
"www_addCommentSave -- Comment was added",
|
||||
);
|
||||
|
|
|
|||
122
t/Asset/File/Image/Photo/makeShortcut.t
Normal file
122
t/Asset/File/Image/Photo/makeShortcut.t
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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 makeShortcut method and www_makeShortcut
|
||||
# pages
|
||||
|
||||
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 $otherParent
|
||||
= $node->addChild({
|
||||
className => "WebGUI::Asset::Wobject::Layout",
|
||||
});
|
||||
my $photo
|
||||
= $node->addChild({
|
||||
className => "WebGUI::Asset::File::Image::Photo",
|
||||
userDefined1 => "ORIGINAL",
|
||||
});
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Cleanup
|
||||
END {
|
||||
$versionTag->rollback();
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
plan tests => 0;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# makeShortcut argument checking
|
||||
ok(
|
||||
!eval{ $photo->makeShortcut(); 1 },
|
||||
"Photo->makeShortcut requires at least one argument",
|
||||
);
|
||||
|
||||
ok(
|
||||
!eval{ $photo->makeShortcut("", ""); 1},
|
||||
"Photo->makeShortcut fails if second argument is not hash reference",
|
||||
);
|
||||
|
||||
ok(
|
||||
!eval{ $photo->makeShortcut(""); 1},
|
||||
"Photo->makeShortcut fails if given parent cannot be instanciated",
|
||||
);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# makeShortcut returns a reference to the new Shortcut asset
|
||||
my $shortcut;
|
||||
ok(
|
||||
eval{ $shortcut = $photo->makeShortcut($otherParent->getId); 1},
|
||||
"Photo->makeShortcut succeeds when valid assetId is given",
|
||||
);
|
||||
|
||||
is(
|
||||
blessed $shortcut, "WebGUI::Asset::Shortcut",
|
||||
"Photo->makeShortcut returns a WebGUI::Shortcut asset",
|
||||
);
|
||||
|
||||
is(
|
||||
$shortcut->getShortcutOriginal->getId, $photo->getId,
|
||||
"Photo->makeShortcut makes a shortcut to the correct asset",
|
||||
);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# makeShortcut creates the appropriate overrides
|
||||
my $overrides = {
|
||||
userDefined1 => "OVERRIDDEN",
|
||||
};
|
||||
ok(
|
||||
eval{ $shortcut = $photo->makeShortcut($otherParent->getId, $overrides); 1},
|
||||
"Photo->makeShortcut succeeds when valid assetId is given",
|
||||
);
|
||||
|
||||
is(
|
||||
blessed $shortcut, "WebGUI::Asset::Shortcut",
|
||||
"Photo->makeShortcut returns a WebGUI::Shortcut asset",
|
||||
);
|
||||
|
||||
is(
|
||||
$shortcut->getShortcutOriginal->getId, $photo->getId,
|
||||
"Photo->makeShortcut makes a shortcut to the correct asset",
|
||||
);
|
||||
|
||||
is_deeply(
|
||||
{$shortcut->getShortcutOverrides}, $overrides,
|
||||
"Photo->makeShortcut makes a shortcut with the correct overrides",
|
||||
);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# www_makeShortcut is only available to those who can edit the photo
|
||||
my $html = WebGUI::Test->getPage($photo, "www_makeShortcut", {
|
||||
userId => 1,
|
||||
});
|
||||
|
||||
like(
|
||||
$html, qr/permission denied/i,
|
||||
"www_makeShortcut is not allowed to those who can't edit the photo",
|
||||
);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# www_makeShortcut
|
||||
129
t/Asset/File/Image/Photo/permissions.t
Normal file
129
t/Asset/File/Image/Photo/permissions.t
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
# Test permissions of Photo assets
|
||||
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../../../../lib";
|
||||
|
||||
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=>"Photo Test"});
|
||||
my ($photo);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Cleanup
|
||||
END {
|
||||
$versionTag->rollback();
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
plan tests => 0;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Photo assets outside of Gallery assets
|
||||
|
||||
# Everyone can view, Admins can edit, Owned by current user
|
||||
$photo
|
||||
= $node->addChild({
|
||||
className => "WebGUI::Asset::File::Image::Photo",
|
||||
groupIdView => "7",
|
||||
groupIdEdit => "3",
|
||||
ownerUserId => $session->user->userId,
|
||||
});
|
||||
|
||||
ok( $photo->canView(1), "Visitor can view" );
|
||||
ok( !$photo->canEdit(1), "Visitor cannot edit" );
|
||||
ok( $photo->canView(2), "Registered users can view" );
|
||||
ok( !$photo->canEdit(2), "Registered users cannot edit" );
|
||||
ok( $photo->canView, "Current user can view" );
|
||||
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") );
|
||||
$photo
|
||||
= $node->addChild({
|
||||
className => "WebGUI::Asset::File::Image::Photo",
|
||||
groupIdView => "3",
|
||||
groupIdEdit => "3",
|
||||
ownerUserId => "3",
|
||||
});
|
||||
|
||||
ok( !$photo->canView, "Visitors cannot view" );
|
||||
ok( !$photo->canEdit, "Visitors cannot edit" );
|
||||
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,
|
||||
});
|
||||
|
||||
# Photo without specific view/edit inherits from gallery properties
|
||||
$photo
|
||||
= $album->addChild({
|
||||
className => "WebGUI::Asset::File::Image::Photo",
|
||||
groupIdView => "",
|
||||
groupIdEdit => "",
|
||||
ownerUserId => $session->user->userId,
|
||||
});
|
||||
|
||||
ok( $photo->canView(1), "Visitors can view" );
|
||||
ok( !$photo->canEdit(1), "Visitors cannot edit" );
|
||||
ok( $photo->canView(2), "Registered Users can view" );
|
||||
ok( !$photo->canEdit(2), "Registered Users cannot edit" );
|
||||
ok( $photo->canView, "Owner can view" );
|
||||
ok( $photo->canEdit, "Owner can edit" );
|
||||
ok( $photo->canView(3), "Admin can view" );
|
||||
ok( $photo->canEdit(3), "Admin can edit" );
|
||||
|
||||
# Photo with specific view uses that instead (friends lists)
|
||||
$photo
|
||||
= $album->addChild({
|
||||
className => "WebGUI::Asset::File::Image::Photo",
|
||||
groupIdView => "3",
|
||||
groupIdEdit => "",
|
||||
ownerUserId => $session->user->userId,
|
||||
});
|
||||
|
||||
ok( !$photo->canView(1), "Visitors cannot view" );
|
||||
ok( !$photo->canEdit(1), "Visitors cannot edit" );
|
||||
ok( !$photo->canView(2), "Registered Users cannot view" );
|
||||
ok( !$photo->canEdit(2), "Registered Users cannot edit" );
|
||||
ok( $photo->canView, "Owner can view" );
|
||||
ok( $photo->canEdit, "Owner can edit" );
|
||||
ok( $photo->canView(3), "Admin can view" );
|
||||
ok( $photo->canEdit(3), "Admin can edit" );
|
||||
Loading…
Add table
Add a link
Reference in a new issue