Merge branch 'WebGUI8' into psgi

Conflicts:
	sbin/testEnvironment.pl
This commit is contained in:
Patrick Donelan 2010-06-04 21:01:03 -04:00
commit f16ba76b86
109 changed files with 1546 additions and 2197 deletions

View file

@ -20,8 +20,9 @@ use Test::More;
use Test::Deep;
use Test::Exception;
use WebGUI::Exception;
use WebGUI::Asset;
use WebGUI::Keyword;
plan tests => 65;
my $session = WebGUI::Test->session;
@ -129,6 +130,20 @@ my $session = WebGUI::Test->session;
}
{
note "get, specific properties";
my $asset = WebGUI::Asset->new({
session => $session,
});
my $properties = $asset->get();
ok !exists $properties->{session}, 'no session';
ok exists $properties->{keywords}, 'keywords'; ##Test for function later
ok exists $properties->{assetId}, 'assetId';
ok exists $properties->{revisionDate}, 'assetId';
ok exists $properties->{parentId}, 'parentId';
ok exists $properties->{lineage}, 'lineage';
}
{
note "getClassById";
my $class;
@ -217,6 +232,32 @@ my $session = WebGUI::Test->session;
$session->db->write("delete from assetData where assetId=?", [$testId]);
}
{
note "setVersionLock";
my $testId1 = 'wg8TestAsset0000000001';
my $testId2 = 'wg8TestAsset0000000002';
my $now = time();
my $baseLineage = $session->db->quickScalar('select lineage from asset where assetId=?',['PBasset000000000000002']);
my $testLineage = $baseLineage. '909090';
$session->db->write("insert into asset (assetId, className, lineage) VALUES (?,?,?)", [$testId1, 'WebGUI::Asset', $testLineage]);
$session->db->write("insert into assetData (assetId, revisionDate, status) VALUES (?,?,?)", [$testId1, $now, 'approved']);
my $testLineage2 = $testLineage . '000001';
$session->db->write("insert into asset (assetId, className, parentId, lineage) VALUES (?,?,?,?)", [$testId2, 'WebGUI::Asset', $testId1, $testLineage2]);
$session->db->write("insert into assetData (assetId, revisionDate) VALUES (?,?)", [$testId2, $now]);
my $testAsset = WebGUI::Asset->new($session, $testId2, $now);
my $originalSessionUser = $session->user->userId;
$session->user({userId => 7});
$testAsset->setVersionLock;
is $testAsset->isLockedBy, 7, 'locked by userId 7';
ok $testAsset->isLocked, 'asset is locked';
is $session->db->quickScalar('select isLockedBy from asset where assetId=?',[$testId2]), 7, 'userId written to db';
$session->db->write("delete from asset where assetId like 'wg8TestAsset00000%'");
$session->db->write("delete from assetData where assetId like 'wg8TestAsset00000%'");
$session->user({userId => $originalSessionUser});
}
{
note "getParent";
my $testId1 = 'wg8TestAsset0000000001';
@ -254,21 +295,28 @@ my $session = WebGUI::Test->session;
$session->db->write("insert into assetData (assetId, revisionDate) VALUES (?,?)", [$testId2, $revisionDate]);
my $testAsset = WebGUI::Asset->new($session, $testId2, $revisionDate);
my $originalSessionUser = $session->user->userId;
$session->user({userId => 7});
$testAsset->title('test title 43');
$testAsset->write();
my $tag = WebGUI::VersionTag->getWorking($session);
my $revAsset = $testAsset->addRevision({}, $now);
my $revAssetDb = $revAsset->cloneFromDb;
isa_ok $revAsset, 'WebGUI::Asset';
is $revAsset->revisionDate, $now, 'revisionDate set correctly on new revision';
is $revAsset->title, 'test title 43', 'data fetch from database correct';
is $revAsset->revisedBy, $session->user->userId, 'revisedBy is current session user';
is $revAsset->tagId, $tag->getId, 'tagId is current working tagId';
ok $revAsset->isLocked, 'new revision is locked';
is $revAsset->isLockedBy, '7', 'locked by userId 7';
is $revAssetDb->isLockedBy, '7', 'database jives with asset data';
my $count = $session->db->quickScalar('SELECT COUNT(*) from assetData where assetId=?',[$testId2]);
is $count, 2, 'two records in the database';
addToCleanup($tag);
$session->db->write("delete from asset where assetId like 'wg8TestAsset00000%'");
$session->db->write("delete from assetData where assetId like 'wg8TestAsset00000%'");
$session->user({userId => $originalSessionUser});
}
{
@ -313,11 +361,26 @@ my $session = WebGUI::Test->session;
my $asset = $default->addChild({
className => 'WebGUI::Asset::Snippet',
});
addToCleanup($asset);
WebGUI::Test->addToCleanup($asset);
can_ok($asset, 'keywords');
$asset->keywords('chess set');
is ($asset->keywords, 'chess set', 'set and get of keywords via direct accessor');
is ($asset->get('keywords'), 'chess set', 'via get method');
my $keygate = WebGUI::Keyword->new($session);
is $keygate->getKeywordsForAsset({assetId => $asset->getId}), '', 'not persisted to the db';
$asset->write;
is $keygate->getKeywordsForAsset({assetId => $asset->assetId}), 'chess set', 'written to the db';
my $asset_copy = $asset->cloneFromDb;
is $asset->keywords, 'chess set', 'refreshed from db';
my $asset2 = $default->addChild({
className => 'WebGUI::Asset::Snippet',
keywords => 'checkmate',
});
WebGUI::Test->addToCleanup($asset2);
is $asset2->keywords, 'checkmate', 'keywords set on addChild';
is $keygate->getKeywordsForAsset({assetId => $asset2->assetId}), 'checkmate', '... and persisted to the db';
}
{
@ -325,3 +388,16 @@ my $session = WebGUI::Test->session;
my $classes = WebGUI::Asset->valid_parent_classes;
cmp_deeply($classes, [qw/WebGUI::Asset/], 'Any asset okay');
}
{
note "url, inherited URLs from parent";
my $home = WebGUI::Asset->getDefault($session);
my $asset = $home->addChild({
className => 'WebGUI::Asset::Wobject::Article',
title => 'sub',
});
WebGUI::Test->addToCleanup($asset);
is $asset->url, 'home/sub', 'by default, asset gets a url from the title, and the parent';
}
done_testing;

View file

@ -35,7 +35,7 @@ my $session = WebGUI::Test->session;
my @getTitleTests = getTitleTests($session);
plan tests => 110
plan tests => 121
+ 2*scalar(@getTitleTests) #same tests used for getTitle and getMenuTitle
;

View file

@ -188,6 +188,10 @@ my $grandChild = $firstChild->addChild({
});
$versionTag->commit;
foreach my $asset ($parent, $firstChild, $grandChild) {
$asset = $asset->cloneFromDb;
}
my $isExportable;
# simple test first. the asset we're checking isn't exportable. should of course return 0.
@ -748,12 +752,12 @@ is($@, '', "exportAsHtml on parent does not throw an error"); ##Note, string com
[ qw/ parent index.html /],
);
my $numberCreatedAll = scalar @createdFiles;
like($message, qr/Exported $numberCreatedAll pages/, "exportAsHtml on parent returns correct message");
# turn them into Path::Class::File objects
@shouldExist = map { Path::Class::File->new($exportPath, @{$_})->absolute->stringify } @createdFiles;
my $numberCreatedAll = scalar @createdFiles;
like($message, qr/Exported $numberCreatedAll pages/, "exportAsHtml on parent returns correct message");
# 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 } );

View file

@ -19,6 +19,7 @@ use WebGUI::User;
use WebGUI::Asset;
use Test::More tests => 94; # increment this value for each test you create
use Test::Deep;
use Test::Exception;
use Data::Dumper;
# Test the methods in WebGUI::AssetLineage
@ -505,7 +506,7 @@ delete $cachedLineage->{$snippet4->get('lineage')}->{class};
my $snippet4 = WebGUI::Asset->newByLineage($session, $snippets[4]->get('lineage'));
is ($snippet4->getId, $snippets[4]->getId, '... failing class cache forces lookup');
is(WebGUI::Asset->newByLineage($session, 'notALineage'), undef, '... returns undef');
dies_ok { WebGUI::Asset->newByLineage($session, 'notALineage') } '... throws an exception';
ok(!exists $session->stow->get('assetLineage')->{assetLineage}, '... no entry for the bad lineage in stow');
####################################################

View file

@ -35,13 +35,15 @@ my $versionTag = WebGUI::VersionTag->getWorking($session);
WebGUI::Test->tagsToRollback($versionTag);
$versionTag->set({name=>"Asset Package test"});
my $time = time() -2;
my $folder = $root->addChild({
url => 'testFolder',
title => 'folder',
menuTitle => 'folderMenuTitle',
className => 'WebGUI::Asset::Wobject::Folder',
isPackage => 1,
});
}, undef, $time);
my $targetFolder = $root->addChild({
url => 'targetFolder',
@ -56,7 +58,7 @@ my $subSnippet = $folder->addChild({
menuTitle => 'snippetMenuTitle',
className => 'WebGUI::Asset::Snippet',
snippet => 'A snippet of text',
});
}, undef, $time);
my $snippet = $root->addChild({
url => 'snip_snip',
@ -64,7 +66,7 @@ my $snippet = $root->addChild({
className => 'WebGUI::Asset::Snippet',
snippet => 'Always upgrade to the latest version',
isPackage => 1,
});
}, undef, $time);
my $packageAssetId = $folder->getId;
$session->request->setup_body({ assetId => $packageAssetId });
@ -75,7 +77,7 @@ is(scalar @{ $targetFolderChildren }, 0, 'target folder has no children');
$versionTag->commit;
sleep 2;
#sleep 2;
my $storage = $snippet->exportPackage();
isa_ok($storage, 'WebGUI::Storage', 'exportPackage returns a WebGUI::Storage object');
@ -110,15 +112,15 @@ my $newVersionTag = WebGUI::VersionTag->getWorking($session);
WebGUI::Test->tagsToRollback($newVersionTag);
$newVersionTag->commit;
my $newFolder = WebGUI::Asset->new($session, $folder->getId);
my $newFolder = WebGUI::Asset->newById($session, $folder->getId);
ok(! $newFolder->get('isPackage'), 'Disabled isPackage in original folder asset');
sleep 1;
my $updatedSnippet = WebGUI::Asset->new($session, $snippet->getId);
my $updatedSnippet = WebGUI::Asset->newById($session, $snippet->getId);
$root->importPackage($storage, { overwriteLatest => 1 });
$updatedSnippet = WebGUI::Asset->new($session, $snippet->getId);
$updatedSnippet = WebGUI::Asset->newById($session, $snippet->getId);
is($updatedSnippet->get('snippet'), 'Always upgrade to the latest version', 'importPackage: overwriteLatest causes revision dates to be ignored');
cmp_ok( $updatedSnippet->get('revisionDate'), '>', $snippetRev->get('revisionDate'), '... revisionDate check on imported package with overwriteLatest');

View file

@ -122,6 +122,7 @@ my $i18n = $ems->i18n;
$versionTag->commit;
$versionTag = WebGUI::VersionTag->getWorking($session);
WebGUI::Test->tagsToRollback($versionTag);
$ems = $ems->cloneFromDb;
my $id1 = $ems->getNextSubmissionId;
my $id2 = $ems->getNextSubmissionId;
@ -353,7 +354,7 @@ is($approveSubmissions->run, 'done', 'approval done');
$sub1 = $sub1->cloneFromDb;
is( $sub1->get('submissionStatus'),'created','approval successfull');
my $ticket = WebGUI::Asset->newByDynamicClass($session, $sub1->get('ticketId'));
my $ticket = WebGUI::Asset->newById($session, $sub1->get('ticketId'));
WebGUI::Test->assetsToPurge( $ticket ) if $ticket ;
SKIP: {
skip 'no ticket created', 1 unless isa_ok( $ticket, 'WebGUI::Asset::Sku::EMSTicket', 'approval created a ticket');
@ -372,7 +373,7 @@ $cleanupSubmissions->reset;
is($cleanupSubmissions->run, 'complete', 'cleanup complete');
is($cleanupSubmissions->run, 'done', 'cleanup done');
$sub2 = WebGUI::Asset->newByDynamicClass($session, $sub2Id);
$sub2 = WebGUI::Asset->newById($session, $sub2Id);
is( $sub2, undef, 'submission deleted');
} # end of workflow skip

View file

