Make AdSpace->get provide a hash ref if none is supplied.
Add tests to improve test coverage and to verify defaults from the DB and the code.
This commit is contained in:
parent
c9726f7b4d
commit
d1ede96e63
2 changed files with 37 additions and 4 deletions
|
|
@ -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";
|
||||
|
|
|
|||
39
t/AdSpace.t
39
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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue