From 6343f648e17670349be6f93651a69a7d2f1e4202 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 8 Dec 2006 17:40:09 +0000 Subject: [PATCH] Fixed the failing FileUrl test and clearly document where the FileUrl macro will work and where it will not. This test failed due to an API change in WebGUI. Before 7.3, if you created a Storage object and then created an Asset with that Storage Id, then WebGUI would do that happily. This is actually a bug, because you could create multiple Assets with that one Storage Id, and when _any_ of the Assets was deleted or rolled back it would delete the Storage location and leave the other Assets with that Id pointing to an empty Storage object. So the API change is actually a bug fix, albeit being a side-effect of the auto-commit work for posts and wikis. --- lib/WebGUI/i18n/English/Macro_FileUrl.pm | 4 ++-- t/Macro/FileUrl.t | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/WebGUI/i18n/English/Macro_FileUrl.pm b/lib/WebGUI/i18n/English/Macro_FileUrl.pm index 0b9d68f10..a9b764848 100644 --- a/lib/WebGUI/i18n/English/Macro_FileUrl.pm +++ b/lib/WebGUI/i18n/English/Macro_FileUrl.pm @@ -16,9 +16,9 @@ our $I18N = { message => q|

^FileUrl();
^FileUrl(Asset URL);
-This macro is used to return a filesystem URL to a File or Image Asset identified by its Asset URL.

+This macro is used to return a filesystem URL to an Asset which stores a single file (File, Image, ZipArchive, etc.) identified by its Asset URL. The Macro will not work on Assets which store multiple files, such as the Post or Article Assets.

|, - lastUpdated => 1153476000, + lastUpdated => 1165599338, }, 'invalid url' => { diff --git a/t/Macro/FileUrl.t b/t/Macro/FileUrl.t index 215a08453..1d4011f7b 100644 --- a/t/Macro/FileUrl.t +++ b/t/Macro/FileUrl.t @@ -84,10 +84,14 @@ my @testSets = ( ); -my $numTests = scalar(@testSets); +my $numTests = 0; $numTests += 1; #For the use_ok $numTests += 1; #non-existant URL +foreach my $testSet (@testSets) { + $numTests += $testSet->{pass} ? 2 : 1; +} + plan tests => $numTests; my $macro = 'WebGUI::Macro::FileUrl'; @@ -106,7 +110,10 @@ my $homeAsset = WebGUI::Asset->getDefault($session); foreach my $testSet (@testSets) { my $output = WebGUI::Macro::FileUrl::process($session, $testSet->{url}); if ($testSet->{pass}) { - is($output, $testSet->{fileUrl}, $testSet->{comment}); + my $storageId = $testSet->{asset}->get("storageId"); + my $expectedUrl = WebGUI::Storage->get($session, $storageId)->getUrl($testSet->{filename}); + ok($expectedUrl, $testSet->{comment}." returns non-null file"); + is($output, $expectedUrl, $testSet->{comment}); } else { is($output, $testSet->{output}, $testSet->{comment}); @@ -127,6 +134,7 @@ sub setupTest { my $storage = WebGUI::Storage->create($session); my $filename = join '.', 'fileName', $testNum; + $testSet->{filename} = $filename; ##Store the filename in the file, just for reference. $storage->addFileFromScalar($filename,$filename); @@ -145,5 +153,6 @@ sub setupTest { } END { ##Clean-up after yourself, always + use Data::Dumper; $versionTag->rollback; }