@ -18,12 +18,14 @@ use Scalar::Util;
use WebGUI::Test;
use WebGUI::Session;
use Test::More;
use Test::Exception;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
WebGUI::Test->addToCleanup($versionTag);
$versionTag->set({name=>"Photo Test"});
@ -90,15 +92,4 @@ is(
my $properties = $photo->get;
$photo->purge;
is(
WebGUI::Asset->newByDynamicClass($session, $properties->{assetId}), undef,
"Photo no longer able to be instanciated",
);
#----------------------------------------------------------------------------
# Cleanup
END {
$versionTag->rollback;
}
dies_ok { WebGUI::Asset->newById($session, $properties->{assetId}) } "Photo no longer able to be instanciated";

View file

@ -31,6 +31,7 @@ my $node = WebGUI::Asset->getImportNode($session);
my @versionTags = ();
push @versionTags, WebGUI::VersionTag->getWorking($session);
$versionTags[-1]->set({name=>"Photo Test, add Gallery, Album and 1 Photo"});
WebGUI::Test->addToCleanup($versionTags[-1]);
my @addArguments = ( undef, undef, { skipAutoCommitWorkflows => 1 } );
my $gallery
@ -326,13 +327,3 @@ TODO: {
# TODO
ok( 0, "Visitor has their IP logged in visitorIp field" );
}
#----------------------------------------------------------------------------
# Cleanup
END {
foreach my $versionTag (@versionTags) {
$versionTag->rollback;
}
};

View file

@ -29,7 +29,7 @@ my $node = WebGUI::Asset->getImportNode($session);
my @versionTags = ();
push @versionTags, WebGUI::VersionTag->getWorking($session);
$versionTags[-1]->set({name=>"Photo Test, add Gallery, Album and 1 Photo"});
my $versionTag = WebGUI::VersionTag->getWorking($session);
WebGUI::Test->addToCleanup($versionTags[-1]);
my $gallery
= $node->addChild({
@ -84,13 +84,3 @@ ok(
"getDownloadFileUrl croaks if resolution doesn't exist",
);
#----------------------------------------------------------------------------
# Cleanup
END {
foreach my $versionTag (@versionTags) {
$versionTag->rollback;
}
}

View file

@ -120,11 +120,11 @@ SKIP: {
};
# Make sure properties were saved
my $photo = WebGUI::Asset->newByDynamicClass( $session, $album->getFileIds->[0] );
my $photo = WebGUI::Asset->newById( $session, $album->getFileIds->[0] );
cmp_deeply( $photo->get, superhashof( $properties ), "Photo properties saved correctly" );
# First File in an album should update assetIdThumbnail
my $album = WebGUI::Asset->newByDynamicClass( $session, $album->getId );
my $album = WebGUI::Asset->newById( $session, $album->getId );
is(
$album->get('assetIdThumbnail'), $photo->getId,
"Album assetIdThumbnail gets set by first File added",

View file

@ -27,6 +27,7 @@ my $session = WebGUI::Test->session;
my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Photo Test"});
WebGUI::Test->addToCleanup($versionTag);
my $gallery
= $node->addChild({
className => "WebGUI::Asset::Wobject::Gallery",
@ -61,13 +62,6 @@ for my $key ( qw{ Directory } ) {
delete $exif->{ $key };
}
#----------------------------------------------------------------------------
# Cleanup
END {
$versionTag->rollback();
}
#----------------------------------------------------------------------------
# Tests
plan tests => 2;

View file

@ -62,6 +62,7 @@ $photo
skipAutoCommitWorkflows => 1,
});
$versionTags[-1]->commit;
WebGUI::Test->addToCleanup($versionTags[-1]);
$photo->getStorageLocation->addFileFromFilesystem( WebGUI::Test->getTestCollateralPath('page_title.jpg') );
$photo->update({ filename => 'page_title.jpg' });
@ -86,6 +87,7 @@ TODO: {
# Array of resolutions passed to makeResolutions overrides defaults from
# parent asset
push @versionTags, WebGUI::VersionTag->getWorking($session);
WebGUI::Test->addToCleanup($versionTags[-1]);
$gallery
= $node->addChild({
className => "WebGUI::Asset::Wobject::Gallery",
@ -139,8 +141,9 @@ TODO: {
# makeResolutions allows API to specify resolutions to make as array reference
# argument
push @versionTags, WebGUI::VersionTag->getWorking($session);
WebGUI::Test->addToCleanup($versionTags[-1]);
$photo
= $node->addChild({
= $album->addChild({
className => "WebGUI::Asset::File::GalleryFile::Photo",
},
undef,
@ -176,8 +179,9 @@ TODO: {
#----------------------------------------------------------------------------
# makeResolutions throws a warning on an invalid resolution but keeps going
push @versionTags, WebGUI::VersionTag->getWorking($session);
WebGUI::Test->addToCleanup($versionTags[-1]);
$photo
= $node->addChild({
= $album->addChild({
className => "WebGUI::Asset::File::GalleryFile::Photo",
},
undef,
@ -220,13 +224,3 @@ $photo->update({ filename => 'page_title.jpg' });
"makeResolutions still makes valid resolutions when invalid resolutions given",
);
}
#----------------------------------------------------------------------------
# Cleanup
END {
foreach my $versionTag (@versionTags) {
$versionTag->rollback;
}
}

View file

@ -20,7 +20,6 @@ use WebGUI::Test;
use WebGUI::Session;
use Test::More;
use Test::Deep;
use WebGUI::Test::Maker::HTML;
use WebGUI::Asset::File::GalleryFile::Photo;
#----------------------------------------------------------------------------
@ -29,13 +28,28 @@ my $session = WebGUI::Test->session;
my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Photo Test"});
my $maker = WebGUI::Test::Maker::HTML->new;
WebGUI::Test->addToCleanup($versionTag);
my $otherParent
= $node->addChild({
className => "WebGUI::Asset::Wobject::Layout",
});
my $photo
my $gallery
= $node->addChild({
className => "WebGUI::Asset::Wobject::Gallery",
imageResolutions => "1600x1200\n1024x768\n800x600\n640x480",
});
my $album
= $gallery->addChild({
className => "WebGUI::Asset::Wobject::GalleryAlbum",
},
undef,
undef,
{
skipAutoCommitWorkflows => 1,
});
my $photo
= $album->addChild({
className => "WebGUI::Asset::File::GalleryFile::Photo",
userDefined1 => "ORIGINAL",
},
@ -118,11 +132,3 @@ cmp_deeply(
#----------------------------------------------------------------------------
# www_makeShortcut
#----------------------------------------------------------------------------
# Cleanup
END {
$versionTag->rollback();
}

View file

@ -72,6 +72,7 @@ my $photo
{
skipAutoCommitWorkflows => 1,
});
$versionTag->commit;
my $photo2 = $photo->cloneFromDb;
my $album2 = $album->cloneFromDb;

View file

@ -73,6 +73,10 @@ my $nextPhoto
skipAutoCommitWorkflows => 1,
});
$versionTag->commit;
foreach my $asset ($gallery, $album) {
$asset = $asset->cloneFromDb;
}
WebGUI::Test->addToCleanup($versionTag);
$photo->setFile( WebGUI::Test->getTestCollateralPath('page_title.jpg') );
#----------------------------------------------------------------------------
@ -148,9 +152,3 @@ cmp_deeply(
$testTemplateVars,
"getTemplateVars is correct and complete",
);
#----------------------------------------------------------------------------
# Cleanup
END {
$versionTag->rollback();
}

View file

@ -31,7 +31,6 @@ use WebGUI::Form::File;
use Test::More; # increment this value for each test you create
use Test::Deep;
use Data::Dumper;
plan tests => 15;
my $session = WebGUI::Test->session;
@ -106,7 +105,7 @@ $templateMock->set_isa('WebGUI::Asset::Template');
$templateMock->set_always('getId', $templateId);
$templateMock->set_true('prepare');
my $templateVars;
$templateMock->mock('process', sub { $templateVars = $_[1]; } );
$templateMock->mock('process', sub { $templateVars = $_[1]; return ''; } );
$asset->update({
parameters => 'alt="alternate"',
@ -123,7 +122,9 @@ $asset->update({
}
$versionTag->commit;
addToCleanup($versionTag);
WebGUI::Test->addToCleanup($versionTag);
done_testing();
sub isnt_array {
my ($a, $b) = @_;

View file

@ -26,6 +26,7 @@ my $session = WebGUI::Test->session;
my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Image Test"});
WebGUI::Test->addToCleanup($versionTag);
my $image
= $node->addChild({
className => "WebGUI::Asset::File::Image",
@ -54,9 +55,3 @@ ok(
"Thumbnail file exists on the filesystem",
);
#----------------------------------------------------------------------------
# Cleanup
END {
$versionTag->rollback();
}

View file

@ -25,6 +25,7 @@ my $session = WebGUI::Test->session;
my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"File Test"});
WebGUI::Test->addToCleanup($versionTag);
my $file
= $node->addChild({
className => "WebGUI::Asset::File",
@ -46,18 +47,10 @@ ok(
#----------------------------------------------------------------------------
# setFile allows file path argument and adds the file
# plan tests => 1
$file->setFile( WebGUI::Test->getTestCollateralPath("WebGUI.pm") );
$file->setFile( WebGUI::Test->getTestCollateralPath("International/lib/WebGUI/i18n/PigLatin/WebGUI.pm") );
my $storage = $file->getStorageLocation;
is_deeply(
$storage->getFiles, ['WebGUI.pm'],
"Storage location contains only the file we added",
);
#----------------------------------------------------------------------------
# Cleanup
END {
$versionTag->rollback();
}

View file

@ -84,6 +84,7 @@ my $post = $collab->addChild($props, @addArgs);
$versionTag->commit();
WebGUI::Test->tagsToRollback($versionTag);
$post = $post->cloneFromDb;
# Test for a sane object type
isa_ok($post, 'WebGUI::Asset::Post::Thread');
@ -120,7 +121,7 @@ $post->update({synopsis => $synopsis});
##There is a bug in DBD::mysql with not properly encoding 8-bit characters. Also, HTML::Entities produces
##8-bit utf8 (not strict) characters. So we write a quick test to make sure our patch in splitTag works correctly.
my $dbPost = WebGUI::Asset->newByDynamicClass($session, $post->getId);
my $dbPost = WebGUI::Asset->newById($session, $post->getId);
like($dbPost->get('synopsis'), qr/Brandhei.e Neuigkeiten rund um's Klettern f.r euch aus der Region /, 'patch test for DBD::Mysql and HTML::Entities');
($synopsis, $content) = $post->getSynopsisAndContent('', q|less than < greater than >|);

View file

@ -49,6 +49,8 @@ my $props = {
my $thread = $collab->addChild($props, @addArgs);
$versionTag->commit();
$collab = $collab->cloneFromDb;
$thread = $thread->cloneFromDb;
my $uncommittedThread = $collab->addChild($props, @addArgs);

View file

@ -61,6 +61,10 @@ my @threads = (
$_->setSkipNotification for @threads;
$versionTags[-1]->commit;
WebGUI::Test->addToCleanup($versionTags[-1]);
foreach my $asset(@threads, $collab) {
$asset = $asset->cloneFromDb;
}
#----------------------------------------------------------------------------
# Tests
@ -133,6 +137,7 @@ $collab->update({
sortOrder => 'desc',
});
push @versionTags, WebGUI::VersionTag->getWorking( $session );
WebGUI::Test->addToCleanup($versionTags[-1]);
push @threads, $collab->addChild( {
className => 'WebGUI::Asset::Post::Thread',
title => "Abababa",
@ -146,12 +151,6 @@ testGetAdjacentThread( "sort by default from asset with version tag", $sort, [ q
$session->scratch->delete($collab->getId.'_sortBy');
$session->scratch->delete($collab->getId.'_sortDir');
#----------------------------------------------------------------------------
# Cleanup
END {
$_->rollback for @versionTags;
}
#----------------------------------------------------------------------------
# testGetAdjacentThread ( label, sort, order, @threads )
# Performs two tests for each thread in [order]
@ -161,10 +160,10 @@ END {
# @threads = all the threads
sub testGetAdjacentThread {
my ( $label, $sort, $order, @threads ) = @_;
my $idxFirst = shift @{$order};
my $idxLast = pop @{$order};
# First
is( $threads[$idxFirst]->getNextThread->getId,
getNextThread( $sort, $threads[$idxFirst], @threads )->getId,
@ -220,7 +219,7 @@ sub sortThreads {
sub getNextThread {
my ( $sortSub, $thread, @threads ) = @_;
my @sorted = @{ sortThreads( $sortSub, @threads ) };
for my $i ( 0..$#sorted ) {
if ( $sorted[$i]->getId eq $thread->getId ) {
return $sorted[$i+1];
@ -232,7 +231,7 @@ sub getPreviousThread {
my ( $sortSub, $thread, @threads ) = @_;
# Use reverse so that $i-1 != -1 (which gets us the last thread)
my @sorted = reverse @{ sortThreads( $sortSub, @threads ) };
for my $i ( 0..$#sorted ) {
if ( $sorted[$i]->getId eq $thread->getId ) {
return $sorted[$i+1];

View file

@ -62,8 +62,8 @@ my $thread
$versionTag->commit( { timeout => 1_000_000 } );
# Re-load the collab to get the newly committed properties
$collab = WebGUI::Asset->newByDynamicClass( $session, $collab->getId );
$thread = WebGUI::Asset->newByDynamicClass( $session, $thread->getId );
$collab = WebGUI::Asset->newById( $session, $collab->getId );
$thread = WebGUI::Asset->newById( $session, $thread->getId );
#----------------------------------------------------------------------------
# Tests
@ -104,7 +104,7 @@ $maker->prepare( {
# Reply with allowReplies = 0
$collab->update({ allowReplies => 0 });
$thread = WebGUI::Asset->newByDynamicClass( $session, $thread->getId );
$thread = WebGUI::Asset->newById( $session, $thread->getId );
$maker->prepare( {
object => $thread,
method => 'canReply',

View file

@ -67,9 +67,9 @@ my $post
$versionTag->commit( { timeout => 1_000_000 } );
# Re-load the collab to get the newly committed properties
$collab = WebGUI::Asset->newByDynamicClass( $session, $collab->getId );
$thread = WebGUI::Asset->newByDynamicClass( $session, $thread->getId );
$post = WebGUI::Asset->newByDynamicClass( $session, $post->getId );
$collab = WebGUI::Asset->newById( $session, $collab->getId );
$thread = WebGUI::Asset->newById( $session, $thread->getId );
$post = WebGUI::Asset->newById( $session, $post->getId );
#----------------------------------------------------------------------------
# Tests

View file

@ -108,7 +108,7 @@ eval {
};
is(
$contentLastModified, 0,
$contentLastModified, undef,
"Purged Linked Asset: getContentLastModified returns 0 when linked asset missing",
);
@ -122,10 +122,10 @@ init();
$snippet->trash();
$snippet->purge();
$shortcut = $shortcut->cloneFromDb();
$shortcut = eval { $shortcut->cloneFromDb(); };
ok(
!defined $shortcut,
Exception::Class->caught(),
"Purge Linked Asset: Shortcut is purged even though it's in the trash"
);
@ -135,10 +135,10 @@ init();
#----------------------------------------------------------------------------
# Test purging snippet purges shortcut also
$snippet->purge;
$shortcut = $shortcut->cloneFromDb();
$shortcut = eval { $shortcut->cloneFromDb(); };
ok(
!defined $shortcut,
Exception::Class->caught(),
"Purge Linked Asset: Shortcut is not defined",
);

View file

@ -30,20 +30,21 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
plan tests => 22; # Increment this number for each test you create
plan tests => 23; # Increment this number for each test you create
#----------------------------------------------------------------------------
# put your tests here
my $root = WebGUI::Asset->getRoot($session);
warn "Make sku\n";
note "Make sku\n";
my $sku = $root->addChild({
className=>"WebGUI::Asset::Sku",
title=>"Test Sku",
});
isa_ok($sku, "WebGUI::Asset::Sku");
addToCleanup($sku);
WebGUI::Test->addToCleanup($sku);
$sku->addToCart;
WebGUI::Test->addToCleanup($sku->getCart);
$sku->applyOptions({
test1 => "YY"
@ -53,6 +54,7 @@ my $options = $sku->getOptions;
is($options->{test1}, "YY", "Can set and get an option.");
is $sku->taxConfiguration, '{}', 'default tax configuration is a string with an empty hashref in it';
is($sku->getMaxAllowedInCart, 99999999, "Got a valid default max in cart.");
is($sku->getQuantityAvailable, 99999999, "skus should have an unlimited quantity by default");
is($sku->getQuantityAvailable, $sku->getMaxAllowedInCart, "quantity available and max allowed in cart should be the same");
@ -81,7 +83,7 @@ ok(! $sku->isShippingRequired, 'Making sure that GLOB is no longer in effect');
isa_ok($sku->getCart, "WebGUI::Shop::Cart", "can get a cart object");
my $item = $sku->addToCart;
isa_ok($item, "WebGUI::Shop::CartItem", "can add to cart");
$item->cart->delete;
my $loadSku = WebGUI::Asset::Sku->newBySku($session, $sku->get("sku"));
is($loadSku->getId, $sku->getId, "newBySku() works.");

View file

@ -302,7 +302,7 @@ my $product6 = $root->addChild({
$newVid = $product6->setCollateral('variantsJSON', 'vid', 'new', { wideChar => qq!on 16\x{201d} hand-crocheted Cord!
, vid => 'new' });
my $product6a = WebGUI::Asset->newByDynamicClass($session, $product6->getId);
my $product6a = WebGUI::Asset->newById($session, $product6->getId);
lives_ok { $product6a->getAllCollateral('variantsJSON', 'vid', $newVid); }, 'Product collateral handles wide-character encodings okay';
$product6->purge;

View file

@ -16,7 +16,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use Test::More tests => 21; # increment this value for each test you create
use Test::More tests => 23; # increment this value for each test you create
use Test::Exception;
use WebGUI::Asset::Snippet;
@ -111,6 +111,12 @@ $snippet2->update({mimeType => 'text/javascript'});
$tag2->commit;
addToCleanup($tag2);
$snippet2->snippet('uncompressable');
is $snippet2->snippetPacked, 'uncompressable', 'packed snippet content was set';
$snippet2->snippet("two\n\nwords");
is $snippet2->snippetPacked, "two words", '... and packed';
open my $JSFILE, WebGUI::Test->getTestCollateralPath('jquery.js')
or die "Unable to open jquery test collateral file: $!";
my $jquery;
@ -120,6 +126,7 @@ my $jquery;
};
close $JSFILE;
$snippet2 = $snippet2->cloneFromDb;
is $snippet2->get('snippetPacked'), undef, 'no packed content';
lives_ok { $snippet2->update({snippet => $jquery}); } 'did not die during packing jquery';
ok $snippet2->get('snippetPacked'), 'snippet content was packed';

View file

@ -18,6 +18,7 @@ use WebGUI::Session;
use WebGUI::Storage;
use WebGUI::User;
use WebGUI::Group;
use WebGUI::Asset::Story;
use Test::More; # increment this value for each test you create
use Test::Deep;
@ -82,18 +83,10 @@ WebGUI::Test->storagesToDelete($storage1, $storage2);
############################################################
my $tests = 45;
plan tests => 1
+ $tests
plan tests => $tests
+ $canEditMaker->plan
;
my $class = 'WebGUI::Asset::Story';
my $loaded = use_ok($class);
SKIP: {
skip "Unable to load module $class", $tests unless $loaded;
############################################################
#
# validParent
@ -439,7 +432,5 @@ cmp_bag(
'...asset package data has the storage locations in it'
);
}
END {
}

View file

@ -57,7 +57,7 @@ use Data::Dumper;
use WebGUI::Asset::Wobject::Calendar;
use WebGUI::Asset::Event;
plan tests => 14 + scalar @icalWrapTests;
plan tests => 12 + scalar @icalWrapTests;
my $session = WebGUI::Test->session;
@ -82,10 +82,6 @@ isa_ok($cal, 'WebGUI::Asset::Wobject::Calendar');
my $event = $cal->addChild({className=>'WebGUI::Asset::Event'});
isa_ok($event, 'WebGUI::Asset::Event','Can add Events as a child to the calendar.');
my $article = $cal->addChild({className=>"WebGUI::Asset::Wobject::Article"});
isnt(ref $article, 'WebGUI::Asset::Wobject::Article', "Can't add an article as a child to the calendar.");
ok(! defined $article, '... addChild returned undef');
my $dt = WebGUI::DateTime->new($session, mysql => '2001-08-16 8:00:00', time_zone => 'America/Chicago');
my $vars = {};

View file

@ -51,7 +51,7 @@ my $collab
$versionTag->commit( { timeout => 1_000_000 } );
# Re-load the collab to get the newly committed properties
$collab = WebGUI::Asset->newByDynamicClass( $session, $collab->getId );
$collab = WebGUI::Asset->newById( $session, $collab->getId );
#----------------------------------------------------------------------------
# Tests

View file

@ -89,7 +89,7 @@ ok( !$posts->[0]->{'user.isVisitor'}, 'first post made by visitor');
ok( $posts->[0]->{'hideProfileUrl'}, 'hide profile url, and user is visitor');
ok( !$posts->[0]->{'lastReply.user.isVisitor'}, 'lastReply not made by visitor');
ok( $posts->[0]->{'lastReply.hideProfileUrl'}, 'lastReply hide profile url, since user is visitor');
is( $posts->[0]->{'lastReply.url'}, $threads[1]->getUrl.'?pn=1#id'.$threads[1]->getId, 'lastReply url has a query fragment prefixed by "id"');
is( $posts->[0]->{'lastReply.url'}, $threads[1]->getUrl.'#id'.$threads[1]->getId, 'lastReply url has a query fragment prefixed by "id"');
is( $posts->[0]->{'url'}, $threads[1]->getUrl.'#id'.$threads[1]->getId, 'url has a query fragment prefixed by "id"');

View file

@ -50,7 +50,7 @@ plan tests => 1; # Increment this number for each test you create
#----------------------------------------------------------------------------
# www_unarchiveAll sets all threads to approved
$collab->www_unarchiveAll;
$threads[0] = WebGUI::Asset->newByDynamicClass( $session, $threads[0]->getId );
$threads[0] = WebGUI::Asset->newById( $session, $threads[0]->getId );
is( $threads[0]->get('status'), 'approved', "unarchiveAll sets thread to approved" );
#vim:ft=perl

View file

@ -310,7 +310,6 @@ $templateMock->mock('process', sub { $templateVars = $_[1]; } );
'stateChangedBy' => ignore(),
'lineage' => ignore(),
'className' => 'WebGUI::Asset::Wobject::EventManagementSystem',
'groupToApproveEvents' => ignore(),
'lastModified' => ignore(),
'title' => 'Test EMS',
'groupIdView' => ignore(),
@ -346,6 +345,8 @@ $templateMock->mock('process', sub { $templateVars = $_[1]; } );
'eventSubmissionQueueTemplateId' => ignore(),
'eventSubmissionTemplateId' => ignore(),
'submittedLocationsList' => ignore(),
'keywords' => ignore(),
'uiLevel' => ignore(),
'tickets_loop' => \@ticketArray,
},
"www_printRemainingTickets: template variables valid"

View file

@ -40,6 +40,8 @@ my $gallery
});
$versionTag->commit;
WebGUI::Test->addToCleanup($versionTag);
$gallery->cloneFromDb;
is(
Scalar::Util::blessed($gallery), "WebGUI::Asset::Wobject::Gallery",
@ -61,14 +63,5 @@ isa_ok(
my $properties = $gallery->get;
$gallery->purge;
is(
WebGUI::Asset->newByDynamicClass($session, $properties->{assetId}), undef,
"Gallery no longer able to be instanciated",
);
#----------------------------------------------------------------------------
# Cleanup
END {
$versionTag->rollback();
}
eval { WebGUI::Asset->newById($session, $properties->{assetId}); };
ok( Exception::Class->caught(), 'Gallery no longer able to be instanciated after purge');

View file

@ -51,6 +51,7 @@ my $album
});
$versionTag->commit;
WebGUI::Test->addToCleanup($versionTag);
is(
Scalar::Util::blessed($album), "WebGUI::Asset::Wobject::GalleryAlbum",
@ -66,14 +67,5 @@ isa_ok(
my $properties = $album->get;
$album->purge;
is(
WebGUI::Asset->newByDynamicClass($session, $properties->{assetId}), undef,
"Album no longer able to be instanciated",
);
#----------------------------------------------------------------------------
# Cleanup
END {
$versionTag->rollback();
}
eval { WebGUI::Asset->newById($session, $properties->{assetId}); };
ok( Exception::Class->caught(), 'Album no longer able to be instanciated');

View file

@ -77,6 +77,7 @@ for (my $i = 0; $i < 5; $i++)
# Commit all changes
$versionTag->commit;
WebGUI::Test->addToCleanup($versionTag);
# Make album default asset
$session->asset( $album );
@ -95,7 +96,7 @@ use_ok("WebGUI::Asset::Wobject::GalleryAlbum");
#----------------------------------------------------------------------------
# Test calling without arguments
diag("general testing");
note("general testing");
# Provide no arguments at all
$result = callAjaxService({ });
@ -105,7 +106,7 @@ ok( $result->{ err } != 0 && $result->{ errMessage }, "Error after call without
#----------------------------------------------------------------------------
# Test moveFile action with incomplete of invalid arguments
diag("moveFile action");
note("moveFile action");
# Omit target
$result = callAjaxService({
@ -256,9 +257,3 @@ sub callAjaxService {
# Call ajax service function and decode reply
return decode_json( $album->www_ajax() );
}
#----------------------------------------------------------------------------
# Cleanup
END {
$versionTag->rollback();
}

View file

@ -49,6 +49,10 @@ my $album
});
$versionTag->commit;
WebGUI::Test->addToCleanup($versionTag);
foreach my $asset ($gallery, $album) {
$asset = $asset->cloneFromDb;
}
#----------------------------------------------------------------------------
# Tests
@ -95,15 +99,6 @@ $maker->prepare({
});
$maker->run;
is(
WebGUI::Asset->newByDynamicClass( $session, $assetId ),
undef,
"GalleryAlbum cannot be instanciated after www_deleteConfirm",
);
eval { WebGUI::Asset->newById( $session, $assetId ); };
ok (Exception::Class->caught(), "GalleryAlbum cannot be instanciated after www_deleteConfirm");
#----------------------------------------------------------------------------
# Cleanup
END {
$versionTag->rollback();
}

View file

@ -109,7 +109,7 @@ $mech->content_contains(
);
# Creates the album with the appropriate properties
my $album = WebGUI::Asset->newByDynamicClass( $session, $gallery->getAlbumIds->[0] );
my $album = WebGUI::Asset->newById( $session, $gallery->getAlbumIds->[0] );
cmp_deeply( $properties, subhashof( $album->get ), "Properties from edit form are set correctly" );
#----------------------------------------------------------------------------

View file

@ -109,6 +109,7 @@ my $matrixListing = $matrix->addChild({className=>'WebGUI::Asset::MatrixListing'
my $secondVersionTag = WebGUI::VersionTag->new($session,$matrixListing->get("tagId"));
$secondVersionTag->commit;
WebGUI::Test->tagsToRollback($secondVersionTag);
$matrixListing = $matrixListing->cloneFromDb;
# Test for sane object type
isa_ok($matrixListing, 'WebGUI::Asset::MatrixListing');
@ -155,7 +156,7 @@ cmp_deeply(
# Test Listings Caching
my $listingsEncoded = WebGUI::Cache->new($session,"matrixListings_".$matrix->getId)->get;
my $listingsEncoded = $session->cache->get("matrixListings_".$matrix->getId);
$listings = JSON->new->decode($listingsEncoded);
cmp_deeply(
@ -229,9 +230,9 @@ cmp_deeply(
# Test statistics caching by view method
WebGUI::Cache->new($session,"matrixStatistics_".$matrix->getId)->delete;
$session->cache->remove("matrixStatistics_".$matrix->getId);
$matrix->view;
my $varStatisticsEncoded = WebGUI::Cache->new($session,"matrixStatistics_".$matrix->getId)->get;
my $varStatisticsEncoded = $session->cache->get("matrixStatistics_".$matrix->getId);
my $varStatistics = JSON->new->decode($varStatisticsEncoded);
cmp_deeply(
@ -302,9 +303,9 @@ $matrixListing->setRatings({category1=>'1',category2=>'9'});
$matrixListing->setRatings({category1=>'3',category2=>'5'});
$matrixListing->setRatings({category1=>'1',category2=>'9'});
WebGUI::Cache->new($session,"matrixStatistics_".$matrix->getId)->delete;
$session->cache->remove("matrixStatistics_".$matrix->getId);
$matrix->view;
my $varStatisticsEncoded = WebGUI::Cache->new($session,"matrixStatistics_".$matrix->getId)->get;
my $varStatisticsEncoded = $session->cache->get("matrixStatistics_".$matrix->getId);
my $varStatistics = JSON->new->decode($varStatisticsEncoded);
cmp_deeply(
@ -349,10 +350,10 @@ cmp_deeply(
'With only 9 ratings, still no statistics'
);
WebGUI::Cache->new($session,"matrixStatistics_".$matrix->getId)->delete;
$session->cache->remove("matrixStatistics_".$matrix->getId);
$matrixListing->setRatings({category1=>'3'});
$matrix->view;
my $varStatisticsEncoded = WebGUI::Cache->new($session,"matrixStatistics_".$matrix->getId)->get;
my $varStatisticsEncoded = $session->cache->get("matrixStatistics_".$matrix->getId);
my $varStatistics = JSON->new->decode($varStatisticsEncoded);
cmp_deeply(
@ -364,7 +365,7 @@ cmp_deeply(
best_rating_loop => [{
url => '/'.$matrixListing->get('url'),
category=> 'category1',
name => 'untitled',
name => 'Untitled',
mean => 2,
median => 3,
count => 10,
@ -380,7 +381,7 @@ cmp_deeply(
worst_rating_loop => [{
url => '/'.$matrixListing->get('url'),
category=> 'category1',
name => 'untitled',
name => 'Untitled',
mean => 2,
median => 3,
count => 10,
@ -397,10 +398,10 @@ cmp_deeply(
'statistics calculated for the category with 10 ratings'
);
WebGUI::Cache->new($session,"matrixStatistics_".$matrix->getId)->delete;
$session->cache->remove("matrixStatistics_".$matrix->getId);
$matrixListing->setRatings({category2=>'5'});
$matrix->view;
my $varStatisticsEncoded = WebGUI::Cache->new($session,"matrixStatistics_".$matrix->getId)->get;
my $varStatisticsEncoded = $session->cache->get("matrixStatistics_".$matrix->getId);
my $varStatistics = JSON->new->decode($varStatisticsEncoded);
cmp_deeply(
@ -412,7 +413,7 @@ cmp_deeply(
best_rating_loop => [{
url => '/'.$matrixListing->get('url'),
category=> 'category1',
name => 'untitled',
name => 'Untitled',
mean => 2,
median => 3,
count => 10,
@ -420,7 +421,7 @@ cmp_deeply(
{
url => '/'.$matrixListing->get('url'),
category=> 'category2',
name => 'untitled',
name => 'Untitled',
mean => 7,
median => 9,
count => 10,
@ -428,7 +429,7 @@ cmp_deeply(
worst_rating_loop => [{
url => '/'.$matrixListing->get('url'),
category=> 'category1',
name => 'untitled',
name => 'Untitled',
mean => 2,
median => 3,
count => 10,
@ -436,7 +437,7 @@ cmp_deeply(
{
url => '/'.$matrixListing->get('url'),
category=> 'category2',
name => 'untitled',
name => 'Untitled',
mean => 7,
median => 9,
count => 10,

View file

@ -123,7 +123,6 @@ $search->update({
$search->update({useContainers => 1});
$search->view;
like $templateVars->{result_set}->[0]->{url}, qr{\?pn=\d}, 'search returns paginated URL for a Thread when useContainers=1';
note Dumper $templateVars;
WebGUI::Test->unmockAssetId($templateId);
$session->request->setup_body({});

View file

@ -63,31 +63,21 @@ $canPostMaker->prepare({
fail => [1, $reader ],
});
my $tests = 50
+ $canPostMaker->plan
;
plan tests => 1
+ $tests;
#----------------------------------------------------------------------------
# put your tests here
my $class = 'WebGUI::Asset::Wobject::StoryArchive';
my $loaded = use_ok($class);
use_ok('WebGUI::Asset::Wobject::StoryArchive');
my $storage;
my $versionTag;
my $creationDateSth = $session->db->prepare('update asset set creationDate=? where assetId=?');
my @skipAutoCommit = (undef, undef, { skipAutoCommitWorkflows => 1 });
my @skipAutoCommit = WebGUI::Test->getAssetSkipCoda;
SKIP: {
skip "Unable to load module $class", $tests unless $loaded;
my $home = WebGUI::Asset->getDefault($session);
$archive = $home->addChild({
className => $class,
className => 'WebGUI::Asset::Wobject::StoryArchive',
title => 'My Stories',
url => '/home/mystories',
styleTemplateId => $home->get('styleTemplateId'),
@ -661,13 +651,11 @@ $archive->update({ url => '/home/mystories.arch' });
is($archive->getKeywordStaticURL('bar'), '/home/mystories/keyword_bar.html', '... correct URL with file extension');
$archive->update({ url => '/home/mystories' });
}
$creationDateSth->finish;
done_testing();
#----------------------------------------------------------------------------
# Cleanup
END {
$creationDateSth->finish;
}
sub simpleHrefParser {
my ($text) = @_;

View file

@ -32,7 +32,9 @@ my $import_node = WebGUI::Asset->getImportNode($session);
# Create a Survey
$survey = $import_node->addChild( { className => 'WebGUI::Asset::Wobject::Survey', } );
my $tag = WebGUI::VersionTag->getWorking($session);
WebGUI::Test->assetsToPurge($survey);
$tag->commit;
$survey = $survey->cloneFromDb;
WebGUI::Test->addToCleanup($survey);
isa_ok($survey, 'WebGUI::Asset::Wobject::Survey');
my $sJSON = $survey->getSurveyJSON;
@ -66,9 +68,9 @@ my $responseId = $survey->responseId;
my $s = WebGUI::Asset::Wobject::Survey->newByResponseId($session, $responseId);
is($s->getId, $survey->getId, 'newByResponseId returns same Survey');
}
is($survey->get('maxResponsesPerUser'), 1, 'maxResponsesPerUser defaults to 1');
is($survey->maxResponsesPerUser, 1, 'maxResponsesPerUser defaults to 1');
ok($survey->canTakeSurvey, '..which means user can take survey');
is($survey->get('revisionDate'), $session->db->quickScalar('select revisionDate from Survey_response where Survey_responseId = ?', [$responseId]), 'Current revisionDate used');
is($survey->revisionDate, $session->db->quickScalar('select revisionDate from Survey_response where Survey_responseId = ?', [$responseId]), 'Current revisionDate used');
####################################################
#
@ -210,7 +212,7 @@ cmp_deeply(from_json($surveyEnd), { type => 'forward', url => '/getting_started'
# Push revisionDate into the past because we can't have 2 revision dates with the same epoch (this is very hacky)
$revisionDate--;
$session->stow->deleteAll();
WebGUI::Cache->new($session)->flush;
$session->cache->clear;
$session->db->write('update Survey set revisionDate = ? where assetId = ?', [$revisionDate, $surveyId]);
$session->db->write('update assetData set revisionDate = ? where assetId = ?', [$revisionDate, $surveyId]);
$session->db->write('update wobject set revisionDate = ? where assetId = ?', [$revisionDate, $surveyId]);
@ -234,7 +236,7 @@ cmp_deeply(from_json($surveyEnd), { type => 'forward', url => '/getting_started'
isa_ok($newerSurvey, 'WebGUI::Asset::Wobject::Survey', 'After change, re-retrieved Survey instance');
is($newerSurvey->getId, $surveyId, '..which is the same survey');
is($newerSurvey->getSurveyJSON->section([0])->{text}, 'newer text', '..with updated text');
ok($newerSurvey->get('revisionDate') > $revisionDate, '..and newer revisionDate');
ok($newerSurvey->revisionDate > $revisionDate, '..and newer revisionDate');
# Create another response (this one will use the new revision)
my $newUser = WebGUI::User->new( $session, 'new' );

View file

@ -24,7 +24,6 @@ use Test::More tests => 22; # increment this value for each test you create
use Test::Deep;
use WebGUI::Asset::Wobject::SyndicatedContent;
use XML::FeedPP;
use WebGUI::Cache;
my $session = WebGUI::Test->session;
my %var;
@ -153,12 +152,11 @@ $syndicated_content->update({
hasTerms => 'WebGUI',
});
my $cache = WebGUI::Cache->new($session, $tbbUrl, 'RSS');
open my $rssFile, '<', WebGUI::Test->getTestCollateralPath('tbb.rss')
or die "Unable to get RSS file";
my $rssContent = do { local $/; <$rssFile>; };
close $rssFile;
$cache->set($rssContent, 60);
$session->cache->set($tbbUrl, $rssContent, 60);
my $filteredFeed = $syndicated_content->generateFeed();
@ -172,7 +170,7 @@ cmp_deeply(
'generateFeed: filters items based on the terms being in title, or description'
);
$cache->delete;
$session->cache->remove($tbbUrl);
####################################################################
#
@ -189,18 +187,16 @@ $syndicated_content->update({
maxHeadlines => 50,
});
my $cache = WebGUI::Cache->new($session, $oncpUrl, 'RSS');
open my $rssFile, '<', WebGUI::Test->getTestCollateralPath('oncp.xml')
or die "Unable to get RSS file: oncp.xml";
my $rssContent = do { local $/; <$rssFile>; };
close $rssFile;
$cache->set($rssContent, 60);
$session->cache->set($oncpUrl, $rssContent, 60);
my $oddFeed1 = $syndicated_content->generateFeed();
my @oddItems = $oddFeed1->get_item();
is (@oddItems, 13, 'feed has items even without pubDates or links');
$cache->delete;
$session->cache->remove($oncpUrl);

View file

@ -33,8 +33,6 @@ use Storable qw/dclone/;
my $session = WebGUI::Test->session;
my @getTitleTests = getTitleTests($session);
my $rootAsset = WebGUI::Asset->getRoot($session);
##Test users.
@ -151,340 +149,12 @@ $canViewMaker->prepare(
},
);
plan tests => 114
+ 2*scalar(@getTitleTests) #same tests used for getTitle and getMenuTitle
+ $canAddMaker->plan
plan tests => $canAddMaker->plan
+ $canAddMaker2->plan
+ $canEditMaker->plan
+ $canViewMaker->plan
;
note "loadModule";
{
my $className = eval { WebGUI::Asset->loadModule('Moose::Asset'); };
my $e = Exception::Class->caught;
isa_ok($e, 'WebGUI::Error::InvalidParam', 'loadModule must get a WebGUI::Asset class');
cmp_deeply(
$e,
methods(
error => 'Not a WebGUI::Asset class',
param => 'Moose::Asset',
),
'... checking error message',
);
}
# Test the default constructor
my $defaultAsset = WebGUI::Asset->getDefault($session);
is($defaultAsset, 'WebGUI::Asset::Wobject::Layout');
# Test the new constructor
my $assetId = "PBnav00000000000000001"; # one of the default nav assets
# - explicit class
my $asset = WebGUI::Asset->newById($session, $assetId);
isa_ok ($asset, 'WebGUI::Asset::Wobject::Navigation');
is ($asset->getId, $assetId, 'new constructor explicit - returns correct asset');
# - new by hashref properties
$asset = undef;
$asset = WebGUI::Asset->newByPropertyHashRef($session, {
className=>"WebGUI::Asset::Wobject::Navigation",
assetId=>$assetId
});
isa_ok ($asset, 'WebGUI::Asset::Wobject::Navigation');
is ($asset->getId, $assetId, 'new constructor newByHashref - returns correct asset');
# - implicit class
$asset = undef;
$asset = WebGUI::Asset::Wobject::Navigation->new($session, $assetId);
isa_ok ($asset, 'WebGUI::Asset::Wobject::Navigation');
is ($asset->getId, $assetId, 'new constructor implicit - returns correct asset');
# - die gracefully
# -- no asset id
note "new, constructor fails";
{
my $deadAsset = eval { WebGUI::Asset->new($session, ''); };
my $e = Exception::Class->caught;
isa_ok($e, 'WebGUI::Error::InvalidParam', 'new must get an assetId');
cmp_deeply(
$e,
methods(
error => 'Asset constructor new() requires an assetId.',
),
'... checking error message',
);
}
# -- no class
my $primevalAsset = WebGUI::Asset->new($session, $assetId);
isa_ok ($primevalAsset, 'WebGUI::Asset');
# Test the newById Constructor
$asset = undef;
note "new";
use WebGUI::Asset::Wobject::Navigation;
$asset = WebGUI::Asset::Wobject::Navigation->new($session, $assetId);
isa_ok ($asset, 'WebGUI::Asset::Wobject::Navigation');
is ($asset->getId, $assetId, 'new constructor - returns correct asset when invoked with correct class');
note "getClassById";
{
my $deadAsset = eval { WebGUI::Asset->getClassById($session, 'RoysNonExistantAssetId'); };
my $e = Exception::Class->caught;
isa_ok($e, 'WebGUI::Error::InvalidParam', 'getClassById must have a valid assetId');
cmp_deeply(
$e,
methods(
error => "Couldn't lookup classname",
param => 'RoysNonExistantAssetId',
),
'... checking error message',
);
}
note "newById";
{
my $deadAsset = eval { WebGUI::Asset->newById($session); };
my $e = Exception::Class->caught;
isa_ok($e, 'WebGUI::Error::InvalidParam', "newById won't work without an assetId");
cmp_deeply(
$e,
methods(
error => "newById must get an assetId",
),
'... checking error message',
);
}
# -- no session
# Root Asset
isa_ok($rootAsset, 'WebGUI::Asset');
is($rootAsset->getId, 'PBasset000000000000001', 'Root Asset ID check');
# getMedia Constructor
my $mediaFolder = WebGUI::Asset->getMedia($session);
isa_ok($mediaFolder, 'WebGUI::Asset::Wobject::Folder');
is($mediaFolder->getId, 'PBasset000000000000003', 'Media Folder Asset ID check');
# getImportNode Constructor
my $importNode = WebGUI::Asset->getImportNode($session);
isa_ok($importNode, 'WebGUI::Asset::Wobject::Folder');
is($importNode->getId, 'PBasset000000000000002', 'Import Node Asset ID check');
is($importNode->getParent->getId, $rootAsset->getId, 'Import Nodes parent is Root Asset');
# tempspace Constructor
my $tempNode = WebGUI::Asset->getTempspace($session);
isa_ok($tempNode, 'WebGUI::Asset::Wobject::Folder');
is($tempNode->getId, 'tempspace0000000000000', 'Tempspace Asset ID check');
is($tempNode->getParent->getId, $rootAsset->getId, 'Tempspace parent is Root Asset');
################################################################
#
# urlExists
#
################################################################
##We need an asset with a URL for this one.
my $importUrl = $importNode->get('url');
my $importId = $importNode->getId;
ok( WebGUI::Asset->urlExists($session, $importUrl), 'url for import node exists');
ok( WebGUI::Asset->urlExists($session, uc($importUrl)), 'url for import node exists, case insensitive');
ok( !WebGUI::Asset->urlExists($session, '/foo/bar/baz'), 'made up url does not exist');
ok( !WebGUI::Asset->urlExists($session, $importUrl, {assetId => $importId}), 'url for import node only exists at specific id');
ok( !WebGUI::Asset->urlExists($session, '/foo/bar/baz', {assetId => $importId}), 'imaginary url does not exist at specific id');
ok( WebGUI::Asset->urlExists($session, $importUrl, {assetId => 'notAnWebGUIId'}), 'imaginary url does not exist at wrong id');
################################################################
#
# addEditLabel
#
################################################################
my $i18n = WebGUI::International->new($session, 'Asset_Wobject');
is($importNode->addEditLabel, $i18n->get('edit').' '.$importNode->getName, 'addEditLabel, default mode is edit mode');
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');
$session->{_request} = $origRequest;
################################################################
#
# fixUrl
#
################################################################
my $versionTag = WebGUI::VersionTag->getWorking($session);
WebGUI::Test->tagsToRollback($versionTag);
$versionTag->set({name=>"Asset tests"});
$properties = {
# '1234567890123456789012'
id => 'fixUrlAsset00000000012',
title => 'fixUrl Asset Test',
className => 'WebGUI::Asset::Wobject::Folder',
url => 'fixUrlFolderURL2',
};
my $fixUrlAsset = $defaultAsset->addChild($properties, $properties->{id});
# '1234567890123456789012'
$properties->{id} = 'fixUrlAsset00000000013';
$properties->{url} = 'fixUrlFolderURL9';
my $fixUrlAsset2 = $defaultAsset->addChild($properties, $properties->{id});
# '1234567890123456789012'
$properties->{id} = 'fixUrlAsset00000000014';
$properties->{url} = 'fixUrlFolderURL00';
my $fixUrlAsset3 = $defaultAsset->addChild($properties, $properties->{id});
# '1234567890123456789012'
$properties->{id} = 'fixUrlAsset00000000015';
$properties->{url} = 'fixUrlFolderURL100';
my $fixUrlAsset4 = $defaultAsset->addChild($properties, $properties->{id});
is($fixUrlAsset4->get('url'), 'fixurlfolderurl100', 'asset setup correctly for 100->101 test');
delete $properties->{url};
# '1234567890123456789012'
$properties->{id} = 'fixUrlAsset00000000016';
$properties->{menuTitle} = 'fix url folder url autogenerated';
my $fixUrlAsset5 = $defaultAsset->addChild($properties, $properties->{id});
my $properties2 = {
# '1234567890123456789012'
id => 'fixTitleAsset000000010',
title => '',
className => 'WebGUI::Asset::Snippet',
url => 'fixTitleAsset1',
};
my $fixTitleAsset = $defaultAsset->addChild($properties2, $properties2->{id});
##Commit this asset right away
$fixTitleAsset->commit;
$properties2 = {
# '1234567890123456789012'
id => 'getTitleAsset000000010',
title => '',
className => 'WebGUI::Asset::Snippet',
url => 'getTitleAsset1',
};
my $getTitleAsset = $defaultAsset->addChild($properties2, $properties2->{id});
$getTitleAsset->commit;
$versionTag->commit;
$session->setting->set('urlExtension', undef);
is($importNode->fixUrl('1234'.'-'x235 . 'abcdefghij'), '1234'.'-'x235 . 'abcdefghij', 'fixUrl leaves long URLs under 250 characters alone');
is($importNode->fixUrl('1234'.'-'x250 . 'abcdefghij'), '1234'.'-'x216, 'fixUrl truncates long URLs over 250 characters to 220 characters');
WebGUI::Test->originalConfig('extrasURL');
WebGUI::Test->originalConfig('uploadsURL');
WebGUI::Test->originalConfig('assets');
$session->config->set('extrasURL', '/extras');
$session->config->set('uploadsURL', '/uploads');
is($importNode->fixUrl('/extras'), '_extras', 'underscore prepended to URLs that match the extrasURL');
is($importNode->fixUrl('/uploads'), '_uploads', 'underscore prepended to URLs that match the uploadsURL');
#Now that we have verified that extrasURL and uploadsURL both work, just test one.
$session->config->set('extrasURL', '/extras1/');
is($importNode->fixUrl('/extras1'), '_extras1', 'trailing underscore in extrasURL does not defeat the check');
$session->config->set('extrasURL', 'http://mysite.com/extras2');
is($importNode->fixUrl('/extras2'), '_extras2', 'underscore prepended to URLs that match the extrasURL, even with http://');
##Now, check extension removal
is($importNode->fixUrl('one.html/two.html'), 'one/two.html', 'extensions are not allowed higher up in the path');
is($importNode->fixUrl('one.html/two.html/three.html'), 'one/two/three.html', 'extensions are not allowed anywhere in the path');
is($importNode->fixUrl('one.one.html/two.html/three.html'), 'one/two/three.html', 'multiple dot extensions are removed in any path element');
is($importNode->fixUrl('.startsWithDot'), '.startswithdot', 'leading dots are okay');
##Now, check duplicate URLs
is($importNode->fixUrl('/rootyRootRoot'), 'rootyrootroot', 'URLs are lowercased');
is($importNode->fixUrl('/root'), 'root2', 'If a node exists, appends a "2" to it');
my $importNodeURL = $importNode->getUrl;
$importNodeURL =~ s{ ^ / }{}x;
is($importNode->fixUrl($importNodeURL), $importNodeURL, q{fixing an asset's own URL returns it unchanged});
is($importNode->fixUrl('fixUrlFolderURL2'), 'fixurlfolderurl3', 'if a URL exists, fix it by incrementing any ending digits 2 -> 3');
is($importNode->fixUrl('fixUrlFolderURL9'), 'fixurlfolderurl10', 'increments past single digits 9 -> 10');
is($importNode->fixUrl('fixUrlFolderURL00'), 'fixurlfolderurl1', 'initial zeroes are not preserved 00 -> 1');
is($importNode->fixUrl('fixUrlFolderURL100'), 'fixurlfolderurl101', '100->101');
is($fixUrlAsset5->fixUrl(), 'home/fix-url-folder-url-autogenerated', 'fixUrl will autogenerate a url if not provided one');
# Automatic extension adding
$session->setting->set('urlExtension', 'html');
is($importNode->fixUrl('fixurl'), 'fixurl.html', 'Automatic adding of extensions works');
is($importNode->fixUrl('fixurl.css'), 'fixurl.css', 'extensions aren\'t automatically added if there is already and extension');
$session->setting->set('urlExtension', undef);
################################################################
#
# getTitle
# getMenuTitle
#
################################################################
my $getTitleAssetName = $getTitleAsset->getName();
foreach my $test (@getTitleTests) {
my $expectedTitle = $test->{assetName} ? $getTitleAssetName : $test->{title};
$getTitleAsset->update({
title => $test->{title},
menuTitle => $test->{title},
});
is($getTitleAsset->getTitle, $expectedTitle, $test->{comment});
is($getTitleAsset->getMenuTitle, $expectedTitle, $test->{comment});
}
################################################################
#
# getIcon
#
################################################################
like($importNode->getIcon, qr{folder.gif$}, 'getIcon gets correct icon for importNode');
like($importNode->getIcon(1), qr{small/folder.gif$}, 'getIcon gets small icon for importNode');
my $extras = $session->config->get('extrasURL');
like($importNode->getIcon(), qr{$extras}, 'getIcon returns an icon from the extras URL');
like($defaultAsset->getIcon, qr{layout.gif$}, 'getIcon gets icon for a layout');
like($fixTitleAsset->getIcon, qr{snippet.gif$}, 'getIcon gets icon for a snippet');
TODO: {
local $TODO = "Coverage test";
ok(0, "Test the default name for the icon, if not given in the definition sub");
}
################################################################
#
# canAdd
@ -493,6 +163,7 @@ TODO: {
$session->config->set('assets/WebGUI::Asset/addGroup', $testGroups{'canAdd asset'}->getId );
$session->asset(WebGUI::Asset->getDefault($session));
$canAddMaker->run;
#Without proper group setup, Turn On Admin is excluded from adding assets via assetAddPrivilege
@ -515,388 +186,4 @@ $canEditMaker->run;
$canViewMaker->run;
################################################################
#
# addMissing
#
################################################################
$session->user({ userId => 3 });
$session->var->switchAdminOff;
is($canEditAsset->addMissing('/nowhereMan'), undef, q{addMissing doesn't return anything unless use is in Admin Mode});
$session->var->switchAdminOn;
my $addMissing = $canEditAsset->addMissing('/nowhereMan');
ok($addMissing, 'addMissing returns some output when in Admin Mode');
{
my $parser = HTML::TokeParser->new(\$addMissing);
my $link = $parser->get_tag('a');
my $url = $link->[1]{'href'} || '-';
like($url, qr{func=add;class=WebGUI::Asset::Wobject::Layout;url=/nowhereMan$}, 'addMissing: Link will add a new page asset with correct URL');
}
################################################################
#
# getContainer
#
################################################################
is($rootAsset->getContainer->getId, $rootAsset->getId, 'getContainer: A folder is a container, its container is itself');
is($fixTitleAsset->getContainer->getId, $defaultAsset->getId, 'getContainer: A snippet is not a container, its container is its parent');
################################################################
#
# getName
#
################################################################
is($fixTitleAsset->getName, $i18n->get('assetName', 'Asset_Snippet'), 'getName: Returns the internationalized name of the Asset, Snippet');
is($importNode->getName, $i18n->get('assetName', 'Asset_Folder'), 'getName: Returns the internationalized name of the Asset, Folder');
is($canEditAsset->getName, $i18n->get('asset', 'Asset'), 'getName: Returns the internationalized name of the Asset, core Asset');
################################################################
#
# getToolbarState
# toggleToolbar
#
################################################################
is($getTitleAsset->getToolbarState, undef, 'getToolbarState: default toolbar state is undef');
$getTitleAsset->toggleToolbar();
is($getTitleAsset->getToolbarState, 1, 'getToolbarState: toggleToolbarState toggled the state to 1');
$getTitleAsset->toggleToolbar();
is($getTitleAsset->getToolbarState, 0, 'getToolbarState: toggleToolbarState toggled the state to 0');
################################################################
#
# getUiLevel
#
################################################################
is($canEditAsset->getUiLevel, 1, 'getUiLevel: WebGUI::Asset uses the default uiLevel of 1');
is($fixTitleAsset->getUiLevel, 5, 'getUiLevel: Snippet has an uiLevel of 5');
my $origAssetUiLevel = $session->config->get('assetUiLevel');
$session->config->set('assets/WebGUI::Asset/uiLevel', 8);
$session->config->set('assets/WebGUI::Asset::Snippet/uiLevel', 8);
is($canEditAsset->getUiLevel, 8, 'getUiLevel: WebGUI::Asset has a configured uiLevel of 8');
is($fixTitleAsset->getUiLevel, 8, 'getUiLevel: Snippet has a configured uiLevel of 8');
################################################################
#
# isValidRssItem
#
################################################################
is($canViewAsset->isValidRssItem, 1, 'isValidRssItem: By default, all Assets are valid RSS items');
################################################################
#
# getEditTabs
#
################################################################
my @tabs = $canViewAsset->getEditTabs;
is(scalar(@tabs), 4, 'getEditTabs: 4 tabs by default');
################################################################
#
# getEditForm
#
################################################################
$session->style->sent(0); ##Prevent extra output from being generated by session->style
##At some point, a test will need to tie STDOUT and make sure
##that the output is correct.
isa_ok($canViewAsset->getEditForm, 'WebGUI::TabForm', 'getEditForm: Returns a tabForm');
TODO: {
local $TODO = 'More getEditForm tests';
ok(0, 'Validate form output');
}
################################################################
#
# newByDynamicClass
#
################################################################
my $newFixTitleAsset = WebGUI::Asset->newByDynamicClass($session, $fixTitleAsset->getId);
isnt($newFixTitleAsset, undef, 'newByDynamicClass did not fail');
isa_ok($newFixTitleAsset, 'WebGUI::Asset', 'newByDynamicClass: able to look up an existing asset by id');
cmp_deeply($newFixTitleAsset->{_properties}, $fixTitleAsset->{_properties}, 'newByDynamicClass created a duplicate asset');
################################################################
#
# getNotFound
#
################################################################
my $origNotFoundPage = $session->setting->get('notFoundPage');
$session->setting->set('notFoundPage', WebGUI::Asset->getDefault($session)->getId);
isa_ok(WebGUI::Asset->getNotFound($session), 'WebGUI::Asset', 'getNotFound: Returns an asset');
is(WebGUI::Asset->getNotFound($session)->getId, WebGUI::Asset->getDefault($session)->getId, 'getNotFound: Returns the correct asset');
$session->setting->set('notFoundPage', $fixTitleAsset->getId);
is(WebGUI::Asset->getNotFound($session)->getId, $fixTitleAsset->getId, 'getNotFound: Returns the correct asset on a different asset');
$session->setting->set('notFoundPage', $origNotFoundPage);
################################################################
#
# isExportable
#
################################################################
is($rootAsset->get('isExportable'), 1, 'isExportable exists, defaults to 1');
################################################################
#
# getSeparator
#
################################################################
is($rootAsset->getSeparator, '~~~PBasset000000000000001~~~', 'getSeparator, known assetId');
is($rootAsset->getSeparator('!'), '!!!PBasset000000000000001!!!', 'getSeparator, given pad character');
isnt($rootAsset->getSeparator, $mediaFolder->getSeparator, 'getSeparator: unique string');
################################################################
#
# get
#
################################################################
my $assetProps = $rootAsset->get();
my $funkyTitle = q{Miss Annie's Whoopie Emporium and Sasparilla Shop};
$assetProps->{title} = $funkyTitle;
isnt( $rootAsset->get('title'), $funkyTitle, 'get returns a safe copy of the Asset properties');
################################################################
#
# getIsa
#
################################################################
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'});
my $getAProduct = WebGUI::Asset::Sku::Product->getIsa($session);
isa_ok($getAProduct, 'CODE', 'getIsa returns a sub ref');
my $counter = 0;
my $productIds = [];
while( my $product = $getAProduct->()) {
++$counter;
push @{ $productIds }, $product->getId;
}
is($counter, 3, 'getIsa: returned only 3 Products');
cmp_bag($productIds, [$product1->getId, $product2->getId, $product3->getId], 'getIsa returned the correct 3 products');
my $getASku = WebGUI::Asset::Sku->getIsa($session);
$counter = 0;
my $skuIds = [];
while( my $sku = $getASku->()) {
++$counter;
push @{ $skuIds }, $sku->getId;
}
is($counter, 3, 'getIsa: returned only 3 Products for a parent class');
cmp_bag($skuIds, [$product1->getId, $product2->getId, $product3->getId], 'getIsa returned the correct 3 products for a parent class');
$product1->purge;
$product2->purge;
$product3->purge;
################################################################
#
# inheritUrlFromParent
#
################################################################
my $versionTag4 = WebGUI::VersionTag->getWorking($session);
WebGUI::Test->tagsToRollback($versionTag4);
$versionTag4->set( { name => 'inheritUrlFromParent tests' } );
$properties = {
# '1234567890123456789012'
id => 'inheritUrlFromParent01',
title => 'inheritUrlFromParent01',
className => 'WebGUI::Asset::Wobject::Layout',
url => 'inheriturlfromparent01',
};
my $iufpAsset = $defaultAsset->addChild($properties, $properties->{id});
$iufpAsset->commit;
$properties2 = {
# '1234567890123456789012'
id => 'inheritUrlFromParent02',
title => 'inheritUrlFromParent02',
className => 'WebGUI::Asset::Wobject::Layout',
url => 'inheriturlfromparent02',
};
my $iufpAsset2 = $iufpAsset->addChild($properties2, $properties2->{id});
$iufpAsset2->update( { inheritUrlFromParent => 1 } );
$iufpAsset2->commit;
is($iufpAsset2->get('url'), 'inheriturlfromparent01/inheriturlfromparent02', 'inheritUrlFromParent works');
my $properties2a = {
# '1234567890123456789012'
id => 'inheritUrlFromParent2a',
title => 'inheritUrlFromParent2a',
className => 'WebGUI::Asset::Wobject::Layout',
url => 'inheriturlfromparent2a',
inheritUrlFromParent => 1,
};
my $iufpAsset2a = $iufpAsset->addChild($properties2a, $properties2a->{id});
$iufpAsset2a->commit;
is($iufpAsset2a->get('url'), 'inheriturlfromparent01/inheriturlfromparent2a', '... works when created with the property');
# works for setting, now try disabling. Should not change the URL.
$iufpAsset2->update( { inheritUrlFromParent => 0 } );
$iufpAsset2->commit;
is($iufpAsset2->get('url'), 'inheriturlfromparent01/inheriturlfromparent02', '... setting inheritUrlFromParent to 0 works');
# also make sure that it is actually disabled
is($iufpAsset2->get('inheritUrlFromParent'), 0, "... disabling inheritUrlFromParent actually works");
# works for setting and disabling, now ensure it recurses
my $properties3 = {
# '1234567890123456789012'
id => 'inheritUrlFromParent03',
title => 'inheritUrlFromParent03',
className => 'WebGUI::Asset::Wobject::Layout',
url => 'inheriturlfromparent03',
};
my $iufpAsset3 = $iufpAsset2->addChild($properties3, $properties3->{id});
$iufpAsset3->commit;
$iufpAsset2->update( { inheritUrlFromParent => 1 } );
$iufpAsset2->commit;
$iufpAsset3->update( { inheritUrlFromParent => 1 } );
$iufpAsset3->commit;
is($iufpAsset3->get('url'), 'inheriturlfromparent01/inheriturlfromparent02/inheriturlfromparent03', '... recurses properly');
$iufpAsset2->update({url => 'iufp2'});
is($iufpAsset2->get('url'), 'inheriturlfromparent01/iufp2', '... update works propertly when iUFP is not passed');
################################################################
#
# requestAutoCommit to move uncommitted child to uncommitted parent
#
################################################################
my $versionTag5 = WebGUI::VersionTag->getWorking($session);
WebGUI::Test->tagsToRollback($versionTag5);
$versionTag5->set( { name => 'move commit of child to uncommitted parent on requestAutoCommit tests vt1' } );
$properties = {
# '1234567890123456789012'
id => 'moveVersionToParent_01',
title => 'moveVersionToParent_01',
className => 'WebGUI::Asset::Wobject::Layout',
url => 'moveVersionToParent_01',
};
my $parentAsset = $defaultAsset->addChild($properties, $properties->{id});
my $parentVersionTag = WebGUI::VersionTag->new($session, $parentAsset->get('tagId'));
is($parentVersionTag->get('isCommitted'),0, 'built non-committed parent asset');
my $versionTag6 = WebGUI::VersionTag->create($session, {});
WebGUI::Test->tagsToRollback($versionTag6);
$versionTag6->set( { name => 'move commit of child to uncommitted parent on requestAutoCommit tests vt2' } );
$versionTag6->setWorking;
$properties2 = {
# '1234567890123456789012'
id => 'moveVersionToParent_03',
title => 'moveVersionToParent_03',
className => 'WebGUI::Asset::Wobject::Layout',
url => 'moveVersionToParent_03',
};
my $childAsset = $parentAsset->addChild($properties, $properties2->{id});
my $testAsset = WebGUI::Asset->newPending($session, $childAsset->get('parentId'));
my $testVersionTag = WebGUI::VersionTag->new($session, $testAsset->get('tagId'));
my $childVersionTag;
$childVersionTag = WebGUI::VersionTag->new($session, $childAsset->get('tagId'));
is($childVersionTag->get('isCommitted'),0, 'built non-committed child asset');
isnt($testAsset->get('tagId'),$childAsset->get('tagId'),'parent asset and child asset have different version tags');
isnt($testVersionTag->getId,$childVersionTag->getId,'parent asset and child asset version tags unmatched');
eval {
$childAsset->requestAutoCommit;
$childVersionTag = WebGUI::VersionTag->new($session, $childAsset->get('tagId'));
};
is($childVersionTag->get('isCommitted'),0, 'confirm non-committed child asset');
is($testAsset->get('tagId'),$childAsset->get('tagId'),'parent asset and child asset have same version tags');
eval {
$testVersionTag->commit;
};
is($testVersionTag->get('isCommitted'),1,'parent asset is now committed');
$childVersionTag = WebGUI::VersionTag->new($session, $childAsset->get('tagId'));
is($childVersionTag->get('isCommitted'),1,'child asset is now committed');
################################################################
#
# cloneFromDb
#
################################################################
my $assetToCommit = $defaultAsset->addChild({ className => 'WebGUI::Asset::Snippet', title => 'Snippet to commit and clone from db', });
my $cloneTag = WebGUI::VersionTag->getWorking($session);
WebGUI::Test->tagsToRollback($cloneTag);
$cloneTag->commit;
is($assetToCommit->get('status'), 'pending', 'cloneFromDb: local asset is still pending');
$assetToCommit = $assetToCommit->cloneFromDb;
is($assetToCommit->get('status'), 'approved', '... returns fresh, commited asset from the db');
##Return an array of hashrefs. Each hashref describes a test
##Return an array of hashrefs. Each hashref describes a test
##for the getTitle and getMenuTitle tests. If "assetName" != 0, they
##will return the Asset's internationalized name.
sub getTitleTests {
my $session = shift;
return ({
title => undef,
assetName => 1,
comment => "getTitle: undef returns the Asset's name",
},
{
title => '',
assetName => 1,
comment => "getTitle: null string returns the Asset's name",
},
{
title => 'untitled',
assetName => 1,
comment => "getTitle: 'untitled' returns the Asset's name",
},
{
title => 'UnTiTlEd',
assetName => 1,
comment => "getTitle: 'untitled' in any case returns the Asset's title",
},
{
title => 'This is a good Title',
assetName => 0,
comment => "getTitle: Good titles are passed",
},
);
}

View file

@ -48,6 +48,7 @@ my $dummy = WebGUI::Asset->getDefault($session)->addChild({
synopsis => 'Dummy Synopsis',
description => 'Dummy Description',
});
WebGUI::Test->addToCleanup($dummy);
#####################################################
#
@ -185,17 +186,4 @@ cmp_bag(
'exportAssetCollateral: feed files exported, shawshank.html file'
);
#####################################################
#
# exportAssetCollateral
#
#####################################################
#----------------------------------------------------------------------------
# Cleanup
END {
$dummy->purge;
my $tag = WebGUI::VersionTag->getWorking($session, 'noCreate');
$tag->rollback if $tag;
}
#vim:ft=perl

View file

@ -31,11 +31,6 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
plan tests => 5; # Increment this number for each test you create
#----------------------------------------------------------------------------
# put your tests here
my $output;
my $home = WebGUI::Asset->getDefault($session);
@ -69,11 +64,15 @@ cmp_deeply(
},
'AssetHelper/Cut returns a message and a redirect'
);
is $safe_page->get('state'), 'clipboard', '... and the asset was really cut';
is $safe_page->state, 'clipboard', '... and the asset was really cut';
$home->paste($safe_page->getId);
$session->asset($home);
ok $home->paste($safe_page->getId), 'page pasted correctly';
$safe_page = $safe_page->cloneFromDb();
is $safe_page->get('state'), 'published', 'reset asset for further testing';
$session->cache->clear;
my $safe_page2 = WebGUI::Asset->newById($session, $safe_page->assetId);
is $safe_page2->state, 'published', 'reset asset for further testing';
done_testing();
#vim:ft=perl

View file

@ -27,12 +27,6 @@ use WebGUI::AssetHelper::Lock;
# Init
my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
plan tests => 3; # Increment this number for each test you create
#----------------------------------------------------------------------------
# put your tests here
@ -54,7 +48,7 @@ my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->commit;
addToCleanup($versionTag);
$newPage = $newPage->cloneFromDb;
$newPage = WebGUI::Asset->newById($session, $newPage->assetId);
$session->user({userId => 1});
$output = WebGUI::AssetHelper::Lock->process($newPage);
@ -76,11 +70,13 @@ cmp_deeply(
'... locks the asset'
);
$newPage = $newPage->cloneFromDb;
my $versionTag2 = WebGUI::VersionTag->getWorking($session);
addToCleanup($versionTag2);
$newPage = WebGUI::Asset->newById($session, $newPage->assetId);
ok $newPage->isLocked, 'Asset is locked, and ready for next test';
is $newPage->getRevisionCount, 2, 'new revision added';
$session->user({userId => $editor->getId});
$output = WebGUI::AssetHelper::Lock->process($newPage);
cmp_deeply(
@ -90,3 +86,5 @@ cmp_deeply(
},
'... returns an error message if the asset is already locked'
);
done_testing;

View file

@ -15,7 +15,7 @@ no warnings qw(uninitialized);
use FindBin;
use lib "$FindBin::Bin/../lib";
use Test::More 'no_plan'; #tests => 1;
use Test::More;
use Test::Deep;
use Test::Exception;
use WebGUI::Test;
@ -108,12 +108,6 @@ use WebGUI::Test;
'->meta->get_property_list returns properties as a list in insertion order'
);
::cmp_deeply(
[ $object->meta->get_all_properties ],
::array_each(::isa('WebGUI::Definition::Meta::Property::Asset')),
'->meta->get_all_properties returns a list of Properties'
);
::cmp_deeply(
[$object->getProperties ],
[qw/property2 property1/],
@ -264,3 +258,4 @@ use WebGUI::Test;
$object->defaulted(undef);
is $object->defaulted(), undef, 'Moose setters accept undef';
}
done_testing;

View file

@ -18,7 +18,6 @@ use WebGUI::Utility;
use WebGUI::User;
use WebGUI::Group;
use WebGUI::Cache;
use Test::More;
use Test::Deep;
@ -78,8 +77,7 @@ my @ipTests = (
plan tests => (151 + scalar(@scratchTests) + scalar(@ipTests)); # increment this value for each test you create
my $session = WebGUI::Test->session;
my $testCache = WebGUI::Cache->new($session, 'myTestKey');
$testCache->flush;
$session->cache->remove('myTestKey');
foreach my $gid ('new', '') {
my $g = WebGUI::Group->new($session, $gid);
@ -437,7 +435,7 @@ cmp_bag($mobUsers, [map {$_->userId} @mob], 'verify SQL table built correctly');
is( $gY->databaseLinkId, 0, "Group Y's databaseLinkId is set to WebGUI");
$gY->dbQuery(q!select userId from myUserTable!);
is( $session->stow->get('isInGroup'), undef, 'setting dbQuery clears cached isInGroup');
WebGUI::Cache->new($session, $gZ->getId)->delete(); ##Delete cached key for testing
$session->cache->remove($gZ->getId);
my @mobIds = map { $_->userId } @mob;
@ -684,5 +682,5 @@ ok(! WebGUI::Group->vitalGroup('27'), '... 27 is not vital');
END {
$session->db->dbh->do('DROP TABLE IF EXISTS myUserTable');
$testCache->flush;
$session->cache->remove('myTestKey');
}

View file

@ -107,7 +107,7 @@ is($userActivity->get('groupId'), $activityGroup->getId, 'group in Workflow Acti
$assetGroup->delete;
my $newSnippet1 = WebGUI::Asset->newByDynamicClass($session, $snippet1->getId);
my $newSnippet1 = WebGUI::Asset->newById($session, $snippet1->getId);
cmp_deeply(
$newSnippet1->get,
@ -118,7 +118,7 @@ cmp_deeply(
'groupIdEdit updated on test snippet'
);
my $newSnippet2 = WebGUI::Asset->newByDynamicClass($session, $snippet2->getId);
my $newSnippet2 = WebGUI::Asset->newById($session, $snippet2->getId);
cmp_deeply(
$newSnippet2->get,
@ -129,7 +129,7 @@ cmp_deeply(
'other snippet not touched'
);
my $newSnippet3 = WebGUI::Asset->newByDynamicClass($session, $snippet3->getId);
my $newSnippet3 = WebGUI::Asset->newById($session, $snippet3->getId);
cmp_deeply(
$newSnippet3->get,
@ -140,7 +140,7 @@ cmp_deeply(
'multiple fields updated'
);
my $newGallery1 = WebGUI::Asset->newByDynamicClass($session, $gallery1->getId);
my $newGallery1 = WebGUI::Asset->newById($session, $gallery1->getId);
cmp_deeply(
$newGallery1->get,

View file

@ -28,14 +28,14 @@ my $numTests = 0;
my $session = WebGUI::Test->session;
my @helpFileSet = WebGUI::Operation::Help::_getHelpFilesList($session);
my @helpFileSet = WebGUI::Pluggable::findAndLoad('WebGUI::Help');
my %helpTable;
foreach my $helpSet (@helpFileSet) {
my $helpName = $helpSet->[1];
my $help = WebGUI::Operation::Help::_load($session, $helpName);
$helpTable{ $helpName } = $help;
my ($namespace) = $helpSet =~ m{WebGUI::Help::(.+$)};
my $help = WebGUI::Operation::Help::_load($session, $namespace);
$helpTable{ $namespace } = $help;
}
##Scan #1, how many tests do we expect?

View file

@ -39,7 +39,7 @@ ok(defined $defTemplate, 'default template is present');
# Call with default values
my $html = WebGUI::Macro::UsersOnline::process($session);
cmp_ok((length $html), '>', 0, 'call with default template and values returns some output');
ok($html, 'call with default template and values returns some output');
# Test labels -------------------------------------------------------------

View file

@ -23,6 +23,7 @@ use Exception::Class;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use WebGUI::Text;
use WebGUI::Shop::AddressBook;
#----------------------------------------------------------------------------
# Init
@ -195,7 +196,7 @@ is($bookCount, 1, 'delete: one book deleted');
$bookClone->delete();
$bookCount = $session->db->quickScalar('select count(*) from addressBook');
my $addrCount = $session->db->quickScalar('select count(*) from address');
$addrCount = $session->db->quickScalar('select count(*) from address');
is($bookCount, 0, '... book deleted');
is($addrCount, 0, '... also deletes addresses in the book');

View file

@ -254,6 +254,7 @@ isnt(
#######################################################################
my $cart = $driver->getCart;
WebGUI::Test->addToCleanup($cart);
isa_ok ($cart, 'WebGUI::Shop::Cart', 'getCart returns an instantiated WebGUI::Shop::Cart object');
#######################################################################

View file

@ -25,6 +25,7 @@ use WebGUI::Shop::Ship;
use WebGUI::Shop::Transaction;
use JSON;
use HTML::Form;
use WebGUI::Shop::PayDriver::ITransact;
#----------------------------------------------------------------------------
# Init
@ -34,26 +35,12 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
my $tests = 28;
plan tests => 1 + $tests;
plan tests => 28;
#----------------------------------------------------------------------------
# figure out if the test can actually run
note('Testing existence');
my $loaded = use_ok('WebGUI::Shop::PayDriver::ITransact');
my $e;
my $ship = WebGUI::Shop::Ship->new($session);
my $cart = WebGUI::Shop::Cart->newBySession($session);
my $shipper = $ship->getShipper('defaultfreeshipping000');
my $address = $cart->getAddressBook->addAddress( { firstName => 'Ellis Boyd', lastName => 'Redding'} );
$cart->update({
shippingAddressId => $address->getId,
shipperId => $shipper->getId,
});
my $transaction;
my $versionTag = WebGUI::VersionTag->getWorking($session);
my $home = WebGUI::Asset->getDefault($session);
@ -82,14 +69,22 @@ my $foreignHammer = $rockHammer->setCollateral('variantsJSON', 'variantId', 'new
$versionTag->commit;
WebGUI::Test->tagsToRollback($versionTag);
WebGUI::Test->addToCleanup($versionTag);
$rockHammer = $rockHammer->cloneFromDb;
my $ship = WebGUI::Shop::Ship->new($session);
my $cart = WebGUI::Shop::Cart->newBySession($session);
WebGUI::Test->addToCleanup($cart);
my $shipper = $ship->getShipper('defaultfreeshipping000');
my $address = $cart->getAddressBook->addAddress( { firstName => 'Ellis Boyd', lastName => 'Redding'} );
$cart->update({
shippingAddressId => $address->getId,
shipperId => $shipper->getId,
});
my $hammerItem = $rockHammer->addToCart($rockHammer->getCollateral('variantsJSON', 'variantId', $smallHammer));
SKIP: {
skip 'Unable to load module WebGUI::Shop::PayDriver::ITransact', $tests unless $loaded;
#######################################################################
#
# definition
@ -272,11 +267,12 @@ $driver->{_billingAddress} = {
};
$transaction = WebGUI::Shop::Transaction->create($session, {
my $transaction = WebGUI::Shop::Transaction->create($session, {
paymentMethod => $driver,
cart => $cart,
isRecurring => $cart->requiresRecurringPayment,
});
WebGUI::Test->addToCleanup($transaction);
my $xml = $driver->_generatePaymentRequestXML($transaction);
@ -292,11 +288,14 @@ TODO: {
#######################################################################
SKIP: {
skip "Skipping XML requests to ITransact due to lack of userId and password", 2 unless $hasTestAccount;
my $response = eval { $driver->doXmlRequest($xml) };
skip "Skipping XML requests to ITransact due to lack of real userId and password", 2 unless $hasTestAccount;
note 'doXmlrequest';
isa_ok($response, 'HTTP::Response', 'returns a HTTP::Response object');
ok( $response->is_success, '... was successful');
my $response = eval { $driver->doXmlRequest($xml) };
my $ok_response = isa_ok($response, 'HTTP::Response', 'returns a HTTP::Response object');
SKIP: {
skip "Skipping response check since we did not get a response", 1 unless $ok_response;
ok( $response->is_success, '... was successful');
}
}
my $hammer2 = $rockHammer->addToCart($rockHammer->getCollateral('variantsJSON', 'variantId', $foreignHammer));
@ -313,7 +312,6 @@ SKIP: {
my $response = eval { $driver->doXmlRequest($xml) };
isa_ok($response, 'HTTP::Response', 'returns a HTTP::Response object');
ok( $response->is_success, '... was successful');
note $response->content;
}
#######################################################################
@ -332,13 +330,4 @@ is ($count, 0, 'delete deleted the object');
undef $driver;
#----------------------------------------------------------------------------
# Cleanup
}
END: {
$cart->delete;
$transaction->delete if defined $transaction;
}
#vim:ft=perl

View file

@ -353,6 +353,7 @@ isnt(
#######################################################################
my $cart = $driver->getCart;
WebGUI::Test->addToCleanup($cart);
isa_ok ($cart, 'WebGUI::Shop::Cart', 'getCart returns an instantiated WebGUI::Shop::Cart object');
#######################################################################

View file

@ -37,15 +37,7 @@ plan tests => 1 + $tests;
#----------------------------------------------------------------------------
# put your tests here
my $loaded = use_ok('WebGUI::Shop::ShipDriver::FlatRate');
my $storage;
my ($driver, $cart, $car, $key);
my $versionTag;
SKIP: {
skip 'Unable to load module WebGUI::Shop::ShipDriver::FlatRate', $tests unless $loaded;
use_ok('WebGUI::Shop::ShipDriver::FlatRate');
#######################################################################
#
@ -142,11 +134,11 @@ my $options = {
pricePerItem => 0.1,
};
$driver = WebGUI::Shop::ShipDriver::FlatRate->create($session, $options);
my $driver2 = WebGUI::Shop::ShipDriver::FlatRate->create($session, $options);
isa_ok($driver, 'WebGUI::Shop::ShipDriver::FlatRate');
isa_ok($driver2, 'WebGUI::Shop::ShipDriver::FlatRate');
isa_ok($driver, 'WebGUI::Shop::ShipDriver');
isa_ok($driver2, 'WebGUI::Shop::ShipDriver');
#######################################################################
#
@ -162,7 +154,7 @@ is (WebGUI::Shop::ShipDriver::FlatRate->getName($session), 'Flat Rate', 'getName
#
#######################################################################
my $form = $driver->getEditForm;
my $form = $driver2->getEditForm;
isa_ok($form, 'WebGUI::HTMLForm', 'getEditForm returns an HTMLForm object');
@ -252,13 +244,13 @@ cmp_deeply(
#
#######################################################################
my $driverId = $driver->getId;
$driver->delete;
my $driverId = $driver2->getId;
$driver2->delete;
my $count = $session->db->quickScalar('select count(*) from shipper where shipperId=?',[$driverId]);
is($count, 0, 'delete deleted the object');
undef $driver;
undef $driver2;
#######################################################################
#
@ -266,7 +258,7 @@ undef $driver;
#
#######################################################################
$car = WebGUI::Asset->getImportNode($session)->addChild({
my $car = WebGUI::Asset->getImportNode($session)->addChild({
className => 'WebGUI::Asset::Sku::Product',
title => 'Automobiles',
isShippingRequired => 1,
@ -302,8 +294,10 @@ my $reallyNiceCar = $car->setCollateral('variantsJSON', 'variantId', 'new',
}
);
$versionTag = WebGUI::VersionTag->getWorking($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->commit;
WebGUI::Test->addToCleanup($versionTag);
$car = $car->cloneFromDb;
$options = {
label => 'flat rate, ship weight',
@ -314,9 +308,11 @@ $options = {
pricePerItem => 10,
};
$driver = WebGUI::Shop::ShipDriver::FlatRate->create($session, $options);
my $driver = WebGUI::Shop::ShipDriver::FlatRate->create($session, $options);
WebGUI::Test->addToCleanup($driver);
$cart = WebGUI::Shop::Cart->newBySession($session);
my $cart = WebGUI::Shop::Cart->newBySession($session);
WebGUI::Test->addToCleanup($cart);
$car->addToCart($car->getCollateral('variantsJSON', 'variantId', $crappyCar));
is($driver->calculate($cart), 1511, 'calculate by weight, perItem and flat fee work');
@ -345,7 +341,7 @@ $driver->update({
pricePerItem => 0,
});
$key = WebGUI::Asset->getImportNode($session)->addChild({
my $key = WebGUI::Asset->getImportNode($session)->addChild({
className => 'WebGUI::Asset::Sku::Product',
title => 'Key',
isShippingRequired => 1,
@ -372,6 +368,8 @@ my $bioKey = $key->setCollateral('variantsJSON', 'variantId', 'new',
}
);
WebGUI::Test->addToCleanup($key);
my $boughtCar = $car->addToCart($car->getCollateral('variantsJSON', 'variantId', $reallyNiceCar));
my $firstKey = $key->addToCart($key->getCollateral('variantsJSON', 'variantId', $metalKey));
is($driver->calculate($cart), 2, 'shipsSeparately: returns two, one for ships separately, one for ships bundled');
@ -388,25 +386,3 @@ is($driver->calculate($cart), 1, '... returns one, since all can be bundled toge
$car->update({shipsSeparately => 1});
$key->update({shipsSeparately => 1});
is($driver->calculate($cart), 4, '... returns four, since all must be shipped separately now');
}
#----------------------------------------------------------------------------
# Cleanup
END {
if (defined $driver && ref $driver eq 'WebGUI::Shop::ShipDriver::FlatRate') {
$driver->delete;
}
if (defined $cart && ref $cart eq 'WebGUI::Shop::Cart') {
$cart->delete;
}
if (defined $car && (ref($car) eq 'WebGUI::Asset::Sku::Product')) {
$car->purge;
}
if (defined $key && (ref($key) eq 'WebGUI::Asset::Sku::Product')) {
$key->purge;
}
if (defined $versionTag) {
$versionTag->rollback;
}
}

View file

@ -110,6 +110,9 @@ my $blueFeather = $feather->setCollateral('variantsJSON', 'variantId', 'new',
$versionTag->commit;
addToCleanup($versionTag);
foreach my $asset($rockHammer, $bible, $feather) {
$asset = $asset->cloneFromDb;
}
#######################################################################
#

View file

@ -109,6 +109,9 @@ my $gospels = $bible->setCollateral('variantsJSON', 'variantId', 'new',
$versionTag->commit;
addToCleanup($versionTag);
foreach my $asset ($bible, $rockHammer) {
$asset = $asset->cloneFromDb;
}
#######################################################################
#

View file

@ -109,6 +109,9 @@ my $singlePage = $bible->setCollateral('variantsJSON', 'variantId', 'new',
$versionTag->commit;
addToCleanup($versionTag);
foreach my $asset ($rockHammer, $bible) {
$asset = $asset->cloneFromDb;
}
#######################################################################
#

File diff suppressed because it is too large Load diff

View file

@ -206,13 +206,16 @@ my $siteWideTag;
$tag->clearWorking();
ok(defined ($userTag = getWorking(1)), 'versionTagMode singlePerUser: reclaim version tag after clearWorking');
is ($userTag->getId(), $userTagId, q{versionTagMode singlePerUser: reclaimed version tag has same id});
my $gotTag = ok(defined ($userTag = getWorking(1)), 'versionTagMode singlePerUser: reclaim version tag after clearWorking');
SKIP: {
skip 1, 'userTag not set' unless $gotTag;
is ($userTag->getId(), $userTagId, q{versionTagMode singlePerUser: reclaimed version tag has same id});
$userTag->clearWorking();
}
#switch to sitewide mode
$userTag->clearWorking();
setSiteVersionTagMode($session, q{siteWide});

View file

@ -41,6 +41,7 @@ my $posters = $import->addChild({
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->commit();
addToCleanup($versionTag);
$posters = $posters->cloneFromDb;
my $ritaVarId = $posters->setCollateral('variantsJSON', 'variantId', 'new',
{
@ -190,7 +191,8 @@ my $instance4 = WebGUI::Workflow::Instance->create($session,
);
#break the asset
$session->db->write('delete from asset where assetId=?', [$otherPosters->getId]);
is(WebGUI::Asset->new($session, $otherPosters->getId), undef, 'middle asset broken');
$otherPosters->purgeCache;
dies_ok { WebGUI::Asset->newById($session, $otherPosters->getId); } 'middle asset broken';
$retVal = $instance4->run();
$retVal = $instance4->run();

View file

@ -36,11 +36,13 @@ WebGUI::Test->tagsToRollback($tag);
my $cart1 = WebGUI::Shop::Cart->create($session);
WebGUI::Test->addToCleanup($cart1);
my $session2 = WebGUI::Session->open(WebGUI::Test->file);
addToCleanup($session2);
my $cart2 = WebGUI::Shop::Cart->create($session2);
$cart2->update({creationDate => time()-10000});
WebGUI::Test->addToCleanup($cart2);
my @cartIds = $session->db->buildArray('select cartId from cart');
cmp_bag(
@ -69,9 +71,7 @@ my $workflow = WebGUI::Workflow->create($session,
mode => 'realtime',
},
);
my $guard0 = cleanupGuard($workflow);
my $guard1 = cleanupGuard($cart1);
my $guard2 = cleanupGuard($cart2);
WebGUI::Test->addToCleanup($workflow);
my $cartNuker = $workflow->addActivity('WebGUI::Workflow::Activity::RemoveOldCarts');
$cartNuker->set('cartTimeout', 3600);
@ -103,7 +103,3 @@ cmp_bag(
[ $item1->getId, ],
'Deleted 1 item, the correct one'
);
END {
$instance1->delete('skipNotify');
}

View file

@ -15,9 +15,14 @@ package WebGUI::Asset::RssAspectDummy;
=cut
use strict;
use Tie::IxHash;
use Class::C3;
use base qw/WebGUI::AssetAspect::RssFeed WebGUI::Asset/;
use Moose;
use WebGUI::Definition::Asset;
extends 'WebGUI::Asset';
define assetName => 'RssAspectDummy';
define icon => 'asset.gif';
with 'WebGUI::Role::Asset::RssFeed';
=head1 NAME
@ -25,7 +30,7 @@ Package WebGUI::Asset::RssAspectDummy
=head1 DESCRIPTION
A dummy module for testing the RssAspect. The module really doesn't
A dummy module for testing the Rss Role. The module really doesn't
do anything, except provide suport modules for testing.
The module inherits directly from WebGUI::Asset.

View file

@ -225,20 +225,20 @@ sub _mockAssetInits {
if $mockedNew;
require WebGUI::Asset;
my $original_new = \&WebGUI::Asset::new;
*WebGUI::Asset::new = sub {
my ($class, $session, $assetId, $className, $revisionDate) = @_;
if ($mockedAssetIds{$assetId}) {
return $mockedAssetIds{$assetId};
}
goto $original_new;
};
my $original_newByDynamicClass = \&WebGUI::Asset::newByDynamicClass;
*WebGUI::Asset::newByDynamicClass = sub {
# *WebGUI::Asset::new = sub {
# my ($class, $session, $assetId, $className, $revisionDate) = @_;
# if ($mockedAssetIds{$assetId}) {
# return $mockedAssetIds{$assetId};
# }
# goto $original_new;
# };
my $original_newById = \&WebGUI::Asset::newById;
*WebGUI::Asset::newById = sub {
my ($class, $session, $assetId, $revisionDate) = @_;
if ($mockedAssetIds{$assetId}) {
return $mockedAssetIds{$assetId};
}
goto $original_newByDynamicClass;
goto $original_newById;
};
my $original_newPending = \&WebGUI::Asset::newPending;
*WebGUI::Asset::newPending = sub {
@ -248,6 +248,14 @@ sub _mockAssetInits {
}
goto $original_newPending;
};
my $original_newByPropertyHashRef = \&WebGUI::Asset::newByPropertyHashRef;
*WebGUI::Asset::newByPropertyHashRef = sub {
my ($class, $session, $url, $revisionDate) = @_;
if ($url && $mockedAssetUrls{$url}) {
return $mockedAssetUrls{$url};
}
goto $original_newByPropertyHashRef;
};
my $original_newByUrl = \&WebGUI::Asset::newByUrl;
*WebGUI::Asset::newByUrl = sub {
my ($class, $session, $url, $revisionDate) = @_;
@ -473,6 +481,25 @@ sub webguiBirthday {
#----------------------------------------------------------------------------
=head2 getAssetSkipCoda ( )
Coded here for the sake of consistency, this returns everything that should be
appended to calls to addChild to autogenerate ids, revisionDates, and to skip
autoCommit workflows, and notifications.
=cut
sub getAssetSkipCoda {
return undef,
undef,
{
skipAutoCommitWorkflows => 1,
skipNotification => 1,
};
}
#----------------------------------------------------------------------------
=head2 getSmokeLDAPProps ( )
Returns a hashref of properties for connecting to smoke's LDAP server.
@ -790,6 +817,10 @@ Example call:
my ($class, $ident) = @_;
return $class->new($CLASS->session, $ident);
},
'WebGUI::Asset' => sub {
my ($class, $ident) = @_;
return WebGUI::Asset->newPending($CLASS->session, $ident);
},
'WebGUI::Storage' => sub {
my ($class, $ident) = @_;
return WebGUI::Storage->get($CLASS->session, $ident);

View file

@ -78,7 +78,93 @@ sub _constructor : Test(4) {
}
sub title : Test(6) {
sub t_00_class_dispatch : Test(2) {
my $test = shift;
my $session = $test->session;
note "Class dispatch";
my $asset = $test->class->new({session => $session});
my $asset = WebGUI::Asset->new({
session => $session,
title => 'testing snippet',
className => 'WebGUI::Asset::Snippet',
});
isa_ok $asset, 'WebGUI::Asset';
is $asset->className, 'WebGUI::Asset', 'passing className is ignored';
}
sub t_00_get_tables : Test(1) {
my $test = shift;
note "get_tables";
my @tables = $test->class->meta->get_tables;
cmp_bag(
\@tables,
$test->list_of_tables,
'Set of tables for properties is correct'
);
}
sub t_00_getParent : Test(2) {
my $test = shift;
my $session = $test->session;
note "getParent";
my $testId1 = 'wg8TestAsset0000000001';
my $testId2 = 'wg8TestAsset0000000002';
my $now = time();
my $baseLineage = $session->db->quickScalar('select lineage from asset where assetId=?',['PBasset000000000000002']);
my $testLineage = $baseLineage. '909090';
$session->db->write("insert into asset (assetId, className, lineage) VALUES (?,?,?)", [$testId1, 'WebGUI::Asset', $testLineage]);
$session->db->write("insert into assetData (assetId, revisionDate, status) VALUES (?,?,?)", [$testId1, $now, 'approved']);
my $testLineage2 = $testLineage . '000001';
$session->db->write("insert into asset (assetId, className, parentId, lineage) VALUES (?,?,?,?)", [$testId2, 'WebGUI::Asset', $testId1, $testLineage2]);
$session->db->write("insert into assetData (assetId, revisionDate) VALUES (?,?)", [$testId2, $now]);
my $testAsset = WebGUI::Asset->new($session, $testId2, $now);
is $testAsset->parentId, $testId1, 'parentId assigned correctly on db fetch in new';
my $testParent = $testAsset->getParent();
isa_ok $testParent, 'WebGUI::Asset';
$session->db->write("delete from asset where assetId like 'wg8TestAsset00000%'");
$session->db->write("delete from assetData where assetId like 'wg8TestAsset00000%'");
}
sub t_00_newByPropertyHashRef : Test(2) {
my $test = shift;
my $session = $test->session;
note "newByPropertyHashRef";
my $asset;
$asset = WebGUI::Asset->newByPropertyHashRef($session, {className => $test->class, title => 'The Shawshank Snippet'});
isa_ok $asset, $test->class;
is $asset->title, 'The Shawshank Snippet', 'title is assigned from the property hash';
}
sub t_00_scan_properties : Test(1) {
note "scan properties for table definitions";
my $test = shift;
my @properties = $test->class->meta->get_all_properties;
my @undefined_tables = ();
foreach my $prop (@properties) {
push @undefined_tables, $prop->name if (!$prop->tableName);
}
ok !@undefined_tables, "all properties have tables defined"
or diag "except these: ".join ", ", @undefined_tables;
}
sub t_01_assetId : Test(4) {
my $test = shift;
my $session = $test->session;
my $asset = $test->class->new({session => $session});
note "assetId, getId";
can_ok $asset, qw/assetId getId/;
ok $session->id->valid( $asset->assetId), 'assetId generated by default is valid';
is $asset->assetId, $asset->getId, '... getId is an alias for assetId';
$asset = $test->class->new({ session => $session, assetId => '' });
ok !$session->id->valid($asset->assetId), 'blank assetId in constructor is okay??';
}
sub t_01_title : Test(6) {
my $test = shift;
my $session = $test->session;
my $asset = $test->class->new({session => $session});
@ -100,7 +186,7 @@ sub title : Test(6) {
}
sub menuTitle : Test(8) {
sub t_01_menuTitle : Test(8) {
my $test = shift;
my $session = $test->session;
my $asset = $test->class->new({session => $session});
@ -136,36 +222,7 @@ sub menuTitle : Test(8) {
is $asset->menuTitle, 'menuTitle asset', '... set via constructor';
}
sub assetId : Test(4) {
my $test = shift;
my $session = $test->session;
my $asset = $test->class->new({session => $session});
note "assetId, getId";
can_ok $asset, qw/assetId getId/;
ok $session->id->valid( $asset->assetId), 'assetId generated by default is valid';
is $asset->assetId, $asset->getId, '... getId is an alias for assetId';
$asset = $test->class->new({ session => $session, assetId => '' });
ok !$session->id->valid($asset->assetId), 'blank assetId in constructor is okay??';
}
sub class_dispatch : Test(2) {
my $test = shift;
my $session = $test->session;
note "Class dispatch";
my $asset = $test->class->new({session => $session});
my $asset = WebGUI::Asset->new({
session => $session,
title => 'testing snippet',
className => 'WebGUI::Asset::Snippet',
});
isa_ok $asset, 'WebGUI::Asset';
is $asset->className, 'WebGUI::Asset', 'passing className is ignored';
}
sub uiLevel : Test(1) {
sub t_01_uiLevel : Test(1) {
my $test = shift;
my $session = $test->session;
note "uiLevel";
@ -173,7 +230,7 @@ sub uiLevel : Test(1) {
is $asset->uiLevel, $test->assetUiLevel, 'asset uiLevel check';
}
sub write_update : Test(8) {
sub t_01_write_update : Test(8) {
my $test = shift;
my $session = $test->session;
note "write, update";
@ -210,89 +267,7 @@ sub write_update : Test(8) {
$session->db->write("delete from assetData where assetId=?", [$testId]);
}
sub keywords : Test(3) {
my $test = shift;
my $session = $test->session;
my ($tag, $asset, @parents) = $test->getAnchoredAsset();
can_ok $asset, 'keywords';
$asset->keywords('chess set');
is $asset->keywords, 'chess set', 'set and get of keywords via direct accessor';
is $asset->get('keywords'), 'chess set', 'via get method';
}
sub get_tables : Test(1) {
my $test = shift;
note "get_tables";
my @tables = $test->class->meta->get_tables;
cmp_bag(
\@tables,
$test->list_of_tables,
'Set of tables for properties is correct'
);
}
sub getParent : Test(2) {
my $test = shift;
my $session = $test->session;
note "getParent";
my $testId1 = 'wg8TestAsset0000000001';
my $testId2 = 'wg8TestAsset0000000002';
my $now = time();
my $baseLineage = $session->db->quickScalar('select lineage from asset where assetId=?',['PBasset000000000000002']);
my $testLineage = $baseLineage. '909090';
$session->db->write("insert into asset (assetId, className, lineage) VALUES (?,?,?)", [$testId1, 'WebGUI::Asset', $testLineage]);
$session->db->write("insert into assetData (assetId, revisionDate, status) VALUES (?,?,?)", [$testId1, $now, 'approved']);
my $testLineage2 = $testLineage . '000001';
$session->db->write("insert into asset (assetId, className, parentId, lineage) VALUES (?,?,?,?)", [$testId2, 'WebGUI::Asset', $testId1, $testLineage2]);
$session->db->write("insert into assetData (assetId, revisionDate) VALUES (?,?)", [$testId2, $now]);
my $testAsset = WebGUI::Asset->new($session, $testId2, $now);
is $testAsset->parentId, $testId1, 'parentId assigned correctly on db fetch in new';
my $testParent = $testAsset->getParent();
isa_ok $testParent, 'WebGUI::Asset';
$session->db->write("delete from asset where assetId like 'wg8TestAsset00000%'");
$session->db->write("delete from assetData where assetId like 'wg8TestAsset00000%'");
}
sub newByPropertyHashRef : Test(2) {
my $test = shift;
my $session = $test->session;
note "newByPropertyHashRef";
my $asset;
$asset = WebGUI::Asset->newByPropertyHashRef($session, {className => $test->class, title => 'The Shawshank Snippet'});
isa_ok $asset, $test->class;
is $asset->title, 'The Shawshank Snippet', 'title is assigned from the property hash';
}
sub scan_properties : Test(1) {
note "scan properties for table definitions";
my $test = shift;
my @properties = $test->class->meta->get_all_properties;
my @undefined_tables = ();
foreach my $prop (@properties) {
push @undefined_tables, $prop->name if (!$prop->tableName);
}
ok !@undefined_tables, "all properties have tables defined"
or diag "except these: ".join ", ", @undefined_tables;
}
sub purge : Test(3) {
note "purge";
my $test = shift;
my $session = $test->session;
my ($tag, $asset, @parents) = $test->getAnchoredAsset();
my @tables = $asset->meta->get_tables;
ok $asset->purge, 'purge returns true if it was purged';
throws_ok { WebGUI::Asset->newById($session, $asset->assetId); } 'WebGUI::Error::InvalidParam', 'Unable to fetch asset by assetId now';
my $exists_in_table = 0;
foreach my $table (@tables) {
$exists_in_table ||= $session->db->quickScalar("select count(*) from `$table` where assetId=?",[$asset->assetId]);
}
ok ! $exists_in_table, 'assetId removed from all asset tables';
}
sub cut_paste : Test(5) {
sub t_03_addRevision : Test(5) {
note "cut";
my $test = shift;
my $session = $test->session;
@ -308,6 +283,46 @@ sub cut_paste : Test(5) {
$session->asset($session_asset);
}
sub t_05_cut_paste : Test(5) {
note "cut";
my $test = shift;
my $session = $test->session;
my ($tag, $asset, @parents) = $test->getAnchoredAsset();
ok $asset->cut, 'cut returns true if it was cut';
is $asset->state, 'clipboard', 'asset state updated';
my $session_asset = $session->asset();
$session->asset($parents[-1]);
ok $asset->canPaste, 'canPaste: allowed to paste here';
ok $parents[-1]->paste($asset->assetId), 'paste returns true when it pastes';
$asset_prime = $asset->cloneFromDb;
is $asset_prime->state, 'published', 'asset state updated';
$session->asset($session_asset);
}
sub t_05_keywords : Test(3) {
my $test = shift;
my $session = $test->session;
my ($tag, $asset, @parents) = $test->getAnchoredAsset();
can_ok $asset, 'keywords';
$asset->keywords('chess set');
is $asset->keywords, 'chess set', 'set and get of keywords via direct accessor';
is $asset->get('keywords'), 'chess set', 'via get method';
}
sub t_05_purge : Test(3) {
note "purge";
my $test = shift;
my $session = $test->session;
my ($tag, $asset, @parents) = $test->getAnchoredAsset();
my @tables = $asset->meta->get_tables;
ok $asset->purge, 'purge returns true if it was purged';
throws_ok { WebGUI::Asset->newById($session, $asset->assetId); } 'WebGUI::Error::InvalidParam', 'Unable to fetch asset by assetId now';
my $exists_in_table = 0;
foreach my $table (@tables) {
$exists_in_table ||= $session->db->quickScalar("select count(*) from `$table` where assetId=?",[$asset->assetId]);
}
ok ! $exists_in_table, 'assetId removed from all asset tables';
}
1;