Add a getArchive method to the Story. Test it.

Make www_edit work.
This commit is contained in:
Colin Kuskie 2009-03-05 01:01:45 +00:00
parent d134336ffc
commit 426bc41b04
2 changed files with 34 additions and 7 deletions

View file

@ -180,9 +180,25 @@ sub exportAssetData {
#-------------------------------------------------------------------
=head2 getArchive ( )
Returns the parent archive for this Story. Cache the entry for speed.
=cut
sub getArchive {
my $self = shift;
if (!$self->{_archive}) {
$self->{_archive} = $self->getParent->getParent;
}
return $self->{_archive};
}
#-------------------------------------------------------------------
=head2 getEditForm ( )
Returns a tempalted form for adding or editing Stories.
Returns a templated form for adding or editing Stories.
=cut
@ -191,7 +207,7 @@ sub getEditForm {
my $session = $self->session;
my $i18n = WebGUI::International->new($session, 'Asset_Story');
my $form = $session->form;
my $archive = $self->getParent->getParent();
my $archive = $self->getArchive;
my $isNew = $self->getId eq 'new';
my $url = $isNew ? $archive->getUrl : $self->getUrl;
my $title = $self->getTitle;
@ -239,7 +255,9 @@ sub getEditForm {
$var->{formHeader} .= WebGUI::Form::hidden($session, { name => 'assetId', value => 'new' })
. WebGUI::Form::hidden($session, { name => 'className', value => $form->process('class', 'className') });
}
return $self->processTemplate($var, $archive->getValue('editStoryTemplateId'));
$self->session->log->warn($archive->get('className'));
$self->session->log->warn($archive->get('editStoryTemplateId'));
return $self->processTemplate($var, $archive->get('editStoryTemplateId'));
}
@ -509,6 +527,7 @@ sub www_edit {
my $session = $self->session;
return $session->privilege->insufficient() unless $self->canEdit;
return $session->privilege->locked() unless $self->canEditIfLocked;
return $self->getArchive->processStyle($self->getEditForm);
}
#-------------------------------------------------------------------

View file

@ -20,7 +20,7 @@ use Test::More; # increment this value for each test you create
use Test::Deep;
my $tests = 1;
plan tests => 12
plan tests => 13
+ $tests
;
@ -33,7 +33,7 @@ my $loaded = use_ok($class);
my $story;
my $defaultNode = WebGUI::Asset->getDefault($session);
my $archive = WebGUI::Asset->newByPropertyHashRef($session, {
my $archive = $defaultNode->addChild({
className => 'WebGUI::Asset::Wobject::StoryArchive',
title => 'Test Archive',
#1234567890123456789012
@ -62,7 +62,7 @@ ok( WebGUI::Asset::Story->validParent($session), 'validParent: StoryArchive is
#
############################################################
$story = $defaultNode->addChild({
$story = $archive->addChild({
className => 'WebGUI::Asset::Story',
title => 'Story 1',
});
@ -74,6 +74,14 @@ is($story->get('isHidden'), 1, 'by default, photos are hidden');
$story->update({isHidden => 0});
is($story->get('isHidden'), 1, 'photos cannot be set to not be hidden');
############################################################
#
# getArchive
#
############################################################
is($story->getArchive->getId, $archive->getId, 'getArchive gets the parent archive for the Story');
############################################################
#
# Photo JSON
@ -118,7 +126,7 @@ cmp_deeply(
}
END {
WebGUI::VersionTag->getWorking($session)->rollback;
$story->purge if $story;
$archive->purge if $archive;
WebGUI::VersionTag->getWorking($session)->rollback;
}