From 80c906b8eb0ab954d0f3bbf7804a6392bcf01632 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 17 Aug 2010 13:30:39 -0700 Subject: [PATCH] Really fix sorting numerically for resolutions. Added tests to check it. --- lib/WebGUI/Asset/File/GalleryFile/Photo.pm | 8 +++++++- t/Asset/File/GalleryFile/Photo/makeResolutions.t | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/WebGUI/Asset/File/GalleryFile/Photo.pm b/lib/WebGUI/Asset/File/GalleryFile/Photo.pm index c26e6abfe..f14ae7e42 100644 --- a/lib/WebGUI/Asset/File/GalleryFile/Photo.pm +++ b/lib/WebGUI/Asset/File/GalleryFile/Photo.pm @@ -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; } #---------------------------------------------------------------------------- diff --git a/t/Asset/File/GalleryFile/Photo/makeResolutions.t b/t/Asset/File/GalleryFile/Photo/makeResolutions.t index a8d1d6861..0ef67aa5d 100644 --- a/t/Asset/File/GalleryFile/Photo/makeResolutions.t +++ b/t/Asset/File/GalleryFile/Photo/makeResolutions.t @@ -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'; }