From 6e818b3eb369219ce68308294fbc0fc096a04c60 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 17 Jul 2006 03:14:42 +0000 Subject: [PATCH] User Macro testing --- t/Macro/User.t | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 t/Macro/User.t diff --git a/t/Macro/User.t b/t/Macro/User.t new file mode 100644 index 000000000..b3571c7e9 --- /dev/null +++ b/t/Macro/User.t @@ -0,0 +1,93 @@ +#------------------------------------------------------------------- +# 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 WebGUI::User; + +use Test::More; # increment this value for each test you create + +my $session = WebGUI::Test->session; + +unless ($session->config->get('macros')->{'User'}) { + Macro_Config::insert_macro($session, 'User', 'User'); +} + +my @testSets = ( + { + firstName => 'Joe', + lastName => 'Bob', + alias => 'joebob', + aim => 'JOEBOB' + }, + { + firstName => 'Pete', + lastName => 'Bob', + alias => 'petebob', + msnIM => 'PeteBob@msn' + }, + { + firstName => 'Tim', + lastName => 'Bob', + alias => 'timbob', + yahooIM => 'tim the yahoo', + }, +); + +my $numTests = 1; +foreach my $testSet (@testSets) { + $numTests += scalar keys %{ $testSet }; +} + +plan tests => $numTests; + +@testSets = setupTest($session, @testSets); +my @users = map { $_->{user} } @testSets; + +foreach my $testSet (@testSets) { + $session->user({ userId => $testSet->{user}->userId }); + foreach my $field (keys %{ $testSet }) { + next if $field eq 'user'; + my $output = sprintf q!^User("%s");!, $field; + WebGUI::Macro::process($session, \$output); + my $comment = sprintf "Checking userid: %s, field: %s", $session->user->userId, $field; + is($output, $testSet->{$field}, $comment); + } +} + +my $field = "NonExistantField"; +my $output = sprintf q!^User("%s")!, $field; +WebGUI::Macro::process($session, \$output); +my $comment = sprintf "Checking userid: %s, field: %s", $session->user->userId, $field; +is($output, $output, $comment); ##Unprocessed macro returns macro + +sub setupTest { + my ($session, @testSets) = @_; + foreach my $testSet (@testSets) { + my $user = WebGUI::User->new($session, "new"); + foreach my $field (keys %{ $testSet} ) { + $user->profileField($field, $testSet->{$field}); + } + $testSet->{user} = $user; + } + return @testSets; +} + +END { ##Clean-up after yourself, always + foreach my $dude (@users) { + $dude->delete if (defined $dude and ref $dude eq 'WebGUI::User'); + } +}