From 870d9dbe46957e3919326c147bb3ca93a0ce8cdf Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sun, 4 Feb 2007 04:12:19 +0000 Subject: [PATCH] more tests for AdSpace and added more POD to AdSpace.pm and Ad.pm --- lib/WebGUI/AdSpace.pm | 12 +++++++----- lib/WebGUI/AdSpace/Ad.pm | 4 +++- t/AdSpace.t | 21 +++++++++++++++++++-- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/lib/WebGUI/AdSpace.pm b/lib/WebGUI/AdSpace.pm index 8a060deba..0e587c5ab 100644 --- a/lib/WebGUI/AdSpace.pm +++ b/lib/WebGUI/AdSpace.pm @@ -60,6 +60,8 @@ sub countClick { =head2 create ( session, properties ) +Object constructor for new AdSpaces. + =head3 session A reference to the current session. @@ -73,7 +75,7 @@ The properties used to create this object. See the set() method for details. sub create { my $class = shift; my $session = shift; - my $properties = shift; + my $properties = shift || {}; return undef unless $properties->{name}; my $test = $class->newByName($session, $properties->{name}); return undef if defined $test; @@ -163,7 +165,7 @@ sub get { =head2 getAds ( ) -Returns an array reference containing all the ad objects in this ad space. +Returns an array reference containing all the ads this ad space as objects. =cut @@ -181,7 +183,7 @@ sub getAds { =head2 getAdSpaces ( session ) -Returns an array reference containing all the ad spaces. This is a class method. +Returns an array reference containing all the ad spaces as objects. This is a class method. =cut @@ -213,7 +215,7 @@ sub getId { =head2 new ( session, id ) -Constructor. +Object constructor for fetching an existing AdSpace by id. =head3 session @@ -238,7 +240,7 @@ sub new { =head2 newByName ( session, name ) -Constructor. +Object constructor for fetching an existing AdSpace by name. =head3 session diff --git a/lib/WebGUI/AdSpace/Ad.pm b/lib/WebGUI/AdSpace/Ad.pm index b4d023a38..48ec60f11 100644 --- a/lib/WebGUI/AdSpace/Ad.pm +++ b/lib/WebGUI/AdSpace/Ad.pm @@ -42,6 +42,8 @@ These methods are available from this class: =head2 create ( session, adSpaceId, properties ) +Object constructor for new Ads. + =head3 session A reference to the current session @@ -133,7 +135,7 @@ sub getId { =head2 new ( session, id ) -Constructor. +Object constructor for fetching an existing Ad. =head3 session diff --git a/t/AdSpace.t b/t/AdSpace.t index ec699f0a5..dd355494b 100644 --- a/t/AdSpace.t +++ b/t/AdSpace.t @@ -14,10 +14,10 @@ use lib "$FindBin::Bin/lib"; use WebGUI::Test; use WebGUI::Session; -#use Test::More tests => 3; use Test::More; +use Test::Deep; -my $numTests = 4; # increment this value for each test you create +my $numTests = 9; # increment this value for each test you create ++$numTests; ##For conditional testing on module load plan tests => $numTests; @@ -41,6 +41,23 @@ SKIP: { is($data->{name}, $adSpace->get("name"), "get()"); is($data->{adSpaceId}, $adSpace->getId, "getId()"); + my $alfred = WebGUI::AdSpace->newByName($session, 'Alfred'); + + cmp_deeply($adSpace, $alfred, 'newByName returns identical object if name exists'); + + my $bruce = WebGUI::AdSpace->newByName($session, 'Bruce'); + is($bruce, undef, 'newByName returns undef if the name does not exist'); + + my $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'); + + isa_ok($alfred->session, 'WebGUI::Session'); + + undef $alfred2; + } END {