Merge branch 'master' into WebGUI8

This commit is contained in:
Graham Knop 2010-04-13 07:50:02 -05:00
commit 2400f19099
797 changed files with 33894 additions and 27196 deletions

View file

@ -0,0 +1,108 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 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 photo assets
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"});
addToCleanup($versionTag);
# Create gallery and a single album
my $gallery
= $node->addChild({
className => "WebGUI::Asset::Wobject::Gallery",
},
undef,
undef,
{
skipAutoCommitWorkflows => 1,
});
my $album
= $gallery->addChild({
className => "WebGUI::Asset::Wobject::GalleryAlbum",
},
undef,
undef,
{
skipAutoCommitWorkflows => 1,
});
# Create 5 photos inside the gallery
my @photo;
for (my $i = 0; $i < 5; $i++)
{
$photo[$i]
= $album->addChild({
className => "WebGUI::Asset::File::GalleryFile::Photo",
},
undef,
undef,
{
skipAutoCommitWorkflows => 1,
});
}
# Commit all changes
$versionTag->commit;
#----------------------------------------------------------------------------
# Tests
plan tests => 11;
#----------------------------------------------------------------------------
# Test module compiles okay
# plan tests => 1
use_ok("WebGUI::Asset::File::GalleryFile::Photo");
#----------------------------------------------------------------------------
# Test getFirstFile method
note('getFirstFile');
is( $photo[2]->getFirstFile->getId, $photo[0]->getId, 'First file is photo no. 1' );
is( $photo[0]->getFirstFile->getId, $photo[0]->getId, 'First file is still photo no. 1' );
#----------------------------------------------------------------------------
# Test getFirstFile method
note('getLastFile');
is( $photo[2]->getLastFile->getId, $photo[4]->getId, 'Last file is photo no. 5' );
is( $photo[4]->getLastFile->getId, $photo[4]->getId, 'Last file is still photo no. 5' );
#----------------------------------------------------------------------------
# Test getPreviousFile method
note('getPreviousFile');
is( $photo[2]->getPreviousFile->getId, $photo[1]->getId, 'Photo previous of photo no. 3 is photo no. 2' );
is( $photo[1]->getPreviousFile->getId, $photo[0]->getId, 'Photo previous of photo no. 2 is photo no. 1' );
is( $photo[0]->getPreviousFile, undef, 'Photo previous of photo no. 1 is undef' );
#----------------------------------------------------------------------------
# Test getNextFile method
note('getNextFile');
is( $photo[2]->getNextFile->getId, $photo[3]->getId, 'Photo next of photo no. 3 is photo no. 4' );
is( $photo[3]->getNextFile->getId, $photo[4]->getId, 'Photo next of photo no. 4 is photo no. 5' );
is( $photo[4]->getNextFile, undef, 'Photo next of photo no. 5 is undef' );

View file

@ -27,10 +27,9 @@ my $node = WebGUI::Asset->getImportNode($session);
my $maker = WebGUI::Test::Maker::Permission->new;
$session->user({ userId => 3 });
my @versionTags = ();
push @versionTags, WebGUI::VersionTag->getWorking($session);
$versionTags[-1]->set({name=>"Photo Test, add Gallery, Album and 1 Photo"});
WebGUI::Test->tagsToRollback(@versionTags);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Photo Test, add Gallery, Album and 1 Photo"});
WebGUI::Test->tagsToRollback($versionTag);
# Add a new user to the test user's friends list
my $friend = WebGUI::User->new($session, "new");
@ -73,7 +72,19 @@ my $photo
{
skipAutoCommitWorkflows => 1,
});
$versionTags[-1]->commit;
my $photo2 = $photo->cloneFromDb;
my $album2 = $album->cloneFromDb;
$session->stow->delete('assetRevision');
$versionTag->leaveTag;
$session->user({userId => $notFriend->userId});
note "If you get stuck here, then there is an infinite loop in getParent/getGallery";
my $album2a = WebGUI::Asset->new($session, $photo2->getId);
$session->user({userId => 1});
$versionTag->commit;
#----------------------------------------------------------------------------
# Tests

View file

