diff --git a/lib/WebGUI/AdSpace.pm b/lib/WebGUI/AdSpace.pm index 4bd83a449..b4d58227a 100644 --- a/lib/WebGUI/AdSpace.pm +++ b/lib/WebGUI/AdSpace.pm @@ -328,7 +328,7 @@ The height, in pixels, of this ad space. sub set { my $self = shift; - my $properties = shift; + my $properties = shift || {}; ##create requires a name, default will never be used $self->{_properties}{name} = $properties->{name} || $self->{_properties}{name} || "Unnamed"; $self->{_properties}{title} = $properties->{title} || $self->{_properties}{title} || "Untitled"; diff --git a/t/AdSpace.t b/t/AdSpace.t index 8607d0afd..cd1ced7d7 100644 --- a/t/AdSpace.t +++ b/t/AdSpace.t @@ -17,7 +17,21 @@ use WebGUI::Session; use Test::More; use Test::Deep; -my $numTests = 11; # increment this value for each test you create +my $newAdSpaceSettings = { + name => "newAdSpaceName", + title => "Ad Space", + description => 'This is a space reserved for ads', + costPerImpression => '1.00', + costPerClick => '1.00', + minimumImpressions => 100, + minimumClicks => 200, + groupToPurchase => "7", + width => "400", + height => "300", +}; + +my $numTests = 12; # increment this value for each test you create +$numTests += 2 * scalar keys %{ $newAdSpaceSettings }; ++$numTests; ##For conditional testing on module load plan tests => $numTests; @@ -47,10 +61,13 @@ SKIP: { $bruce = WebGUI::AdSpace->newByName($session, 'Bruce'); is($bruce, undef, 'newByName returns undef if the name does not exist'); - + + $bruce = WebGUI::AdSpace->new($session, $session->getId); + is($bruce, undef, 'new returns undef if the id does not exist'); + $alfred2 = WebGUI::AdSpace->create($session); is($alfred2, undef, 'create returns undef unless you pass it a name'); - + $alfred2 = WebGUI::AdSpace->create($session, {name => 'Alfred'}); is($alfred2, undef, 'create returns undef if the name already exists'); @@ -70,6 +87,22 @@ SKIP: { my $adSpaces = WebGUI::AdSpace->getAdSpaces($session); cmp_deeply($adSpaces, [$alfred, $bruce, $catWoman], 'getAdSpaces returns all AdSpaces in alphabetical order by title'); + + $catWoman->set($newAdSpaceSettings); + + foreach my $setting (keys %{ $newAdSpaceSettings } ) { + is($newAdSpaceSettings->{$setting}, $catWoman->get($setting), + sprintf "set and get for %s", $setting); + } + + ##Bare call to set doesn't change anything + $catWoman->set(); + + foreach my $setting (keys %{ $newAdSpaceSettings } ) { + is($newAdSpaceSettings->{$setting}, $catWoman->get($setting), + sprintf "empty call to set does not change %s", $setting); + } + } END {