Adding Page macro test. If there complaints about not being able to

access variables from an Asset, the test is very easy to extend to add
new fields or asset types.
The remaining t's have had their URLs lower-cased to be URL compliant.
This commit is contained in:
Colin Kuskie 2006-07-19 22:20:49 +00:00
parent 531d4284e3
commit ac953d2043
6 changed files with 96 additions and 5 deletions

View file

@ -158,7 +158,7 @@ sub addTemplate {
my $properties = {
title => 'AdminToggle test template',
className => 'WebGUI::Asset::Template',
url => 'AdminToggle-test',
url => 'admintoggle-test',
namespace => 'Macro/AdminToggle',
template => "HREF=<tmpl_var toggle.url>\nLABEL=<tmpl_var toggle.text>",
id => 'AdminToggleTemplate--Z',

View file

@ -101,7 +101,7 @@ sub setupTest {
my $properties = {
title => 'CanEditText test template',
className => 'WebGUI::Asset::Wobject::Article',
url => '/home/CanEditText-test',
url => '/home/canedittext-test',
description => 'This is a test article for viewing privileges',
id => 'CanEditTextTestAsset01',
groupIdEdit => $editGroup->getId(),

View file

@ -267,7 +267,7 @@ sub setupTest {
my $properties = {
title => 'EditableToggle test template',
className => 'WebGUI::Asset::Template',
url => 'EditableToggle-test',
url => 'editabletoggle-test',
namespace => 'Macro/EditableToggle',
template => "HREF=<tmpl_var toggle.url>\nLABEL=<tmpl_var toggle.text>",
groupIdEdit => $editGroup->getId(),

View file

@ -95,7 +95,7 @@ sub addTemplate {
my $properties = {
title => 'H_homeLink test template',
className => 'WebGUI::Asset::Template',
url => 'H_homeLink-test',
url => 'h_homelink-test',
namespace => 'Macro/H_homeLink',
template => "HREF=<tmpl_var homeLink.url>\nLABEL=<tmpl_var homeLink.text>",
id => 'testTemplateH_HomeLink'

91
t/Macro/Page.t Normal file
View file

@ -0,0 +1,91 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2006 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Macro;
use WebGUI::Session;
use WebGUI::Macro_Config;
use Data::Dumper;
use Test::More; # increment this value for each test you create
my $session = WebGUI::Test->session;
unless ($session->config->get('macros')->{'Page'}) {
Macro_Config::insert_macro($session, 'Page', 'Page');
}
my @testSets = (
{
className => 'WebGUI::Asset::Wobject::Layout',
# '1234567890123456789012'
assetId => 'LayoutTestAsset0011001',
title => 'Layout Test Asset',
url => 'pagetest-layout',
description => 'Test Layout Asset for the Page macro test',
},
{
className => 'WebGUI::Asset::Snippet',
# '1234567890123456789012'
assetId => 'SnippetTestAsset001001',
title => 'Snippet Test Asset',
url => 'pagetest-snippet',
snippet => 'Hello, this is a Snippet',
},
);
my $numTests = 0;
foreach my $testSet (@testSets) {
$numTests += scalar keys %{ $testSet };
}
plan tests => $numTests;
my $macroText = '^Page("%s");';
my $output = $macroText;
my $homeAsset = WebGUI::Asset->getDefault($session);
my $versionTag;
($versionTag, @testSets) = setupTest($session, $homeAsset, @testSets);
foreach my $testSet (@testSets) {
$session->asset($testSet->{asset});
my $class = $testSet->{className};
foreach my $field (keys %{ $testSet }) {
next if $field eq 'asset';
my $output = sprintf $macroText, $field;
WebGUI::Macro::process($session, \$output);
my $comment = sprintf "Checking asset: %s, field: %s", $class, $field;
is($output, $testSet->{$field}, $comment);
}
}
sub setupTest {
my ($session, $homeAsset, @testSets) = @_;
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Page macro test"});
foreach my $testSet (@testSets) {
my %properties = %{ $testSet };
my $asset = $homeAsset->addChild(\%properties, $properties{assetId});
$testSet->{asset} = $asset;
}
$versionTag->commit;
return $versionTag, @testSets;
}
END { ##Clean-up after yourself, always
$versionTag->rollback;
}

View file

@ -56,7 +56,7 @@ my $properties = {
id => 'ThumbnailAsset00000001',
title => 'Thumbnail macro test',
className => 'WebGUI::Asset::File::Image',
url => 'Thumbnail-test',
url => 'thumbnail-test',
storageId => $storage->getId,
filename => 'square.png',
};