Test cleanup, and add extra tests for sanity checks.

This commit is contained in:
Colin Kuskie 2010-02-03 18:34:21 -08:00
parent 622a20877a
commit 4a240ba0e0

View file

@ -30,7 +30,7 @@ use WebGUI::Form::File;
use Test::More; # increment this value for each test you create use Test::More; # increment this value for each test you create
use Test::Deep; use Test::Deep;
plan tests => 11; plan tests => 13;
my $session = WebGUI::Test->session; my $session = WebGUI::Test->session;
@ -55,54 +55,50 @@ $session->user({userId=>3});
my $versionTag = WebGUI::VersionTag->getWorking($session); my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Image Asset test"}); $versionTag->set({name=>"Image Asset test"});
my $properties = { my $properties = {
# '1234567890123456789012' # '1234567890123456789012'
id => 'ImageAssetTest00000001', id => 'ImageAssetTest00000001',
title => 'Image Asset Test', title => 'Image Asset Test',
className => 'WebGUI::Asset::File::Image', className => 'WebGUI::Asset::File::Image',
url => 'image-asset-test', url => 'image-asset-test',
}; };
my $defaultAsset = WebGUI::Asset->getDefault($session); my $defaultAsset = WebGUI::Asset->getDefault($session);
my $asset = $defaultAsset->addChild($properties, $properties->{id}); my $asset = $defaultAsset->addChild($properties, $properties->{id});
ok($asset->getStorageLocation, 'Image Asset getStorageLocation initialized'); ok($asset->getStorageLocation, 'Image Asset getStorageLocation initialized');
ok($asset->get('storageId'), 'getStorageLocation updates Image asset object with storage location'); ok($asset->storageId, 'getStorageLocation updates Image asset object with storage location');
is($asset->get('storageId'), $asset->getStorageLocation->getId, 'Image Asset storageId and cached storageId agree'); is($asset->storageId, $asset->getStorageLocation->getId, 'Image Asset storageId and cached storageId agree');
$asset->update({ $asset->update({
storageId => $storage->getId, storageId => $storage->getId,
filename => 'blue.png', filename => 'blue.png',
}); });
my $filename = $asset->getStorageLocation->getPath . "/" . $asset->get("filename"); my $filename = $asset->getStorageLocation->getPath($asset->filename);
ok(-e $filename, 'file exists in the storage location for following tests');
my @stat_before = stat($filename); my @stat_before = stat($filename);
$asset->getStorageLocation->rotate($asset->get("filename"), 90); ok($asset->getStorageLocation->rotate($asset->filename, 90), 'rotate worked');
my @stat_after = stat($filename); my @stat_after = stat($filename);
is(isnt_array(\@stat_before, \@stat_after), 1, 'Image is different after rotation'); is(isnt_array(\@stat_before, \@stat_after), 1, 'Image is different after rotation');
@stat_before = stat($filename); @stat_before = stat($filename);
$asset->getStorageLocation->resize($asset->get("filename"), 200, 300); $asset->getStorageLocation->resize($asset->filename, 200, 300);
my @stat_after = stat($filename); my @stat_after = stat($filename);
is(isnt_array(\@stat_before, \@stat_after), 1, 'Image is different after resize'); is(isnt_array(\@stat_before, \@stat_after), 1, 'Image is different after resize');
@stat_before = stat($filename); @stat_before = stat($filename);
$asset->getStorageLocation->crop($asset->get("filename"), 100, 125, 10, 25); $asset->getStorageLocation->crop($asset->filename, 100, 125, 10, 25);
my @stat_after = stat($filename); my @stat_after = stat($filename);
is(isnt_array(\@stat_before, \@stat_after), 1, 'Image is different after crop'); is(isnt_array(\@stat_before, \@stat_after), 1, 'Image is different after crop');
my $sth = $session->db->read('describe ImageAsset annotations'); my $sth = $session->db->read('describe ImageAsset annotations');
isnt($sth->hashRef, undef, 'Annotations column is defined'); isnt($sth->hashRef, undef, 'Annotations column is defined');
is($storage->getId, $asset->get('storageId'), 'Asset updated with correct new storageId'); 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'); is($storage->getId, $asset->getStorageLocation->getId, 'Cached Asset storage location updated with correct new storageId');
$versionTag->commit; $versionTag->commit;
addToCleanup($versionTag);
END {
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') {
$versionTag->rollback;
}
}
sub isnt_array { sub isnt_array {
my ($a, $b) = @_; my ($a, $b) = @_;