revert oops

This commit is contained in:
Graham Knop 2008-08-19 20:48:47 +00:00
parent 57b8cc4bae
commit edebe7e2b9
9 changed files with 122 additions and 70 deletions

View file

@ -109,21 +109,28 @@ C<options> 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' ) );
}
}

View file

@ -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 => '<b></b>',
fixed => '',
comment => "If there is no title left after processing, then it is set to untitled.",
},
);
}

View file

@ -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");

View file

@ -97,6 +97,7 @@ sub hack_session_request {
return $id
},
);
$request->mock('param', sub { shift->body(@_) });
$session->{_request} = $request;
}

View file

@ -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,

View file

@ -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 {

View file

@ -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 } ],

View file

@ -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

View file

@ -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" );