diff --git a/lib/WebGUI/Macro/PageTitle.pm b/lib/WebGUI/Macro/PageTitle.pm index 4227df80b..630934cb4 100644 --- a/lib/WebGUI/Macro/PageTitle.pm +++ b/lib/WebGUI/Macro/PageTitle.pm @@ -24,7 +24,7 @@ Macro for returning the title of the current Asset. Returns the title of the current Asset. If a WebGUI operation or function is active, then the title is returned as a link to the Asset. If there is -no asset cached in the session variable, nothing is returned. +no asset cached in the session variable, undef is returned. =cut diff --git a/lib/WebGUI/Session/Stow.pm b/lib/WebGUI/Session/Stow.pm index c684f323c..059881576 100644 --- a/lib/WebGUI/Session/Stow.pm +++ b/lib/WebGUI/Session/Stow.pm @@ -95,7 +95,9 @@ sub DESTROY { =head2 get( varName ) -Retrieves the current value of a stow variable. +Retrieves the current value of a stow variable. Note that if you use references, you're +getting back a reference and modifying the contents of the reference will change the +contents of the stow variable. =head3 varName @@ -155,7 +157,7 @@ The name of the stow variable. =head3 value -The value of the stow variable. Any scalar or reference. +The value of the stow variable. Any scalar or reference. =cut diff --git a/t/Macro/CanEditText.t b/t/Macro/CanEditText.t index 2d50fb893..aa75f6e72 100644 --- a/t/Macro/CanEditText.t +++ b/t/Macro/CanEditText.t @@ -21,7 +21,6 @@ my $session = WebGUI::Test->session; use Test::More; # increment this value for each test you create my $homeAsset = WebGUI::Asset->getDefault($session); -$session->asset($homeAsset); my ($versionTag, $asset, $group, @users) = setupTest($session, $homeAsset); my @testSets = ( @@ -62,7 +61,7 @@ my @testSets = ( }, ); -my $numTests = scalar @testSets + 1; +my $numTests = scalar @testSets + 2; plan tests => $numTests; @@ -73,6 +72,12 @@ SKIP: { skip "Unable to load $macro", $numTests-1 unless $loaded; +is( + WebGUI::Macro::CanEditText::process($session,''), + '', + q!Call with no default session asset returns ''!, +); + foreach my $testSet (@testSets) { $session->user({userId=>$testSet->{userId}}); $session->asset($testSet->{asset}); diff --git a/t/Macro/EditableToggle.t b/t/Macro/EditableToggle.t index 21b09af44..5034d4d54 100644 --- a/t/Macro/EditableToggle.t +++ b/t/Macro/EditableToggle.t @@ -22,7 +22,6 @@ use Test::More; # increment this value for each test you create my $session = WebGUI::Test->session; my $homeAsset = WebGUI::Asset->getDefault($session); -$session->asset($homeAsset); my ($versionTag, $asset, @users) = setupTest($session, $homeAsset); my $i18n = WebGUI::International->new($session,'Macro_EditableToggle'); @@ -185,7 +184,7 @@ foreach my $testSet (@testSets) { $numTests += 1 + (ref $testSet->{output} eq 'CODE'); } -$numTests += 1; +$numTests += 1 + 1; ##Empty session Asset plus use_ok plan tests => $numTests; @@ -196,6 +195,12 @@ SKIP: { skip "Unable to load $macro", $numTests-1 unless $loaded; +is( + WebGUI::Macro::EditableToggle::process($session,'on','off',''), + '', + q!Call with no default session asset returns ''!, +); + foreach my $testSet (@testSets) { $session->user({userId=>$testSet->{userId}}); $session->asset($testSet->{asset}); diff --git a/t/Macro/H_homeLink.t b/t/Macro/H_homeLink.t index d497330f9..da86158d9 100644 --- a/t/Macro/H_homeLink.t +++ b/t/Macro/H_homeLink.t @@ -35,7 +35,7 @@ my @testSets = ( comment => 'linkonly argument', }, { - label => $i18n->get(47), + label => q!!, template => q!!, url => $homeAsset->getUrl(), output => \&simpleHTMLParser, @@ -75,6 +75,7 @@ skip "Unable to load $macro", $numTests-1 unless $loaded; foreach my $testSet (@testSets) { my $output = WebGUI::Macro::H_homeLink::process($session, $testSet->{label}, $testSet->{template}); + $testSet->{label} ||= $i18n->get(47); if (ref $testSet->{output} eq 'CODE') { my ($url, $label) = $testSet->{output}->($output); is($label, $testSet->{label}, $testSet->{comment}.", label"); diff --git a/t/Macro/Page.t b/t/Macro/Page.t index cddb7ab01..5f21e8cfb 100644 --- a/t/Macro/Page.t +++ b/t/Macro/Page.t @@ -47,6 +47,7 @@ foreach my $testSet (@testSets) { } $numTests += 1; #For the use_ok +$numTests += 1; #For macro call with undefined session asset plan tests => $numTests; @@ -62,6 +63,12 @@ SKIP: { skip "Unable to load $macro", $numTests-1 unless $loaded; +is( + WebGUI::Macro::Page::process($session,'url'), + '', + q!Call with no default session asset returns ''!, +); + foreach my $testSet (@testSets) { $session->asset($testSet->{asset}); my $class = $testSet->{className}; diff --git a/t/Macro/PageTitle.t b/t/Macro/PageTitle.t index 589ce2ac8..55cdcc48b 100644 --- a/t/Macro/PageTitle.t +++ b/t/Macro/PageTitle.t @@ -20,7 +20,7 @@ use Test::More; # increment this value for each test you create my $session = WebGUI::Test->session; -my $numTests = 2; +my $numTests = 3; $numTests += 1; #For the use_ok plan tests => $numTests; @@ -49,6 +49,12 @@ SKIP: { skip "Unable to load $macro", $numTests-1 unless $loaded; +is( + WebGUI::Macro::PageTitle::process($session), + undef, + q!Call with no default session asset returns undef!, +); + ##Make the homeAsset the default asset in the session. $session->asset($homeAsset); @@ -61,6 +67,23 @@ is($macroOutput, $snippet->get('title'), "testing title returned from localy cre } +my $origSessionRequest = $session->{_request}; + +my ($operation, $function) = (0,0); + +my $request = Test::MockObject->new; +$request->mock('body', + sub { + my ($self, $value) = @_; + return 1 if $operation; + return 1 if $function; + return 0; + } +); + +$output = WebGUI::Macro::PageTitle::process($session); +is($output, $homeAsset->get('title'), 'fetching title for site default asset'); + END { $versionTag->rollback; } diff --git a/t/Macro/Spacer.t b/t/Macro/Spacer.t index a95c20fb9..dd1f5de66 100644 --- a/t/Macro/Spacer.t +++ b/t/Macro/Spacer.t @@ -43,12 +43,24 @@ my @testSets = ( width => '', height => 7, }, + { + comment => 'width only, undef', + width => 9, + height => undef, + }, + { + comment => 'height only, undef', + width => undef, + height => 17, + }, ); plan tests => 5 + 2 * scalar @testSets; foreach my $testSet (@testSets) { my $output = WebGUI::Macro::Spacer::process($session, $testSet->{width}, $testSet->{height}); + $testSet->{width} = '' unless defined $testSet->{width}; + $testSet->{height} = '' unless defined $testSet->{height}; my ($width, $height) = simpleHTMLParser($output); is($width, $testSet->{width}, $testSet->{comment}.", width"); is($height, $testSet->{height}, $testSet->{comment}.", height"); diff --git a/t/Macro/Thumbnail.t b/t/Macro/Thumbnail.t index e79e26c07..6ecf0ce3b 100644 --- a/t/Macro/Thumbnail.t +++ b/t/Macro/Thumbnail.t @@ -22,10 +22,16 @@ use Image::Magick; use Test::More; # increment this value for each test you create use Test::Deep; -plan tests => 7; +plan tests => 8; my $session = WebGUI::Test->session; +is( + WebGUI::Macro::Thumbnail::process($session, '/url-that-does-not-resolve'), + undef, + 'non-existant URL returns undef' +); + my $square = WebGUI::Image->new($session, 100, 100); $square->setBackgroundColor('#0000FF'); diff --git a/t/Session/Stow.t b/t/Session/Stow.t index 4383bea03..101bff02a 100644 --- a/t/Session/Stow.t +++ b/t/Session/Stow.t @@ -15,7 +15,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; -use Test::More tests => 26; # increment this value for each test you create +use Test::More tests => 29; # increment this value for each test you create my $session = WebGUI::Test->session; @@ -59,3 +59,9 @@ my $milList = $stow->get("military"); push @{ $milList }, qw/foxtrot echo/; is_deeply($stow->get("military"), [ @orig_list, qw/foxtrot echo/ ], "modifying fetched list changes stow'ed list because it is a reference"); + +is($stow->delete(), undef, 'deleting with no key returns undef'); +is($stow->delete('noSuchKey'), undef, 'deleting non-existant variable returns undef'); + +$stow->set('countedKey', 5); +is($stow->delete('countedKey'), 5, 'delete method returns what was deleted');