From c9726f7b4d6dd3d94a17aada4656e261b2f94d43 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 5 Feb 2007 01:01:20 +0000 Subject: [PATCH] New AdSpace tests, need to start looking at coverage. Added some comments and fixed some POD in AdSpace.pm and Ad.pm --- lib/WebGUI/AdSpace.pm | 1 + lib/WebGUI/AdSpace/Ad.pm | 2 +- t/AdSpace.t | 30 ++++++++++++++++++++++-------- t/AdSpace/Ad.t | 9 +++++---- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/lib/WebGUI/AdSpace.pm b/lib/WebGUI/AdSpace.pm index 0e587c5ab..4bd83a449 100644 --- a/lib/WebGUI/AdSpace.pm +++ b/lib/WebGUI/AdSpace.pm @@ -329,6 +329,7 @@ The height, in pixels, of this ad space. sub set { my $self = 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"; $self->{_properties}{description} = $properties->{description} || $self->{_properties}{description}; diff --git a/lib/WebGUI/AdSpace/Ad.pm b/lib/WebGUI/AdSpace/Ad.pm index 48ec60f11..d10d40a40 100644 --- a/lib/WebGUI/AdSpace/Ad.pm +++ b/lib/WebGUI/AdSpace/Ad.pm @@ -213,7 +213,7 @@ The hex color to be used to display the border on a text based ad. =head4 textColor -The hex color to be used to display the text on a test based ad. +The hex color to be used to display the text on a text based ad. =head4 backgroundColor diff --git a/t/AdSpace.t b/t/AdSpace.t index dd355494b..8607d0afd 100644 --- a/t/AdSpace.t +++ b/t/AdSpace.t @@ -17,7 +17,7 @@ use WebGUI::Session; use Test::More; use Test::Deep; -my $numTests = 9; # increment this value for each test you create +my $numTests = 11; # increment this value for each test you create ++$numTests; ##For conditional testing on module load plan tests => $numTests; @@ -25,7 +25,7 @@ plan tests => $numTests; my $loaded = use_ok('WebGUI::AdSpace'); my $session = WebGUI::Test->session; -my $adSpace; +my ($adSpace, $alfred, $alfred2, $bruce, $catWoman, $defaultAdSpace ); SKIP: { @@ -41,14 +41,14 @@ SKIP: { is($data->{name}, $adSpace->get("name"), "get()"); is($data->{adSpaceId}, $adSpace->getId, "getId()"); - my $alfred = WebGUI::AdSpace->newByName($session, 'Alfred'); + $alfred = WebGUI::AdSpace->newByName($session, 'Alfred'); cmp_deeply($adSpace, $alfred, 'newByName returns identical object if name exists'); - my $bruce = WebGUI::AdSpace->newByName($session, 'Bruce'); + $bruce = WebGUI::AdSpace->newByName($session, 'Bruce'); is($bruce, undef, 'newByName returns undef if the name does not exist'); - my $alfred2 = WebGUI::AdSpace->create($session); + $alfred2 = WebGUI::AdSpace->create($session); is($alfred2, undef, 'create returns undef unless you pass it a name'); $alfred2 = WebGUI::AdSpace->create($session, {name => 'Alfred'}); @@ -58,10 +58,24 @@ SKIP: { undef $alfred2; + $alfred->set({title => "Alfred's Ad"}); + is($alfred->get('title'), "Alfred's Ad", "get, set work on title"); + + $bruce = WebGUI::AdSpace->create($session, {name => 'Bruce'}); + $bruce->set({title => "Bruce's Ad"}); + + $catWoman = WebGUI::AdSpace->create($session, {name => 'CatWoman'}); + $catWoman->set({title => "CatWoman's Ad"}); + + my $adSpaces = WebGUI::AdSpace->getAdSpaces($session); + + cmp_deeply($adSpaces, [$alfred, $bruce, $catWoman], 'getAdSpaces returns all AdSpaces in alphabetical order by title'); } END { - if (defined $adSpace and ref $adSpace eq 'WebGUI::AdSpace') { - $adSpace->delete; - } + foreach my $ad_space ($adSpace, $bruce, $alfred, $alfred2, $catWoman, $defaultAdSpace ) { + if (defined $ad_space and ref $ad_space eq 'WebGUI::AdSpace') { + $ad_space->delete; + } + } } diff --git a/t/AdSpace/Ad.t b/t/AdSpace/Ad.t index 3b9db05eb..f3afa1212 100644 --- a/t/AdSpace/Ad.t +++ b/t/AdSpace/Ad.t @@ -31,11 +31,12 @@ my $adSpace; SKIP: { - skip "Unable to load WebGUI::AdSpace::Ad", $numTests-1 unless $loaded; - $adSpace = WebGUI::AdSpace->create($session, {name=>"Alfred"}); - $ad=WebGUI::AdSpace::Ad->create($session, $adSpace->getId, {"type", "text"}); - isa_ok($ad,"WebGUI::AdSpace::Ad","testing create with no properties"); + skip "Unable to load WebGUI::AdSpace::Ad", $numTests-1 unless $loaded; + $adSpace = WebGUI::AdSpace->create($session, {name=>"Alfred"}); + $ad=WebGUI::AdSpace::Ad->create($session, $adSpace->getId, {"type" => "text"}); + isa_ok($ad,"WebGUI::AdSpace::Ad","testing create with no properties"); } + END { if (defined $ad and ref $ad eq 'WebGUI::AdSpace::Ad') { $ad->delete;