Merge commit 'v7.10.21' into WebGUI8. Also, add POD and fix broken tests.

This commit is contained in:
Colin Kuskie 2011-10-27 16:45:19 -07:00
commit 4855816a29
72 changed files with 1357 additions and 82 deletions

View file

@ -162,6 +162,11 @@ $storage->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath('lamp.jpg'))
$storage->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath('littleTextFile'));
my $attachment_loop = $post1->getTemplateVars()->{attachment_loop};
use Data::Dumper;
diag Dumper($attachment_loop);
my @extensions = map { [ $_->{filename}, $_->{extension} ] } @{ $attachment_loop };
cmp_bag(
$attachment_loop,
[
@ -170,6 +175,7 @@ cmp_bag(
url => $storage->getUrl('gooey.jpg'),
icon => $session->url->extras('fileIcons/jpg.gif'),
thumbnail => $storage->getThumbnailUrl('gooey.jpg'),
extension => 'jpg',
isImage => bool(1),
},
{
@ -177,6 +183,7 @@ cmp_bag(
url => $storage->getUrl('lamp.jpg'),
icon => $session->url->extras('fileIcons/jpg.gif'),
thumbnail => $storage->getThumbnailUrl('lamp.jpg'),
extension => 'jpg',
isImage => bool(1),
},
{
@ -184,6 +191,7 @@ cmp_bag(
url => $storage->getUrl('littleTextFile'),
icon => $session->url->extras('fileIcons/unknown.gif'),
thumbnail => '',
extension => undef,
isImage => bool(0),
},
],

View file

@ -14,8 +14,11 @@ use File::Spec;
##The goal of this test is to test the creation of Article Wobjects.
use WebGUI::Test;
use WebGUI::Test::MockAsset;
use WebGUI::Session;
use Test::More tests => 23; # increment this value for each test you create
use Test::More tests => 24; # increment this value for each test you create
use Test::Deep;
use Data::Dumper;
use WebGUI::Asset::Wobject::Article;
my $session = WebGUI::Test->session;
@ -61,9 +64,10 @@ foreach my $newSetting (keys %{$newArticleSettings}) {
}
# Test the duplicate method... not for assets, just the extended duplicate functionality of the article wobject
my $filename = "page_title.jpg";
my $filename = "extensions.tar";
my $pathedFile = WebGUI::Test->getTestCollateralPath($filename);
# Use some test collateral to create a storage location and assign it to our article
my $storage = WebGUI::Storage->create($session);
WebGUI::Test->addToCleanup($storage);
@ -75,6 +79,10 @@ diag(join("\n", @{ $storage->getErrors })) unless $filenameOK;
$article->update({storageId=>$storage->getId});
my $storageOK = is($article->get('storageId'), $storage->getId, 'correct storage id stored');
SKIP: {
skip 'storage test setup problem', 3 unless $filenameOK and $storageOK;
@ -117,6 +125,55 @@ $cachedOutput = $session->cache->get('view_'.$article->getId); # Check cache po
isnt ($output, $cachedOutput, 'purgeCache method deletes cache');
# lets test that our new template variable for the fileloop in the main view method returns the
# right values for the new field in the attached files loop: <tmpl_var extension>
# first we create a new template with only the <tmpl_var extension> field in it
# --------------------------------------------------------------------------------------------------
my $templateId = 'DUMMY_TEMPLATE________';
my $templateMock = WebGUI::Test::MockAsset->new('WebGUI::Asset::Template');
$templateMock->mock_id($templateId);
my $templateVars;
$templateMock->set_true('prepare', sub { } );
$templateMock->mock('process', sub { $templateVars = $_[1]; } );
my @extTestFiles = ("rotation_test.png","littleTextFile","jquery.js","tooWide.gif");
foreach my $f (@extTestFiles) {
my $pathedFile = WebGUI::Test->getTestCollateralPath($f);
my $storedFilename = $storage->addFileFromFilesystem($pathedFile);
}
$article->update({templateId=>$templateId});
$article->prepareView;
$article->view;
cmp_bag(
$templateVars->{attachment_loop},
[
superhashof({
filename => 'rotation_test.png',
extension => 'png',
}),
superhashof({
filename => 'littleTextFile',
extension => undef,
}),
superhashof({
filename => 'jquery.js',
extension => 'js',
}),
superhashof({
filename => 'tooWide.gif',
extension => 'gif',
}),
superhashof({
filename => 'extensions.tar',
extension => 'tar',
}),
],
) or diag Dumper($templateVars->{attachment_loop});
TODO: {
local $TODO = "Tests to make later";
ok(0, 'Test exportAssetData method');
@ -126,3 +183,7 @@ TODO: {
ok(0, 'Test www_deleteFile method');
ok(0, 'Test www_view method... maybe?');
}

View file

@ -81,4 +81,4 @@ my $field1 = $thingy->getFields($thingId)->hashRef;
note 'getFieldValue';
is $thingy->getFieldValue(WebGUI::Test->webguiBirthday, $field1), '8/16/2001', 'with epoch as default';
is $thingy->getFieldValue('2011-07-04', $field1), '7/4/2011', 'with mysql date as default';
is $thingy->getFieldValue('2011-07-04', $field1), '7/3/2011', 'with mysql date as default';

View file

@ -0,0 +1,43 @@
use warnings;
use strict;
use FindBin;
use lib "$FindBin::Bin/../lib";
use lib "$FindBin::Bin/../t/lib";
use WebGUI::Test;
use WebGUI::Asset;
use Test::More tests => 2;
use Monkey::Patch qw(patch_class);
my $session = WebGUI::Test->session;
WebGUI::Test->originalConfig('assets/WebGUI::Asset::Wobject::Layout');
my $asset = WebGUI::Asset->getTempspace($session)->addChild(
{
className => 'WebGUI::Asset::Wobject::Layout',
}
);
WebGUI::Test->addToCleanup($asset);
sub capture {
my $save;
my $patch = patch_class 'WebGUI::Form::Control' => new => sub {
my $orig = shift;
my $self = $orig->(@_);
my $name = $self->get('name');
$save = $self if $name && $name eq 'assetsToHide';
return $self;
};
$asset->getEditForm;
#use Data::Dumper::Concise;
#print STDERR '# ' . Dumper $save->{_params};
return $save;
}
my $config = $session->config;
my $pfx = 'assets/WebGUI::Asset::Wobject::Layout/fields/assetsToHide';
$config->set("$pfx/uiLevel", 1);
is capture->get('uiLevel'), 1, 'uiLevel override to 1';
$config->set("$pfx/uiLevel", "2");
is capture->get('uiLevel'), 2, 'uiLEvel override to 2';

View file

@ -42,7 +42,7 @@ sub setSiteVersionTagMode {
sub setUserVersionTagMode {
my ($user, $newMode) = @_;
$user->profileField(q{versionTagMode}, $newMode);
$user->update(versionTagMode => $newMode);
return;
} #setUserVersionTagMode
@ -158,10 +158,16 @@ ok(!defined $tagAgain2, 'nonexistent tag cannot be instantiated');
$tag2->rollback;
($tag, $tagAgain1, $tag2, $tagAgain2) = ();
my $master_tag = WebGUI::VersionTag->getWorking($session);
my $node = WebGUI::Test->asset;
$master_tag->commit;
$node = $node->cloneFromDb;
WebGUI::Test->addToCleanup($master_tag);
my $tag3 = WebGUI::VersionTag->create($session, {});
$tag3->setWorking;
my $asset1 = WebGUI::Test->asset->addChild({ className => 'WebGUI::Asset::Snippet', });
my $asset2 = WebGUI::Test->asset->addChild({ className => 'WebGUI::Asset::Snippet', });
my $asset1 = $node->addChild({ className => 'WebGUI::Asset::Snippet', });
my $asset2 = $node->addChild({ className => 'WebGUI::Asset::Snippet', });
is($tag3->getAssetCount, 2, 'tag with two assets');
is($tag3->getRevisionCount, 2, 'tag with two revisions');
$asset1 = $asset1->addRevision({ title => 'revised once', }, time+10);
@ -171,7 +177,7 @@ is($tag3->getRevisionCount, 5, 'tag with five revisions');
my $tag4 = WebGUI::VersionTag->create($session, {});
$tag4->setWorking;
my $asset3 = WebGUI::Test->asset->addChild({ className => 'WebGUI::Asset::Snippet', });
my $asset3 = $node->addChild({ className => 'WebGUI::Asset::Snippet', });
is($tag4->getAssetCount, 1, 'other tag with one asset');
is($tag4->getRevisionCount, 1, 'other tag with one revision');
$asset3->addRevision({ title => 'again revised once', }, time+40);
@ -186,7 +192,7 @@ $tag4->rollback;
#Test commitAsUser
my $tag5 = WebGUI::VersionTag->create($session, {});
$tag5->setWorking;
my $asset5 = WebGUI::Test->asset->addChild({ className => 'WebGUI::Asset::Snippet', });
my $asset5 = $node->addChild({ className => 'WebGUI::Asset::Snippet', });
is($tag5->get("createdBy"),1,'tag created by visitor');
$tag5->commitAsUser(3);
$tag5 = WebGUI::VersionTag->new($session, $tag5->getId); #Get the tag again - properties have changed
@ -197,7 +203,7 @@ $tag5->rollback;
#Test commitAsUser with options
my $tag6 = WebGUI::VersionTag->create($session, {});
$tag6->setWorking;
my $asset6 = WebGUI::Test->asset->addChild({ className => 'WebGUI::Asset::Snippet', });
my $asset6 = $node->addChild({ className => 'WebGUI::Asset::Snippet', });
$tag6->commitAsUser(3, { commitNow => "yes" });
$tag6 = WebGUI::VersionTag->new($session, $tag6->getId); #Get the tag again - properties have changed
is($tag6->get("committedBy"),3,'tag committed by admin again');
@ -253,7 +259,7 @@ ok($siteWideTag->getId() ne $userTagId, 'versionTagMode siteWide: siteWide tag h
$siteWideTag->clearWorking();
my $asset4 = WebGUI::Test->asset->addChild({ className => 'WebGUI::Asset::Snippet' });
my $asset4 = $node->addChild({ className => 'WebGUI::Asset::Snippet' });
ok(defined ($siteWideTag = getWorking(1)), 'versionTagMode siteWide: reclaim version tag after clearWorking and addding new asset');
@ -321,7 +327,7 @@ $siteWideTag->rollback();
setUserVersionTagMode($user, q{singlePerUser});
my $tag = WebGUI::VersionTag->create($session, {});
$tag->setWorking;
my $asset = WebGUI::Test->asset->addChild({ className => 'WebGUI::Asset::Snippet', });
my $asset = $node->addChild({ className => 'WebGUI::Asset::Snippet', });
is($tag->getAssetCount, 1, qq{$test_prefix [singlePerUser] tag with 1 asset});
# create admin session
@ -372,7 +378,7 @@ $siteWideTag->rollback();
setUserVersionTagMode($user, q{siteWide});
$tag = WebGUI::VersionTag->create($session, {});
$tag->setWorking;
$asset = WebGUI::Test->asset->addChild({ className => 'WebGUI::Asset::Snippet', });
$asset = $node->addChild({ className => 'WebGUI::Asset::Snippet', });
is($tag->getAssetCount, 1, qq{$test_prefix [siteWide] tag with 1 asset});
# create admin session

View file

@ -0,0 +1,110 @@
use warnings;
use strict;
use FindBin;
use lib "$FindBin::Bin/../../lib";
use lib "$FindBin::Bin/../../t/lib";
use WebGUI::Test;
use Test::More tests => 28;
use Test::MockObject;
use Test::MockObject::Extends;
use WebGUI::Workflow::Activity;
use Kwargs;
use URI;
my $session = WebGUI::Test->session;
my $act = WebGUI::Workflow::Activity->newByPropertyHashRef(
$session, {
className => 'WebGUI::Workflow::Activity::WaitForUserConfirmation',
activityId => 'test-activity',
expireAfter => 60*60*24,
waitBetween => 60*5,
emailFrom => 3,
emailSubject => 'Confirmation Email',
templateParser => 'WebGUI::Asset::Template::TemplateToolkit',
template => 'Hey [% user.firstName %] [% user.lastName %], '
. 'click $link!',
}
);
is $act->wait, $act->WAITING(60*5), 'wait helper method';
$act = Test::MockObject::Extends->new($act);
my (%scratch, %profile);
%profile = (
email => 'target@test.com',
firstName => 'Target',
lastName => 'Targetson',
);
my $user = Test::MockObject->new
->mock(get => sub { \%profile })
->mock(userId => sub { 'test-user-id' });
my $workflow = Test::MockObject->new
->mock(setScratch => sub { $scratch{$_[1]} = $_[2] })
->mock(getScratch => sub { $scratch{$_[1]} })
->mock(getId => sub { 'test-workflow' });
my ($expired, $sent) = (0,0);
$act->mock(sendEmail => sub { $sent++ })
->mock(expire => sub { $expired++ })
->mock(now => sub { 100 })
->mock(token => sub { 'test-token' });
my $st = 'test-activity-status';
sub ex { $act->execute($user, $workflow) }
sub clr {
delete @scratch{'test-activity-started', $st};
$sent = 0;
$expired = 0;
}
is ex, $act->wait, 'from scratch returns waiting';
is $sent, 1, 'one email sent';
is $scratch{$st}, 'waiting', 'scratch is waiting';
is $scratch{'test-activity-started'}, 100, 'started at mocked time';
is ex, $act->wait, 'still waiting';
is $sent, 1, 'did not send second email';
is $scratch{$st}, 'waiting', 'scratch still waiting';
$scratch{$st} = 'done';
is ex, $act->COMPLETE, 'returns complete after done';
is ex, $act->COMPLETE, 'forever';
is $expired, 0, 'not expired though';
clr;
is $act->execute($user, $workflow), $act->wait, 'waiting after clear';
is $sent, 1, 'one email sent';
$act->mock(now => sub { 60*60*24+101 });
is ex, $act->COMPLETE, 'complete after expired';
is $scratch{$st}, 'expired', 'expired status';
is $expired, 1, 'expire called';
clr;
my ($self, $to, $from, $subject, $body);
$act->mock(
sendEmail => sub {
($self, $to, $from, $subject, $body) = kwn @_, 1,
qw(to from subject body);
}
);
ex;
is $to, $user->userId, 'to';
is $from, 3, 'from';
is $subject, 'Confirmation Email', 'subject';
my $link = URI->new($act->link($workflow));
my %p = $link->query_form;
is $body, "Hey Target Targetson, click $link!", 'body';
is $p{token}, 'test-token', 'token in link';
is $p{instanceId}, 'test-workflow', 'instance id in link';
is $p{activityId}, 'test-activity', 'activity id in link';
$act->unmock('token');
is $act->link($workflow), $link, 'token only generated once';
ok !$act->confirm($workflow, 'not-the-token'), 'bad token';
is $scratch{$st}, 'waiting', 'wait after bad';
ok $act->confirm($workflow, 'test-token'), 'good token';
is $scratch{$st}, 'done', 'done after good';