From 9e2cdeca1352714ddea271787f088ce0f793fd31 Mon Sep 17 00:00:00 2001 From: Patrick Donelan Date: Mon, 11 May 2009 11:06:55 +0000 Subject: [PATCH] Added some tests for Survey visualization --- lib/WebGUI/Asset/Wobject/Survey.pm | 6 +++++- t/Asset/Wobject/Survey.t | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/WebGUI/Asset/Wobject/Survey.pm b/lib/WebGUI/Asset/Wobject/Survey.pm index 08d24893f..23db1987b 100644 --- a/lib/WebGUI/Asset/Wobject/Survey.pm +++ b/lib/WebGUI/Asset/Wobject/Survey.pm @@ -618,7 +618,11 @@ sub graph { my $method = "as_$format"; $g->$method($path); - return $storage->getUrl($filename); + if (wantarray) { + return ( $storage, $filename); + } else { + return $storage->getUrl($filename); + } } #------------------------------------------------------------------- diff --git a/t/Asset/Wobject/Survey.t b/t/Asset/Wobject/Survey.t index 0fc38ad23..995ba2fd7 100644 --- a/t/Asset/Wobject/Survey.t +++ b/t/Asset/Wobject/Survey.t @@ -18,7 +18,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -my $tests = 19; +my $tests = 20; plan tests => $tests + 1; #---------------------------------------------------------------------------- @@ -114,6 +114,23 @@ ok($s->responseId, '..(and similarly for responseId)'); } +} + +eval 'use GraphViz'; + +SKIP: { + +skip "Unable to load GraphViz", 1 if $@; + +$survey->surveyJSON->remove([1]); +my ($storage, $filename) = $survey->graph( { format => 'plain', layout => 'dot' } ); +like($storage->getFileContentsAsScalar($filename), qr{ + ^graph .* # starts with graph + (node .*){3} # ..then 3 nodes + (edge .*){3} # ..then 3 edges + stop$ # ..and end with stop +}xs, 'Generated graph looks roughly okay'); + } #----------------------------------------------------------------------------