diff --git a/lib/WebGUI/Asset/Sku/Product.pm b/lib/WebGUI/Asset/Sku/Product.pm index 4380ac4b2..71c5e89bb 100644 --- a/lib/WebGUI/Asset/Sku/Product.pm +++ b/lib/WebGUI/Asset/Sku/Product.pm @@ -61,15 +61,19 @@ property image1 => ( default => undef, maxAttachments => 1, label => ['7', 'Asset_Product'], - #deleteFileUrl => $session->url->page("func=deleteFileConfirm;file=image1;filename="), + deleteFileUrl => \&_product_delete_file_url, persist => 1, ); +sub _product_delete_file_url { + my ($self, $property) = @_; + return $self->session->url->page(sprintf "func=deleteFileConfirm;file=%s;filename=", $property->name); +} property image2 => ( tab => "properties", fieldType => "image", maxAttachments => 1, label => ['8', 'Asset_Product'], - #deleteFileUrl => $session->url->page("func=deleteFileConfirm;file=image2;filename="), + deleteFileUrl => \&_product_delete_file_url, default => undef, persist => 1, ); @@ -78,7 +82,7 @@ property image3 => ( fieldType => "image", maxAttachments => 1, label => ['9', 'Asset_Product'], - #deleteFileUrl => $session->url->page("func=deleteFileConfirm;file=image3;filename="), + deleteFileUrl => \&_product_delete_file_url, default => undef, persist => 1, ); @@ -87,7 +91,7 @@ property brochure => ( fieldType => "file", maxAttachments => 1, label => ['13', 'Asset_Product'], - #deleteFileUrl => $session->url->page("func=deleteFileConfirm;file=brochure;filename="), + deleteFileUrl => \&_product_delete_file_url, default => undef, persist => 1, ); @@ -96,7 +100,7 @@ property manual => ( fieldType => "file", maxAttachments => 1, label => ['14', 'Asset_Product'], - #deleteFileUrl => $session->url->page("func=deleteFileConfirm;file=manual;filename="), + deleteFileUrl => \&_product_delete_file_url, default => undef, persist => 1, ); @@ -112,7 +116,7 @@ property warranty => ( fieldType => "file", maxAttachments => 1, label => ['15', 'Asset_Product'], - #deleteFileUrl => $session->url->page("func=deleteFileConfirm;file=warranty;filename="), + deleteFileUrl => \&_product_delete_file_url, default => undef, persist => 1, ); diff --git a/t/Asset/Sku/Product.t b/t/Asset/Sku/Product.t index 98409d01c..c5fce4584 100644 --- a/t/Asset/Sku/Product.t +++ b/t/Asset/Sku/Product.t @@ -37,7 +37,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -plan tests => 13; # Increment this number for each test you create +plan tests => 19; # Increment this number for each test you create #---------------------------------------------------------------------------- # put your tests here @@ -50,6 +50,12 @@ my $product = $node->addChild({ is($product->getThumbnailUrl(), '', 'Product with no image1 property returns the empty string'); +note "Checking automatically generated deleteFileUrl links"; +foreach my $file_property (qw/image1 image2 image3 brochure manual warranty/) { + my $form_properties = $product->getFormProperties($file_property); + like $form_properties->{deleteFileUrl}, qr/file=$file_property/, '...' . $file_property; +} + my $image = WebGUI::Storage->create($session); WebGUI::Test->storagesToDelete($image); $image->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath('lamp.jpg')); @@ -164,7 +170,7 @@ $tag2->commit; WebGUI::Test->tagsToRollback($tag2); ##Fetch a copy from the db, just like a page fetch -$viewProduct = WebGUI::Asset->new($session, $viewProduct->getId, 'WebGUI::Asset::Sku::Product'); +$viewProduct = WebGUI::Asset->newById($session, $viewProduct->getId); $viewProduct->prepareView(); my $json = $viewProduct->view();