Add tests to check how getThumbnailUrl is supposed to work in the Product.
Then fix the bugs I added to it yesterday.
This commit is contained in:
parent
2dac29bce5
commit
14724cbbef
5 changed files with 57 additions and 7 deletions
|
|
@ -9,6 +9,7 @@
|
||||||
- fixed: can now turn off inheritUrlFromParent and the code is now more
|
- fixed: can now turn off inheritUrlFromParent and the code is now more
|
||||||
robust, moved from Asset->update to Asset->fixUrl.
|
robust, moved from Asset->update to Asset->fixUrl.
|
||||||
- fixed: Time tracker can't post time once it's been posted.
|
- fixed: Time tracker can't post time once it's been posted.
|
||||||
|
- fixed: Shop: Product asset- image not showing
|
||||||
|
|
||||||
7.5.13
|
7.5.13
|
||||||
- fixed: storage locations for some assets in packages not imported correctly
|
- fixed: storage locations for some assets in packages not imported correctly
|
||||||
|
|
|
||||||
|
|
@ -442,12 +442,32 @@ sub getQuantityAvailable {
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 getThumbnailUrl ( [$store] )
|
||||||
|
|
||||||
|
Return a URL to the thumbnail for an image stored in this Product by creating
|
||||||
|
a WebGUI::Storage::Image object and calling its getThumbnailUrl method.
|
||||||
|
|
||||||
|
=head3 $store
|
||||||
|
|
||||||
|
This should be a WebGUI::Storage::Image object. If it is not defined,
|
||||||
|
then by default getThumbnailUrl will attempt to look up the URL for
|
||||||
|
the 'image1' property.
|
||||||
|
|
||||||
|
If image1 is not defined for this Product and a separate storage object is not
|
||||||
|
sent in, it will return the empty string.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
sub getThumbnailUrl {
|
sub getThumbnailUrl {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $store = shift;
|
my $store = shift;
|
||||||
if (! defined $store and $self->get('image1')) {
|
if (defined $store) {
|
||||||
|
return $store->getThumbnailUrl($store->getFiles->[0]);
|
||||||
|
}
|
||||||
|
elsif ($self->get('image1')) {
|
||||||
$store = WebGUI::Storage::Image->get($self->session, $self->get('image1'));
|
$store = WebGUI::Storage::Image->get($self->session, $self->get('image1'));
|
||||||
return $store->getThumbnailUrl($store->getFiles->[0]);
|
return $store->getThumbnailUrl($store->getFiles->[0]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return '';
|
return '';
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||||
use WebGUI::Session;
|
use WebGUI::Session;
|
||||||
use WebGUI::Asset;
|
use WebGUI::Asset;
|
||||||
use WebGUI::Asset::Sku::Product;
|
use WebGUI::Asset::Sku::Product;
|
||||||
|
use WebGUI::Storage::Image;
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Init
|
# Init
|
||||||
|
|
@ -33,7 +34,7 @@ my $session = WebGUI::Test->session;
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Tests
|
# Tests
|
||||||
|
|
||||||
plan tests => 2; # Increment this number for each test you create
|
plan tests => 7; # Increment this number for each test you create
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# put your tests here
|
# put your tests here
|
||||||
|
|
@ -41,10 +42,38 @@ my $node = WebGUI::Asset::Sku::Product->getProductImportNode($session);
|
||||||
isa_ok($node, 'WebGUI::Asset::Wobject::Folder', 'getProductImportNode returns a Folder');
|
isa_ok($node, 'WebGUI::Asset::Wobject::Folder', 'getProductImportNode returns a Folder');
|
||||||
is($node->getId, 'PBproductimportnode001', 'Product Import Node has the correct GUID');
|
is($node->getId, 'PBproductimportnode001', 'Product Import Node has the correct GUID');
|
||||||
|
|
||||||
|
my $product = $node->addChild({
|
||||||
|
className => "WebGUI::Asset::Sku::Product",
|
||||||
|
title => "Rock Hammer",
|
||||||
|
});
|
||||||
|
|
||||||
|
is($product->getThumbnailUrl(), '', 'Product with no image1 property returns the empty string');
|
||||||
|
|
||||||
|
my $image = WebGUI::Storage::Image->create($session);
|
||||||
|
$image->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath('lamp.jpg'));
|
||||||
|
|
||||||
|
my $imagedProduct = $node->addChild({
|
||||||
|
className => "WebGUI::Asset::Sku::Product",
|
||||||
|
title => "Bible",
|
||||||
|
image1 => $image->getId,
|
||||||
|
});
|
||||||
|
|
||||||
|
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::Image->create($session);
|
||||||
|
$otherImage->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath('gooey.jpg'));
|
||||||
|
|
||||||
|
ok($imagedProduct->getThumbnailUrl($otherImage), 'getThumbnailUrl with an explicit storageId returns something');
|
||||||
|
is($imagedProduct->getThumbnailUrl($otherImage), $otherImage->getThumbnailUrl('gooey.jpg'), 'getThumbnailUrl with an explicit storageId returns the right path to the URL');
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Cleanup
|
# Cleanup
|
||||||
END {
|
END {
|
||||||
|
$product->purge;
|
||||||
|
$imagedProduct->purge;
|
||||||
|
$image->delete;
|
||||||
|
$otherImage->delete;
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,9 @@ plan tests => 33; # Increment this number for each test you create
|
||||||
# put your tests here
|
# put your tests here
|
||||||
my $root = WebGUI::Asset->getRoot($session);
|
my $root = WebGUI::Asset->getRoot($session);
|
||||||
my $product = $root->addChild({
|
my $product = $root->addChild({
|
||||||
className => "WebGUI::Asset::Sku::Product",
|
className => "WebGUI::Asset::Sku::Product",
|
||||||
title => "Rock Hammer",
|
title => "Rock Hammer",
|
||||||
});
|
});
|
||||||
isa_ok($product, "WebGUI::Asset::Sku::Product");
|
isa_ok($product, "WebGUI::Asset::Sku::Product");
|
||||||
ok(! exists $product->{_collateral}, 'object cache does not exist yet');
|
ok(! exists $product->{_collateral}, 'object cache does not exist yet');
|
||||||
|
|
||||||
|
|
|
||||||
BIN
t/supporting_collateral/gooey.jpg
Normal file
BIN
t/supporting_collateral/gooey.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
Loading…
Add table
Add a link
Reference in a new issue