Conflicts: docs/gotcha.txt lib/WebGUI.pm lib/WebGUI/Asset.pm lib/WebGUI/Asset/File/GalleryFile/Photo.pm lib/WebGUI/Asset/Post.pm lib/WebGUI/Asset/Story.pm lib/WebGUI/Asset/Template.pm lib/WebGUI/Asset/Wobject/Calendar.pm lib/WebGUI/Asset/Wobject/GalleryAlbum.pm lib/WebGUI/Asset/Wobject/Navigation.pm lib/WebGUI/AssetLineage.pm lib/WebGUI/AssetTrash.pm lib/WebGUI/Config.pm lib/WebGUI/Form/Template.pm lib/WebGUI/Group.pm lib/WebGUI/Inbox.pm lib/WebGUI/Workflow/Activity/DeleteExpiredSessions.pm lib/WebGUI/Workflow/Activity/TrashExpiredEvents.pm sbin/testEnvironment.pl t/AdSpace.t t/AdSpace/Ad.t t/Asset/Asset.t t/Asset/AssetExportHtml.t t/Asset/AssetLineage.t t/Asset/EMSSubmissionForm.t t/Asset/Event.t t/Asset/File/GalleryFile/Photo/00base.t t/Asset/File/GalleryFile/Photo/comment.t t/Asset/File/GalleryFile/Photo/download.t t/Asset/File/GalleryFile/Photo/edit.t t/Asset/File/GalleryFile/Photo/exif.t t/Asset/File/GalleryFile/Photo/makeResolutions.t t/Asset/File/GalleryFile/Photo/makeShortcut.t t/Asset/File/Image/setfile.t t/Asset/File/setfile.t t/Asset/Post.t t/Asset/Post/Thread/getAdjacentThread.t t/Asset/Sku.t t/Asset/Sku/ProductCollateral.t t/Asset/Story.t t/Asset/Template.t t/Asset/Template/HTMLTemplateExpr.t t/Asset/Wobject/Gallery/00base.t t/Asset/Wobject/GalleryAlbum/00base.t t/Asset/Wobject/GalleryAlbum/ajax.t t/Asset/Wobject/GalleryAlbum/delete.t t/Asset/Wobject/Matrix.t t/Asset/Wobject/StoryArchive.t t/Asset/Wobject/Survey/ExpressionEngine.t t/Asset/Wobject/Survey/Reports.t t/AssetAspect/RssFeed.t t/Auth/mech.t t/Config.t t/Group.t t/Help/isa.t t/International.t t/Mail/Send.t t/Operation/AdSpace.t t/Operation/Auth.t t/Pluggable.t t/Session.t t/Session/DateTime.t t/Session/ErrorHandler.t t/Session/Scratch.t t/Session/Stow.t t/Shop/Cart.t t/Shop/Pay.t t/Shop/PayDriver/ITransact.t t/Shop/PayDriver/PayPalStd.t t/Shop/Ship.t t/Shop/ShipDriver.t t/Shop/TaxDriver/EU.t t/Shop/TaxDriver/Generic.t t/Shop/Transaction.t t/Shop/Vendor.t t/VersionTag.t t/Workflow/Activity/ArchiveOldStories.t t/Workflow/Activity/ExpireIncompleteSurveyResponses.t t/lib/WebGUI/Test.pm
229 lines
7.1 KiB
Perl
229 lines
7.1 KiB
Perl
#-------------------------------------------------------------------
|
|
# 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 of photo download
|
|
# resolutions
|
|
|
|
use WebGUI::Test;
|
|
use WebGUI::Session;
|
|
use Test::More;
|
|
use Test::Deep;
|
|
use Image::Magick;
|
|
use WebGUI::Asset::File::GalleryFile::Photo;
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Init
|
|
my $session = WebGUI::Test->session;
|
|
my $node = WebGUI::Asset->getImportNode($session);
|
|
my @versionTags = ();
|
|
push @versionTags, WebGUI::VersionTag->getWorking($session);
|
|
$versionTags[-1]->set({name=>"Photo Test"});
|
|
WebGUI::Test->addToCleanup($versionTags[-1]);
|
|
|
|
my ($gallery, $album, $photo);
|
|
$gallery
|
|
= $node->addChild({
|
|
className => "WebGUI::Asset::Wobject::Gallery",
|
|
imageResolutions => "1600x1200\n1024x768\n800x600\n640x480",
|
|
});
|
|
$album
|
|
= $gallery->addChild({
|
|
className => "WebGUI::Asset::Wobject::GalleryAlbum",
|
|
},
|
|
undef,
|
|
undef,
|
|
{
|
|
skipAutoCommitWorkflows => 1,
|
|
});
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Tests
|
|
plan tests => 13;
|
|
|
|
#----------------------------------------------------------------------------
|
|
# makeResolutions gets default resolutions from a parent Photo Gallery asset
|
|
$photo
|
|
= $album->addChild({
|
|
className => "WebGUI::Asset::File::GalleryFile::Photo",
|
|
},
|
|
undef,
|
|
undef,
|
|
{
|
|
skipAutoCommitWorkflows => 1,
|
|
});
|
|
$versionTags[-1]->commit;
|
|
WebGUI::Test->addToCleanup($versionTags[-1]);
|
|
$photo->getStorageLocation->addFileFromFilesystem( WebGUI::Test->getTestCollateralPath('page_title.jpg') );
|
|
$photo->update({ filename => 'page_title.jpg' });
|
|
|
|
ok(
|
|
eval{ $photo->makeResolutions; 1 },
|
|
"makeResolutions succeeds when photo under photo gallery and no resolution given",
|
|
);
|
|
diag( $@ )
|
|
if $@;
|
|
|
|
cmp_deeply(
|
|
$photo->getStorageLocation->getFiles,
|
|
bag( '1024x768.jpg', '1600x1200.jpg', '640x480.jpg', '800x600.jpg', 'page_title.jpg' ),
|
|
"makeResolutions makes all the required resolutions with the appropriate names.",
|
|
);
|
|
|
|
TODO: {
|
|
local $TODO = 'Test to ensure the files are created with correct resolution and density';
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Array of resolutions passed to makeResolutions overrides defaults from
|
|
# parent asset
|
|
push @versionTags, WebGUI::VersionTag->getWorking($session);
|
|
WebGUI::Test->addToCleanup($versionTags[-1]);
|
|
$gallery
|
|
= $node->addChild({
|
|
className => "WebGUI::Asset::Wobject::Gallery",
|
|
imageResolutions => "1600x1200\n1024x768\n800x600\n640x480",
|
|
});
|
|
$album
|
|
= $gallery->addChild({
|
|
className => "WebGUI::Asset::Wobject::GalleryAlbum",
|
|
},
|
|
undef,
|
|
undef,
|
|
{
|
|
skipAutoCommitWorkflows => 1,
|
|
});
|
|
$photo
|
|
= $album->addChild({
|
|
className => "WebGUI::Asset::File::GalleryFile::Photo",
|
|
},
|
|
undef,
|
|
undef,
|
|
{
|
|
skipAutoCommitWorkflows => 1,
|
|
});
|
|
$versionTags[-1]->commit;
|
|
$photo->getStorageLocation->addFileFromFilesystem( WebGUI::Test->getTestCollateralPath('page_title.jpg') );
|
|
$photo->update({ filename => 'page_title.jpg' });
|
|
|
|
ok(
|
|
!eval{ $photo->makeResolutions('100x100','200x200'); 1 },
|
|
"makeResolutions fails when first argument is not array reference",
|
|
);
|
|
|
|
ok(
|
|
eval{ $photo->makeResolutions(['100x100','200x200']); 1 },
|
|
"makeResolutions succeeds when first argument is array reference of resolutions to make",
|
|
);
|
|
diag( $@ )
|
|
if $@;
|
|
|
|
is_deeply(
|
|
[ sort({ $a cmp $b} @{ $photo->getStorageLocation->getFiles }) ],
|
|
['100x100.jpg', '200x200.jpg', 'page_title.jpg'],
|
|
"makeResolutions makes all the required resolutions with the appropriate names.",
|
|
);
|
|
|
|
TODO: {
|
|
local $TODO = 'Test to ensure the files are created with correct resolution and density';
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
# makeResolutions allows API to specify resolutions to make as array reference
|
|
# argument
|
|
push @versionTags, WebGUI::VersionTag->getWorking($session);
|
|
WebGUI::Test->addToCleanup($versionTags[-1]);
|
|
$photo
|
|
= $album->addChild({
|
|
className => "WebGUI::Asset::File::GalleryFile::Photo",
|
|
},
|
|
undef,
|
|
undef,
|
|
{
|
|
skipAutoCommitWorkflows => 1,
|
|
});
|
|
$versionTags[-1]->commit;
|
|
|
|
$photo->getStorageLocation->addFileFromFilesystem( WebGUI::Test->getTestCollateralPath('page_title.jpg') );
|
|
$photo->update({ filename => 'page_title.jpg' });
|
|
|
|
ok(
|
|
!eval{ $photo->makeResolutions('100x100','200x200'); 1 },
|
|
"makeResolutions fails when first argument is not array reference",
|
|
);
|
|
|
|
ok(
|
|
eval{ $photo->makeResolutions(['100x100','200x200']); 1 },
|
|
"makeResolutions succeeds when first argument is array reference of resolutions to make",
|
|
);
|
|
|
|
is_deeply(
|
|
[ sort({ $a cmp $b} @{ $photo->getStorageLocation->getFiles }) ],
|
|
['100x100.jpg', '200x200.jpg', 'page_title.jpg'],
|
|
"makeResolutions makes all the required resolutions with the appropriate names.",
|
|
);
|
|
|
|
TODO: {
|
|
local $TODO = 'Test to ensure the files are created with correct resolution and density';
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
# makeResolutions throws a warning on an invalid resolution but keeps going
|
|
push @versionTags, WebGUI::VersionTag->getWorking($session);
|
|
WebGUI::Test->addToCleanup($versionTags[-1]);
|
|
$photo
|
|
= $album->addChild({
|
|
className => "WebGUI::Asset::File::GalleryFile::Photo",
|
|
},
|
|
undef,
|
|
undef,
|
|
{
|
|
skipAutoCommitWorkflows => 1,
|
|
});
|
|
$versionTags[-1]->commit;
|
|
$photo->getStorageLocation->addFileFromFilesystem( WebGUI::Test->getTestCollateralPath('page_title.jpg') );
|
|
$photo->update({ filename => 'page_title.jpg' });
|
|
{ # localize our signal handler
|
|
my @warnings;
|
|
local $SIG{__WARN__} = sub { push @warnings, $_[0]; };
|
|
|
|
ok(
|
|
eval{ $photo->makeResolutions(['abc','200','3d400']); 1 },
|
|
"makeResolutions succeeds when invalid resolutions are given",
|
|
);
|
|
diag( $@ )
|
|
if $@;
|
|
|
|
is(
|
|
scalar @warnings, 2,
|
|
"makeResolutions throws a warning for each invalid resolution given",
|
|
);
|
|
|
|
like(
|
|
$warnings[0], qr/abc/,
|
|
"makeResolutions throws a warning for the correct invalid resolution 'abc'",
|
|
);
|
|
|
|
like(
|
|
$warnings[1], qr/3d400/,
|
|
"makeResolutions throws a warning for the correct invalid resolution '3d400'",
|
|
);
|
|
|
|
is_deeply(
|
|
[ sort({ $a cmp $b} @{ $photo->getStorageLocation->getFiles }) ],
|
|
['200.jpg', 'page_title.jpg'],
|
|
"makeResolutions still makes valid resolutions when invalid resolutions given",
|
|
);
|
|
}
|
|
|
|
#vim:ft=perl
|