@ -42,6 +42,16 @@ my $album
{
skipAutoCommitWorkflows => 1,
});
my $previousPhoto
= $album->addChild({
className => "WebGUI::Asset::File::GalleryFile::Photo",
ownerUserId => 3,
},
undef,
undef,
{
skipAutoCommitWorkflows => 1,
});
my $photo
= $album->addChild({
className => "WebGUI::Asset::File::GalleryFile::Photo",
@ -52,6 +62,16 @@ my $photo
{
skipAutoCommitWorkflows => 1,
});
my $nextPhoto
= $album->addChild({
className => "WebGUI::Asset::File::GalleryFile::Photo",
ownerUserId => 3,
},
undef,
undef,
{
skipAutoCommitWorkflows => 1,
});
$versionTag->commit;
$photo->setFile( WebGUI::Test->getTestCollateralPath('page_title.jpg') );
@ -87,7 +107,23 @@ my $testTemplateVars = {
numberOfComments => scalar @{ $photo->getCommentIds },
exifLoop => ignore(), # Tested elsewhere
isPending => ( $photo->get("status") eq "pending" ),
firstFile_url => $previousPhoto->getUrl,
firstFile_thumbnailUrl
=> $previousPhoto->getThumbnailUrl,
firstFile_title => $previousPhoto->get("title"),
previousFile_url => $previousPhoto->getUrl,
previousFile_thumbnailUrl
=> $previousPhoto->getThumbnailUrl,
previousFile_title => $previousPhoto->get("title"),
nextFile_url => $nextPhoto->getUrl,
nextFile_thumbnailUrl
=> $nextPhoto->getThumbnailUrl,
nextFile_title => $nextPhoto->get("title"),
firstFile_title => $previousPhoto->get("title"),
lastFile_url => $nextPhoto->getUrl,
lastFile_thumbnailUrl
=> $nextPhoto->getThumbnailUrl,
lastFile_title => $nextPhoto->get("title"),
};
# Ignore all EXIF tags, they're tested in exif.t

View file

@ -13,6 +13,7 @@ use strict;
use lib "$FindBin::Bin/../../lib";
use Test::MockObject;
use Test::MockObject::Extends;
my $mocker;
BEGIN {
$mocker = Test::MockObject->new();
@ -20,7 +21,6 @@ BEGIN {
$mocker->fake_new('WebGUI::Form::Image');
}
use File::Copy;
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Image;
@ -30,7 +30,8 @@ use WebGUI::Form::File;
use Test::More; # increment this value for each test you create
use Test::Deep;
plan tests => 13;
use Data::Dumper;
plan tests => 15;
my $session = WebGUI::Test->session;
@ -39,7 +40,7 @@ $rectangle->setBackgroundColor('#0000FF');
##Create a storage location
my $storage = WebGUI::Storage->create($session);
WebGUI::Test->storagesToDelete($storage);
addToCleanup($storage);
##Save the image to the location
$rectangle->saveToStorageLocation($storage, 'blue.png');
@ -73,8 +74,10 @@ $asset->update({
filename => 'blue.png',
});
my $filename = $asset->getStorageLocation->getPath($asset->filename);
ok(-e $filename, 'file exists in the storage location for following tests');
is($storage->getId, $asset->storageId, 'Asset updated with correct new storageId');
is($storage->getId, $asset->getStorageLocation->getId, 'Cached Asset storage location updated with correct new storageId');
my $filename = $asset->getStorageLocation->getPath . "/" . $asset->filename;
my @stat_before = stat($filename);
ok($asset->getStorageLocation->rotate($asset->filename, 90), 'rotate worked');
@ -94,8 +97,30 @@ is(isnt_array(\@stat_before, \@stat_after), 1, 'Image is different after crop');
my $sth = $session->db->read('describe ImageAsset annotations');
isnt($sth->hashRef, undef, 'Annotations column is defined');
is($storage->getId, $asset->storageId, 'Asset updated with correct new storageId');
is($storage->getId, $asset->getStorageLocation->getId, 'Cached Asset storage location updated with correct new storageId');
#------------------------------------------------------------------------------
# Template variables
my $templateId = 'FILE_IMAGE_TEMPLATE___';
my $templateMock = Test::MockObject->new({});
$templateMock->set_isa('WebGUI::Asset::Template');
$templateMock->set_always('getId', $templateId);
$templateMock->set_true('prepare');
my $templateVars;
$templateMock->mock('process', sub { $templateVars = $_[1]; } );
$asset->update({
parameters => 'alt="alternate"',
templateId => $templateId,
});
{
WebGUI::Test->mockAssetId($templateId, $templateMock);
$asset->prepareView();
$asset->view();
like($templateVars->{parameters}, qr{ id="[^"]{22}"}, 'id in parameters is quoted');
like($templateVars->{parameters}, qr{alt="alternate"}, 'original parameters included');
WebGUI::Test->unmockAssetId($templateId);
}
$versionTag->commit;
addToCleanup($versionTag);