migrate Survey graph to formbuilder

This commit is contained in:
Doug Bell 2011-02-03 16:56:03 -06:00
parent db8b507b94
commit 1fb51f2e75
2 changed files with 24 additions and 10 deletions

View file

@ -694,22 +694,20 @@ sub www_graph {
my $i18n = WebGUI::International->new($session, "Asset_Survey"); my $i18n = WebGUI::International->new($session, "Asset_Survey");
my $ac = $self->getAdminConsole;
eval { require GraphViz }; eval { require GraphViz };
if ($@) { if ($@) {
return $ac->render('Survey Visualization requires the GraphViz module', $i18n->get('survey visualization')); return '<h1>' . $i18n->get('survey visualization') . '</h1>Survey Visualization requires the GraphViz module';
} }
my $format = $self->session->form->param('format'); my $format = $self->session->form->param('format');
my $layout = $self->session->form->param('layout'); my $layout = $self->session->form->param('layout');
my $f = WebGUI::HTMLForm->new($session); my $f = WebGUI::FormBuilder->new($session, action => $self->getUrl);
$f->hidden( $f->addField( "hidden",
name=>'func', name=>'func',
value=>'graph' value=>'graph'
); );
$f->selectBox( $f->addField( "selectBox",
name => 'format', name => 'format',
label => $i18n->get('visualization format'), label => $i18n->get('visualization format'),
hoverHelp => $i18n->get('visualization format help'), hoverHelp => $i18n->get('visualization format help'),
@ -717,7 +715,7 @@ sub www_graph {
defaultValue => [$format], defaultValue => [$format],
sortByValue => 1, sortByValue => 1,
); );
$f->selectBox( $f->addField( "selectBox",
name => 'layout', name => 'layout',
label => $i18n->get('visualization layout algorithm'), label => $i18n->get('visualization layout algorithm'),
hoverHelp => $i18n->get('visualization layout algorithm help'), hoverHelp => $i18n->get('visualization layout algorithm help'),
@ -725,7 +723,7 @@ sub www_graph {
defaultValue => [$layout], defaultValue => [$layout],
sortByValue => 1, sortByValue => 1,
); );
$f->submit( $f->addField( "submit",
defaultValue => $i18n->get('generate'), defaultValue => $i18n->get('generate'),
); );
@ -735,7 +733,7 @@ sub www_graph {
$output .= "<p>" . $i18n->get('visualization success') . qq{ <a href="$url">survey.$format</a></p>}; $output .= "<p>" . $i18n->get('visualization success') . qq{ <a href="$url">survey.$format</a></p>};
} }
} }
return $ac->render($f->print . $output, $i18n->get('survey visualization')); return '<h1>' . $i18n->get('survey visualization') . '</h1>' . $f->toHtml . $output;
} }
=head2 hasResponses =head2 hasResponses

View file

@ -8,6 +8,7 @@ use Test::More;
use Test::Deep; use Test::Deep;
use Data::Dumper; use Data::Dumper;
use WebGUI::Test; # Must use this before any other WebGUI modules use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Test::Mechanize;
use WebGUI::Session; use WebGUI::Session;
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
@ -16,7 +17,7 @@ my $session = WebGUI::Test->session;
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
# Tests # Tests
plan tests => 47; plan tests => 51;
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
# put your tests here # put your tests here
@ -261,6 +262,21 @@ like($storage->getFileContentsAsScalar($filename), qr{
stop$ # ..and end with stop stop$ # ..and end with stop
}xs, 'Generated graph looks roughly okay'); }xs, 'Generated graph looks roughly okay');
my $mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file );
$mech->get_ok( '/' );
$mech->session->user({ userId => 3 });
$mech->get_ok( $survey->getUrl( 'func=graph' ) );
$mech->submit_form_ok({
fields => {
format => "plain",
layout => "dot",
},
},
"generate a graph",
);
# Can only test for the uploads, mech doesn't have uploads handler
$mech->content_contains( 'uploads/temp', 'uploads link exists' );
} }
#################################################### ####################################################