Added more tests. Cleaned up the OO of File and Image a bit (removed a healthy bit of unnecessary code from Image). Done with File and Image for the time being...
This commit is contained in:
parent
fad056cfa5
commit
5746ded766
12 changed files with 523 additions and 119 deletions
|
|
@ -26,6 +26,8 @@ use Test::More; # increment this value for each test you create
|
|||
use Test::Deep;
|
||||
plan tests => 9;
|
||||
|
||||
#TODO: This script tests certain aspects of WebGUI::Storage and it should not
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
##Create a storage location
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../../../../lib";
|
||||
use lib "$FindBin::Bin/../../lib";
|
||||
|
||||
## The goal of this test is to test the creation and deletion of photo assets
|
||||
|
||||
|
|
@ -39,15 +39,25 @@ END {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
plan tests => 0;
|
||||
plan tests => 2;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# setFile allows file path argument and fails if can't find file
|
||||
# plan tests => 1
|
||||
ok(
|
||||
!eval { $file->setFile( WebGUI::Test->getTestCollateralPath("DOES_NOT_EXIST.NO") ); 1},
|
||||
"setFile allows file path argument and croaks if can't find file"
|
||||
);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# setFile allows filehandle argument, requires name argument and removes old
|
||||
# file
|
||||
|
||||
|
||||
# setFile allows file path argument and adds the file
|
||||
# plan tests => 1
|
||||
$file->setFile( WebGUI::Test->getTestCollateralPath("WebGUI.pm") );
|
||||
my $storage = $file->getStorageLocation;
|
||||
|
||||
is_deeply(
|
||||
$storage->getFiles, ['WebGUI.pm'],
|
||||
"Storage location contains only the file we added",
|
||||
);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -40,9 +40,23 @@ END {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
plan tests => 0;
|
||||
plan tests => 2;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# setFile allows file path argument and adds the file
|
||||
# setFile also generates thumbnail
|
||||
# plan tests => 2
|
||||
$image->setFile( WebGUI::Test->getTestCollateralPath("page_title.jpg") );
|
||||
my $storage = $image->getStorageLocation;
|
||||
|
||||
is_deeply(
|
||||
$storage->getFiles, ['page_title.jpg'],
|
||||
"Storage location contains only the file we added",
|
||||
);
|
||||
|
||||
# We must do a filesystem test because getFiles doesn't include 'thumb-'
|
||||
ok(
|
||||
-e $storage->getPath('thumb-page_title.jpg'),
|
||||
"Thumbnail file exists on the filesystem",
|
||||
);
|
||||
|
||||
|
|
|
|||
194
t/Asset/File/Image/Photo/000-makeResolutions.t
Normal file
194
t/Asset/File/Image/Photo/000-makeResolutions.t
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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 creation of photo download
|
||||
# resolutions
|
||||
|
||||
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 ($gallery, $album, $photo);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Cleanup
|
||||
END {
|
||||
$versionTag->rollback();
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Photo not added under a Photo Gallery asset does NOT generate any
|
||||
# default resolutions
|
||||
$photo
|
||||
= $node->addChild({
|
||||
className => "WebGUI::Asset::File::Image::Photo",
|
||||
});
|
||||
$photo->getStorageLocation->addFileFromFilesystem( WebGUI::Test->getTestCollateralPath('page_title.jpg') );
|
||||
|
||||
ok(
|
||||
eval{ $photo->makeResolutions(); 1 },
|
||||
"makeResolutions succeeds when photo not under photo gallery and no resolutions to make",
|
||||
);
|
||||
|
||||
is_deeply(
|
||||
$photo->getStorageLocation->getFiles, ['page_title.jpg'],
|
||||
"makeResolutions does not make any extra resolutions when photo not under photo gallery",
|
||||
);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# makeResolutions allows API to specify resolutions to make as array reference
|
||||
# argument
|
||||
$photo
|
||||
= $node->addChild({
|
||||
className => "WebGUI::Asset::File::Image::Photo",
|
||||
});
|
||||
$photo->getStorageLocation->addFileFromFilesystem( WebGUI::Test->getTestCollateralPath('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
|
||||
$photo
|
||||
= $node->addChild({
|
||||
className => "WebGUI::Asset::File::Image::Photo",
|
||||
});
|
||||
$photo->getStorageLocation->addFileFromFilesystem( WebGUI::Test->getTestCollateralPath('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",
|
||||
);
|
||||
|
||||
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",
|
||||
);
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# makeResolutions gets default resolutions from a parent Photo Gallery asset
|
||||
$gallery
|
||||
= $node->addChild({
|
||||
className => "WebGUI::Asset::Wobject::PhotoGallery",
|
||||
imageResolutions => "1600x1200\n1024x768\n800x600\n640x480",
|
||||
});
|
||||
$album
|
||||
= $gallery->addChild({
|
||||
className => "WebGUI::Asset::Wobject::PhotoAlbum",
|
||||
});
|
||||
$photo
|
||||
= $album->addChild({
|
||||
className => "WebGUI::Asset::File::Image::Photo",
|
||||
});
|
||||
$photo->getStorageLocation->addFileFromFilesystem( WebGUI::Test->getTestCollateralPath('page_title.jpg') );
|
||||
|
||||
ok(
|
||||
eval{ $photo->makeResolutions; 1 },
|
||||
"makeResolutions succeeds when photo under photo gallery and no resolution given",
|
||||
);
|
||||
|
||||
is_deeply(
|
||||
[ sort({ $a cmp $b} @{ $photo->getStorageLocation->getFiles }) ],
|
||||
[ '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
|
||||
$gallery
|
||||
= $node->addChild({
|
||||
className => "WebGUI::Asset::Wobject::PhotoGallery",
|
||||
imageResolutions => "1600x1200\n1024x768\n800x600\n640x480",
|
||||
});
|
||||
$album
|
||||
= $gallery->addChild({
|
||||
className => "WebGUI::Asset::Wobject::PhotoAlbum",
|
||||
});
|
||||
$photo
|
||||
= $album->addChild({
|
||||
className => "WebGUI::Asset::File::Image::Photo",
|
||||
});
|
||||
$photo->getStorageLocation->addFileFromFilesystem( WebGUI::Test->getTestCollateralPath('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';
|
||||
}
|
||||
|
||||
|
|
@ -26,8 +26,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",
|
||||
imageResolutions => "1024x768",
|
||||
});
|
||||
my $album
|
||||
= $gallery->addChild({
|
||||
className => "WebGUI::Asset::Wobject::PhotoAlbum",
|
||||
});
|
||||
my $photo
|
||||
= $album->addChild({
|
||||
className => "WebGUI::Asset::File::Image::Photo",
|
||||
});
|
||||
|
||||
|
|
@ -39,9 +48,21 @@ END {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
plan tests => 0;
|
||||
plan tests => 2;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# setFile also makes download versions
|
||||
$photo->setFile( WebGUI::Test->getTestCollateralPath('page_title.jpg') );
|
||||
my $storage = $photo->getStorageLocation;
|
||||
|
||||
is_deeply(
|
||||
$storage->getFiles, ['page_title.jpg'],
|
||||
"Storage location contains only the file we added",
|
||||
);
|
||||
|
||||
ok(
|
||||
-e $storage->getPath($gallery->get('imageResolutions') . '.jpg'),
|
||||
"Generated resolution file exists on the filesystem",
|
||||
);
|
||||
|
||||
|
||||
|
|
|
|||
48
t/Asset/File/Image/Photo/100-comment.t
Normal file
48
t/Asset/File/Image/Photo/100-comment.t
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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 adding, deleting, editing, and
|
||||
# getting comments for photos
|
||||
|
||||
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 $photo
|
||||
= $node->addChild({
|
||||
className => "WebGUI::Asset::File::Image::Photo",
|
||||
});
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Cleanup
|
||||
END {
|
||||
$versionTag->rollback();
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
plan tests => 0;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
#
|
||||
|
||||
|
||||
|
|
@ -40,12 +40,12 @@ END {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
plan tests => 2;
|
||||
plan tests => 3;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test module compiles okay
|
||||
# plan tests => 0
|
||||
BEGIN { use_ok("WebGUI::Asset::Shortcut"); }
|
||||
# plan tests => 1
|
||||
use_ok("WebGUI::Asset::Shortcut");
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test creating a shortcut to snippet
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue