Complete rework of Story autocommit.

Tests for status of Stories that have been autocommitted.
Keyword search interface with UI and tests.
This commit is contained in:
Colin Kuskie 2009-03-09 20:59:28 +00:00
parent 6dc31e64ae
commit 9487b7d4ac
4 changed files with 150 additions and 50 deletions

View file

@ -60,6 +60,8 @@ sub addChild {
Copy storage locations so that purging individual revisions works correctly.
Request autocommit.
=cut
sub addRevision {
@ -76,6 +78,7 @@ sub addRevision {
}
$newSelf->update($newProperties);
$newSelf->requestAutoCommit;
return $newSelf;
}
@ -233,6 +236,27 @@ sub getArchive {
return $self->{_archive};
}
#-------------------------------------------------------------------
=head2 getAutoCommitWorkflowId ( )
Get the autocommit workflow from the archive containing this Story and
use it.
=cut
sub getAutoCommitWorkflowId {
my $self = shift;
my $archive = $self->getArchive;
if ($archive->hasBeenCommitted) {
$self->session->log->warn($archive->get('approvalWorkflowId'));
return $archive->get('approvalWorkflowId')
|| $self->session->setting->get('defaultVersionTagWorkflow');
}
return undef;
}
#-------------------------------------------------------------------
=head2 getEditForm ( )

View file

@ -259,7 +259,13 @@ sub view {
my $session = $self->session;
#This automatically creates template variables for all of your wobject's properties.
my $var = $self->viewTemplateVariables();
my $mode = $session->form->hasParam('keywords')
? 'search'
: 'view';
my $var = $self->viewTemplateVariables($mode);
use Data::Dumper;
$session->log->warn( Dumper $var );
return $self->processTemplate($var, undef, $self->{_viewTemplate});
}
@ -277,16 +283,30 @@ Whether to get assets in view mode, by time, or search mode, by keywords.
=cut
sub viewTemplateVariables {
my ($self) = @_;
my $session = $self->session;
my $keywords = $session->form->get('keywords');
##Only return assetIds, we'll build data for the things that are actually displayed.
my $storySql = $self->getLineageSql(['descendants'],{
excludeClasses => ['WebGUI::Asset::Wobject::Folder'],
orderByClause => 'creationDate, lineage',
});
my $p = WebGUI::Paginator->new($session, $self->getUrl, $self->get('storiesPerPage'));
$p->setDataByQuery($storySql);
my ($self, $mode) = @_;
my $session = $self->session;
my $keywords = $session->form->get('keywords');
my $p;
if ($mode eq "search") {
my $wordList = WebGUI::Keyword::string2list($keywords);
my $key = WebGUI::Keyword->new($session);
$p = $key->getMatchingAssets({
startAsset => $self,
keywords => $wordList,
isa => 'WebGUI::Asset::Story',
usePaginator => 1,
rowsPerPage => $self->get('storiesPerPage'),
});
}
else {
##Only return assetIds, we'll build data for the things that are actually displayed.
my $storySql = $self->getLineageSql(['descendants'],{
excludeClasses => ['WebGUI::Asset::Wobject::Folder'],
orderByClause => 'creationDate desc, lineage',
});
$p = WebGUI::Paginator->new($session, $self->getUrl, $self->get('storiesPerPage'));
$p->setDataByQuery($storySql);
}
my $storyIds = $p->getPageData();
my $var = $self->get;
$p->appendTemplateVars($var);
@ -318,7 +338,7 @@ sub viewTemplateVariables {
$var->{canPostStories} = $self->canPostStories;
$var->{keywordCloud} = WebGUI::Keyword->new($session)->generateCloud({
startAsset => $self,
displayFunc => 'search',
displayFunc => 'view',
});
my $i18n = WebGUI::International->new($session, 'Asset');
$var->{searchHeader} = WebGUI::Form::formHeader($session, { action => $self->getUrl })

View file

@ -21,7 +21,7 @@ use Test::Deep;
use Data::Dumper;
my $tests = 1;
plan tests => 23
plan tests => 25
+ $tests
;
@ -41,6 +41,8 @@ my $archive = $defaultNode->addChild({
#1234567890123456789012
assetId => 'TestStoryArchiveAsset1',
});
my $archiveTag = WebGUI::VersionTag->getWorking($session);
$archiveTag->commit;
SKIP: {
@ -72,9 +74,18 @@ $story = $archive->addChild({
isa_ok($story, 'WebGUI::Asset::Story', 'Created a Story asset');
is($story->get('storageId'), '', 'by default, there is no storageId');
is($story->get('photo'), '{}', 'by default, photos is an empty JSON hash');
is($story->get('isHidden'), 1, 'by default, photos are hidden');
is($story->get('isHidden'), 1, 'by default, stories are hidden');
$story->update({isHidden => 0});
is($story->get('isHidden'), 1, 'photos cannot be set to not be hidden');
is($story->get('isHidden'), 1, 'stories cannot be set to not be hidden');
is($story->get('state'), 'published', 'Story is published');
{
##Version control does not alter the current object's status, fetch an updated copy from the
##db.
my $storyDB = WebGUI::Asset->newByUrl($session, $story->getUrl);
is($storyDB->get('status'), 'approved', 'Story is approved');
}
############################################################
#
@ -179,5 +190,6 @@ END {
$story->purge if $story;
$wgBday->purge if $wgBday;
$archive->purge if $archive;
$archiveTag->rollback;
WebGUI::VersionTag->getWorking($session)->rollback;
}

View file

@ -59,7 +59,7 @@ $canPostMaker->prepare({
});
my $tests = 1;
plan tests => 22
plan tests => 24
+ $tests
+ $canPostMaker->plan
;
@ -162,7 +162,7 @@ is($folder->getFirstChild->getTitle, 'First Story', '... and it is the correct c
my $wgBday = 997966800;
my $oldFolder = $archive->getFolder($wgBday);
my $tomorrow = time()+24*3600;
my $tomorrow = $now+24*3600;
my $newFolder = $archive->getFolder($tomorrow);
my ($wgBdayMorn,undef) = $session->datetime->dayStartEnd($wgBday);
@ -170,6 +170,12 @@ my ($tomorrowMorn,undef) = $session->datetime->dayStartEnd($tomorrow);
my $story = $oldFolder->addChild({ className => 'WebGUI::Asset::Story', title => 'WebGUI is released'});
$session->db->write('update asset set creationDate=997966800 where assetId=?',[$story->getId]);
{
my $storyDB = WebGUI::Asset->newByUrl($session, $story->getUrl);
is ($storyDB->get('status'), 'approved', 'addRevision always calls for an autocommit');
}
my $futureStory = $newFolder->addChild({ className => 'WebGUI::Asset::Story', title => "There's always tomorrow" });
$session->db->write("update asset set creationDate=$tomorrow where assetId=?",[$futureStory->getId]);
@ -187,11 +193,11 @@ cmp_deeply(
addStoryUrl => '/home/mystories?func=add;class=WebGUI::Asset::Story',
date_loop => [
{
epochDate => $wgBdayMorn,
story_loop => [ {
creationDate => $wgBday,
url => '/home/mystories/august_16_2001/webgui-is-released',
title => 'WebGUI is released',
epochDate => $tomorrowMorn,
story_loop => [{
creationDate => $tomorrow,
url => re('theres-always-tomorrow'),
title => "There's always tomorrow",
}, ],
},
{
@ -203,11 +209,11 @@ cmp_deeply(
}, ],
},
{
epochDate => $tomorrowMorn,
story_loop => [{
creationDate => $tomorrow,
url => re('theres-always-tomorrow'),
title => "There's always tomorrow",
epochDate => $wgBdayMorn,
story_loop => [ {
creationDate => $wgBday,
url => '/home/mystories/august_16_2001/webgui-is-released',
title => 'WebGUI is released',
}, ],
},
]
@ -215,9 +221,12 @@ cmp_deeply(
'viewTemplateVariables: returns expected template variables with 3 stories in different folders'
);
$folder->addChild({ className => 'WebGUI::Asset::Story', title => 'Story 2'});
$folder->addChild({ className => 'WebGUI::Asset::Story', title => 'Story 3'});
$folder->addChild({ className => 'WebGUI::Asset::Story', title => 'Story 4'});
my $story2 = $folder->addChild({ className => 'WebGUI::Asset::Story', title => 'Story 2', keywords => "roger foxtrot"});
my $story3 = $folder->addChild({ className => 'WebGUI::Asset::Story', title => 'Story 3', keywords => "foxtrot echo"});
my $story4 = $folder->addChild({ className => 'WebGUI::Asset::Story', title => 'Story 4', keywords => "roger echo"});
foreach my $storilet ($story2, $story3, $story4) {
$session->db->write("update asset set creationDate=$now where assetId=?",[$storilet->getId]);
}
$archive->update({storiesPerPage => 3});
##Don't assume that Admin and Visitor have the same timezone.
@ -232,7 +241,6 @@ KEY: foreach my $key (keys %{ $templateVars }) {
delete $templateVars->{$key};
}
cmp_deeply(
$templateVars,
{
@ -240,11 +248,11 @@ cmp_deeply(
addStoryUrl => '/home/mystories?func=add;class=WebGUI::Asset::Story',
date_loop => [
{
epochDate => $wgBdayMorn,
story_loop => [ {
creationDate => $wgBday,
url => '/home/mystories/august_16_2001/webgui-is-released',
title => 'WebGUI is released',
epochDate => $tomorrowMorn,
story_loop => [{
creationDate => $tomorrow,
url => re('theres-always-tomorrow'),
title => "There's always tomorrow",
}, ],
},
{
@ -267,6 +275,51 @@ cmp_deeply(
'viewTemplateVariables: returns expected template variables with 3 stories in different folders'
);
################################################################
#
# viewTemplateVariables, keywords search mode
#
################################################################
$session->request->setup_body({ keywords => 'foxtrot' } );
$archive->update({storiesPerPage => 25});
$templateVars = $archive->viewTemplateVariables('search');
cmp_deeply(
$templateVars->{date_loop},
[
{
epochDate => ignore(),
story_loop => [
{
creationDate => ignore(),
url => ignore(),
title => 'Story 2',
},
{
creationDate => ignore(),
url => ignore(),
title => 'Story 3',
},
],
},
{
epochDate => $wgBdayMorn,
story_loop => [
{
creationDate => ignore(),
url => ignore(),
title => 'WebGUI is released',
},
],
},
],
'viewTemplateVariables: search mode returns the correct assets in the same form as view mode'
);
$archive->update({storiesPerPage => 2});
$session->request->setup_body({ } );
################################################################
#
@ -276,22 +329,13 @@ cmp_deeply(
$templateVars = $archive->viewTemplateVariables();
my @anchors = simpleHrefParser($templateVars->{keywordCloud});
my @expectedAnchors = ();
foreach my $keyword(qw/echo foxtrot roger/) {
push @expectedAnchors, [ $keyword, '/home/mystories?func=view;keyword='.$keyword ];
}
cmp_bag(
\@anchors,
[
[
'echo',
'/home/mystories?func=search;keyword=echo',
],
[
'foxtrot',
'/home/mystories?func=search;keyword=foxtrot',
],
[
'roger',
'/home/mystories?func=search;keyword=roger',
],
],
\@expectedAnchors,
'keywordCloud template variable has keywords and correct links',
);