Really fix sorting numerically for resolutions. Added tests to check it.

This commit is contained in:
Colin Kuskie 2010-08-17 13:30:39 -07:00
parent eac7fe8a64
commit 80c906b8eb
2 changed files with 14 additions and 2 deletions

View file

@ -305,8 +305,14 @@ sub getResolutions {
my $self = shift;
my $storage = $self->getStorageLocation;
##Filter out the web view image and thumbnail files.
my @resolutions = grep { $_ ne $self->get("filename") } @{ $storage->getFiles };
# Return a list not including the web view image.
return [ sort { $a <=> $b } grep { $_ ne $self->get("filename") } @{ $storage->getFiles } ];
@resolutions = map { $_->[1] }
sort { $a->[0] <=> $b->[0] }
map { my $number = $_; $number =~ s/\.\w+$//; [ $number, $_ ] } @resolutions;
return \@resolutions;
}
#----------------------------------------------------------------------------

View file

@ -49,7 +49,7 @@ $album
#----------------------------------------------------------------------------
# Tests
plan tests => 13;
plan tests => 14;
#----------------------------------------------------------------------------
# makeResolutions gets default resolutions from a parent Photo Gallery asset
@ -79,6 +79,12 @@ cmp_deeply(
"makeResolutions makes all the required resolutions with the appropriate names.",
);
cmp_deeply(
$photo->getResolutions,
[qw/640.jpg 800.jpg 1024.jpg 1600.jpg/],
'getResolutions: sorts numerically'
);
TODO: {
local $TODO = 'Test to ensure the files are created with correct resolution and density';
}