From e8bfd8a0a76d657ef5b8382c10123f3276123b0d Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 27 Jul 2009 16:21:04 +0000 Subject: [PATCH] Empty warranty, brochure and manual show empty areas in the Product. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Sku/Product.pm | 24 +++++++----- t/Asset/Sku/Product.t | 69 +++++++++++++++++++++++++++++++-- 3 files changed, 82 insertions(+), 12 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index cf68e3fa7..343cfcb53 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -6,6 +6,7 @@ - fixed #10596: Dates in calendar wrong offset - fixed #10698: hard coded root paths in account templates - fixed #10700: Default My Sales template needs i18n + - fixed #10702: Product displays empty brochure, warranty, manual fields 7.7.16 - fixed #10590: Session::DateTime->secondsToInterval doesn't allow 7 weeks diff --git a/lib/WebGUI/Asset/Sku/Product.pm b/lib/WebGUI/Asset/Sku/Product.pm index aeed8fe39..e6ae0da82 100644 --- a/lib/WebGUI/Asset/Sku/Product.pm +++ b/lib/WebGUI/Asset/Sku/Product.pm @@ -1686,23 +1686,29 @@ sub view { my $i18n = WebGUI::International->new($session,'Asset_Product'); if ($brochure) { my $file = WebGUI::Storage->get($session,$brochure); - $var{"brochure_icon"} = $self->getFileIconUrl($file); - $var{"brochure_label"} = $i18n->get(13); - $var{"brochure_URL"} = $self->getFileUrl($file); + if ($self->getFilename($file)) { + $var{"brochure_icon"} = $self->getFileIconUrl($file); + $var{"brochure_label"} = $i18n->get(13); + $var{"brochure_URL"} = $self->getFileUrl($file); + } } #---manual if ($manual) { my $file = WebGUI::Storage->get($session,$manual); - $var{"manual_icon"} = $self->getFileIconUrl($file); - $var{"manual_label"} = $i18n->get(14); - $var{"manual_URL"} = $self->getFileUrl($file); + if ($self->getFilename($file)) { + $var{"manual_icon"} = $self->getFileIconUrl($file); + $var{"manual_label"} = $i18n->get(14); + $var{"manual_URL"} = $self->getFileUrl($file); + } } #---warranty if ($warranty) { my $file = WebGUI::Storage->get($session,$warranty); - $var{"warranty_icon"} = $self->getFileIconUrl($file); - $var{"warranty_label"} = $i18n->get(15); - $var{"warranty_URL"} = $self->getFileUrl($file); + if ($self->getFilename($file)) { + $var{"warranty_icon"} = $self->getFileIconUrl($file); + $var{"warranty_label"} = $i18n->get(15); + $var{"warranty_URL"} = $self->getFileUrl($file); + } } #---image1 if ($image1) { diff --git a/t/Asset/Sku/Product.t b/t/Asset/Sku/Product.t index a26b47467..09b73f2f2 100644 --- a/t/Asset/Sku/Product.t +++ b/t/Asset/Sku/Product.t @@ -27,6 +27,7 @@ use WebGUI::Session; use WebGUI::Asset; use WebGUI::Asset::Sku::Product; use WebGUI::Storage; +use JSON; #---------------------------------------------------------------------------- # Init @@ -36,7 +37,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -plan tests => 12; # Increment this number for each test you create +plan tests => 13; # Increment this number for each test you create #---------------------------------------------------------------------------- # put your tests here @@ -53,8 +54,6 @@ my $image = WebGUI::Storage->create($session); WebGUI::Test->storagesToDelete($image); $image->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath('lamp.jpg')); -WebGUI::Test->tagsToRollback(WebGUI::VersionTag->getWorking($session)); - my $imagedProduct = $node->addChild({ className => "WebGUI::Asset::Sku::Product", title => "Bible", @@ -109,6 +108,10 @@ cmp_deeply( '... form only has 1 variant, since the other one has 0 quantity' ); +my $tag = WebGUI::VersionTag->getWorking($session); +$tag->commit; +WebGUI::Test->tagsToRollback($tag); + #################################################### # # addRevision @@ -120,3 +123,63 @@ my $newImagedProduct = $imagedProduct->addRevision({title => 'Bible and hammer'} like($newImagedProduct->get('image1'), $session->id->getValidator, 'addRevision: new product rev got an image1 storage location'); isnt($newImagedProduct->get('image1'), $imagedProduct->get('image1'), '... and it is not the same as the old one'); + +WebGUI::Test->tagsToRollback(WebGUI::VersionTag->getWorking($session)); +WebGUI::VersionTag->getWorking($session)->commit; + +#################################################### +# +# view, template variables +# +#################################################### + +my $jsonTemplate = $node->addChild({ + className => 'WebGUI::Asset::Template', + title => 'JSON template for Product testing', + template => q| +{ + "brochure_icon":"", + "brochure_url" :"", + "warranty_icon":"", + "warranty_url" :"", + "manual_icon" :"", + "manual_url" :"" +} +|, +}); + +my @storages = map { WebGUI::Storage->create($session) } 0..2; + +my $viewProduct = $node->addChild({ + className => 'WebGUI::Asset::Sku::Product', + title => 'View Product for template variable tests', + templateId => $jsonTemplate->getId, + brochure => $storages[0]->getId, + warranty => $storages[1]->getId, + manual => $storages[2]->getId, +}); + +my $tag2 = WebGUI::VersionTag->getWorking($session); +$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->prepareView(); +my $json = $viewProduct->view(); +diag $json; + +my $vars = JSON::from_json($json); +cmp_deeply( + $vars, + { + brochure_icon => '', + brochure_url => '', + warranty_icon => '', + warranty_url => '', + manual_icon => '', + manual_url => '', + }, + 'brochure, warranty and manual vars are blank since their storages are empty' +);