From 1a9da53abf9387cb091fd20577feafb8d77058c8 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 14 Apr 2009 01:54:28 +0000 Subject: [PATCH] Modify tests to use the automatic storage cleanup provided by WebGUI::Test. Several tests previously leaked storage locations. --- t/AdSpace/Ad.t | 4 +--- t/Asset/AssetExportHtml.t | 2 ++ t/Asset/File.t | 2 ++ t/Asset/File/Image.t | 1 + t/Asset/Sku/Product.t | 4 ++-- t/Asset/Wobject/Article.t | 1 + t/Asset/Wobject/DataForm/DataForm.t | 2 ++ t/Macro/FileUrl.t | 1 + t/Macro/Include.t | 2 +- t/Macro/Thumbnail.t | 1 + t/Storage/Image.t | 9 ++++----- 11 files changed, 18 insertions(+), 11 deletions(-) diff --git a/t/AdSpace/Ad.t b/t/AdSpace/Ad.t index d81603190..2055a41d1 100644 --- a/t/AdSpace/Ad.t +++ b/t/AdSpace/Ad.t @@ -49,6 +49,7 @@ my $ad; my ($richAd, $textAd, $imageAd, $nonAd, $setAd); my $adSpace; my $imageStorage = WebGUI::Storage->create($session); +WebGUI::Test->storagesToDelete($imageStorage); $imageStorage->addFileFromScalar('foo.bmp', 'This is not really an image'); SKIP: { @@ -219,7 +220,4 @@ END { if (defined $adSpace and ref $adSpace eq 'WebGUI::AdSpace') { $adSpace->delete; } - if (defined $imageStorage and ref $imageStorage eq 'WebGUI::Storage') { - $imageStorage->delete; - } } diff --git a/t/Asset/AssetExportHtml.t b/t/Asset/AssetExportHtml.t index caabba26c..9910650a9 100644 --- a/t/Asset/AssetExportHtml.t +++ b/t/Asset/AssetExportHtml.t @@ -269,6 +269,7 @@ is($gcAsPath->absolute($exportPath)->stringify, $litmus->absolute($exportPath)-> # now let's get tricky and test different file extensions my $storage = WebGUI::Storage->create($session); +WebGUI::Test->storagesToDelete($storage->getId); my $filename = 'somePerlFile_pl.txt'; $storage->addFileFromScalar($filename, $filename); $session->user({userId=>3}); @@ -299,6 +300,7 @@ is($fileAsPath->absolute($exportPath)->stringify, $litmus->absolute($exportPath) # test a different extension, the .foobar extension $storage = WebGUI::Storage->create($session); +WebGUI::Test->storagesToDelete($storage->getId); $filename = 'someFoobarFile.foobar'; $storage->addFileFromScalar($filename, $filename); $properties = { diff --git a/t/Asset/File.t b/t/Asset/File.t index 0cf42029b..c4a1a7947 100644 --- a/t/Asset/File.t +++ b/t/Asset/File.t @@ -32,6 +32,7 @@ my $session = WebGUI::Test->session; ##Create a storage location my $storage = WebGUI::Storage->create($session); +WebGUI::Test->storagesToDelete($storage); ##Save the image to the location my $filename = "someScalarFile.txt"; @@ -84,6 +85,7 @@ $versionTag->commit; ############################################ my $fileStorage = WebGUI::Storage->create($session); +WebGUI::Test->storagesToDelete($fileStorage); $mocker->set_always('getValue', $fileStorage->getId); my $fileFormStorage = $asset->getStorageFromPost(); isa_ok($fileFormStorage, 'WebGUI::Storage', 'Asset::File::getStorageFromPost'); diff --git a/t/Asset/File/Image.t b/t/Asset/File/Image.t index 9d5ac63f8..9b2a8bc97 100644 --- a/t/Asset/File/Image.t +++ b/t/Asset/File/Image.t @@ -39,6 +39,7 @@ $rectangle->setBackgroundColor('#0000FF'); ##Create a storage location my $storage = WebGUI::Storage->create($session); +WebGUI::Test->storagesToDelete($storage); ##Save the image to the location $rectangle->saveToStorageLocation($storage, 'blue.png'); diff --git a/t/Asset/Sku/Product.t b/t/Asset/Sku/Product.t index 4a13ca977..3052b733c 100644 --- a/t/Asset/Sku/Product.t +++ b/t/Asset/Sku/Product.t @@ -48,6 +48,7 @@ my $product = $node->addChild({ is($product->getThumbnailUrl(), '', 'Product with no image1 property returns the empty string'); my $image = WebGUI::Storage->create($session); +WebGUI::Test->storagesToDelete($image); $image->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath('lamp.jpg')); my $imagedProduct = $node->addChild({ @@ -61,6 +62,7 @@ ok($imagedProduct->getThumbnailUrl(), 'getThumbnailUrl is not empty'); is($imagedProduct->getThumbnailUrl(), $image->getThumbnailUrl('lamp.jpg'), 'getThumbnailUrl returns the right path to the URL'); my $otherImage = WebGUI::Storage->create($session); +WebGUI::Test->storagesToDelete($otherImage); $otherImage->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath('gooey.jpg')); ok($imagedProduct->getThumbnailUrl($otherImage), 'getThumbnailUrl with an explicit storageId returns something'); @@ -89,8 +91,6 @@ is($imagedProduct->getConfiguredTitle, 'Bible - English', 'getConfiguredTitle is END { $product->purge; $imagedProduct->purge; - $image->delete; - $otherImage->delete; } 1; diff --git a/t/Asset/Wobject/Article.t b/t/Asset/Wobject/Article.t index c3a0ca1d3..324ae507c 100644 --- a/t/Asset/Wobject/Article.t +++ b/t/Asset/Wobject/Article.t @@ -70,6 +70,7 @@ my $pathedFile = WebGUI::Test->getTestCollateralPath($filename); # Use some test collateral to create a storage location and assign it to our article my $storage = WebGUI::Storage->create($session); +WebGUI::Test->storagesToDelete($storage); my $storedFilename = $storage->addFileFromFilesystem($pathedFile); my $filenameOK = is ($storedFilename, $filename, 'storage created correctly'); diff --git a/t/Asset/Wobject/DataForm/DataForm.t b/t/Asset/Wobject/DataForm/DataForm.t index 3a587311b..a69090a14 100644 --- a/t/Asset/Wobject/DataForm/DataForm.t +++ b/t/Asset/Wobject/DataForm/DataForm.t @@ -70,6 +70,7 @@ my $pathedFile = WebGUI::Test->getTestCollateralPath($filename); # Use some test collateral to create a storage location and assign it to our article my $storage = WebGUI::Storage->create($session); +WebGUI::Test->storagesToDelete($storage); my $storedFilename = $storage->addFileFromFilesystem($pathedFile); my $filenameOK = is ($storedFilename, $filename, 'storage created correctly'); @@ -87,6 +88,7 @@ isa_ok($duplicateArticle, 'WebGUI::Asset::Wobject::Article'); my $duplicateStorageId = $duplicateArticle->get("storageId"); my $duplicateStorage = WebGUI::Storage->get($session,$duplicateStorageId); +WebGUI::Test->storagesToDelete($duplicateStorage); my $duplicateFilename = $duplicateStorage->getFiles->[0]; is ($duplicateFilename, $filename, "duplicate method copies collateral"); diff --git a/t/Macro/FileUrl.t b/t/Macro/FileUrl.t index 6d4cdb605..8795a8d9b 100644 --- a/t/Macro/FileUrl.t +++ b/t/Macro/FileUrl.t @@ -126,6 +126,7 @@ sub setupTest { foreach my $testSet (@testSets) { my $storage = WebGUI::Storage->create($session); + WebGUI::Test->storagesToDelete($storage); my $filename = join '.', 'fileName', $testNum; $testSet->{filename} = $filename; diff --git a/t/Macro/Include.t b/t/Macro/Include.t index 436b28911..a10fab767 100644 --- a/t/Macro/Include.t +++ b/t/Macro/Include.t @@ -28,6 +28,7 @@ my $spectreConf = WebGUI::Test->root . '/etc/spectre.conf'; my $goodFile = 'The contents of this file are accessible'; my $twoLines = "This file contains two lines of text\nThis is the second line"; my $storage = WebGUI::Storage->createTemp($session); +WebGUI::Test->storagesToDelete($storage); $storage->addFileFromScalar('goodFile', $goodFile); $storage->addFileFromScalar('twoLines', $twoLines); $storage->addFileFromScalar('unreadableFile', 'The contents of this file are not readable'); @@ -112,5 +113,4 @@ SKIP: { } END { - $storage->delete; } diff --git a/t/Macro/Thumbnail.t b/t/Macro/Thumbnail.t index c89b04d23..799c064bd 100644 --- a/t/Macro/Thumbnail.t +++ b/t/Macro/Thumbnail.t @@ -35,6 +35,7 @@ $square->setBackgroundColor('#0000FF'); ##Create a storage location my $storage = WebGUI::Storage->create($session); +WebGUI::Test->storagesToDelete($storage); ##Save the image to the location $square->saveToStorageLocation($storage, 'square.png'); diff --git a/t/Storage/Image.t b/t/Storage/Image.t index 166ef9d3d..152ace69a 100644 --- a/t/Storage/Image.t +++ b/t/Storage/Image.t @@ -82,6 +82,7 @@ ok ($uploadUrl, "uploadDir defined in config"); #################################################### my $imageStore = WebGUI::Storage->create($session); +WebGUI::Test->storagesToDelete($imageStore); my $expectedFiles = ['.', '..']; cmp_bag($imageStore->getFiles(1), $expectedFiles, 'Starting with an empty storage object, no files in here except for . and ..'); $imageStore->addFileFromScalar('.dotfile', 'dot file'); @@ -118,6 +119,7 @@ foreach my $extTest ( @{ $extensionTests } ) { WebGUI::Test->interceptLogging(); my $thumbStore = WebGUI::Storage->create($session); +WebGUI::Test->storagesToDelete($thumbStore); my $square = WebGUI::Image->new($session, 500, 500); $square->setBackgroundColor('#FF0000'); $square->saveToStorageLocation($thumbStore, 'square.png'); @@ -168,6 +170,7 @@ like($WebGUI::Test::logger_error, qr/^Couldn't read image to check the size of i #################################################### my $imageCopy = $thumbStore->copy(); +WebGUI::Test->storagesToDelete($imageCopy); isa_ok($imageCopy, 'WebGUI::Storage', 'copy returns an object'); cmp_bag( $imageCopy->getFiles(), @@ -216,6 +219,7 @@ is($thumbStore->getThumbnailUrl('square.png'), $thumbStore->getUrl('thumb-square my $origMaxImageSize = $session->setting->get('maxImageSize'); my $sizeTest = WebGUI::Storage->create($session); +WebGUI::Test->storagesToDelete($sizeTest); my $resizeTarget = 80; $session->setting->set('maxImageSize', 200 ); @@ -279,9 +283,4 @@ TODO: { } END { - foreach my $stor ( - $imageStore, $thumbStore, $imageCopy, $sizeTest, - ) { - ref $stor eq "WebGUI::Storage" and $stor->delete; - } }