From ac953d2043efd845170ac885c983d62e5ff304ed Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 19 Jul 2006 22:20:49 +0000 Subject: [PATCH] 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. --- t/Macro/AdminToggle.t | 2 +- t/Macro/CanEditText.t | 2 +- t/Macro/EditableToggle.t | 2 +- t/Macro/H_homeLink.t | 2 +- t/Macro/Page.t | 91 ++++++++++++++++++++++++++++++++++++++++ t/Macro/Thumbnail.t | 2 +- 6 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 t/Macro/Page.t diff --git a/t/Macro/AdminToggle.t b/t/Macro/AdminToggle.t index a4767ff81..aca8d13e4 100644 --- a/t/Macro/AdminToggle.t +++ b/t/Macro/AdminToggle.t @@ -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=\nLABEL=", id => 'AdminToggleTemplate--Z', diff --git a/t/Macro/CanEditText.t b/t/Macro/CanEditText.t index 4c71f337e..8a9b5968d 100644 --- a/t/Macro/CanEditText.t +++ b/t/Macro/CanEditText.t @@ -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(), diff --git a/t/Macro/EditableToggle.t b/t/Macro/EditableToggle.t index 40b3f7c7a..09b73680c 100644 --- a/t/Macro/EditableToggle.t +++ b/t/Macro/EditableToggle.t @@ -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=\nLABEL=", groupIdEdit => $editGroup->getId(), diff --git a/t/Macro/H_homeLink.t b/t/Macro/H_homeLink.t index 7872d59f6..7a67833fa 100644 --- a/t/Macro/H_homeLink.t +++ b/t/Macro/H_homeLink.t @@ -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=\nLABEL=", id => 'testTemplateH_HomeLink' diff --git a/t/Macro/Page.t b/t/Macro/Page.t new file mode 100644 index 000000000..ec43db3ef --- /dev/null +++ b/t/Macro/Page.t @@ -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; +} diff --git a/t/Macro/Thumbnail.t b/t/Macro/Thumbnail.t index 449a92c62..7b8bdf687 100644 --- a/t/Macro/Thumbnail.t +++ b/t/Macro/Thumbnail.t @@ -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', };