more tests

This commit is contained in:
Doug Bell 2007-10-11 18:45:58 +00:00
parent 2accef7a9d
commit 983a725558
9 changed files with 678 additions and 47 deletions

View file

@ -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;

View file

@ -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",
);

View file

@ -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",
);

View 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

View 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" );