A bunch more Ad tests. Need to check the coverage to see if anything has been

missed.
Removed a duplicate alt attribute in the image ad.
This commit is contained in:
Colin Kuskie 2007-02-17 00:36:49 +00:00
parent ab6d0d2ce6
commit fd9e2ecd21
2 changed files with 57 additions and 4 deletions

View file

@ -36,7 +36,7 @@ my $newAdSettings = {
priority => "0",
};
my $numTests = 13; # increment this value for each test you create
my $numTests = 22; # increment this value for each test you create
$numTests += scalar keys %{ $newAdSettings };
++$numTests; ##For conditional testing on module load
@ -46,8 +46,10 @@ my $loaded = use_ok('WebGUI::AdSpace::Ad');
my $session = WebGUI::Test->session;
my $ad;
my ($richAd, $textAd);
my ($richAd, $textAd, $imageAd);
my $adSpace;
my $imageStorage = WebGUI::Storage::Image->create($session);
$imageStorage->addFileFromScalar('foo.bmp', 'This is not really an image');
SKIP: {
@ -121,10 +123,58 @@ SKIP: {
$style = $token->[1]{style};
like($style, qr/background-color:white/, 'ad link background is white');
$token = $textP->get_tag("span");
$style = $token->[1]{style};
like($style, qr/color:blue/, 'ad title text foreground is blue');
$token = $textP->get_tag("span");
$style = $token->[1]{style};
like($style, qr/color:blue/, 'ad title text foreground is blue');
my $adText = $textP->get_trimmed_text('/span');
is($adText, $textAd->get('adText'), 'ad text is correct');
##Ditto for the image ad
$adSpace->set({
width => 250,
height => 250
});
$imageAd = WebGUI::AdSpace::Ad->create($session, $adSpace->getId);
$imageAd->set({
type => 'image',
title => 'This is an image ad',
storageId => $imageStorage->getId,
});
my $renderedImageAd = $imageAd->get('renderedAd');
my $textP = HTML::TokeParser->new(\$renderedImageAd);
##Outer div checks
my $token = $textP->get_tag("div");
my $style = $token->[1]{style};
like($style, qr/height:250/, 'adSpace height rendered correctly, image');
like($style, qr/width:250/, 'adSpace width rendered correctly, image');
##Link checks
$token = $textP->get_tag("a");
my $href = $token->[1]{href};
like($href, qr/op=clickAd/, 'ad link has correct operation, image');
$adId = $imageAd->getId;
like($href, qr/id=$adId/, 'ad link has correct ad id, image');
$token = $textP->get_tag("img");
$style = $token->[1]{src};
is($style, $imageStorage->getUrl($imageStorage->getFiles->[0]), 'ad image points at correct file');
$style = $token->[1]{alt};
is($style, $imageAd->get('title'), 'ad title matches, image');
}
END {
foreach my $advertisement ($ad, $richAd, $textAd) {
foreach my $advertisement ($ad, $richAd, $textAd, $imageAd) {
if (defined $advertisement and ref $advertisement eq 'WebGUI::AdSpace::Ad') {
$advertisement->delete;
}
@ -132,4 +182,7 @@ END {
if (defined $adSpace and ref $adSpace eq 'WebGUI::AdSpace') {
$adSpace->delete;
}
if (defined $imageStorage and ref $imageStorage eq 'WebGUI::Storage::Image') {
$imageStorage->delete;
}
}