From 67272517ce463ae1649f2710b65fc0fe108d6af7 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 6a6d519c6..65f7e95ac 100644 --- a/lib/WebGUI/Asset/File/GalleryFile/Photo.pm +++ b/lib/WebGUI/Asset/File/GalleryFile/Photo.pm @@ -278,8 +278,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 7647d4d27..a558677ed 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 @@ -80,6 +80,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'; }