diff --git a/lib/WebGUI/Asset/File/GalleryFile/Photo.pm b/lib/WebGUI/Asset/File/GalleryFile/Photo.pm index 5b34c7b4d..bec196849 100644 --- a/lib/WebGUI/Asset/File/GalleryFile/Photo.pm +++ b/lib/WebGUI/Asset/File/GalleryFile/Photo.pm @@ -109,21 +109,28 @@ C is a hash reference of options and is currently not used. sub applyConstraints { my $self = shift; + my $options = shift; my $gallery = $self->getGallery; # Update the asset's size and make a thumbnail - my $maxImageSize = $self->getGallery->get("imageViewSize") + my $maxImageSize = $gallery->get("imageViewSize") || $self->session->setting->get("maxImageSize"); - my $thumbnailSize = $self->getGallery->get("imageThumbnailSize") - || $self->session->setting->get("thumbnailSize"); my $parameters = $self->get("parameters"); my $storage = $self->getStorageLocation; my $file = $self->get("filename"); + + # Make resolutions before fixing image, so that we can get higher quality + # resolutions + $self->makeResolutions; + + # adjust density before size, so that the dimensions won't change + $storage->resize( $file, undef, undef, $gallery->get( 'imageDensity' ) ); $storage->adjustMaxImageSize($file, $maxImageSize); + $self->generateThumbnail; $self->setSize; - $self->makeResolutions; $self->updateExifDataFromFile; + $self->SUPER::applyConstraints( $options ); } #------------------------------------------------------------------- @@ -361,7 +368,7 @@ sub makeResolutions { } my $newFilename = $res . ".jpg"; $storage->copyFile( $self->get("filename"), $newFilename ); - $storage->resize( $newFilename, $res ); + $storage->resize( $newFilename, $res, undef, $self->getGallery->get( 'imageDensity' ) ); } } diff --git a/t/Asset/Asset.t b/t/Asset/Asset.t index 6f98e6335..9ffbe51a6 100644 --- a/t/Asset/Asset.t +++ b/t/Asset/Asset.t @@ -283,6 +283,7 @@ my $origRequest = $session->{_request}; my $newRequest = Test::MockObject->new(); my $func; $newRequest->set_bound('body', \$func); +$newRequest->set_bound('param', \$func); $session->{_request} = $newRequest; $func = 'add'; is($importNode->addEditLabel, $i18n->get('add').' '.$importNode->getName, 'addEditLabel, use add mode'); @@ -435,7 +436,7 @@ my $importNodeTitle = $importNode->getTitle(); foreach my $test (@fixTitleTests) { my $fixedTitle = $importNode->fixTitle($test->{title}, 'ownerUserId'); - my $expectedTitle = $test->{fixed} || $importNodeTitle; + my $expectedTitle = defined $test->{fixed} ? $test->{fixed} : $importNodeTitle; is($fixedTitle, $expectedTitle, $test->{comment}); } @@ -697,9 +698,7 @@ is($rootAsset->get('isExportable'), 1, 'isExportable exists, defaults to 1'); ################################################################ my $assetProps = $rootAsset->get(); my $funkyTitle = q{Miss Annie's Whoopie Emporium and Sasparilla Shop}; -diag $assetProps->{title}; $assetProps->{title} = $funkyTitle; -diag $assetProps->{title}; isnt( $rootAsset->get('title'), $funkyTitle, 'get returns a safe copy of the Asset properties'); @@ -708,7 +707,7 @@ isnt( $rootAsset->get('title'), $funkyTitle, 'get returns a safe copy of the Ass # getIsa # ################################################################ -my $node = WebGUI::Asset::Sku::Product->getProductImportNode($session); +my $node = WebGUI::Asset->getRoot($session); my $product1 = $node->addChild({ className => 'WebGUI::Asset::Sku::Product'}); my $product2 = $node->addChild({ className => 'WebGUI::Asset::Sku::Product'}); my $product3 = $node->addChild({ className => 'WebGUI::Asset::Sku::Product'}); @@ -894,29 +893,29 @@ sub getFixIdTests { } ##Return an array of hashrefs. Each hashref describes a test -##for the fixTitle method. If "fixed" != 0, it should +##for the fixTitle method. If "fixed" != undef, it should ##contain what the fixTitle method will return. sub getFixTitleTests { my $session = shift; return ({ title => undef, - fixed => 0, + fixed => undef, comment => "undef returns the Asset's title", }, { title => '', - fixed => 0, + fixed => undef, comment => "null string returns the Asset's title", }, { title => 'untitled', - fixed => 0, + fixed => undef, comment => "'untitled' returns the Asset's title", }, { title => 'UnTiTlEd', - fixed => 0, + fixed => undef, comment => "'untitled' in any case returns the Asset's title", }, { @@ -939,6 +938,11 @@ sub getFixTitleTests { fixed => 'This is a good Title', comment => "Good titles are passed", }, + { + title => '', + fixed => '', + comment => "If there is no title left after processing, then it is set to untitled.", + }, ); } diff --git a/t/Asset/AssetExportHtml.t b/t/Asset/AssetExportHtml.t index ade702964..408ef227a 100644 --- a/t/Asset/AssetExportHtml.t +++ b/t/Asset/AssetExportHtml.t @@ -742,40 +742,45 @@ $exportPath->rmtree; # list of files that should exist. obtained by running previous known working # export function on a full stock asset tree @createdFiles = ( - [ qw/ getting_started getting-started index.html /], - [ qw/ getting_started getting-started-part2 index.html /], - [ qw/ getting_started index.html /], - [ qw/ home ad index.html /], - [ qw/ home ad2 index.html /], - [ qw/ home index.html /], - [ qw/ home key-benefits index.html /], - [ qw/ home welcome index.html /], - [ qw/ site_map index.html /], - [ qw/ site_map site_map index.html /], - [ qw/ tell_a_friend index.html /], - [ qw/ tell_a_friend tell_a_friend index.html /], - [ qw/ the_latest_news index.html /], - [ qw/ the_latest_news the_latest_news index.html /], - [ qw/ yns docs index.html /], - [ qw/ yns experts index.html /], - [ qw/ yns features index.html /], - [ qw/ yns hosting index.html /], - [ qw/ yns promotion index.html /], - [ qw/ yns style index.html /], - [ qw/ yns support index.html /], - [ qw/ yns translated index.html /], - [ qw/ your_next_step index.html /], + [ qw/ getting_started getting-started index.html /], + [ qw/ getting_started getting-started-part2 index.html /], + [ qw/ getting_started index.html /], + [ qw/ home ad index.html /], + [ qw/ home ad2 index.html /], + [ qw/ home index.html /], + [ qw/ home key-benefits index.html /], + [ qw/ home welcome index.html /], + [ qw/ site_map index.html /], + [ qw/ site_map site_map index.html /], + [ qw/ tell_a_friend index.html /], + [ qw/ tell_a_friend tell_a_friend index.html /], + [ qw/ the_latest_news index.html /], + [ qw/ the_latest_news the_latest_news index.html /], + [ qw/ yns docs index.html /], + [ qw/ yns experts index.html /], + [ qw/ yns features index.html /], + [ qw/ yns hosting index.html /], + [ qw/ yns promotion index.html /], + [ qw/ yns style index.html /], + [ qw/ yns support index.html /], + [ qw/ yns translated index.html /], + [ qw/ your_next_step index.html /], + [ qw/ documentation index.html /], + [ qw/ documentation commercial-documentation index.html /], + [ qw/ documentation free-documentation index.html /], ); +my $numberCreatedAll = scalar @createdFiles; + # turn them into Path::Class::File objects my @shouldExist = map { Path::Class::File->new($exportPath, @{$_})->absolute->stringify } @createdFiles; # ensure that the files that should exist do exist my @doExist; $exportPath->recurse( callback => sub { my $o = shift; $o->is_dir ? return : push @doExist, $o->absolute->stringify } ); -cmp_deeply(sort @shouldExist, sort @doExist, "exportAsHtml on home writes correct files"); +cmp_bag(\@shouldExist, \@doExist, "exportAsHtml on home writes correct files"); is($success, 1, "exportAsHtml on home returns true"); -like($message, qr/Exported 23 pages/, "exportAsHtml on home returns correct message"); +like($message, qr/Exported $numberCreatedAll pages/, "exportAsHtml on home returns correct message"); $exportPath->rmtree; @doExist = (); @@ -861,13 +866,17 @@ $gettingStarted->update({ isExportable => 0 }); [ qw/ yns support index.html /], [ qw/ yns translated index.html /], [ qw/ your_next_step index.html /], + [ qw/ documentation index.html /], + [ qw/ documentation commercial-documentation index.html /], + [ qw/ documentation free-documentation index.html /], ); +my $numberCreated = scalar @createdFiles; @shouldExist = map { Path::Class::File->new($exportPath, @{$_})->absolute->stringify } @createdFiles; $exportPath->recurse( callback => sub { my $o = shift; $o->is_dir ? return : push @doExist, $o->absolute->stringify } ); -cmp_deeply(sort @shouldExist, sort @doExist, "exportAsHtml on home with non-exportable getting-started writes correct files"); +cmp_bag(\@shouldExist, \@doExist, "exportAsHtml on home with non-exportable getting-started writes correct files"); is($success, 1, "exportAsHtml on home with non-exportable getting-started returns true"); -like($message, qr/Exported 19 pages/, "exportAsHtml on home with non-exportable getting-started returns correct message"); +like($message, qr/Exported $numberCreated pages/, "exportAsHtml on home with non-exportable getting-started returns correct message"); # restore the original setting $gettingStarted->update({ isExportable => 1 }); @@ -906,24 +915,24 @@ $config->delete('exportPath'); # undefined exportPath eval { ($success, $message) = $home->exportAsHtml( { userId => 3, depth => 99 } ) }; -is($@, '', "exportAsHtml catches undefined exportPath exception"); -is($success, 0, "exportAsHtml returns 0 for undefined exportPath"); +is($@, '', "exportAsHtml catches undefined exportPath exception"); +is($success, 0, "exportAsHtml returns 0 for undefined exportPath"); is($message, 'exportPath must be defined and not ""', "exportAsHtml returns correct message for undefined exportPath"); # inaccessible exportPath $config->set('exportPath', Path::Class::Dir->new('')->stringify); eval { ($success, $message) = $home->exportAsHtml( { userId => 3, depth => 99 } ) }; -is($@, '', "exportAsHtml catches inaccessible exportPath "); -is($success, 0, "exportAsHtml returns 0 for inaccessible exportPath"); +is($@, '', "exportAsHtml catches inaccessible exportPath "); +is($success, 0, "exportAsHtml returns 0 for inaccessible exportPath"); is($message, "can't access " . Path::Class::Dir->new('')->stringify, "exportAsHtml returns correct message for inaccessible exportPath"); # exportPath is a file, not a directory $config->set('exportPath', $exportPathFile); eval { ($success, $message) = $home->exportAsHtml( { userId => 3, depth => 99 } ) }; -is($@, '', "exportAsHtml catches exportPath is file exception"); -is($success, 0, "exportAsHtml returns 0 if exportPath is a file"); +is($@, '', "exportAsHtml catches exportPath is file exception"); +is($success, 0, "exportAsHtml returns 0 if exportPath is a file"); is($message, "$exportPathFile isn't a directory", "exportAsHtml returns correct message if exportPath is a file"); # can't create export path @@ -931,8 +940,8 @@ chmod 0000, $tempDirectory; $config->set('exportPath', $inaccessibleDirectory->stringify); eval { ($success, $message) = $home->exportAsHtml( { userId => 3, depth => 99 } ) }; -is($@, '', "exportAsHtml catches uncreatable exportPath exception"); -is($success, 0, "exportAsHtml returns 0 for uncreatable exportPath"); +is($@, '', "exportAsHtml catches uncreatable exportPath exception"); +is($success, 0, "exportAsHtml returns 0 for uncreatable exportPath"); is($message, "can't create exportPath $inaccessibleDirectory", "exportAsHtml returns correct message for uncreatable exportPath"); # user can't view asset @@ -966,18 +975,21 @@ $exportPath->rmtree; ($success, $message) = $home->exportAsHtml( { userId => 3, depth => 99, extrasUploadAction => 'symlink', quiet => 1 } ); $extrasSymlink = Path::Class::File->new($exportPath, $extrasUrl); $uploadsSymlink = Path::Class::File->new($exportPath, $uploadsUrl); -is($success, 1, "exportAsHtml when linking extras and uploads returns true"); -like($message, qr/Exported 23 pages/, "exportAsHtml when linking extras and uploads returns correct message"); -ok(-e $extrasSymlink->absolute->stringify, "exportAsHtml writes extras symlink"); + +is($success, 1, "exportAsHtml when linking extras and uploads returns true"); +like($message, qr/Exported $numberCreatedAll pages/, "exportAsHtml when linking extras and uploads returns correct message"); + +ok(-e $extrasSymlink->absolute->stringify, "exportAsHtml writes extras symlink"); is($extrasPath, readlink $extrasSymlink->absolute->stringify, "exportAsHtml extras symlink points to right place"); -ok(-e $uploadsSymlink->absolute->stringify, "exportAsHtml writes uploads symlink"); + +ok(-e $uploadsSymlink->absolute->stringify, "exportAsHtml writes uploads symlink"); is($uploadsPath, readlink $uploadsSymlink->absolute->stringify, "exportAsHtml uploads symlink points to right place"); # next, make sure the root URL symlinking works. ($success, $message) = $home->exportAsHtml( { userId => 3, depth => 99, rootUrlAction => 'symlink', quiet => 1 } ); my $rootUrlSymlink = Path::Class::File->new($exportPath, 'index.html'); is($success, 1, 'exportAsHtml when linking root URL returns true'); -like($message, qr/Exported 23 pages/, "exportAsHtml when linking root URL returns correct message"); +like($message, qr/Exported $numberCreatedAll pages/, "exportAsHtml when linking root URL returns correct message"); ok(-e $rootUrlSymlink->absolute->stringify, "exportAsHtml writes root URL symlink"); is($home->exportGetUrlAsPath->absolute->stringify, readlink $rootUrlSymlink->absolute->stringify, "exportAsHtml root URL symlink points to right place"); diff --git a/t/Asset/AssetPackage.t b/t/Asset/AssetPackage.t index 1e6bdf0c7..0141d1648 100644 --- a/t/Asset/AssetPackage.t +++ b/t/Asset/AssetPackage.t @@ -97,6 +97,7 @@ sub hack_session_request { return $id }, ); + $request->mock('param', sub { shift->body(@_) }); $session->{_request} = $request; } diff --git a/t/Asset/File/GalleryFile/Photo/view.t b/t/Asset/File/GalleryFile/Photo/view.t index d03d51db3..6426bcfae 100644 --- a/t/Asset/File/GalleryFile/Photo/view.t +++ b/t/Asset/File/GalleryFile/Photo/view.t @@ -79,7 +79,7 @@ my $testTemplateVars = { url_listFilesForOwner => $gallery->getUrl('func=listFilesForUser;userId=3'), url_promote => $photo->getUrl('func=promote'), - url_album => $album->getUrl, + url_album => $album->getUrl('pn=1'), url_thumbnails => $album->getUrl('func=thumbnails'), url_slideshow => $album->getUrl('func=slideshow'), fileUrl => $photo->getFileUrl, diff --git a/t/Asset/Sku/Product.t b/t/Asset/Sku/Product.t index fce39fbbc..91de3033e 100644 --- a/t/Asset/Sku/Product.t +++ b/t/Asset/Sku/Product.t @@ -34,13 +34,11 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -plan tests => 7; # Increment this number for each test you create +plan tests => 8; # Increment this number for each test you create #---------------------------------------------------------------------------- # put your tests here -my $node = WebGUI::Asset::Sku::Product->getProductImportNode($session); -isa_ok($node, 'WebGUI::Asset::Wobject::Folder', 'getProductImportNode returns a Folder'); -is($node->getId, 'PBproductimportnode001', 'Product Import Node has the correct GUID'); +my $node = WebGUI::Asset->getRoot($session); my $product = $node->addChild({ className => "WebGUI::Asset::Sku::Product", @@ -53,9 +51,10 @@ 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, + className => "WebGUI::Asset::Sku::Product", + title => "Bible", + image1 => $image->getId, + isShippingRequired => 1, }); ok($imagedProduct->getThumbnailUrl(), 'getThumbnailUrl is not empty'); @@ -67,6 +66,24 @@ $otherImage->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath('gooey.jp 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'); +is($imagedProduct->get('isShippingRequired'), 1, 'isShippingRequired set to 1 in db'); +is($imagedProduct->isShippingRequired, 1, 'isShippingRequired accessor works'); + +my $englishVarId = $imagedProduct->setCollateral('variantsJSON', 'variantId', 'new', + { + shortdesc => 'English', + varSku => 'english-bible', + price => 10, + weight => 5, + quantity => 1000, + } +); + +use Data::Dumper; +$imagedProduct->applyOptions($imagedProduct->getCollateral('variantsJSON', 'variantId', $englishVarId)); + +is($imagedProduct->getConfiguredTitle, 'Bible - English', 'getConfiguredTitle is overridden and concatenates the Product Title and the variant shortdesc'); + #---------------------------------------------------------------------------- # Cleanup END { diff --git a/t/Asset/Sku/ProductCollateral.t b/t/Asset/Sku/ProductCollateral.t index 46f9508e1..d9bc039e7 100644 --- a/t/Asset/Sku/ProductCollateral.t +++ b/t/Asset/Sku/ProductCollateral.t @@ -55,7 +55,7 @@ ok($session->id->valid($vid), 'a valid id was generated for the new collateral e my $json; $json = $product->get('variantsJSON'); -my $jsonData = from_json($json); +my $jsonData = decode_json($json); cmp_deeply( $jsonData, [ {a => 'aye', b => 'bee', vid => $vid } ], diff --git a/t/Asset/Wobject/GalleryAlbum/view.t b/t/Asset/Wobject/GalleryAlbum/view.t index b67c49497..69d4ae2a0 100644 --- a/t/Asset/Wobject/GalleryAlbum/view.t +++ b/t/Asset/Wobject/GalleryAlbum/view.t @@ -69,18 +69,27 @@ plan tests => 7; #---------------------------------------------------------------------------- # Test getFileIds and getFilePaginator -cmp_bag( $album->getFileIds, [ map { $_->getId } @photos ] ); +cmp_bag( $album->getFileIds, [ map { $_->getId } @photos ], 'getFileIds returns ids of all photos' ); my $p = $album->getFilePaginator; isa_ok( $p, "WebGUI::Paginator" ); -cmp_deeply( $p->getPageData, subbagof( map { $_->getId } @photos ) ); +cmp_deeply( $p->getPageData, subbagof( map { $_->getId } @photos ), 'getPageData contains a subset of the ids o the photos'); #---------------------------------------------------------------------------- # Test getTemplateVars # Is a superset of Asset->get # NOTE: url is Asset->getUrl -cmp_deeply( $album->getTemplateVars, superhashof( { %{$album->get}, url => $album->getUrl, } ) ); +# NOTE: undef description remapped to empty string '' +cmp_deeply( + $album->getTemplateVars, + superhashof( { + %{$album->get}, + url => $album->getUrl, + description => '', + } ), + q|getTemplateVariables returns the Album's asset properties| +); # Contains specific keys/values my $expected = { @@ -114,7 +123,7 @@ my $expected = { => WebGUI::User->new($session, 3)->username, }; -cmp_deeply( $album->getTemplateVars, superhashof( $expected ) ); +cmp_deeply( $album->getTemplateVars, superhashof( $expected ), '... and also returns a set of other template variables' ); #---------------------------------------------------------------------------- # Test appendTemplateVarsFileLoop diff --git a/t/Asset/Wobject/SyndicatedContent.t b/t/Asset/Wobject/SyndicatedContent.t index dc6a788bd..0052cf42d 100644 --- a/t/Asset/Wobject/SyndicatedContent.t +++ b/t/Asset/Wobject/SyndicatedContent.t @@ -25,7 +25,7 @@ use WebGUI::Asset::Wobject::SyndicatedContent; my $session = WebGUI::Test->session; my %var; -my ($items, @rss_feeds); +my (@rss_feeds); ############################## ## SETUP ## @@ -99,8 +99,10 @@ my $rss_info = WebGUI::Asset::Wobject::SyndicatedContent::_get_rss_data($session ok(ref($rss_info) eq 'HASH', "Hashref returned from _get_rss_data"); push(@rss_feeds, $rss_info); -my $xml_list = WebGUI::Asset::Wobject::SyndicatedContent::_create_interleaved_items($items, \@rss_feeds , $max_headlines, $hasTermsRegex); -ok($xml_list , "Got results back from XML " ); + +my $items = []; +WebGUI::Asset::Wobject::SyndicatedContent::_create_interleaved_items($items, \@rss_feeds , $max_headlines, $hasTermsRegex); +ok($items , "Got results back from XML" ); my($item_loop,$rss_feeds) = $syndicated_content->_get_items(\@validated_urls, $max_headlines); ok(ref($item_loop) eq 'ARRAY',"Arrayref of items returned from _get_items" );